From cdcb919ff7ffb337f21a60375a8738e0558bc91d Mon Sep 17 00:00:00 2001 From: Adam Stephens Date: Thu, 1 Feb 2024 22:38:16 -0500 Subject: [PATCH] nixos/tests/incus: check system is running for verifying up It can can take a few seconds for the generator to initialize in slow environments. Switch to using systemctl is-system-running which should reflect the system is fully booted. --- nixos/tests/incus/container.nix | 10 ++-------- nixos/tests/incus/lxd-to-incus.nix | 4 ++-- nixos/tests/incus/virtual-machine.nix | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/nixos/tests/incus/container.nix b/nixos/tests/incus/container.nix index 2fa1709c7484..0e65cc1e1529 100644 --- a/nixos/tests/incus/container.nix +++ b/nixos/tests/incus/container.nix @@ -31,7 +31,7 @@ in testScript = '' def instance_is_up(_) -> bool: - status, _ = machine.execute("incus exec container --disable-stdin --force-interactive /run/current-system/sw/bin/true") + status, _ = machine.execute("incus exec container --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running") return status == 0 def set_container(config): @@ -81,11 +81,7 @@ in assert meminfo_bytes == "125000 kB", f"Wrong amount of memory reported from /proc/meminfo, want: '125000 kB', got: '{meminfo_bytes}'" with subtest("lxc-container generator configures plain container"): - machine.execute("incus delete --force container") - machine.succeed("incus launch nixos container") - with machine.nested("Waiting for instance to start and be usable"): - retry(instance_is_up) - + # reuse the existing container to save some time machine.succeed("incus exec container test -- -e /run/systemd/system/service.d/zzz-lxc-service.conf") with subtest("lxc-container generator configures nested container"): @@ -103,8 +99,6 @@ in machine.succeed("incus launch nixos container --config security.privileged=true") with machine.nested("Waiting for instance to start and be usable"): retry(instance_is_up) - # give generator an extra second to run - machine.sleep(1) machine.succeed("incus exec container test -- -e /run/systemd/system/service.d/zzz-lxc-service.conf") ''; diff --git a/nixos/tests/incus/lxd-to-incus.nix b/nixos/tests/incus/lxd-to-incus.nix index 67245b54e752..42a47a6a07af 100644 --- a/nixos/tests/incus/lxd-to-incus.nix +++ b/nixos/tests/incus/lxd-to-incus.nix @@ -77,11 +77,11 @@ import ../make-test-python.nix ( return ("inactive" in output) def lxd_instance_is_up(_) -> bool: - status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/true") + status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running") return status == 0 def incus_instance_is_up(_) -> bool: - status, _ = machine.execute("incus exec container --disable-stdin --force-interactive /run/current-system/sw/bin/true") + status, _ = machine.execute("incus exec container --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running") return status == 0 with machine.nested("initialize lxd and resources"): diff --git a/nixos/tests/incus/virtual-machine.nix b/nixos/tests/incus/virtual-machine.nix index 343a25ca7297..c76e4f448f2f 100644 --- a/nixos/tests/incus/virtual-machine.nix +++ b/nixos/tests/incus/virtual-machine.nix @@ -36,7 +36,7 @@ in testScript = '' def instance_is_up(_) -> bool: - status, _ = machine.execute("incus exec ${instance-name} --disable-stdin --force-interactive /run/current-system/sw/bin/true") + status, _ = machine.execute("incus exec ${instance-name} --disable-stdin --force-interactive /run/current-system/sw/bin/systemctl -- is-system-running") return status == 0 machine.wait_for_unit("incus.service")