nixos/lxd-virtual-machine: enable CPU hotplug for x86 VMs

This commit is contained in:
Adam Stephens 2024-04-17 18:08:39 -04:00
parent b2cd5e15fb
commit 76c69af624
No known key found for this signature in database
2 changed files with 13 additions and 0 deletions

View file

@ -45,6 +45,10 @@ in {
boot.kernelParams = ["console=tty1" "console=${serialDevice}"];
services.udev.extraRules = ''
SUBSYSTEM=="cpu", CONST{arch}=="x86-64", TEST=="online", ATTR{online}=="0", ATTR{online}="1"
'';
virtualisation.lxd.agent.enable = lib.mkDefault true;
};
}

View file

@ -57,5 +57,14 @@ in
with subtest("lxd-agent has a valid path"):
machine.succeed("incus exec ${instance-name} -- bash -c 'true'")
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}"
'';
})