Files
mtusi2026lab5/scripts/verify_persistence.py

16 lines
918 B
Python

"""Check that the persistence hook actually restarted every running service."""
import json
from pathlib import Path
root=Path(__file__).resolve().parents[1]/'evidence'
before={c['name']:c for c in json.loads((root/'persistence-before.json').read_text()) if c['status']=='running'}
after={c['name']:c for c in json.loads((root/'persistence-after.json').read_text())}
rows=[]
for name,old in before.items():
new=after[name]
assert old['id']==new['id'],name+': container unexpectedly replaced'
assert old['started_at']!=new['started_at'],name+': process not restarted'
assert old['volumes']==new['volumes'],name+': volumes changed'
assert new['status']=='running',name+': not running'
rows.append(dict(name=name,service=new['service'],same_container=True,process_restarted=True,same_volumes=True))
print(json.dumps({'status':'PASS','running_processes_restarted':len(rows),'rows':rows},indent=2))