1 import ../make-test-python.nix (
5 releases = import ../../release.nix {
7 # Building documentation makes the test unnecessarily take a longer time:
8 documentation.enable = lib.mkForce false;
10 # Our tests require `grep` & friends:
11 environment.systemPackages = with pkgs; [ busybox ];
15 lxd-image-metadata = releases.lxdContainerMeta.${pkgs.stdenv.hostPlatform.system};
16 lxd-image-rootfs = releases.lxdContainerImage.${pkgs.stdenv.hostPlatform.system};
17 lxd-image-rootfs-squashfs = releases.lxdContainerImageSquashfs.${pkgs.stdenv.hostPlatform.system};
21 name = "lxd-container";
29 # Since we're testing `limits.cpu`, we've gotta have a known number of
33 # Ditto, for `limits.memory`
36 lxc.lxcfs.enable = true;
42 def instance_is_up(_) -> bool:
43 status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/true")
46 machine.wait_for_unit("sockets.target")
47 machine.wait_for_unit("lxd.service")
48 machine.wait_for_file("/var/lib/lxd/unix.socket")
50 # Wait for lxd to settle
51 machine.succeed("lxd waitready")
53 # no preseed should mean no service
54 machine.fail("systemctl status lxd-preseed.service")
56 machine.succeed("lxd init --minimal")
59 "lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos"
62 with subtest("Container can be managed"):
63 machine.succeed("lxc launch nixos container")
64 with machine.nested("Waiting for instance to start and be usable"):
66 machine.succeed("echo true | lxc exec container /run/current-system/sw/bin/bash -")
67 machine.succeed("lxc delete -f container")
69 with subtest("Squashfs image is functional"):
71 "lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs-squashfs}/nixos-lxc-image-${pkgs.stdenv.hostPlatform.system}.squashfs --alias nixos-squashfs"
73 machine.succeed("lxc launch nixos-squashfs container")
74 with machine.nested("Waiting for instance to start and be usable"):
76 machine.succeed("echo true | lxc exec container /run/current-system/sw/bin/bash -")
77 machine.succeed("lxc delete -f container")
79 with subtest("Container is mounted with lxcfs inside"):
80 machine.succeed("lxc launch nixos container")
81 with machine.nested("Waiting for instance to start and be usable"):
87 machine.succeed("lxc config set container limits.cpu 1")
88 machine.succeed("lxc restart container")
89 with machine.nested("Waiting for instance to start and be usable"):
94 == machine.succeed("lxc exec container grep -- -c ^processor /proc/cpuinfo").strip()
97 machine.succeed("lxc config set container limits.cpu 2")
98 machine.succeed("lxc restart container")
99 with machine.nested("Waiting for instance to start and be usable"):
100 retry(instance_is_up)
104 == machine.succeed("lxc exec container grep -- -c ^processor /proc/cpuinfo").strip()
110 machine.succeed("lxc config set container limits.memory 64MB")
111 machine.succeed("lxc restart container")
112 with machine.nested("Waiting for instance to start and be usable"):
113 retry(instance_is_up)
117 == machine.succeed("lxc exec container grep -- MemTotal /proc/meminfo").strip()
120 machine.succeed("lxc config set container limits.memory 128MB")
121 machine.succeed("lxc restart container")
122 with machine.nested("Waiting for instance to start and be usable"):
123 retry(instance_is_up)
126 "MemTotal: 125000 kB"
127 == machine.succeed("lxc exec container grep -- MemTotal /proc/meminfo").strip()
130 machine.succeed("lxc delete -f container")