diff options
author | Jacek Galowicz <jacek@galowicz.de> | 2023-12-14 06:55:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-14 06:55:06 +0100 |
commit | 66ca9c90e28640bb5740a1d6f3a578880b3b6a14 (patch) | |
tree | 7878f8ccb829851b9273a9f97ab2cf2b513f3bc5 /nixos | |
parent | 3e2b9bd399e39ab53d161253734c641d6a27fa55 (diff) | |
parent | 392fbc90a86a696810a853e9eedf2fd7e2dafcdf (diff) |
Merge pull request #267937 from SomeoneSerge/fix/test-driver-activestate
nixos/lib/test-driver: make wait_for_unit ask for ActiveState only
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/lib/test-driver/test_driver/machine.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/nixos/lib/test-driver/test_driver/machine.py b/nixos/lib/test-driver/test_driver/machine.py index f430321bb6076..da60b669fa27e 100644 --- a/nixos/lib/test-driver/test_driver/machine.py +++ b/nixos/lib/test-driver/test_driver/machine.py @@ -447,8 +447,7 @@ class Machine: """ def check_active(_: Any) -> bool: - info = self.get_unit_info(unit, user) - state = info["ActiveState"] + state = self.get_unit_property(unit, "ActiveState", user) if state == "failed": raise Exception(f'unit "{unit}" reached state "{state}"') @@ -491,6 +490,35 @@ class Machine: if line_pattern.match(line) ) + def get_unit_property( + self, + unit: str, + property: str, + user: Optional[str] = None, + ) -> str: + status, lines = self.systemctl( + f'--no-pager show "{unit}" --property="{property}"', + user, + ) + if status != 0: + raise Exception( + f'retrieving systemctl property "{property}" for unit "{unit}"' + + ("" if user is None else f' under user "{user}"') + + f" failed with exit code {status}" + ) + + invalid_output_message = ( + f'systemctl show --property "{property}" "{unit}"' + f"produced invalid output: {lines}" + ) + + line_pattern = re.compile(r"^([^=]+)=(.*)$") + match = line_pattern.match(lines) + assert match is not None, invalid_output_message + + assert match[1] == property, invalid_output_message + return match[2] + def systemctl(self, q: str, user: Optional[str] = None) -> Tuple[int, str]: """ Runs `systemctl` commands with optional support for |