prole/tests/test_init_kerberos_ad_forwarder_readiness.py
chrisfu 5a0f8ab4f8 Make init-script secret checks warning-only and unblock Next
Co-authored-by: Junie <junie@jetbrains.com>
2026-03-30 01:26:38 -07:00

55 lines
1.8 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
import subprocess
def test_init_kerberos_waits_for_ad_forwarder_ready_and_endpoints():
"""Regression: Kerberos test must not run against an AD forwarder Service with no endpoints.
Historically `init_kerberos.sh` would `kubectl apply` the AD forwarder Deployment/Service and then
proceed immediately (or ignore rollout failures), which could yield `kinit: Cannot contact any KDC`.
"""
text = Path("etc/init_kerberos.sh").read_text(encoding="utf-8")
assert "wait_for_ad_forwarder_ready" in text
assert "wait_for_ad_forwarder_ready \"$KRB5_AD_NAMESPACE\" \"$KRB5_AD_PROXY_NAME\" \"$KRB5_AD_SERVICE_NAME\"" in text
# Ensure we don't silently ignore readiness.
assert "rollout status deploy/${KRB5_AD_PROXY_NAME} --timeout=120s || true" not in text
def test_check_kerberos_cleanup_handles_missing_namespace(tmp_path):
"""Regression: cleanup path should not crash when PROLE_NAMESPACE is unset."""
prole_conf = tmp_path / "conf"
prole_conf.mkdir()
(prole_conf / "prole.cfg").write_text("[Global]\nDEPLOYMENT_MODE = k3s\n", encoding="utf-8")
home_dir = tmp_path / "home"
home_dir.mkdir()
env = os.environ.copy()
env.pop("PROLE_NAMESPACE", None)
env.pop("NAMESPACE", None)
env.pop("SERVICE_NAMESPACE", None)
env["PROLE_CONF"] = str(prole_conf)
env["PROLE_HOME"] = ""
env["HOME"] = str(home_dir)
repo_root = Path(__file__).resolve().parents[1]
script = repo_root / "scripts/validation/check_kerberos.sh"
result = subprocess.run(
["bash", str(script), "cleanup"],
cwd=repo_root,
env=env,
check=False,
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stderr
assert "No test pods to cleanup" in result.stdout