Files
mtusi2026lab7/scripts/restart-evidence.py
T
2026-11-18 11:36:21 +03:00

15 lines
1012 B
Python

#!/usr/bin/env python3
import json,subprocess,sys
from pathlib import Path
root=Path(__file__).resolve().parents[1];path=root/'evidence/restart-evidence.json'
phase=sys.argv[1];out={}
for cid in subprocess.check_output([str(root/'scripts/compose.sh'),'ps','-q'],text=True).split():
c=json.loads(subprocess.check_output(['docker','inspect',cid],text=True))[0]
out[c['Name']]={'id':c['Id'],'started_at':c['State']['StartedAt'],'volumes':[{'name':m.get('Name'),'destination':m['Destination']} for m in c['Mounts'] if m['Type']=='volume']}
data=json.loads(path.read_text()) if phase=='after' and path.exists() else {};data[phase]=out
if phase=='after':
required=['postgres','redis','broker','s3','openbao','prometheus','loki','tempo','grafana']
data['all_stores_restarted']=all(any('-'+role+'-' in name and value['started_at']!=data['before'].get(name,{}).get('started_at') for name,value in out.items()) for role in required)
assert data['all_stores_restarted']
path.write_text(json.dumps(data,indent=2)+'\n')