at 22.05-pre 2.4 kB view raw
1# This test ensures that the nixOS lxd images builds and functions properly 2# It has been extracted from `lxd.nix` to seperate failures of just the image and the lxd software 3 4import ./make-test-python.nix ({ pkgs, ...} : let 5 release = import ../release.nix { 6 /* configuration = { 7 environment.systemPackages = with pkgs; [ stdenv ]; # inject stdenv so rebuild test works 8 }; */ 9 }; 10 11 metadata = release.lxdMeta.${pkgs.system}; 12 image = release.lxdImage.${pkgs.system}; 13 14 lxd-config = pkgs.writeText "config.yaml" '' 15 storage_pools: 16 - name: default 17 driver: dir 18 config: 19 source: /var/lxd-pool 20 21 networks: 22 - name: lxdbr0 23 type: bridge 24 config: 25 ipv4.address: auto 26 ipv6.address: none 27 28 profiles: 29 - name: default 30 devices: 31 eth0: 32 name: eth0 33 network: lxdbr0 34 type: nic 35 root: 36 path: / 37 pool: default 38 type: disk 39 ''; 40in { 41 name = "lxd-image"; 42 43 meta = with pkgs.lib.maintainers; { 44 maintainers = [ mkg20001 ]; 45 }; 46 47 machine = { lib, ... }: { 48 virtualisation = { 49 # disk full otherwise 50 diskSize = 2048; 51 52 lxc.lxcfs.enable = true; 53 lxd.enable = true; 54 }; 55 }; 56 57 testScript = '' 58 machine.wait_for_unit("sockets.target") 59 machine.wait_for_unit("lxd.service") 60 machine.wait_for_file("/var/lib/lxd/unix.socket") 61 62 # It takes additional second for lxd to settle 63 machine.sleep(1) 64 65 # lxd expects the pool's directory to already exist 66 machine.succeed("mkdir /var/lxd-pool") 67 68 machine.succeed( 69 "cat ${lxd-config} | lxd init --preseed" 70 ) 71 72 # TODO: test custom built container aswell 73 74 with subtest("importing container works"): 75 machine.succeed("lxc image import ${metadata}/*/*.tar.xz ${image}/*/*.tar.xz --alias nixos") 76 77 with subtest("launching container works"): 78 machine.succeed("lxc launch nixos machine -c security.nesting=true") 79 # make sure machine boots up properly 80 machine.sleep(5) 81 82 with subtest("container shell works"): 83 machine.succeed("echo true | lxc exec machine /run/current-system/sw/bin/bash -") 84 machine.succeed("lxc exec machine /run/current-system/sw/bin/true") 85 86 # with subtest("rebuilding works"): 87 # machine.succeed("lxc exec machine /run/current-system/sw/bin/nixos-rebuild switch") 88 ''; 89})