forked from mtusi2026/mtusi2026lab5
37 lines
1.9 KiB
Python
37 lines
1.9 KiB
Python
"""Публичный persistence + доказательство реального restart каждого постоянного сервиса."""
|
|
from datetime import datetime, timezone
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def verify(env):
|
|
def run(*args):
|
|
return subprocess.check_output(args, cwd=ROOT, env=env, text=True, timeout=180).strip()
|
|
def snapshot():
|
|
ids = run('docker', 'compose', 'ps', '-q').split()
|
|
infos = json.loads(run('docker', 'inspect', *ids))
|
|
return {info['Id']: {'service': info['Config']['Labels']['com.docker.compose.service'],
|
|
'started_at': info['State']['StartedAt'],
|
|
'volumes': sorted(m['Name'] for m in info['Mounts'] if m['Type'] == 'volume')}
|
|
for info in infos}
|
|
before = snapshot()
|
|
print(run('make', 'test-persistence', 'PYTHON=' + sys.executable, 'ACTION_SCRIPT=scripts/restart.sh'), flush=True)
|
|
after = snapshot()
|
|
assert before.keys() == after.keys()
|
|
assert all(before[key]['started_at'] != after[key]['started_at'] for key in before)
|
|
assert all(before[key]['volumes'] == after[key]['volumes'] for key in before)
|
|
required = {'api', 'lb', 'postgres', 'valkey', 'broker', 's3', 's3-storage', 'cleanup', 'publisher', 'worker'}
|
|
assert required == {value['service'] for value in after.values()}
|
|
return {'passed': True, 'before': before, 'after': after, 'same_containers_and_volumes': True}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
result = {'utc': datetime.now(timezone.utc).isoformat(), 'command': '.venv/bin/python student-tests/verify_restart.py', **verify(dict(os.environ))}
|
|
(ROOT / 'evidence/lab5-restart.json').write_text(json.dumps(result, indent=2) + '\n')
|
|
print('PASS: all persistent services actually restarted; container IDs and volumes preserved')
|