107 lines
4.3 KiB
Python
107 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercise the actual CLI-only scratch image; never starts an inference worker."""
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
import time
|
|
import uuid
|
|
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 = (
|
|
('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:
|
|
report_best_effort(
|
|
f'Owned container {label} (exit {result.returncode}):\n{output}')
|
|
else:
|
|
report_best_effort(
|
|
f'Owned container {label}: no output (exit {result.returncode})')
|
|
except Exception as error:
|
|
report_best_effort(
|
|
f'Owned container {label} diagnostics unavailable: {type(error).__name__}')
|
|
|
|
|
|
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
|
|
license_text = docker('run', '--rm', *common, '--network', 'none', image,
|
|
'--engine-license').stdout
|
|
assert license_text == (root / 'engine/strata/LICENSE').read_text()
|
|
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
|
|
try:
|
|
docker('run', '-d', *common, '--network', 'none',
|
|
'-e', 'STRATA_BIND=127.0.0.1:8081', image, 'serve', timeout=120)
|
|
except subprocess.TimeoutExpired:
|
|
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:
|
|
try:
|
|
assert request(name, '/health') == (200, {'status': 'ok'})
|
|
break
|
|
except (OSError, AssertionError, subprocess.CalledProcessError):
|
|
if time.monotonic() >= deadline:
|
|
raise
|
|
time.sleep(0.1)
|
|
status, ready = request(name, '/ready')
|
|
assert status == 503 and ready['ready'] is False, (status, ready)
|
|
docker('stop', '--time', '10', name)
|
|
state = json.loads(docker('inspect', '--format', '{{json .State}}', name).stdout)
|
|
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:
|
|
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
|
|
report_best_effort(
|
|
f'Owned container cleanup failed after {type(primary_error).__name__}: '
|
|
f'{type(cleanup_error).__name__}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv[1])
|