nixos/test-driver: simplify logic, reduce interaction surface

This commit is contained in:
Patrick Hilhorst
2022-01-02 22:52:17 +01:00
parent 7830f000c5
commit a2f5092867
3 changed files with 28 additions and 24 deletions

View File

@@ -17,7 +17,7 @@ class Driver:
tests: str
vlans: List[VLan]
machines: List[Machine]
polling_conditions: List[Callable]
polling_conditions: List[PollingCondition]
def __init__(
self,
@@ -46,7 +46,7 @@ class Driver:
keep_vm_state=keep_vm_state,
name=cmd.machine_name,
tmp_dir=tmp_dir,
fail_early=self.fail_early,
callbacks=[self.check_polling_conditions],
)
for cmd in cmd(start_scripts)
]
@@ -166,8 +166,9 @@ class Driver:
def serial_stdout_off(self) -> None:
rootlog._print_serial_logs = False
def fail_early(self) -> bool:
return any(not f() for f in self.polling_conditions)
def check_polling_conditions(self) -> None:
for condition in self.polling_conditions:
condition.maybe_raise()
def polling_condition(
self,
@@ -184,7 +185,7 @@ class Driver:
fun,
seconds_interval,
description,
).check
)
def __enter__(self) -> None:
driver.polling_conditions.append(self.condition)