forked from mtusi2026/mtusi2026lab3
74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
"""Проверка реализации в новом клоне: контракт, restart и отказ одной API."""
|
|
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
from replicas import ROOT, compose, containers, describe, wait_ready, wait_visible
|
|
|
|
|
|
def check(name, *command):
|
|
result = subprocess.run(command, cwd=ROOT, text=True, capture_output=True)
|
|
(ROOT / "evidence" / ("lab3-transfer-" + name + ".txt")).write_text(
|
|
result.stdout + result.stderr
|
|
)
|
|
print(name, "PASS" if result.returncode == 0 else "FAIL", flush=True)
|
|
if result.returncode:
|
|
raise RuntimeError((result.stdout + result.stderr)[-2000:])
|
|
|
|
|
|
check(
|
|
"persistence",
|
|
sys.executable,
|
|
"tests/resilience.py",
|
|
"--mode",
|
|
"persistence",
|
|
"--action-script",
|
|
"scripts/restart.sh",
|
|
)
|
|
try:
|
|
check(
|
|
"failover",
|
|
sys.executable,
|
|
"tests/resilience.py",
|
|
"--mode",
|
|
"failover",
|
|
"--action-script",
|
|
"scripts/stop-one.sh",
|
|
)
|
|
finally:
|
|
compose("up", "-d", "--no-deps", "--wait", "api")
|
|
for cid in containers():
|
|
wait_visible(wait_ready(cid))
|
|
check("final-smoke", sys.executable, "tests/smoke.py")
|
|
logs = compose("logs", "--no-color", "migration")
|
|
(ROOT / "evidence/lab3-transfer-migrations.txt").write_text(logs + "\n")
|
|
proof = {
|
|
"project": "mtusi2026lab3",
|
|
"schema_revision": "006",
|
|
"api_instances": len(containers()),
|
|
"api_states": {
|
|
cid[:12]: {
|
|
"status": describe(cid)["Status"],
|
|
"health": describe(cid).get("Health", {}).get("Status"),
|
|
}
|
|
for cid in containers()
|
|
},
|
|
"public_sha256": {
|
|
name: hashlib.sha256((ROOT / name).read_bytes()).hexdigest()
|
|
for name in [
|
|
"contracts/openapi.json",
|
|
"tests/client.py",
|
|
"tests/smoke.py",
|
|
"tests/resilience.py",
|
|
"tests/load.py",
|
|
]
|
|
},
|
|
}
|
|
assert proof["api_instances"] == 2
|
|
(ROOT / "evidence/lab3-transfer-runtime.json").write_text(
|
|
json.dumps(proof, ensure_ascii=False, indent=2) + "\n"
|
|
)
|
|
print("PASS: transferred application retains data/session and survives API failover", flush=True)
|