test: preserve container smoke failures on cleanup
This commit is contained in:
@@ -9,6 +9,13 @@ import subprocess
|
||||
from docker_smoke_http import ISOLATION, docker, prepare_probe, request
|
||||
|
||||
|
||||
def report_best_effort(message):
|
||||
try:
|
||||
print(message, file=sys.stderr, flush=True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def diagnose_owned_container(name):
|
||||
"""Emit bounded state/log diagnostics for this invocation's unique container."""
|
||||
commands = (
|
||||
@@ -22,14 +29,14 @@ def diagnose_owned_container(name):
|
||||
if len(output) > 8192:
|
||||
output = '[earlier output truncated]\n' + output[-8192:]
|
||||
if output:
|
||||
print(f'Owned container {label} (exit {result.returncode}):\n{output}',
|
||||
file=sys.stderr, flush=True)
|
||||
report_best_effort(
|
||||
f'Owned container {label} (exit {result.returncode}):\n{output}')
|
||||
else:
|
||||
print(f'Owned container {label}: no output (exit {result.returncode})',
|
||||
file=sys.stderr, flush=True)
|
||||
report_best_effort(
|
||||
f'Owned container {label}: no output (exit {result.returncode})')
|
||||
except Exception as error:
|
||||
print(f'Owned container {label} diagnostics unavailable: {type(error).__name__}',
|
||||
file=sys.stderr, flush=True)
|
||||
report_best_effort(
|
||||
f'Owned container {label} diagnostics unavailable: {type(error).__name__}')
|
||||
|
||||
|
||||
def main(image):
|
||||
@@ -52,7 +59,11 @@ def main(image):
|
||||
docker('run', '-d', *common, '--network', 'none',
|
||||
'-e', 'STRATA_BIND=127.0.0.1:8081', image, 'serve', timeout=120)
|
||||
except subprocess.TimeoutExpired:
|
||||
diagnose_owned_container(name)
|
||||
try:
|
||||
diagnose_owned_container(name)
|
||||
except Exception as error:
|
||||
report_best_effort(
|
||||
f'Owned container diagnostics failed: {type(error).__name__}')
|
||||
raise
|
||||
deadline = time.monotonic() + 15
|
||||
while True:
|
||||
@@ -86,8 +97,9 @@ def main(image):
|
||||
if cleanup_error is not None:
|
||||
if primary_error is None:
|
||||
raise cleanup_error
|
||||
print(f'Owned container cleanup failed after {type(primary_error).__name__}: '
|
||||
f'{type(cleanup_error).__name__}', file=sys.stderr, flush=True)
|
||||
report_best_effort(
|
||||
f'Owned container cleanup failed after {type(primary_error).__name__}: '
|
||||
f'{type(cleanup_error).__name__}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user