2024-05-09 14:03:07 +00:00
|
|
|
import ../make-test-python.nix ({ pkgs, lib, incus ? pkgs.incus-lts, ... }:
|
2023-10-20 04:10:59 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
releases = import ../../release.nix {
|
|
|
|
configuration = {
|
|
|
|
# Building documentation makes the test unnecessarily take a longer time:
|
|
|
|
documentation.enable = lib.mkForce false;
|
|
|
|
|
|
|
|
# Our tests require `grep` & friends:
|
|
|
|
environment.systemPackages = with pkgs; [busybox];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
vm-image-metadata = releases.lxdVirtualMachineImageMeta.${pkgs.stdenv.hostPlatform.system};
|
|
|
|
vm-image-disk = releases.lxdVirtualMachineImage.${pkgs.stdenv.hostPlatform.system};
|
|
|
|
|
|
|
|
instance-name = "instance1";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "incus-virtual-machine";
|
|
|
|
|
2023-12-02 14:38:44 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.lxc.members;
|
|
|
|
};
|
2023-10-20 04:10:59 +00:00
|
|
|
|
|
|
|
nodes.machine = {...}: {
|
|
|
|
virtualisation = {
|
|
|
|
# Ensure test VM has enough resources for creating and managing guests
|
|
|
|
cores = 2;
|
|
|
|
memorySize = 1024;
|
|
|
|
diskSize = 4096;
|
|
|
|
|
2024-04-23 09:55:16 +00:00
|
|
|
# Provide a TPM to test vTPM support for guests
|
|
|
|
tpm.enable = true;
|
|
|
|
|
2024-05-09 14:03:07 +00:00
|
|
|
incus = {
|
|
|
|
enable = true;
|
|
|
|
package = incus;
|
|
|
|
};
|
2023-10-20 04:10:59 +00:00
|
|
|
};
|
2024-03-09 16:21:55 +00:00
|
|
|
networking.nftables.enable = true;
|
2023-10-20 04:10:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
def instance_is_up(_) -> bool:
|
2024-02-02 03:38:16 +00:00
|
|
|
status, _ = machine.execute("incus exec ${instance-name} --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running")
|
2023-10-20 04:10:59 +00:00
|
|
|
return status == 0
|
|
|
|
|
|
|
|
machine.wait_for_unit("incus.service")
|
|
|
|
|
|
|
|
machine.succeed("incus admin init --minimal")
|
|
|
|
|
|
|
|
with subtest("virtual-machine image can be imported"):
|
|
|
|
machine.succeed("incus image import ${vm-image-metadata}/*/*.tar.xz ${vm-image-disk}/nixos.qcow2 --alias nixos")
|
|
|
|
|
2024-04-23 09:55:16 +00:00
|
|
|
with subtest("virtual-machine can be created"):
|
|
|
|
machine.succeed("incus create nixos ${instance-name} --vm --config limits.memory=512MB --config security.secureboot=false")
|
|
|
|
|
|
|
|
with subtest("virtual tpm can be configured"):
|
|
|
|
machine.succeed("incus config device add ${instance-name} vtpm tpm path=/dev/tpm0")
|
|
|
|
|
2023-10-20 04:10:59 +00:00
|
|
|
with subtest("virtual-machine can be launched and become available"):
|
2024-04-23 09:55:16 +00:00
|
|
|
machine.succeed("incus start ${instance-name}")
|
2023-10-20 04:10:59 +00:00
|
|
|
with machine.nested("Waiting for instance to start and be usable"):
|
|
|
|
retry(instance_is_up)
|
|
|
|
|
|
|
|
with subtest("lxd-agent is started"):
|
|
|
|
machine.succeed("incus exec ${instance-name} systemctl is-active lxd-agent")
|
2023-12-28 03:47:02 +00:00
|
|
|
|
|
|
|
with subtest("lxd-agent has a valid path"):
|
|
|
|
machine.succeed("incus exec ${instance-name} -- bash -c 'true'")
|
2024-04-17 22:08:39 +00:00
|
|
|
|
|
|
|
with subtest("guest supports cpu hotplug"):
|
|
|
|
machine.succeed("incus config set ${instance-name} limits.cpu=1")
|
|
|
|
count = int(machine.succeed("incus exec ${instance-name} -- nproc").strip())
|
|
|
|
assert count == 1, f"Wrong number of CPUs reported, want: 1, got: {count}"
|
|
|
|
|
|
|
|
machine.succeed("incus config set ${instance-name} limits.cpu=2")
|
|
|
|
count = int(machine.succeed("incus exec ${instance-name} -- nproc").strip())
|
|
|
|
assert count == 2, f"Wrong number of CPUs reported, want: 2, got: {count}"
|
2024-05-02 13:49:35 +00:00
|
|
|
|
|
|
|
with subtest("Instance remains running when softDaemonRestart is enabled and services is stopped"):
|
|
|
|
pid = machine.succeed("incus info ${instance-name} | grep 'PID'").split(":")[1].strip()
|
|
|
|
machine.succeed(f"ps {pid}")
|
|
|
|
machine.succeed("systemctl stop incus")
|
|
|
|
machine.succeed(f"ps {pid}")
|
2023-10-20 04:10:59 +00:00
|
|
|
'';
|
|
|
|
})
|