1 import ./make-test-python.nix ({ pkgs, lib, ... } :
4 lxd-image = import ../release.nix {
6 # Building documentation makes the test unnecessarily take a longer time:
7 documentation.enable = lib.mkForce false;
9 # Our tests require `grep` & friends:
10 environment.systemPackages = with pkgs; [ busybox ];
14 lxd-image-metadata = lxd-image.lxdMeta.${pkgs.stdenv.hostPlatform.system};
15 lxd-image-rootfs = lxd-image.lxdImage.${pkgs.stdenv.hostPlatform.system};
20 meta = with pkgs.lib.maintainers; {
21 maintainers = [ patryk27 ];
24 nodes.machine = { lib, ... }: {
28 # Since we're testing `limits.cpu`, we've gotta have a known number of
32 # Ditto, for `limits.memory`
35 lxc.lxcfs.enable = true;
41 machine.wait_for_unit("sockets.target")
42 machine.wait_for_unit("lxd.service")
43 machine.wait_for_file("/var/lib/lxd/unix.socket")
45 # It takes additional second for lxd to settle
48 # lxd expects the pool's directory to already exist
49 machine.succeed("mkdir /var/lxd-pool")
52 "cat ${./common/lxd/config.yaml} | lxd init --preseed"
56 "lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos"
59 with subtest("Container can be managed"):
60 machine.succeed("lxc launch nixos container")
62 machine.succeed("echo true | lxc exec container /run/current-system/sw/bin/bash -")
63 machine.succeed("lxc exec container true")
64 machine.succeed("lxc delete -f container")
66 with subtest("Container is mounted with lxcfs inside"):
67 machine.succeed("lxc launch nixos container")
73 machine.succeed("lxc config set container limits.cpu 1")
74 machine.succeed("lxc restart container")
79 == machine.succeed("lxc exec container grep -- -c ^processor /proc/cpuinfo").strip()
82 machine.succeed("lxc config set container limits.cpu 2")
83 machine.succeed("lxc restart container")
88 == machine.succeed("lxc exec container grep -- -c ^processor /proc/cpuinfo").strip()
94 machine.succeed("lxc config set container limits.memory 64MB")
95 machine.succeed("lxc restart container")
100 == machine.succeed("lxc exec container grep -- MemTotal /proc/meminfo").strip()
103 machine.succeed("lxc config set container limits.memory 128MB")
104 machine.succeed("lxc restart container")
108 "MemTotal: 125000 kB"
109 == machine.succeed("lxc exec container grep -- MemTotal /proc/meminfo").strip()
112 machine.succeed("lxc delete -f container")