nixos/tests/lxd: move into subdir, use minimal init, remove sleeps

Changed files
+36 -51
nixos
pkgs
tools
admin
+1 -3
nixos/tests/all-tests.nix
···
loki = handleTest ./loki.nix {};
luks = handleTest ./luks.nix {};
lvm2 = handleTest ./lvm2 {};
-
lxd = handleTest ./lxd.nix {};
-
lxd-nftables = handleTest ./lxd-nftables.nix {};
+
lxd = handleTest ./lxd {};
lxd-image-server = handleTest ./lxd-image-server.nix {};
-
lxd-ui = handleTest ./lxd-ui.nix {};
#logstash = handleTest ./logstash.nix {};
lorri = handleTest ./lorri/default.nix {};
maddy = discoverTests (import ./maddy { inherit handleTest; });
-24
nixos/tests/common/lxd/config.yaml
···
-
storage_pools:
-
- name: default
-
driver: dir
-
config:
-
source: /var/lxd-pool
-
-
networks:
-
- name: lxdbr0
-
type: bridge
-
config:
-
ipv4.address: auto
-
ipv6.address: none
-
-
profiles:
-
- name: default
-
devices:
-
eth0:
-
name: eth0
-
network: lxdbr0
-
type: nic
-
root:
-
path: /
-
pool: default
-
type: disk
+3 -3
nixos/tests/lxd-image-server.nix
···
machine.wait_for_unit("lxd.service")
machine.wait_for_file("/var/lib/lxd/unix.socket")
-
# It takes additional second for lxd to settle
-
machine.sleep(1)
+
# Wait for lxd to settle
+
machine.succeed("lxd waitready")
# lxd expects the pool's directory to already exist
machine.succeed("mkdir /var/lxd-pool")
machine.succeed(
-
"cat ${./common/lxd/config.yaml} | lxd init --preseed"
+
"lxd init --minimal"
)
machine.succeed(
+1 -1
nixos/tests/lxd-nftables.nix nixos/tests/lxd/nftables.nix
···
# iptables to nftables requires a full reboot, which is a bit hard inside NixOS
# tests.
-
import ./make-test-python.nix ({ pkgs, ...} : {
+
import ../make-test-python.nix ({ pkgs, ...} : {
name = "lxd-nftables";
meta = with pkgs.lib.maintainers; {
+1 -1
nixos/tests/lxd-ui.nix nixos/tests/lxd/ui.nix
···
-
import ./make-test-python.nix ({ pkgs, lib, ... }: {
+
import ../make-test-python.nix ({ pkgs, lib, ... }: {
name = "lxd-ui";
meta = with pkgs.lib.maintainers; {
+21 -17
nixos/tests/lxd.nix nixos/tests/lxd/container.nix
···
-
import ./make-test-python.nix ({ pkgs, lib, ... } :
+
import ../make-test-python.nix ({ pkgs, lib, ... } :
let
-
lxd-image = import ../release.nix {
+
lxd-image = import ../../release.nix {
configuration = {
# Building documentation makes the test unnecessarily take a longer time:
documentation.enable = lib.mkForce false;
···
};
testScript = ''
+
def instance_is_up(_) -> bool:
+
status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/true")
+
return status == 0
+
machine.wait_for_unit("sockets.target")
machine.wait_for_unit("lxd.service")
machine.wait_for_file("/var/lib/lxd/unix.socket")
-
# It takes additional second for lxd to settle
-
machine.sleep(1)
+
# Wait for lxd to settle
+
machine.succeed("lxd waitready")
-
# lxd expects the pool's directory to already exist
-
machine.succeed("mkdir /var/lxd-pool")
-
-
machine.succeed(
-
"cat ${./common/lxd/config.yaml} | lxd init --preseed"
-
)
+
machine.succeed("lxd init --minimal")
machine.succeed(
"lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos"
···
with subtest("Container can be managed"):
machine.succeed("lxc launch nixos container")
-
machine.sleep(5)
+
with machine.nested("Waiting for instance to start and be usable"):
+
retry(instance_is_up)
machine.succeed("echo true | lxc exec container /run/current-system/sw/bin/bash -")
-
machine.succeed("lxc exec container true")
machine.succeed("lxc delete -f container")
with subtest("Container is mounted with lxcfs inside"):
machine.succeed("lxc launch nixos container")
-
machine.sleep(5)
+
with machine.nested("Waiting for instance to start and be usable"):
+
retry(instance_is_up)
## ---------- ##
## limits.cpu ##
machine.succeed("lxc config set container limits.cpu 1")
machine.succeed("lxc restart container")
-
machine.sleep(5)
+
with machine.nested("Waiting for instance to start and be usable"):
+
retry(instance_is_up)
assert (
"1"
···
machine.succeed("lxc config set container limits.cpu 2")
machine.succeed("lxc restart container")
-
machine.sleep(5)
+
with machine.nested("Waiting for instance to start and be usable"):
+
retry(instance_is_up)
assert (
"2"
···
machine.succeed("lxc config set container limits.memory 64MB")
machine.succeed("lxc restart container")
-
machine.sleep(5)
+
with machine.nested("Waiting for instance to start and be usable"):
+
retry(instance_is_up)
assert (
"MemTotal: 62500 kB"
···
machine.succeed("lxc config set container limits.memory 128MB")
machine.succeed("lxc restart container")
-
machine.sleep(5)
+
with machine.nested("Waiting for instance to start and be usable"):
+
retry(instance_is_up)
assert (
"MemTotal: 125000 kB"
+9
nixos/tests/lxd/default.nix
···
+
{
+
system ? builtins.currentSystem,
+
config ? {},
+
pkgs ? import ../../.. {inherit system config;},
+
}: {
+
container = import ./container.nix {inherit system pkgs;};
+
nftables = import ./nftables.nix {inherit system pkgs;};
+
ui = import ./ui.nix {inherit system pkgs;};
+
}
-2
pkgs/tools/admin/lxd/default.nix
···
'';
passthru.tests.lxd = nixosTests.lxd;
-
passthru.tests.lxd-nftables = nixosTests.lxd-nftables;
-
passthru.tests.lxd-ui = nixosTests.lxd-ui;
passthru.ui = callPackage ./ui.nix { };
passthru.updateScript = gitUpdater {
url = "https://github.com/canonical/lxd.git";