forked from mtusi2026/mtusi2026lab3
ЛР 3 — БВТ2303 — Брезгунова — на 5
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Cross-platform verification entry point; never rewrites public checks."""
|
||||
import datetime as dt
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'scripts'))
|
||||
from actions import base_url, command, containers, restore
|
||||
|
||||
|
||||
def main():
|
||||
suffix = '.cmd' if os.name == 'nt' else '.sh'
|
||||
if os.name != 'nt':
|
||||
for name in ('restart', 'stop-one', 'rolling-update'):
|
||||
(ROOT/'scripts'/(name+'.sh')).chmod(0o755)
|
||||
checks = [
|
||||
('offline', ['scripts/check_contract.py']),
|
||||
('smoke', ['tests/smoke.py', '--base-url', base_url()]),
|
||||
('integration', ['student-tests/integration.py']),
|
||||
('persistence', ['tests/resilience.py', '--mode', 'persistence', '--action-script', 'scripts/restart'+suffix, '--base-url', base_url()]),
|
||||
('failover', ['tests/resilience.py', '--mode', 'failover', '--action-script', 'scripts/stop-one'+suffix, '--base-url', base_url()]),
|
||||
('all-replica-failures', ['student-tests/resilience_load.py']),
|
||||
('final-smoke', ['tests/smoke.py', '--base-url', base_url()]),
|
||||
]
|
||||
result = {'at_utc': dt.datetime.now(dt.timezone.utc).isoformat(), 'checks': []}
|
||||
folder = ROOT/'evidence'/'checks'
|
||||
folder.mkdir(exist_ok=True)
|
||||
restore()
|
||||
try:
|
||||
for name, args in checks:
|
||||
# Infrastructure is stable before each public test.
|
||||
if name in ('all-replica-failures', 'final-smoke'):
|
||||
restore()
|
||||
completed = subprocess.run([sys.executable, '-X', 'utf8']+args, cwd=ROOT, capture_output=True,
|
||||
text=True, encoding='utf-8', errors='replace', timeout=600)
|
||||
(folder/(name+'.txt')).write_text(completed.stdout+completed.stderr, encoding='utf-8')
|
||||
result['checks'].append({'name':name,'command':['python','-X','utf8']+args,
|
||||
'exit_code':completed.returncode, 'evidence':'evidence/checks/'+name+'.txt'})
|
||||
(ROOT/'evidence'/'verification.json').write_text(json.dumps(result, indent=2)+'\n')
|
||||
print(name+': '+('PASS' if completed.returncode==0 else 'FAIL'), flush=True)
|
||||
if completed.returncode:
|
||||
print(completed.stdout+completed.stderr)
|
||||
raise SystemExit(completed.returncode)
|
||||
finally:
|
||||
restore()
|
||||
result['containers'] = containers()
|
||||
result['all_passed'] = True
|
||||
(ROOT/'evidence'/'verification.json').write_text(json.dumps(result, indent=2)+'\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user