feat(api): expose reboot drill preflight
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 20s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 20s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
This commit is contained in:
183
apps/api/src/services/reboot_auto_recovery_drill_preflight.py
Normal file
183
apps/api/src/services/reboot_auto_recovery_drill_preflight.py
Normal file
@@ -0,0 +1,183 @@
|
||||
"""P0-006 reboot drill preflight readback.
|
||||
|
||||
This service turns the remaining fresh-boot-window blocker into a machine
|
||||
readable preflight package. It does not reboot hosts, restart services, trigger
|
||||
workflows, or write runtime state.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from src.services.reboot_auto_recovery_slo_scorecard import (
|
||||
load_latest_reboot_auto_recovery_slo_scorecard,
|
||||
)
|
||||
|
||||
_API_SCHEMA_VERSION = "reboot_auto_recovery_drill_preflight_readback_v1"
|
||||
_FRESH_BOOT_BLOCKER = "host_boot_observation_older_than_target_window"
|
||||
|
||||
|
||||
def load_latest_reboot_auto_recovery_drill_preflight(
|
||||
operations_dir: Path | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Build a read-only drill preflight contract from the latest scorecard."""
|
||||
scorecard = load_latest_reboot_auto_recovery_slo_scorecard(operations_dir)
|
||||
return _build_payload(scorecard)
|
||||
|
||||
|
||||
def _build_payload(scorecard: dict[str, Any]) -> dict[str, Any]:
|
||||
host_boot = _dict(scorecard.get("host_boot_detection"))
|
||||
rollups = _dict(scorecard.get("rollups"))
|
||||
operation_boundaries = _dict(scorecard.get("operation_boundaries"))
|
||||
active_blockers = _strings(scorecard.get("active_blockers"))
|
||||
required_hosts = _strings(host_boot.get("required_hosts"))
|
||||
target_minutes = _int(_dict(scorecard.get("readback")).get("target_minutes"))
|
||||
target_seconds = target_minutes * 60
|
||||
|
||||
preconditions = {
|
||||
"source_controls_present": _dict(scorecard.get("required_checks")).get(
|
||||
"source_controls_present"
|
||||
)
|
||||
is True,
|
||||
"service_green": scorecard.get("service_green") is True,
|
||||
"product_data_green": scorecard.get("product_data_green") is True,
|
||||
"backup_core_green": scorecard.get("backup_core_green") is True,
|
||||
"host_188_service_green": scorecard.get("host_188_service_green") is True,
|
||||
"all_required_hosts_observed": _int(scorecard.get("observed_host_count"))
|
||||
== len(required_hosts)
|
||||
and _int(scorecard.get("missing_host_count")) == 0,
|
||||
"all_required_hosts_reachable": _int(scorecard.get("unreachable_host_count"))
|
||||
== 0,
|
||||
"latest_verify_only_metric_present": scorecard.get(
|
||||
"latest_verify_only_metric_present"
|
||||
)
|
||||
is True,
|
||||
"stockplatform_freshness_ok": scorecard.get("stockplatform_freshness_status")
|
||||
== "ok",
|
||||
"stockplatform_ingestion_ok": scorecard.get("stockplatform_ingestion_status")
|
||||
== "ok",
|
||||
"blocked_only_by_fresh_reboot_window": active_blockers == [_FRESH_BOOT_BLOCKER],
|
||||
}
|
||||
preflight_ready = all(preconditions.values())
|
||||
blocker_count = sum(1 for value in preconditions.values() if not value)
|
||||
status = (
|
||||
"ready_for_break_glass_reboot_drill_authorization"
|
||||
if preflight_ready
|
||||
else "blocked_reboot_drill_preflight_not_ready"
|
||||
)
|
||||
return {
|
||||
"schema_version": _API_SCHEMA_VERSION,
|
||||
"generated_at": str(scorecard.get("generated_at") or ""),
|
||||
"priority": "P0-006",
|
||||
"scope": "reboot_auto_recovery_drill_preflight",
|
||||
"status": status,
|
||||
"preflight_ready": preflight_ready,
|
||||
"preflight_blocker_count": blocker_count,
|
||||
"break_glass_authorization_required": True,
|
||||
"execution_authorized_by_this_endpoint": False,
|
||||
"safe_next_step": (
|
||||
"collect_separate_reboot_drill_authorization_or_wait_for_next_"
|
||||
"real_all_host_reboot_event_then_rerun_verify_only"
|
||||
),
|
||||
"target_selector": {
|
||||
"scope": "awoooi_p0_reboot_slo_hosts",
|
||||
"required_host_aliases": required_hosts,
|
||||
"required_host_count": len(required_hosts),
|
||||
"observed_host_count": _int(scorecard.get("observed_host_count")),
|
||||
"missing_host_count": _int(scorecard.get("missing_host_count")),
|
||||
"unreachable_host_count": _int(scorecard.get("unreachable_host_count")),
|
||||
"stale_host_count": _int(scorecard.get("stale_host_count")),
|
||||
"selector_source": "P0-006 committed reboot auto-recovery scorecard",
|
||||
},
|
||||
"preconditions": preconditions,
|
||||
"current_readback": {
|
||||
"scorecard_status": str(scorecard.get("status") or ""),
|
||||
"readiness_percent": _int(scorecard.get("readiness_percent")),
|
||||
"active_blocker_count": _int(scorecard.get("active_blocker_count")),
|
||||
"active_blockers": active_blockers,
|
||||
"service_green": scorecard.get("service_green") is True,
|
||||
"product_data_green": scorecard.get("product_data_green") is True,
|
||||
"backup_core_green": scorecard.get("backup_core_green") is True,
|
||||
"post_start_blocked": _int(rollups.get("post_start_blocked")),
|
||||
"latest_verify_only_metric_ready": _int(
|
||||
scorecard.get("latest_verify_only_metric_ready")
|
||||
),
|
||||
"latest_verify_only_metric_blocker_count": _int(
|
||||
scorecard.get("latest_verify_only_metric_blocker_count")
|
||||
),
|
||||
"latest_verify_only_metric_max_host_uptime_seconds": _int(
|
||||
scorecard.get("latest_verify_only_metric_max_host_uptime_seconds")
|
||||
),
|
||||
"stockplatform_freshness_status": str(
|
||||
scorecard.get("stockplatform_freshness_status") or ""
|
||||
),
|
||||
"stockplatform_ingestion_status": str(
|
||||
scorecard.get("stockplatform_ingestion_status") or ""
|
||||
),
|
||||
},
|
||||
"check_mode": {
|
||||
"verify_only_available": True,
|
||||
"verify_only_source": (
|
||||
"scripts/reboot-recovery/reboot-auto-recovery-slo-scorecard.py"
|
||||
),
|
||||
"post_apply_verifier_endpoint": (
|
||||
"/api/v1/agents/reboot-auto-recovery-slo-scorecard"
|
||||
),
|
||||
"expected_after_real_fresh_boot_or_approved_drill": {
|
||||
"status": "slo_ready",
|
||||
"active_blocker_count": 0,
|
||||
"latest_verify_only_metric_ready": 1,
|
||||
"latest_verify_only_metric_blocker_count": 0,
|
||||
"max_host_uptime_seconds_lte": target_seconds,
|
||||
},
|
||||
},
|
||||
"rollback_plan": {
|
||||
"preflight_is_read_only": True,
|
||||
"rollback_required_for_this_endpoint": False,
|
||||
"if_separately_approved_drill_fails": [
|
||||
"stop further reboot waves",
|
||||
"run post-reboot readiness summary",
|
||||
"keep startup recovery units as the recovery source of truth",
|
||||
"rerun SLO verify-only and expose blockers without manual DB writes",
|
||||
],
|
||||
},
|
||||
"operation_boundaries": {
|
||||
**operation_boundaries,
|
||||
"host_reboot_authorized_by_this_endpoint": False,
|
||||
"host_reboot_performed": False,
|
||||
"service_restart_performed": False,
|
||||
"database_write_or_restore_performed": False,
|
||||
"workflow_trigger_performed": False,
|
||||
"secret_value_collection_allowed": False,
|
||||
"github_api_used": False,
|
||||
"runtime_write_allowed": False,
|
||||
},
|
||||
"forbidden_without_separate_break_glass": [
|
||||
"host_reboot",
|
||||
"node_drain",
|
||||
"service_restart",
|
||||
"database_write_or_restore",
|
||||
"firewall_cutover",
|
||||
"workflow_dispatch",
|
||||
"secret_or_token_read",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def _dict(value: Any) -> dict[str, Any]:
|
||||
return value if isinstance(value, dict) else {}
|
||||
|
||||
|
||||
def _int(value: Any) -> int:
|
||||
if isinstance(value, bool):
|
||||
return int(value)
|
||||
if isinstance(value, int | float):
|
||||
return int(value)
|
||||
return 0
|
||||
|
||||
|
||||
def _strings(value: Any) -> list[str]:
|
||||
if not isinstance(value, list):
|
||||
return []
|
||||
return [str(item) for item in value if item is not None]
|
||||
Reference in New Issue
Block a user