From 46726134a65434b52263efedd69ae624d5e4fbe2 Mon Sep 17 00:00:00 2001 From: Assil Ksiksi Date: Tue, 24 Sep 2024 13:05:12 -0400 Subject: [PATCH] test: use systemctl to get property --- nixos-test/test.nix | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/nixos-test/test.nix b/nixos-test/test.nix index 9ee98e5..9154c3e 100644 --- a/nixos-test/test.nix +++ b/nixos-test/test.nix @@ -48,21 +48,10 @@ in }; # https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests testScript = '' - import re - d = {"docker": docker, "podman": podman} start_all() - def assert_service_value(service: str, key: str, want: str) -> None: - out = m.succeed(f"systemctl show {service}.service") - pat = r"\b%s=(\S+)$" % key - match = re.search(pat, out, flags=re.M) - if not match: - raise Exception(f"value for \"{key}\" not found in output using pattern \"{pat}\":\n{out}") - got = match.group(1) - assert got == want, f"got: \"{key} = {got}\", want: \"{key} = {want}\"" - # Create required directories for Docker Compose volumes and bind mounts. for runtime, m in d.items(): m.succeed("mkdir -p /mnt/media") @@ -86,10 +75,10 @@ in m.wait_until_succeeds(f"{runtime} inspect service-b | jq .[0].State.Health.Status | grep healthy", timeout=30) # Ensure that service-b has its restart setting overriden by this test. - assert_service_value(f"{runtime}-service-b", "Restart", "on-success") + m.succeed(f"systemctl show -p Restart {runtime}-service-b.service | grep -E '=on-success$'") # Ensure that no-restart service has restart disabled. - assert_service_value(f"{runtime}-myproject-no-restart", "Restart", "no") + m.succeed(f"systemctl show -p Restart {runtime}-myproject-no-restart.service | grep -E '=no$'") # Stop the root unit. m.systemctl(f"stop {runtime}-compose-myproject-root.target")