Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e0382c3ba |
@@ -366,9 +366,30 @@ def image_inspect(image):
|
|||||||
return json.loads(run(['docker', 'image', 'inspect', image], 'read image identity'))[0]
|
return json.loads(run(['docker', 'image', 'inspect', image], 'read image identity'))[0]
|
||||||
|
|
||||||
|
|
||||||
|
def container_log_tail(name, lines=5, limit=400):
|
||||||
|
"""Give the failure text a symptom, not just a verdict.
|
||||||
|
|
||||||
|
A non-running container used to surface only as "expected container is not
|
||||||
|
running"; the actual cause (missing zoneinfo, refused DSN, bad bind) lives in
|
||||||
|
the container log and was thrown away with the container.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
result = subprocess.run(['docker', 'logs', '--tail', str(lines), name], capture_output=True, timeout=15)
|
||||||
|
except (OSError, subprocess.TimeoutExpired):
|
||||||
|
return 'no container log'
|
||||||
|
# docker CLI forwards the container's stderr to its own stderr; keep both.
|
||||||
|
text = ' '.join((result.stdout + result.stderr).decode('utf-8', 'replace').split())
|
||||||
|
return text[-limit:] if text else 'no container log'
|
||||||
|
|
||||||
|
|
||||||
def inspect(name):
|
def inspect(name):
|
||||||
obj = json.loads(run(['docker', 'container', 'inspect', name], 'read running container'))[0]
|
obj = json.loads(run(['docker', 'container', 'inspect', name], 'read running container'))[0]
|
||||||
require(obj['State']['Status'] == 'running' and matches(IMAGE, obj.get('Image')), 'expected container is not running')
|
state = obj.get('State') or {}
|
||||||
|
if state.get('Status') != 'running':
|
||||||
|
raise CDError(f'{name}: container is {state.get("Status") or "unknown"} '
|
||||||
|
f'(exit {state.get("ExitCode")}); log: {container_log_tail(name)}')
|
||||||
|
require(matches(IMAGE, obj.get('Image')),
|
||||||
|
f'{name}: running image {obj.get("Image")!r} is not an approved image ID')
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user