container-test-driver: add Machine.fail

This commit is contained in:
Michael Hoang
2025-04-29 12:11:58 +10:00
parent 82b3ba97b7
commit 7d46237b67

View File

@@ -333,6 +333,15 @@ class Machine:
raise RuntimeError(msg)
return res.stdout
def fail(self, command: str, timeout: int | None = None) -> str:
res = self.execute(command, timeout=timeout)
if res.returncode == 0:
msg = f"command `{command}` unexpectedly succeeded\n"
msg += f"Exit code: {res.returncode}\n"
msg += f"Stdout: {res.stdout}"
raise RuntimeError(msg)
return res.stdout
def shutdown(self) -> None:
"""
Shut down the machine, waiting for the VM to exit.