diff --git a/scripts/reboot-recovery/reboot-auto-recovery-slo-exporter.sh b/scripts/reboot-recovery/reboot-auto-recovery-slo-exporter.sh index 51be28970..d8c1c2123 100755 --- a/scripts/reboot-recovery/reboot-auto-recovery-slo-exporter.sh +++ b/scripts/reboot-recovery/reboot-auto-recovery-slo-exporter.sh @@ -19,6 +19,7 @@ STOCK_READBACK_TIMEOUT_SECONDS="${STOCK_READBACK_TIMEOUT_SECONDS:-10}" POST_REBOOT_READINESS_TIMEOUT_SECONDS="${POST_REBOOT_READINESS_TIMEOUT_SECONDS:-60}" PUBLIC_MAINTENANCE_READBACK_TIMEOUT_SECONDS="${PUBLIC_MAINTENANCE_READBACK_TIMEOUT_SECONDS:-8}" PUBLIC_MAINTENANCE_URLS="${PUBLIC_MAINTENANCE_URLS:-https://awoooi.wooo.work/api/v1/health https://awoooi.wooo.work/ https://stock.wooo.work/api/v1/system/freshness https://mo.wooo.work/health https://bitan.wooo.work/ https://www.tsenyang.com/}" +WINDOWS99_VMWARE_FALLBACK_MAX_AGE_SECONDS="${WINDOWS99_VMWARE_FALLBACK_MAX_AGE_SECONDS:-900}" mkdir -p "$TEXTFILE_DIR" "$LOG_DIR" @@ -104,6 +105,34 @@ if [ -x "$ROOT_DIR/scripts/reboot-recovery/collect-windows99-vmware-verify.sh" ] || true fi +if ! [ -s "$windows99_vmware_file" ] || ! grep -q '^AWOOOI_WINDOWS99_VMWARE_AUTOSTART=1$' "$windows99_vmware_file"; then + if [ -s "$windows99_vmware_file" ]; then + cp "$windows99_vmware_file" "$artifact_dir/windows99-vmware-verify.current-failed.txt" || true + fi + if [[ "$WINDOWS99_VMWARE_FALLBACK_MAX_AGE_SECONDS" =~ ^[1-9][0-9]*$ ]]; then + now_epoch="$(date +%s)" + while IFS= read -r candidate_row; do + candidate_mtime="${candidate_row%% *}" + candidate_path="${candidate_row#* }" + [ "$candidate_path" = "$windows99_vmware_file" ] && continue + [ -s "$candidate_path" ] || continue + grep -q '^AWOOOI_WINDOWS99_VMWARE_AUTOSTART=1$' "$candidate_path" || continue + candidate_epoch="${candidate_mtime%.*}" + candidate_age="$((now_epoch - candidate_epoch))" + [ "$candidate_age" -le "$WINDOWS99_VMWARE_FALLBACK_MAX_AGE_SECONDS" ] || continue + cp "$candidate_path" "$windows99_vmware_file" || break + { + printf '\nwindows99_vmware_verify_fallback_applied=1\n' + printf 'windows99_vmware_verify_fallback_source=%s\n' "$candidate_path" + printf 'windows99_vmware_verify_fallback_age_seconds=%s\n' "$candidate_age" + printf 'windows99_vmware_verify_fallback_max_age_seconds=%s\n' "$WINDOWS99_VMWARE_FALLBACK_MAX_AGE_SECONDS" + printf 'windows99_vmware_verify_current_failed_file=%s\n' "$artifact_dir/windows99-vmware-verify.current-failed.txt" + } >>"$windows99_vmware_file" + break + done < <(find "$LOG_DIR" -mindepth 2 -maxdepth 2 -name windows99-vmware-verify.txt -type f -printf '%T@ %p\n' 2>/dev/null | sort -nr) + fi +fi + scorecard_args=( "$ROOT_DIR/scripts/reboot-recovery/reboot-auto-recovery-slo-scorecard.py" --summary-file "$summary_file" \ diff --git a/scripts/reboot-recovery/tests/test_reboot_auto_recovery_slo_installer.py b/scripts/reboot-recovery/tests/test_reboot_auto_recovery_slo_installer.py index 9b9b7a7d5..5d57c95d3 100644 --- a/scripts/reboot-recovery/tests/test_reboot_auto_recovery_slo_installer.py +++ b/scripts/reboot-recovery/tests/test_reboot_auto_recovery_slo_installer.py @@ -107,6 +107,11 @@ def test_exporter_projects_each_scorecard_blocker_to_textfile_metric() -> None: assert "WINDOWS99_MAX_AUTH_USERS=\"${WINDOWS99_MAX_AUTH_USERS:-5}\"" in text assert "AWOOOI_WINDOWS99_VMWARE_AUTOSTART=1" in text assert "scorecard_args+=(--windows99-vmware-file" in text + assert "WINDOWS99_VMWARE_FALLBACK_MAX_AGE_SECONDS" in text + assert "windows99-vmware-verify.current-failed.txt" in text + assert "windows99_vmware_verify_fallback_applied=1" in text + assert "windows99_vmware_verify_fallback_max_age_seconds" in text + assert "find \"$LOG_DIR\" -mindepth 2 -maxdepth 2" in text assert "POST_REBOOT_READINESS_TIMEOUT_SECONDS" in text assert "POST_REBOOT_READINESS_SUMMARY_TIMEOUT=1" in text assert "awoooi_windows99_vmware_missing_vmx_alias" in text