forked from mtusi2026/mtusi2026lab3
solution
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Статические ограничения стенда lab3; не заменяет docker compose config/nginx -t."""
|
||||
|
||||
import ast
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import yaml
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main():
|
||||
config = yaml.safe_load((ROOT / "compose.yaml").read_text())
|
||||
services = config["services"]
|
||||
assert {"api-a", "api-b", "migrate", "nginx", "db", "redis"} <= services.keys()
|
||||
assert config["networks"]["data"]["internal"] is True
|
||||
for name, service in services.items():
|
||||
assert "container_name" not in service, name
|
||||
assert float(service["cpus"]) > 0 and service["mem_limit"], name
|
||||
if name != "nginx":
|
||||
assert "ports" not in service, name
|
||||
for name in ("api-a", "api-b"):
|
||||
assert services[name]["depends_on"]["migrate"]["condition"] == "service_completed_successfully"
|
||||
assert services[name]["stop_grace_period"] == "10s"
|
||||
assert services["migrate"]["command"] == ["python", "-m", "app.migrate"]
|
||||
assert services["nginx"]["image"] == "nginx:1.28.0-alpine"
|
||||
assert services["nginx"]["networks"] == ["edge"]
|
||||
assert not any("docker.sock" in str(s) for s in services.values())
|
||||
spec = json.loads((ROOT / "contracts/openapi.json").read_text())
|
||||
operation = spec["paths"]["/api/v1/chats/{chat_id}/messages"]["post"]
|
||||
assert any(p["name"] == "Idempotency-Key" and p["required"] for p in operation["parameters"])
|
||||
for directory in ("app", "scripts", "student-tests", "unit-tests", "tests"):
|
||||
for path in (ROOT / directory).rglob("*.py"):
|
||||
ast.parse(path.read_text(), filename=str(path))
|
||||
for path in list((ROOT / "scripts").glob("*.sh")) + list((ROOT / "infra").rglob("*.sh")):
|
||||
subprocess.run(["sh", "-n", str(path)], check=True)
|
||||
for filename in ("scripts/stop-one.sh", "scripts/restart.sh"):
|
||||
assert (ROOT / filename).stat().st_mode & 0o111
|
||||
print("PASS: lab3 static structure, resource/port isolation, contract, Python/sh syntax; runtime NOT tested.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user