Add focused homelab status reports
This commit is contained in:
parent
c4aee8b391
commit
01d99f09d8
|
|
@ -0,0 +1,45 @@
|
|||
# Fast homelab status
|
||||
|
||||
Run on the Debian server (or use the same arguments after `./jeannie remote`):
|
||||
|
||||
```sh
|
||||
./jeannie status
|
||||
./jeannie status debian
|
||||
./jeannie status opi5
|
||||
./jeannie status rpi
|
||||
./jeannie status oci
|
||||
./jeannie status cluster
|
||||
```
|
||||
|
||||
`status` and `status all` check all five areas. A scope runs only its checks.
|
||||
Use `--details` or `--json` after the scope for evidence or structured output.
|
||||
For example: `./jeannie remote status opi5 --json`. Scoped reports display
|
||||
passing checks too and do not invoke an AI model. Checks run concurrently and
|
||||
use configured inventory addresses, ports and the selected cluster profile.
|
||||
Warnings return exit status zero; failed checks return a nonzero status.
|
||||
|
||||
Each host scope lists discovered Docker Compose containers by project and
|
||||
service, including Docker health when available. One-off containers are
|
||||
excluded. Stopped, starting, or unhealthy containers are warnings because
|
||||
they may have been stopped intentionally. Discovery uses one Docker snapshot
|
||||
per host; services with no container cannot be inferred from that snapshot.
|
||||
Remote snapshots require noninteractive SSH and sudo and warn when access is
|
||||
unavailable. The OCI edge snapshot uses its inventoried Tailscale address.
|
||||
|
||||
The cluster scope lists Argo CD application health and sync state from one
|
||||
snapshot. Degraded or missing applications are failures; progressing, unknown,
|
||||
or out-of-sync applications are warnings. These are Argo CD's reported states,
|
||||
not a separate endpoint probe. Applications outside Argo CD are not included.
|
||||
|
||||
The Orange Pi K3s service and storage checks are skipped when the selected
|
||||
profile does not put K3s on that host. The cluster scope checks the selected
|
||||
profile, which can be mixed, all-Pimox, or K3s. The OCI scope checks the
|
||||
inventoried edge peer, Compose containers, and public HTTP endpoint; it does not inspect
|
||||
other OCI instances or their cloud lifecycle. HTTP checks do not validate TLS
|
||||
certificates. An SSH warning can indicate an unavailable host, credentials or
|
||||
an untrusted host key. These quick probes are point-in-time observations.
|
||||
|
||||
Existing unscoped options such as `status --json`, `status --deep`,
|
||||
`status --ai`, and `status --heal-plan` retain their existing detailed report
|
||||
and machine-readable behavior. Focused status accepts `--json`, `--details`,
|
||||
`--all`, and `--no-local-rca`.
|
||||
2
jeannie
2
jeannie
|
|
@ -26,6 +26,7 @@ JEANNIE_STEP_TOTAL=0
|
|||
|
||||
# shellcheck disable=SC1091
|
||||
source "${REPO_ROOT}/scripts/report-ui"
|
||||
source "${REPO_ROOT}/scripts/status-focus"
|
||||
source "${REPO_ROOT}/lib/jeannie/core.sh"
|
||||
source "${REPO_ROOT}/lib/jeannie/env.sh"
|
||||
source "${REPO_ROOT}/lib/jeannie/cluster-context.sh"
|
||||
|
|
@ -119,6 +120,7 @@ Cluster Lifecycle
|
|||
|
||||
Operator View And Reports
|
||||
status [--fast|--deep] [--ai] [--all|--details|--verbose|--json] Check health; --deep includes logs and backups.
|
||||
status {all|oci|rpi|opi5|debian|cluster} [--json|--details] Fast inventory-scoped overview.
|
||||
status --heal-plan Build a guarded self-heal plan from status.
|
||||
status --heal Dry-run auto-eligible self-heal actions.
|
||||
scorecard Compact pass/warn/fail operator scorecard.
|
||||
|
|
|
|||
|
|
@ -2298,6 +2298,20 @@ status_report() {
|
|||
|
||||
require_debian_server "status"
|
||||
|
||||
if (($# == 0)); then
|
||||
status_focused_report all
|
||||
return $?
|
||||
fi
|
||||
|
||||
case "${1:-}" in
|
||||
all|oci|rpi|opi5|debian|cluster)
|
||||
local focus="$1"
|
||||
shift
|
||||
status_focused_report "${focus}" "$@"
|
||||
return $?
|
||||
;;
|
||||
esac
|
||||
|
||||
while (($# > 0)); do
|
||||
case "$1" in
|
||||
--fast|--deep)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ mapping = {
|
|||
"services.ollama.igpu_enable": "LAB_OLLAMA_IGPU_ENABLE",
|
||||
"services.rpi_dns.pihole_web_port": "PIHOLE_WEB_PORT",
|
||||
"services.rpi_dns.uptime_kuma_port": "UPTIME_KUMA_PORT",
|
||||
"services.rpi_dns.pihole_dns_port": "LAB_PIHOLE_DNS_PORT",
|
||||
"services.matrix.synapse_port": "LAB_MATRIX_SYNAPSE_PORT",
|
||||
"services.ai_stack.install_dir": "LAB_AI_STACK_INSTALL_DIR",
|
||||
"services.ai_stack.port": "LAB_OMNIROUTE_PORT",
|
||||
"ai_gateway.provider": "LAB_AI_GATEWAY_PROVIDER",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Convert read-only Docker or Argo CD snapshots to status report rows."""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def clean(value):
|
||||
return str(value).replace("\t", " ").replace("\r", " ").replace("\n", " ")
|
||||
|
||||
|
||||
def emit(status, name, detail):
|
||||
print("\t".join(map(clean, (status, name, detail))))
|
||||
|
||||
|
||||
def compose(lines):
|
||||
count = 0
|
||||
for line in lines:
|
||||
if not line.strip():
|
||||
continue
|
||||
item = json.loads(line)
|
||||
labels = dict(part.split("=", 1) for part in item.get("Labels", "").split(",") if "=" in part)
|
||||
if labels.get("com.docker.compose.oneoff", "").lower() == "true":
|
||||
continue
|
||||
project = labels.get("com.docker.compose.project")
|
||||
service = labels.get("com.docker.compose.service")
|
||||
if not project or not service:
|
||||
continue
|
||||
state = item.get("State", "unknown").lower()
|
||||
description = item.get("Status", state)
|
||||
unhealthy = "(unhealthy)" in description.lower() or "(health: starting)" in description.lower()
|
||||
status = "ok" if state == "running" and not unhealthy else "warn"
|
||||
name = item.get("Names", service)
|
||||
emit(status, f"{project}/{service} ({name})", description)
|
||||
count += 1
|
||||
if not count:
|
||||
emit("skip", "Compose services", "No Compose-managed containers found; absent services cannot be assessed")
|
||||
|
||||
|
||||
def applications(document):
|
||||
items = document.get("items")
|
||||
if not isinstance(items, list):
|
||||
raise ValueError("Invalid Kubernetes application list")
|
||||
if not items:
|
||||
emit("skip", "Argo CD applications", "No Argo CD applications found")
|
||||
for app in sorted(items, key=lambda item: item.get("metadata", {}).get("name", "")):
|
||||
metadata, status = app.get("metadata", {}), app.get("status", {})
|
||||
name = metadata.get("name", "unknown")
|
||||
health = status.get("health", {}).get("status", "Unknown")
|
||||
sync = status.get("sync", {}).get("status", "Unknown")
|
||||
if health in ("Degraded", "Missing"):
|
||||
severity = "fail"
|
||||
elif health != "Healthy" or sync != "Synced":
|
||||
severity = "warn"
|
||||
else:
|
||||
severity = "ok"
|
||||
emit(severity, name, f"health={health}, sync={sync}")
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
if len(sys.argv) != 2:
|
||||
raise ValueError("Expected compose or applications")
|
||||
if sys.argv[1] == "compose":
|
||||
compose(sys.stdin)
|
||||
elif sys.argv[1] == "applications":
|
||||
applications(json.load(sys.stdin))
|
||||
else:
|
||||
raise ValueError("Unknown snapshot type")
|
||||
except (ValueError, TypeError, AttributeError) as exc:
|
||||
print(f"Cannot interpret status snapshot: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
#!/usr/bin/env bash
|
||||
# Fast inventory-scoped status checks. Sourced by Jeannie after report-ui.
|
||||
|
||||
status_focus_ssh() {
|
||||
local host="$1" user="$2" key="$3"
|
||||
if [[ -z "${host}" || -z "${user}" ]]; then
|
||||
echo "Host or user is missing from the inventory." >&2
|
||||
return 1
|
||||
fi
|
||||
ssh -n -i "${key}" -o BatchMode=yes -o ConnectTimeout=3 \
|
||||
-o ConnectionAttempts=1 -o StrictHostKeyChecking=yes \
|
||||
"${user}@${host}" true
|
||||
}
|
||||
|
||||
status_focus_edge_peer() {
|
||||
local edge_ip="${LAB_EDGE_TAILSCALE_IP:-}"
|
||||
if [[ -z "${edge_ip}" ]]; then
|
||||
echo "OCI edge Tailscale IP is not configured." >&2
|
||||
return 1
|
||||
fi
|
||||
if ! command -v tailscale >/dev/null 2>&1; then
|
||||
echo "Tailscale client is unavailable." >&2
|
||||
return 1
|
||||
fi
|
||||
timeout 4 tailscale status --json | python3 -c '
|
||||
import json, sys
|
||||
try:
|
||||
status = json.load(sys.stdin)
|
||||
if status.get("BackendState") != "Running":
|
||||
raise ValueError("Debian Tailscale is not running")
|
||||
peer = next((p for p in (status.get("Peer") or {}).values() if sys.argv[1] in (p.get("TailscaleIPs") or [])), None)
|
||||
if peer is None:
|
||||
raise ValueError("OCI edge peer is not visible in the tailnet")
|
||||
if not peer.get("Online"):
|
||||
raise ValueError("OCI edge peer is reported offline")
|
||||
print("OCI edge peer is online")
|
||||
except (ValueError, TypeError, json.JSONDecodeError) as exc:
|
||||
print(str(exc), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
' "${edge_ip}"
|
||||
}
|
||||
|
||||
status_focus_http_ok() {
|
||||
local code
|
||||
code="$(curl -k -sS -o /dev/null -w '%{http_code}' --connect-timeout 2 --max-time 4 "$1")" || return 1
|
||||
[[ "${code}" =~ ^[23][0-9][0-9]$ ]] || { echo "HTTP ${code}" >&2; return 1; }
|
||||
echo "HTTP ${code}"
|
||||
}
|
||||
|
||||
status_focus_dns() {
|
||||
local host="${LAB_RPI_HOST:-}" port="${LAB_PIHOLE_DNS_PORT:-53}"
|
||||
[[ -n "${host}" && "${port}" =~ ^[0-9]+$ ]] && (( 10#${port} >= 1 && 10#${port} <= 65535 )) || {
|
||||
echo "Pi-hole host or DNS port is invalid in the inventory." >&2; return 1;
|
||||
}
|
||||
if command -v dig >/dev/null 2>&1; then
|
||||
local answer
|
||||
answer="$(dig +time=2 +tries=1 +short -p "${port}" @"${host}" example.com A)" || return 1
|
||||
[[ -n "${answer}" ]] || { echo "DNS returned no answer." >&2; return 1; }
|
||||
elif command -v nslookup >/dev/null 2>&1; then
|
||||
nslookup -timeout=2 -retry=1 -port="${port}" example.com "${host}" >/dev/null || return 1
|
||||
else
|
||||
echo "Neither dig nor nslookup is installed." >&2; return 1
|
||||
fi
|
||||
echo "DNS query answered"
|
||||
}
|
||||
|
||||
# One snapshot per host, with one report row for each Compose service instance.
|
||||
status_focus_compose_report() {
|
||||
local area="$1" host="$2" user="$3" key="$4" snapshot rows severity name detail
|
||||
local -a docker_cmd=(sudo -n docker ps -a --filter label=com.docker.compose.project --format '{{json .}}')
|
||||
if [[ "${host}" == local ]]; then
|
||||
snapshot="$(timeout 8 "${docker_cmd[@]}" 2>&1)" || {
|
||||
report_ui_emit warn "${area}" "Compose inventory" "Cannot read Docker containers" "${snapshot}"; return 0;
|
||||
}
|
||||
else
|
||||
if [[ -z "${host}" || -z "${user}" ]]; then
|
||||
report_ui_emit warn "${area}" "Compose inventory" "Host or user missing from inventory" ""; return 0
|
||||
fi
|
||||
snapshot="$(timeout 8 ssh -n -i "${key}" -o BatchMode=yes -o ConnectTimeout=3 \
|
||||
-o ConnectionAttempts=1 -o StrictHostKeyChecking=yes "${user}@${host}" \
|
||||
"sudo -n docker ps -a --filter label=com.docker.compose.project --format '{{json .}}'" 2>&1)" || {
|
||||
report_ui_emit warn "${area}" "Compose inventory" "Cannot read remote Docker containers" "${snapshot}"; return 0;
|
||||
}
|
||||
fi
|
||||
rows="$(printf '%s\n' "${snapshot}" | python3 "${REPO_ROOT}/scripts/status-app-snapshot.py" compose 2>&1)" || {
|
||||
report_ui_emit warn "${area}" "Compose inventory" "Cannot interpret Docker snapshot" "${rows}"; return 0;
|
||||
}
|
||||
while IFS=$'\t' read -r severity name detail; do
|
||||
[[ -n "${severity}" ]] || continue
|
||||
report_ui_emit "${severity}" "${area}" "${name}" "${detail}" "${detail}"
|
||||
done <<<"${rows}"
|
||||
}
|
||||
|
||||
status_focus_applications_report() {
|
||||
local snapshot rows severity name detail failed=0
|
||||
snapshot="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" --request-timeout=8s -n argocd get applications -o json 2>&1)" || {
|
||||
report_ui_emit warn "Kubernetes apps" "Argo CD applications" "Cannot read application status" "${snapshot}"; return 0;
|
||||
}
|
||||
rows="$(printf '%s' "${snapshot}" | python3 "${REPO_ROOT}/scripts/status-app-snapshot.py" applications 2>&1)" || {
|
||||
report_ui_emit warn "Kubernetes apps" "Argo CD applications" "Cannot interpret application status" "${rows}"; return 0;
|
||||
}
|
||||
while IFS=$'\t' read -r severity name detail; do
|
||||
[[ -n "${severity}" ]] || continue
|
||||
report_ui_emit "${severity}" "Kubernetes apps" "${name}" "${detail}" "${detail}"
|
||||
[[ "${severity}" != fail ]] || failed=1
|
||||
done <<<"${rows}"
|
||||
return "${failed}"
|
||||
}
|
||||
|
||||
status_focus_collect() {
|
||||
local scope="$1"
|
||||
local key="${HOME}/.ssh/id_ed25519"
|
||||
local rpi="${LAB_RPI_HOST:-}" rpi_user="${LAB_RPI_USER:-}"
|
||||
local opi="${LAB_PIMOX_HOST:-}" opi_user="${LAB_PIMOX_USER:-}"
|
||||
local public_url="${LAB_PUBLIC_URL:-}"
|
||||
local ollama_url="${LAB_OLLAMA_URL:-http://${LAB_DEBIAN_LAN_IP:-192.168.100.73}:11434}"
|
||||
if [[ "${scope}" == all || "${scope}" == debian ]]; then
|
||||
report_ui_enqueue status_focus_compose_report "Debian Compose" local "" ""
|
||||
report_ui_check fail "Debian" "Docker service" "./jeannie status debian --details" "" "" check_systemd_active docker
|
||||
report_ui_check fail "Debian" "Gitea HTTP" "./jeannie status debian --details" "" "" status_focus_http_ok "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/"
|
||||
report_ui_check warn "Debian" "Dex HTTP" "./jeannie status debian --details" "" "" status_focus_http_ok "http://127.0.0.1:${LAB_DEX_HTTP_PORT:-5556}/healthz"
|
||||
report_ui_check warn "Debian" "Matrix API" "./jeannie status debian --details" "" "" status_focus_http_ok "http://127.0.0.1:${LAB_MATRIX_SYNAPSE_PORT:-8008}/_matrix/client/versions"
|
||||
report_ui_check warn "Debian" "Ollama API" "./jeannie status debian --details" "" "" status_focus_http_ok "${ollama_url%/}/api/tags"
|
||||
report_ui_check warn "Debian" "Disk usage" "./jeannie status debian --details" "" "" status_disk_pressure
|
||||
fi
|
||||
if [[ "${scope}" == all || "${scope}" == rpi ]]; then
|
||||
report_ui_enqueue status_focus_compose_report "RPi4 Compose" "${rpi}" "${rpi_user}" "${LAB_RPI_SSH_KEY_PATH:-${key}}"
|
||||
report_ui_check warn "RPi4" "SSH access" "./jeannie status rpi --details" "" "" status_focus_ssh "${rpi}" "${rpi_user}" "${LAB_RPI_SSH_KEY_PATH:-${key}}"
|
||||
report_ui_check fail "RPi4" "Pi-hole DNS resolution" "./jeannie status rpi --details" "" "" status_focus_dns
|
||||
report_ui_check warn "RPi4" "Uptime Kuma HTTP" "./jeannie status rpi --details" "" "" status_focus_http_ok "http://${rpi}:${UPTIME_KUMA_PORT:-3001}/"
|
||||
fi
|
||||
if [[ "${scope}" == all || "${scope}" == opi5 ]]; then
|
||||
report_ui_enqueue status_focus_compose_report "Orange Pi Compose" "${opi}" "${opi_user}" "${LAB_PIMOX_SSH_KEY_PATH:-${key}}"
|
||||
report_ui_check warn "Orange Pi" "SSH access" "./jeannie status opi5 --details" "" "" status_focus_ssh "${opi}" "${opi_user}" "${LAB_PIMOX_SSH_KEY_PATH:-${key}}"
|
||||
if [[ "${LAB_CLUSTER_RUNTIME:-}" == k3s && "${LAB_CLUSTER_CONTROL_PLANE_LAN_IP:-}" == "${opi}" && -n "${opi}" ]]; then
|
||||
report_ui_check fail "Orange Pi" "K3s runtime" "./jeannie status opi5 --details" "" "" status_cluster_control_runtime
|
||||
report_ui_check warn "Orange Pi" "K3s storage mount" "./jeannie status opi5 --details" "" "" status_cluster_storage
|
||||
else
|
||||
report_ui_emit skip "Orange Pi" "Native K3s checks" "Not selected on this host" "profile=${LAB_CLUSTER_PROFILE:-unknown} runtime=${LAB_CLUSTER_RUNTIME:-unknown}"
|
||||
fi
|
||||
fi
|
||||
if [[ "${scope}" == all || "${scope}" == cluster ]]; then
|
||||
report_ui_enqueue status_focus_applications_report
|
||||
report_ui_check fail "Kubernetes" "API readiness" "./jeannie status cluster --details" "" "" status_kubernetes_api_ok
|
||||
report_ui_check fail "Kubernetes" "Nodes ready" "./jeannie status cluster --details" "" "" status_kubernetes_nodes_ready
|
||||
report_ui_check warn "Kubernetes" "Node pressure" "./jeannie status cluster --details" "" "" status_node_pressure
|
||||
fi
|
||||
if [[ "${scope}" == all || "${scope}" == oci ]]; then
|
||||
report_ui_enqueue status_focus_compose_report "OCI edge Compose" "${LAB_EDGE_TAILSCALE_IP:-}" "${LAB_EDGE_USER:-}" "${LAB_EDGE_SSH_KEY_PATH:-${LAB_OCI_SSH_PRIVATE_KEY:-${key}}}"
|
||||
report_ui_check warn "OCI edge" "Tailscale peer visibility" "./jeannie status oci --details" "" "" status_focus_edge_peer
|
||||
if [[ -n "${public_url}" ]]; then
|
||||
report_ui_check fail "OCI edge" "Public edge HTTP health" "./jeannie status oci --details" "" "" status_focus_http_ok "${public_url%/}/edge-health"
|
||||
else
|
||||
report_ui_emit warn "OCI edge" "Public edge HTTP health" "Public URL missing from inventory" ""
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
status_focused_report() {
|
||||
local scope="$1" rc=0 arg
|
||||
shift
|
||||
# These dynamically scoped variables are consumed by the report helpers.
|
||||
# shellcheck disable=SC2034
|
||||
local REPORT_UI_ONLY=all REPORT_UI_LOCAL_RCA=false REPORT_UI_PARALLEL=true
|
||||
# shellcheck disable=SC2034
|
||||
local LAB_REPORT_PARALLELISM="${LAB_REPORT_PARALLELISM:-8}"
|
||||
for arg in "$@"; do
|
||||
case "${arg}" in
|
||||
--json|--all|--details|--no-local-rca) ;;
|
||||
*) echo "Usage: ./jeannie status ${scope} [--json|--all|--details|--no-local-rca]" >&2; return 2 ;;
|
||||
esac
|
||||
done
|
||||
report_ui_parse_args "$@" || return 2
|
||||
report_ui_begin
|
||||
status_focus_collect "${scope}"
|
||||
report_ui_finish
|
||||
((REPORT_UI_FAILURES == 0)) || rc=1
|
||||
report_ui_render "Jeannie Status: ${scope}"
|
||||
report_ui_cleanup
|
||||
return "${rc}"
|
||||
}
|
||||
|
|
@ -122,6 +122,8 @@ validate_unit_tests() {
|
|||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_progressive_lab.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_ai_lab.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_ai_lab_suite.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_status_focus.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_status_app_snapshot.py'
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "status-app-snapshot.py"
|
||||
|
||||
|
||||
def parse(kind, data):
|
||||
return subprocess.run([sys.executable, str(SCRIPT), kind], input=data,
|
||||
capture_output=True, text=True, check=True).stdout
|
||||
|
||||
|
||||
class ApplicationSnapshotTests(unittest.TestCase):
|
||||
def test_compose_services_distinguish_health_and_oneoff_jobs(self):
|
||||
def container(name, state, status, oneoff="False"):
|
||||
return json.dumps({"Names": name, "State": state, "Status": status,
|
||||
"Labels": "com.docker.compose.project=lab,"
|
||||
"com.docker.compose.service=" + name + ","
|
||||
"com.docker.compose.oneoff=" + oneoff})
|
||||
data = "\n".join((container("web", "running", "Up 5 minutes (healthy)"),
|
||||
container("db", "running", "Up 2 minutes (unhealthy)"),
|
||||
container("worker", "exited", "Exited (0)"),
|
||||
container("job", "exited", "Exited (0)", "True")))
|
||||
result = parse("compose", data)
|
||||
self.assertIn("ok\tlab/web (web)", result)
|
||||
self.assertIn("warn\tlab/db (db)", result)
|
||||
self.assertIn("warn\tlab/worker (worker)", result)
|
||||
self.assertNotIn("lab/job", result)
|
||||
|
||||
def test_argocd_applications_report_health_and_sync(self):
|
||||
def app(name, health, sync):
|
||||
return {"metadata": {"name": name}, "status": {
|
||||
"health": {"status": health}, "sync": {"status": sync}}}
|
||||
result = parse("applications", json.dumps({"items": [
|
||||
app("healthy", "Healthy", "Synced"),
|
||||
app("updating", "Progressing", "Synced"),
|
||||
app("broken", "Degraded", "OutOfSync")]}))
|
||||
self.assertIn("ok\thealthy\t", result)
|
||||
self.assertIn("warn\tupdating\t", result)
|
||||
self.assertIn("fail\tbroken\t", result)
|
||||
|
||||
def test_empty_snapshot_does_not_claim_apps_are_healthy(self):
|
||||
self.assertIn("skip\tCompose services\t", parse("compose", ""))
|
||||
self.assertIn("skip\tArgo CD applications\t", parse("applications", '{"items":[]}'))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
"""Exercise selection and profile logic without contacting homelab hosts."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPT = ROOT / "scripts" / "status-focus"
|
||||
|
||||
|
||||
def collect(scope, **overrides):
|
||||
env = os.environ.copy()
|
||||
env.update(
|
||||
HOME="/tmp/test-home",
|
||||
LAB_RPI_HOST="192.0.2.4",
|
||||
LAB_RPI_USER="pi",
|
||||
LAB_PIMOX_HOST="192.0.2.5",
|
||||
LAB_PIMOX_USER="opi",
|
||||
LAB_CLUSTER_CONTROL_PLANE_LAN_IP="192.0.2.5",
|
||||
LAB_CLUSTER_RUNTIME="k3s",
|
||||
LAB_CLUSTER_PROFILE="k3s",
|
||||
LAB_PUBLIC_URL="https://example.com",
|
||||
LAB_MATRIX_SYNAPSE_PORT="8808",
|
||||
)
|
||||
env.update(overrides)
|
||||
code = r'''
|
||||
source "$1"
|
||||
report_ui_check() { printf '%s|%s|%s\n' "$2" "$3" "${*:7}"; }
|
||||
report_ui_emit() { printf '%s|%s|%s\n' "$2" "$3" "$1"; }
|
||||
report_ui_enqueue() {
|
||||
case "$1" in
|
||||
status_focus_compose_report) printf '%s|Compose snapshot|%s\n' "$2" "$3" ;;
|
||||
status_focus_applications_report) printf 'Kubernetes apps|Application snapshot|queued\n' ;;
|
||||
esac
|
||||
}
|
||||
status_focus_collect "$2"
|
||||
'''
|
||||
return subprocess.run(
|
||||
["bash", "-c", code, "test", str(SCRIPT), scope],
|
||||
env=env, text=True, capture_output=True, check=True,
|
||||
).stdout
|
||||
|
||||
|
||||
class FocusedStatusTests(unittest.TestCase):
|
||||
def test_scopes_do_not_collect_other_hosts(self):
|
||||
for scope, groups in (("debian", {"Debian", "Debian Compose"}),
|
||||
("rpi", {"RPi4", "RPi4 Compose"}),
|
||||
("opi5", {"Orange Pi", "Orange Pi Compose"}),
|
||||
("oci", {"OCI edge", "OCI edge Compose"}),
|
||||
("cluster", {"Kubernetes", "Kubernetes apps"})):
|
||||
with self.subTest(scope=scope):
|
||||
lines = collect(scope).splitlines()
|
||||
self.assertTrue(lines)
|
||||
self.assertEqual({line.split("|")[0] for line in lines}, groups)
|
||||
|
||||
def test_all_covers_each_area_and_inventory_matrix_port(self):
|
||||
result = collect("all")
|
||||
self.assertEqual({line.split("|")[0] for line in result.splitlines()},
|
||||
{"Debian", "RPi4", "Orange Pi", "OCI edge", "Kubernetes",
|
||||
"Debian Compose", "RPi4 Compose", "Orange Pi Compose",
|
||||
"OCI edge Compose", "Kubernetes apps"})
|
||||
self.assertIn("127.0.0.1:8808/_matrix/client/versions", result)
|
||||
self.assertIn("https://example.com/edge-health", result)
|
||||
|
||||
def test_k3s_checks_only_for_selected_orange_pi_runtime(self):
|
||||
self.assertIn("Orange Pi|K3s runtime|", collect("opi5"))
|
||||
for overrides in ({"LAB_CLUSTER_RUNTIME": "kubeadm"},
|
||||
{"LAB_CLUSTER_CONTROL_PLANE_LAN_IP": "192.0.2.9"}):
|
||||
with self.subTest(overrides=overrides):
|
||||
result = collect("opi5", **overrides)
|
||||
self.assertIn("Orange Pi|Native K3s checks|skip", result)
|
||||
self.assertNotIn("Orange Pi|K3s runtime|", result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue