|
1 | | -{ self, nixpkgs, system, hypervisor }: |
| 1 | +{ |
| 2 | + self, |
| 3 | + nixpkgs, |
| 4 | + system, |
| 5 | + hypervisor, |
| 6 | +}: |
2 | 7 |
|
3 | 8 | let |
4 | | - pkgs = nixpkgs.legacyPackages.${system}; |
5 | 9 | vmName = "machined-test"; |
| 10 | + vsockCid = 4242; |
6 | 11 | in |
7 | 12 | { |
8 | 13 | # Test that MicroVMs can be registered with systemd-machined |
9 | | - "machined-${hypervisor}" = pkgs.nixosTest { |
10 | | - name = "machined-${hypervisor}"; |
11 | | - nodes.host = { lib, ... }: { |
12 | | - imports = [ self.nixosModules.host ]; |
13 | | - |
14 | | - virtualisation.qemu.options = [ |
15 | | - "-cpu" |
| 14 | + "machined-${hypervisor}" = |
| 15 | + import (nixpkgs + "/nixos/tests/make-test-python.nix") |
| 16 | + ( |
| 17 | + { lib, ... }: |
16 | 18 | { |
17 | | - "aarch64-linux" = "cortex-a72"; |
18 | | - "x86_64-linux" = "kvm64,+svm,+vmx"; |
19 | | - }.${system} |
20 | | - ]; |
21 | | - virtualisation.diskSize = 4096; |
22 | | - |
23 | | - # Define a VM with machined registration enabled |
24 | | - microvm.vms.${vmName}.config = { |
25 | | - microvm = { |
26 | | - hypervisor = hypervisor; |
27 | | - # Enable machined registration on the VM |
28 | | - registerWithMachined = true; |
29 | | - }; |
30 | | - networking.hostName = vmName; |
31 | | - system.stateVersion = lib.trivial.release; |
32 | | - }; |
33 | | - }; |
34 | | - testScript = '' |
35 | | - # Wait for the MicroVM service to start |
36 | | - host.wait_for_unit("microvm@${vmName}.service", timeout = 1200) |
| 19 | + name = "machined-${hypervisor}"; |
| 20 | + nodes.host = { |
| 21 | + imports = [ self.nixosModules.host ]; |
| 22 | + |
| 23 | + virtualisation.qemu.options = [ |
| 24 | + "-cpu" |
| 25 | + { |
| 26 | + "aarch64-linux" = "cortex-a72"; |
| 27 | + "x86_64-linux" = "kvm64,+svm,+vmx"; |
| 28 | + } |
| 29 | + .${system} |
| 30 | + ]; |
| 31 | + virtualisation.diskSize = 4096; |
37 | 32 |
|
38 | | - # Verify the VM is registered with machined |
39 | | - host.succeed("machinectl list | grep -q '${vmName}'") |
| 33 | + # Define a VM with machined registration enabled |
| 34 | + microvm.vms.${vmName}.config = { |
| 35 | + microvm = { |
| 36 | + hypervisor = hypervisor; |
| 37 | + # Enable machined registration on the VM |
| 38 | + registerWithMachined = true; |
| 39 | + } |
| 40 | + // lib.optionalAttrs (hypervisor != "cloud-hypervisor") { |
| 41 | + vsock.cid = vsockCid; |
| 42 | + }; |
| 43 | + networking.hostName = vmName; |
| 44 | + system.stateVersion = lib.trivial.release; |
| 45 | + }; |
| 46 | + }; |
| 47 | + testScript = '' |
| 48 | + # Wait for the MicroVM service to start |
| 49 | + host.wait_for_unit("microvm@${vmName}.service", timeout = 1200) |
40 | 50 |
|
41 | | - # Verify machine status works |
42 | | - host.succeed("machinectl status '${vmName}'") |
| 51 | + # Verify the VM is registered with machined |
| 52 | + host.succeed("machinectl list | grep -q '${vmName}'") |
43 | 53 |
|
44 | | - # Verify the machine class is 'vm' |
45 | | - host.succeed("machinectl show '${vmName}' --property=Class | grep -q 'vm'") |
| 54 | + # Verify machine status works |
| 55 | + host.succeed("machinectl status '${vmName}'") |
46 | 56 |
|
47 | | - # Verify leader PID exists |
48 | | - host.succeed("machinectl show '${vmName}' --property=Leader | grep -q '^Leader=[0-9]'") |
| 57 | + # Verify the machine class is 'vm' |
| 58 | + host.succeed("machinectl show '${vmName}' --property=Class | grep -q 'vm'") |
49 | 59 |
|
50 | | - # Terminate the VM via machinectl (sends SIGTERM to hypervisor) |
51 | | - host.succeed("machinectl terminate '${vmName}'") |
| 60 | + ${lib.optionalString (hypervisor != "cloud-hypervisor") '' |
| 61 | + # On systemd >=259 RegisterMachineEx path should expose VSOCK/SSH metadata |
| 62 | + host.succeed("machinectl show '${vmName}' --property=VSockCID | grep -q 'VSockCID=${toString vsockCid}'") |
| 63 | + host.succeed("machinectl show '${vmName}' --property=SSHAddress | grep -q 'SSHAddress=vsock/${toString vsockCid}'") |
| 64 | + ''} |
52 | 65 |
|
53 | | - # Wait for the service to stop |
54 | | - host.wait_until_fails("machinectl status '${vmName}'", timeout = 30) |
55 | | - ''; |
56 | | - meta.timeout = 1800; |
57 | | - }; |
| 66 | + # Test kill command (send signal 0 to check process exists) |
| 67 | + host.succeed("machinectl kill '${vmName}' --signal=0") |
| 68 | +
|
| 69 | + # Terminate the VM via machinectl (sends SIGTERM to hypervisor) |
| 70 | + host.succeed("machinectl terminate '${vmName}'") |
| 71 | +
|
| 72 | + # Wait for the service to stop |
| 73 | + host.wait_until_fails("machinectl status '${vmName}'", timeout = 30) |
| 74 | + ''; |
| 75 | + meta.timeout = 1800; |
| 76 | + } |
| 77 | + ) |
| 78 | + { |
| 79 | + inherit system; |
| 80 | + pkgs = nixpkgs.legacyPackages.${system}; |
| 81 | + }; |
58 | 82 | } |
0 commit comments