Files

77 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Смоук-тесты сервисов комбайна: все эндпойнты отвечают и данные не пустые."""
import json
import sys
import urllib.request
SVC = {
"catalog": "http://127.0.0.1:8101",
"engine": "http://127.0.0.1:8102",
"project": "http://127.0.0.1:8103",
"draw": "http://127.0.0.1:8104",
"docs": "http://127.0.0.1:8105",
}
HOST = "meetingbara50"
ITEMS = "item=UVC86&item=CTP25&item=MeetingDisplay"
def get(url, timeout=60):
with urllib.request.urlopen(url, timeout=timeout) as r:
return r.status, r.read()
CHECKS = [
("catalog", "/hosts", lambda b: len(json.loads(b).get("hosts") or []) > 10),
("catalog", "/matrix", lambda b: len(json.loads(b).get("rows") or []) > 10),
("catalog", "/vendors", lambda b: len(json.loads(b).get("vendors") or []) >= 1),
("catalog", "/port-objects?name=UVC86", lambda b: len(json.loads(b).get("ports") or []) > 0),
("engine", "/groups?host=%s" % HOST, lambda b: len(json.loads(b).get("groups") or []) > 3),
("engine", "/autofill?host=%s&seats=10" % HOST,
lambda b: len(json.loads(b).get("items") or []) >= 3),
("engine", "/checklist?host=%s&%s" % (HOST, ITEMS),
lambda b: json.loads(b).get("total", 0) >= 5),
("engine", "/signals?host=%s&%s" % (HOST, ITEMS),
lambda b: json.loads(b).get("total", 0) >= 1),
("engine", "/cables?host=%s&%s" % (HOST, ITEMS),
lambda b: "cables" in json.loads(b)),
("engine", "/ports?host=%s&%s" % (HOST, ITEMS),
lambda b: "free_in" in json.loads(b)),
("engine", "/capacity?host=%s&%s" % (HOST, ITEMS),
lambda b: "vch_ports" in json.loads(b)),
("engine", "/review?host=%s&%s" % (HOST, ITEMS),
lambda b: "issues" in json.loads(b)),
("engine", "/check?host=meetingeye500&device=VCM36-W",
lambda b: json.loads(b).get("supported") is False),
("engine", "/accessory?device=WPP30",
lambda b: json.loads(b).get("count", 0) > 5),
("engine", "/bom?host=%s&seats=10" % HOST, lambda b: len(json.loads(b).get("bom") or []) > 2),
("engine", "/xlsx?host=%s&seats=10" % HOST, lambda b: len(b) > 3000),
("engine", "/spec?host=%s&seats=10" % HOST, lambda b: len(b) > 500),
("engine", "/ask?q=MeetingEye+500+%2B+VCM38", lambda b: bool(json.loads(b).get("answer"))),
("project", "/list", lambda b: "projects" in json.loads(b)),
("draw", "/diagram?host=%s&%s" % (HOST, ITEMS),
lambda b: b"<svg" in b and len(b) > 800),
("draw", "/layout?host=%s&w=8&l=10&%s" % (HOST, ITEMS), lambda b: b"<svg" in b),
("draw", "/heatmap?host=%s&w=8&l=10&%s" % (HOST, ITEMS), lambda b: b"<svg" in b),
("draw", "/rack?item=MCore&item=AP08", lambda b: b"<svg" in b),
("draw", "/ipplan?item=MCore&item=AP08", lambda b: json.loads(b).get("count", 0) >= 1),
("docs", "/docs?device=UVC86", lambda b: "docs" in json.loads(b)),
]
fails = 0
for svc, path, check in CHECKS:
url = SVC[svc] + path
try:
code, body = get(url)
ok = code == 200 and check(body)
print("%s %-6s %-52s %s (%.0f Б)" % ("✓" if ok else "✗", svc, path[:52],
"ok" if ok else "ПРОВАЛ", len(body)))
if not ok:
fails += 1
except Exception as e:
print("✗ %-6s %-52s ошибка: %s" % (svc, path[:52], str(e)[:80]))
fails += 1
print("\nпроверок: %d, провалов: %d" % (len(CHECKS), fails))
sys.exit(1 if fails else 0)