test: bound CLI container startup wait
This commit is contained in:
@@ -9,12 +9,36 @@ import subprocess
|
||||
from docker_smoke_http import ISOLATION, docker, prepare_probe, request
|
||||
|
||||
|
||||
def diagnose_owned_container(name):
|
||||
"""Emit bounded state/log diagnostics for this invocation's unique container."""
|
||||
commands = (
|
||||
('inspect', ('inspect', '--format', '{{json .State}}', name)),
|
||||
('logs', ('logs', '--tail', '40', name)),
|
||||
)
|
||||
for label, args in commands:
|
||||
try:
|
||||
result = docker(*args, check=False, timeout=8)
|
||||
output = (result.stdout or '') + (result.stderr or '')
|
||||
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)
|
||||
else:
|
||||
print(f'Owned container {label}: no output (exit {result.returncode})',
|
||||
file=sys.stderr, flush=True)
|
||||
except Exception as error:
|
||||
print(f'Owned container {label} diagnostics unavailable: {type(error).__name__}',
|
||||
file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
def main(image):
|
||||
name = 'strata-cli-smoke-' + uuid.uuid4().hex
|
||||
common = ['--name', name, *ISOLATION]
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
prepare_probe()
|
||||
|
||||
primary_error = None
|
||||
try:
|
||||
version = docker('run', '--rm', *common, '--network', 'none', image, '--version').stdout
|
||||
assert version.startswith('strata-next '), version
|
||||
@@ -24,8 +48,12 @@ def main(image):
|
||||
info = json.loads(docker('run', '--rm', *common, '--network', 'none', image,
|
||||
'engine-info').stdout)
|
||||
assert info['embedded'] is False and info['model_bundled'] is False, info
|
||||
docker('run', '-d', *common, '--network', 'none',
|
||||
'-e', 'STRATA_BIND=127.0.0.1:8081', image, 'serve')
|
||||
try:
|
||||
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)
|
||||
raise
|
||||
deadline = time.monotonic() + 15
|
||||
while True:
|
||||
try:
|
||||
@@ -42,8 +70,24 @@ def main(image):
|
||||
assert state['ExitCode'] == 0 and not state['OOMKilled'], state
|
||||
print('CLI OCI passed: actual image, exact upstream license, no embedded engine/model, '
|
||||
'non-root read-only health200/ready503, graceful stop. No GPU inference qualified.')
|
||||
except BaseException as error:
|
||||
primary_error = error
|
||||
raise
|
||||
finally:
|
||||
docker('rm', '-f', name, check=False)
|
||||
cleanup_error = None
|
||||
try:
|
||||
result = docker('rm', '-f', name, check=False, timeout=10)
|
||||
if result.returncode:
|
||||
cleanup_error = subprocess.CalledProcessError(
|
||||
result.returncode, ['docker', 'rm', '-f', name],
|
||||
output=result.stdout, stderr=result.stderr)
|
||||
except Exception as error:
|
||||
cleanup_error = error
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user