1 import ../make-test-python.nix ({ pkgs, lib, incus ? pkgs.incus-lts, ... }:
4 releases = import ../../release.nix {
6 # Building documentation makes the test unnecessarily take a longer time:
7 documentation.enable = lib.mkForce false;
9 # Our tests require `grep` & friends:
10 environment.systemPackages = with pkgs; [busybox];
14 vm-image-metadata = releases.incusVirtualMachineImageMeta.${pkgs.stdenv.hostPlatform.system};
15 vm-image-disk = releases.incusVirtualMachineImage.${pkgs.stdenv.hostPlatform.system};
17 instance-name = "instance1";
20 name = "incus-virtual-machine";
23 maintainers = lib.teams.lxc.members;
26 nodes.machine = {...}: {
28 # Ensure test VM has enough resources for creating and managing guests
33 # Provide a TPM to test vTPM support for guests
41 networking.nftables.enable = true;
45 def instance_is_up(_) -> bool:
46 status, _ = machine.execute("incus exec ${instance-name} --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running")
49 machine.wait_for_unit("incus.service")
51 machine.succeed("incus admin init --minimal")
53 with subtest("virtual-machine image can be imported"):
54 machine.succeed("incus image import ${vm-image-metadata}/*/*.tar.xz ${vm-image-disk}/nixos.qcow2 --alias nixos")
56 with subtest("virtual-machine can be created"):
57 machine.succeed("incus create nixos ${instance-name} --vm --config limits.memory=512MB --config security.secureboot=false")
59 with subtest("virtual tpm can be configured"):
60 machine.succeed("incus config device add ${instance-name} vtpm tpm path=/dev/tpm0")
62 with subtest("virtual-machine can be launched and become available"):
63 machine.succeed("incus start ${instance-name}")
64 with machine.nested("Waiting for instance to start and be usable"):
67 with subtest("incus-agent is started"):
68 machine.succeed("incus exec ${instance-name} systemctl is-active incus-agent")
70 with subtest("incus-agent has a valid path"):
71 machine.succeed("incus exec ${instance-name} -- bash -c 'true'")
73 with subtest("guest supports cpu hotplug"):
74 machine.succeed("incus config set ${instance-name} limits.cpu=1")
75 count = int(machine.succeed("incus exec ${instance-name} -- nproc").strip())
76 assert count == 1, f"Wrong number of CPUs reported, want: 1, got: {count}"
78 machine.succeed("incus config set ${instance-name} limits.cpu=2")
79 count = int(machine.succeed("incus exec ${instance-name} -- nproc").strip())
80 assert count == 2, f"Wrong number of CPUs reported, want: 2, got: {count}"
82 with subtest("Instance remains running when softDaemonRestart is enabled and services is stopped"):
83 pid = machine.succeed("incus info ${instance-name} | grep 'PID'").split(":")[1].strip()
84 machine.succeed(f"ps {pid}")
85 machine.succeed("systemctl stop incus")
86 machine.succeed(f"ps {pid}")