forked from mtusi2026/mtusi2026lab5
34 lines
2.1 KiB
Python
34 lines
2.1 KiB
Python
"""Explicit local verification with sanitized logs; never deletes volumes."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
EVIDENCE=ROOT/'evidence'
|
|
def run(name,args):
|
|
start=time.monotonic()
|
|
result=subprocess.run(['docker','compose','--env-file','.env',*args],cwd=ROOT,
|
|
stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,encoding='utf-8',errors='replace')
|
|
(EVIDENCE/name).write_text(result.stdout,encoding='utf-8')
|
|
if result.returncode:raise RuntimeError(name+' failed; inspect evidence')
|
|
print('PASS',name,flush=True)
|
|
return round(time.monotonic()-start,3)
|
|
def main():
|
|
EVIDENCE.mkdir(exist_ok=True)
|
|
results={}
|
|
if '--build' in sys.argv:run('build.txt',['build','api','checks'])
|
|
run('startup.txt',['up','-d','--no-build','--wait','--wait-timeout','180'])
|
|
results['public']=run('smoke.txt',['run','--rm','--no-deps','checks','make','check','test'])
|
|
results['images']=run('images.txt',['run','--rm','--no-deps','-e','PYTHONPATH=/app','checks','python','-m','unittest','discover','-s','student-tests','-p','test_images.py','-v'])
|
|
results['pipeline']=run('pipeline.txt',['run','--rm','--no-deps','-e','PYTHONPATH=/app','checks','python','student-tests/pipeline_checks.py'])
|
|
run('before-restart.json',['run','--rm','--no-deps','checks','python','scripts/ops.py','summary'])
|
|
results['persistence']=run('persistence.txt',['run','--rm','--no-deps','checks','sh','-ec','chmod +x scripts/restart.sh; make test-persistence ACTION_SCRIPT=scripts/restart.sh'])
|
|
run('after-restart.json',['run','--rm','--no-deps','checks','python','scripts/ops.py','summary'])
|
|
results['failover']=run('failover.txt',['run','--rm','--no-deps','checks','sh','-ec','chmod +x scripts/stop-one.sh; make test-failover ACTION_SCRIPT=scripts/stop-one.sh'])
|
|
run('restore.txt',['start','api'])
|
|
results['final_smoke']=run('smoke-final.txt',['run','--rm','--no-deps','checks','make','test'])
|
|
(EVIDENCE/'verification.json').write_text(json.dumps({'date':'2026-11-21','seconds':results,'result':'PASS'},indent=2))
|
|
if __name__=='__main__':main()
|