63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
import types
|
|
|
|
from ariadne.services.metis import MetisService
|
|
|
|
|
|
def test_watch_sentinel_reads_snapshot_dir(monkeypatch, tmp_path) -> None:
|
|
monkeypatch.setattr(
|
|
"ariadne.services.metis.settings",
|
|
types.SimpleNamespace(
|
|
metis_sentinel_dir=str(tmp_path),
|
|
metis_sentinel_stale_after_sec=3600.0,
|
|
),
|
|
)
|
|
|
|
Path(tmp_path, "node-a.json").write_text(
|
|
json.dumps(
|
|
{
|
|
"hostname": "titan-13",
|
|
"kernel": "6.6.63",
|
|
"containerd": "1.7.23",
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
Path(tmp_path, "node-b.json").write_text(
|
|
json.dumps(
|
|
{
|
|
"hostname": "titan-19",
|
|
"kernel": "6.6.63",
|
|
"containerd": "1.7.23",
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
summary = MetisService().watch_sentinel()
|
|
|
|
assert summary.status == "ok"
|
|
assert summary.snapshots == 2
|
|
assert summary.hosts == 2
|
|
assert summary.hostnames == ["titan-13", "titan-19"]
|
|
assert summary.source == str(tmp_path)
|
|
|
|
|
|
def test_watch_sentinel_skips_when_unconfigured(monkeypatch) -> None:
|
|
monkeypatch.setattr(
|
|
"ariadne.services.metis.settings",
|
|
types.SimpleNamespace(
|
|
metis_sentinel_dir="",
|
|
metis_sentinel_stale_after_sec=3600.0,
|
|
),
|
|
)
|
|
|
|
summary = MetisService().watch_sentinel()
|
|
|
|
assert summary.status == "skipped"
|
|
assert summary.snapshots == 0
|
|
assert summary.hosts == 0
|