Log errors on docker run/exec failure

This commit is contained in:
Ayaz Salikhov
2025-03-25 08:46:26 +00:00
parent c135254c87
commit de998c41eb
2 changed files with 17 additions and 6 deletions

View File

@@ -47,6 +47,9 @@ class DockerRunner:
exec_result = container.exec_run(cmd)
output = exec_result.output.decode().rstrip()
assert isinstance(output, str)
LOGGER.debug(f"Command output: {output}")
assert exec_result.exit_code == 0, f"Command: `{cmd}` failed"
if exec_result.exit_code != 0:
LOGGER.error(f"Command output:\n{output}")
raise AssertionError(f"Command: `{cmd}` failed")
else:
LOGGER.debug(f"Command output:\n{output}")
return output

View File

@@ -75,8 +75,11 @@ class TrackedContainer:
exec_result = container.exec_run(cmd, **final_kwargs)
output = exec_result.output.decode().rstrip()
assert isinstance(output, str)
LOGGER.debug(f"Command output: {output}")
assert exec_result.exit_code == 0, f"Command: `{cmd}` failed"
if exec_result.exit_code != 0:
LOGGER.error(f"Command output:\n{output}")
raise AssertionError(f"Command: `{cmd}` failed")
else:
LOGGER.debug(f"Command output:\n{output}")
return output
def run_and_wait(
@@ -91,10 +94,15 @@ class TrackedContainer:
assert self.container is not None
rv = self.container.wait(timeout=timeout)
logs = self.get_logs()
LOGGER.debug(logs)
failed = rv["StatusCode"] != 0
if failed:
LOGGER.error(f"Command output:\n{logs}")
else:
LOGGER.debug(f"Command output:\n{logs}")
assert no_failure != failed
assert no_warnings == (not self.get_warnings(logs))
assert no_errors == (not self.get_errors(logs))
assert no_failure == (rv["StatusCode"] == 0)
self.remove()
return logs