fix(backup): monitor gitea private bundle coverage
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 33s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 33s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
This commit is contained in:
86
scripts/ops/tests/test_backup_health_textfile_exporter.py
Normal file
86
scripts/ops/tests/test_backup_health_textfile_exporter.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT_ROOT = Path(__file__).resolve().parents[1]
|
||||
EXPORTER_PATH = SCRIPT_ROOT / "backup-health-textfile-exporter.py"
|
||||
|
||||
|
||||
def load_exporter():
|
||||
spec = importlib.util.spec_from_file_location("backup_health_textfile_exporter", EXPORTER_PATH)
|
||||
assert spec and spec.loader
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_gitea_bundle_metrics_require_all_expected_repos(tmp_path: Path, monkeypatch) -> None:
|
||||
exporter = load_exporter()
|
||||
bundle_root = tmp_path / "latest-private-complete"
|
||||
bundle_root.mkdir()
|
||||
monkeypatch.setattr(exporter, "GITEA_BUNDLE_ROOT", bundle_root)
|
||||
monkeypatch.setattr(exporter, "GITEA_BUNDLE_MAX_AGE_HOURS", 25)
|
||||
monkeypatch.setenv("AIOPS_GITEA_BUNDLE_EXPECTED_REPOS", "wooo/awoooi,wooo/tsenyang-website")
|
||||
|
||||
(bundle_root / "manifest.remote.tsv").write_text(
|
||||
"\n".join(
|
||||
[
|
||||
"repo\tstatus\thead_count\tbundle\tchecksum",
|
||||
f"wooo/awoooi\tok\t2\t{bundle_root / 'wooo__awoooi.bundle'}\t{bundle_root / 'wooo__awoooi.bundle.sha256'}",
|
||||
]
|
||||
)
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(bundle_root / "wooo__awoooi.bundle").write_text("bundle", encoding="utf-8")
|
||||
(bundle_root / "wooo__awoooi.bundle.sha256").write_text(
|
||||
"a" * 64 + " wooo__awoooi.bundle\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(bundle_root / "tsenyang-website-local-20260701.bundle").write_text("bundle", encoding="utf-8")
|
||||
(bundle_root / "tsenyang-website-local-20260701.bundle.sha256").write_text(
|
||||
"b" * 64 + " tsenyang-website-local-20260701.bundle\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
metrics, all_ok = exporter._gitea_bundle_metric_lines("188")
|
||||
|
||||
rendered = "\n".join(metrics)
|
||||
assert all_ok == 1
|
||||
assert 'awoooi_gitea_bundle_expected_repo_count{host="188"' in rendered
|
||||
assert 'awoooi_gitea_bundle_expected_repo_missing_count{host="188"' in rendered
|
||||
assert 'awoooi_gitea_bundle_failed_repo_count{host="188"' in rendered
|
||||
assert 'repo="wooo/tsenyang-website",status="bundle_file_only"' in rendered
|
||||
assert 'awoooi_gitea_bundle_all_expected_ok{host="188"' in rendered
|
||||
assert rendered.rstrip().endswith(" 1")
|
||||
|
||||
|
||||
def test_gitea_bundle_metrics_fail_when_checksum_missing(tmp_path: Path, monkeypatch) -> None:
|
||||
exporter = load_exporter()
|
||||
bundle_root = tmp_path / "latest-private-complete"
|
||||
bundle_root.mkdir()
|
||||
monkeypatch.setattr(exporter, "GITEA_BUNDLE_ROOT", bundle_root)
|
||||
monkeypatch.setenv("AIOPS_GITEA_BUNDLE_EXPECTED_REPOS", "wooo/awoooi")
|
||||
|
||||
(bundle_root / "manifest.remote.tsv").write_text(
|
||||
"\n".join(
|
||||
[
|
||||
"repo\tstatus\thead_count\tbundle\tchecksum",
|
||||
f"wooo/awoooi\tok\t2\t{bundle_root / 'wooo__awoooi.bundle'}\t{bundle_root / 'wooo__awoooi.bundle.sha256'}",
|
||||
]
|
||||
)
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(bundle_root / "wooo__awoooi.bundle").write_text("bundle", encoding="utf-8")
|
||||
|
||||
metrics, all_ok = exporter._gitea_bundle_metric_lines("188")
|
||||
|
||||
rendered = "\n".join(metrics)
|
||||
assert all_ok == 0
|
||||
assert 'awoooi_gitea_bundle_checksum_missing_count{host="188"' in rendered
|
||||
assert rendered.rstrip().endswith(" 0")
|
||||
Reference in New Issue
Block a user