41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Public persistence test plus proof all three real containers restarted, volumes unchanged."""
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def snapshot():
|
|
ids = subprocess.check_output(['docker','compose','ps','-q'],cwd=ROOT,text=True).split()
|
|
data = json.loads(subprocess.check_output(['docker','inspect',*ids],text=True))
|
|
return {item['Config']['Labels']['com.docker.compose.service']: {
|
|
'container': item['Name'].lstrip('/'), 'started_at': item['State']['StartedAt'],
|
|
'image': item['Config']['Image'],
|
|
'volumes': sorted(m['Name'] for m in item['Mounts'] if m['Type']=='volume')
|
|
} for item in data}
|
|
|
|
|
|
def main():
|
|
before = snapshot()
|
|
result = subprocess.run([sys.executable, 'tests/resilience.py', '--mode', 'persistence',
|
|
'--action-script', 'scripts/restart.sh'],cwd=ROOT,capture_output=True,text=True)
|
|
after = snapshot()
|
|
print(result.stdout, end='')
|
|
if result.returncode:
|
|
print(result.stderr, file=sys.stderr)
|
|
raise SystemExit(result.returncode)
|
|
for service in ['api','postgres','redis']:
|
|
assert before[service]['started_at'] != after[service]['started_at'], service + ' did not restart'
|
|
assert before[service]['volumes'] == after[service]['volumes'], service + ' volumes changed'
|
|
evidence = {'result':'PASS','before':before,'after':after,'public_test':result.stdout.strip()}
|
|
path = ROOT / 'evidence' / 'persistence.json'
|
|
path.write_text(json.dumps(evidence, indent=2)+'\n')
|
|
print('PASS: actual API/PostgreSQL/Redis restart confirmed; volume identities unchanged.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|