Open-status ticket filtering and shorter list TTL, FreeScout API via jump host with write-path cache clear, OpenBoard finance-hold flags on board create, and expanded shenzhou web tab UX.
57 lines
2 KiB
Python
57 lines
2 KiB
Python
"""Unit tests for joy.dashboard.shenzhou (no live SSH)."""
|
|
from joy.dashboard.shenzhou import parse_probe_output, _merge_hosts, _classify_sites
|
|
|
|
|
|
SAMPLE = """
|
|
OK|weixiaoduo-prod|HOST=iZ;UP=100;LOAD=2.90 2.82 2.91;DISK=46|40G|18G;MEM=26|8280|30815;
|
|
OK|wenpai-org|HOST=wenpai-org;UP=200;LOAD=235.51 154.60 85.44;DISK=59|60G|36G;MEM=62|9508|15197;
|
|
FAIL|gz-1p|
|
|
"""
|
|
|
|
|
|
def test_parse_probe_output():
|
|
m = parse_probe_output(SAMPLE)
|
|
assert m["weixiaoduo-prod"]["reachable"] is True
|
|
assert m["weixiaoduo-prod"]["disk_pct"] == 46
|
|
assert m["weixiaoduo-prod"]["load1"] == 2.9
|
|
assert m["weixiaoduo-prod"]["status"] == "ok"
|
|
assert m["wenpai-org"]["status"] == "load_crit"
|
|
assert m["gz-1p"]["reachable"] is False
|
|
assert m["gz-1p"]["status"] == "unreachable"
|
|
|
|
|
|
def test_merge_hosts():
|
|
cfg = [
|
|
{"id": "weixiaoduo-prod", "role": "wp", "ssh": "weixiaoduo-prod"},
|
|
{"id": "gz-1p", "role": "edge", "ssh": "gz-1p"},
|
|
{"id": "wptea-prod", "role": "gone", "retired": True},
|
|
]
|
|
probe = parse_probe_output(SAMPLE)
|
|
rows = _merge_hosts(cfg, probe)
|
|
by = {r["id"]: r for r in rows}
|
|
assert by["weixiaoduo-prod"]["reachable"] is True
|
|
assert by["gz-1p"]["reachable"] is False
|
|
assert by["wptea-prod"]["status"] == "retired"
|
|
|
|
|
|
def test_classify_sites_alert():
|
|
cfg = [
|
|
{"url": "admincdn.com", "watch": True},
|
|
{"url": "ok.example", "watch": True},
|
|
]
|
|
idx = {
|
|
"admincdn.com": [{"type": "HTTP_FAIL", "detail": "timeout"}],
|
|
}
|
|
rows, cnt = _classify_sites(cfg, idx)
|
|
assert cnt["down"] == 1
|
|
assert rows[0]["status"] == "down"
|
|
assert rows[1]["status"] == "ok"
|
|
|
|
|
|
def test_default_critical_paths_exist():
|
|
from joy.dashboard.shenzhou import _DEFAULT_CRITICAL_PATHS
|
|
# 路径清单会随业务扩展;至少含核心电商入口
|
|
assert len(_DEFAULT_CRITICAL_PATHS) >= 8
|
|
money = [p for p in _DEFAULT_CRITICAL_PATHS if p.get("money")]
|
|
assert any(p["id"] == "mall" for p in money)
|
|
assert any(p["id"] == "weixiaoduo" for p in money)
|