44 lines
2.4 KiB
Python
44 lines
2.4 KiB
Python
"""Snapshot diagnostic regressions; run on the Debian deployment host."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[2] / "scripts/report-kubernetes.py"
|
|
|
|
|
|
def check(action, items, *args):
|
|
return subprocess.run([sys.executable, str(SCRIPT), action, *args],
|
|
input=json.dumps({"items": items}), text=True, capture_output=True)
|
|
|
|
|
|
class KubernetesReportTests(unittest.TestCase):
|
|
def test_scaled_down_deployment_is_healthy(self):
|
|
deployment = {"metadata": {"namespace": "gitea-runner", "name": "runner", "generation": 1},
|
|
"spec": {"replicas": 0}, "status": {"observedGeneration": 1}}
|
|
self.assertEqual(check("deployments", [deployment]).returncode, 0)
|
|
self.assertEqual(check("deployment-ready", [deployment], "gitea-runner", "runner").returncode, 0)
|
|
|
|
def test_incomplete_rollout_and_missing_workload_fail(self):
|
|
deployment = {"metadata": {"namespace": "app", "name": "web", "generation": 2},
|
|
"spec": {"replicas": 1}, "status": {"observedGeneration": 1, "availableReplicas": 1}}
|
|
self.assertNotEqual(check("deployment-ready", [deployment], "app", "web").returncode, 0)
|
|
self.assertNotEqual(check("deployment-ready", [], "app", "web").returncode, 0)
|
|
|
|
def test_crashloop_and_notready_are_not_hidden(self):
|
|
pod = {"metadata": {"namespace": "app", "name": "web"}, "status": {"phase": "Running",
|
|
"containerStatuses": [{"restartCount": 5, "state": {"waiting": {"reason": "CrashLoopBackOff"}}}]}}
|
|
node = {"metadata": {"name": "node"}, "status": {"conditions": [{"type": "Ready", "status": "False"}]}}
|
|
self.assertIn("CrashLoopBackOff", check("pods-problems", [pod]).stderr)
|
|
self.assertNotEqual(check("pod-restarts", [pod], "3").returncode, 0)
|
|
self.assertNotEqual(check("nodes-ready", [node]).returncode, 0)
|
|
|
|
def test_partitioned_statefulset_requires_ready_replicas(self):
|
|
workload = {"metadata": {"namespace": "app", "name": "db", "generation": 1},
|
|
"spec": {"replicas": 2, "updateStrategy": {"rollingUpdate": {"partition": 1}}},
|
|
"status": {"observedGeneration": 1, "readyReplicas": 1, "updatedReplicas": 1}}
|
|
self.assertNotEqual(check("statefulset-ready", [workload], "app", "db").returncode, 0)
|