at 23.11-beta 2.0 kB view raw
1import ../make-test-python.nix ({ pkgs, lib, ... }: 2 3let 4 releases = import ../../release.nix { 5 configuration = { 6 # Building documentation makes the test unnecessarily take a longer time: 7 documentation.enable = lib.mkForce false; 8 9 # Our tests require `grep` & friends: 10 environment.systemPackages = with pkgs; [busybox]; 11 }; 12 }; 13 14 lxd-image-metadata = releases.lxdVirtualMachineImageMeta.${pkgs.stdenv.hostPlatform.system}; 15 lxd-image-disk = releases.lxdVirtualMachineImage.${pkgs.stdenv.hostPlatform.system}; 16 17 instance-name = "instance1"; 18in { 19 name = "lxd-virtual-machine"; 20 21 meta = with pkgs.lib.maintainers; { 22 maintainers = [adamcstephens]; 23 }; 24 25 nodes.machine = {lib, ...}: { 26 virtualisation = { 27 diskSize = 4096; 28 29 cores = 2; 30 31 # Ensure we have enough memory for the nested virtual machine 32 memorySize = 1024; 33 34 lxc.lxcfs.enable = true; 35 lxd.enable = true; 36 }; 37 }; 38 39 testScript = '' 40 def instance_is_up(_) -> bool: 41 status, _ = machine.execute("lxc exec ${instance-name} --disable-stdin --force-interactive /run/current-system/sw/bin/true") 42 return status == 0 43 44 machine.wait_for_unit("sockets.target") 45 machine.wait_for_unit("lxd.service") 46 machine.wait_for_file("/var/lib/lxd/unix.socket") 47 48 # Wait for lxd to settle 49 machine.succeed("lxd waitready") 50 51 machine.succeed("lxd init --minimal") 52 53 with subtest("virtual-machine image can be imported"): 54 machine.succeed("lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-disk}/nixos.qcow2 --alias nixos") 55 56 with subtest("virtual-machine can be launched and become available"): 57 machine.succeed("lxc launch nixos ${instance-name} --vm --config limits.memory=512MB --config security.secureboot=false") 58 with machine.nested("Waiting for instance to start and be usable"): 59 retry(instance_is_up) 60 61 with subtest("lxd-agent is started"): 62 machine.succeed("lxc exec ${instance-name} systemctl is-active lxd-agent") 63 ''; 64})