1import ./make-test-python.nix (
2 { pkgs, ... }:
3 {
4 name = "libvirtd";
5 meta.maintainers = with pkgs.lib.maintainers; [ fpletz ];
6
7 nodes = {
8 virthost =
9 { pkgs, ... }:
10 {
11 virtualisation = {
12 cores = 2;
13 memorySize = 2048;
14
15 libvirtd.enable = true;
16 libvirtd.hooks.qemu.is_working = "${pkgs.writeShellScript "testHook.sh" ''
17 touch /tmp/qemu_hook_is_working
18 ''}";
19 libvirtd.nss.enable = true;
20 };
21 boot.supportedFilesystems = [ "zfs" ];
22 networking.hostId = "deadbeef"; # needed for zfs
23 security.polkit.enable = true;
24 environment.systemPackages = with pkgs; [ virt-manager ];
25
26 # This adds `resolve` to the `hosts` line of /etc/nsswitch.conf; NSS modules placed after it
27 # will not be consulted. Therefore this tests that the libvirtd NSS modules will be
28 # be placed early enough for name resolution to work.
29 services.resolved.enable = true;
30 };
31 };
32
33 testScript =
34 let
35 nixosInstallISO = (import ../release.nix { }).iso_minimal.${pkgs.stdenv.hostPlatform.system};
36 virshShutdownCmd = if pkgs.stdenv.hostPlatform.isx86_64 then "shutdown" else "destroy";
37 in
38 ''
39 start_all()
40
41 virthost.wait_for_unit("multi-user.target")
42
43 with subtest("enable default network"):
44 virthost.succeed("virsh net-start default")
45 virthost.succeed("virsh net-autostart default")
46 virthost.succeed("virsh net-info default")
47
48 with subtest("check if partition disk pools works with parted"):
49 virthost.succeed("fallocate -l100m /tmp/foo; losetup /dev/loop0 /tmp/foo; echo 'label: dos' | sfdisk /dev/loop0")
50 virthost.succeed("virsh pool-create-as foo disk --source-dev /dev/loop0 --target /dev")
51 virthost.succeed("virsh vol-create-as foo loop0p1 25MB")
52 virthost.succeed("virsh vol-create-as foo loop0p2 50MB")
53
54 with subtest("check if virsh zfs pools work"):
55 virthost.succeed("fallocate -l100m /tmp/zfs; losetup /dev/loop1 /tmp/zfs;")
56 virthost.succeed("zpool create zfs_loop /dev/loop1")
57 virthost.succeed("virsh pool-define-as --name zfs_storagepool --source-name zfs_loop --type zfs")
58 virthost.succeed("virsh pool-start zfs_storagepool")
59 virthost.succeed("virsh vol-create-as zfs_storagepool disk1 25MB")
60
61 with subtest("check if nixos install iso boots, network and autostart works"):
62 virthost.succeed(
63 "virt-install -n nixos --osinfo nixos-unstable --memory 1024 --graphics none --disk `find ${nixosInstallISO}/iso -type f | head -n1`,readonly=on --import --noautoconsole --autostart"
64 )
65 virthost.succeed("virsh domstate nixos | grep running")
66 virthost.wait_until_succeeds("ping -c 1 nixos")
67 virthost.succeed("virsh ${virshShutdownCmd} nixos")
68 virthost.wait_until_succeeds("virsh domstate nixos | grep 'shut off'")
69 virthost.shutdown()
70 virthost.wait_for_unit("multi-user.target")
71 virthost.wait_until_succeeds("ping -c 1 nixos")
72
73 with subtest("test if hooks are linked and run"):
74 virthost.succeed("ls /var/lib/libvirt/hooks/qemu.d/is_working")
75 virthost.succeed("ls /tmp/qemu_hook_is_working")
76 '';
77 }
78)