Accept validated PostgreSQL self-restart demotion

This commit is contained in:
Lyncoln
2026-09-18 09:43:41 -04:00
parent 798aa40ae5
commit 3937de82dc
4 changed files with 139 additions and 8 deletions
+118
View File
@@ -0,0 +1,118 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
FILE="$ROOT/ocf/loxthelion/managed-container.d/applications/postgresql/native_peers.sh"
FAKE="$(mktemp)"
cleanup()
{
rm -f "$FAKE"
}
trap cleanup EXIT
ocf_log()
{
:
}
export OCF_RESOURCE_INSTANCE=postgresql-ha
export MC_PROXY_CLIENT="$FAKE"
export MC_DEMOTE_DATABASE_GATE=true
# shellcheck disable=SC1090
. "$FILE"
write_response()
{
cat > "$FAKE"
chmod 0755 "$FAKE"
}
echo "===== REMOTE HANDOFF ====="
write_response <<'PY'
import json
print(json.dumps({
"ocf_rc": 0,
"ready": True,
"mutation": False,
"final_handoff_required": True,
"reason": "demotion_preflight_ready",
}))
PY
if ! mc_pg_demote_database_shadow; then
echo "FAIL: valid remote handoff response was rejected"
exit 1
fi
echo "remote_handoff accepted"
echo
echo "===== LOCAL RESTART ====="
write_response <<'PY'
import json
print(json.dumps({
"ocf_rc": 0,
"ready": True,
"mutation": False,
"final_handoff_required": False,
"handoff_mode": "local_restart",
"reason": "local_restart_demotion_ready",
}))
PY
if ! mc_pg_demote_database_shadow; then
echo "FAIL: valid local restart response was rejected"
exit 1
fi
echo "local_restart accepted"
echo
echo "===== ARBITRARY FALSE HANDOFF ====="
write_response <<'PY'
import json
print(json.dumps({
"ocf_rc": 0,
"ready": True,
"mutation": False,
"final_handoff_required": False,
}))
PY
if mc_pg_demote_database_shadow; then
echo "FAIL: arbitrary final_handoff_required=false was accepted"
exit 1
fi
echo "arbitrary_false rejected"
echo
echo "===== FAKE LOCAL RESTART ====="
write_response <<'PY'
import json
print(json.dumps({
"ocf_rc": 0,
"ready": True,
"mutation": False,
"final_handoff_required": False,
"handoff_mode": "local_restart",
"reason": "wrong_reason",
}))
PY
if mc_pg_demote_database_shadow; then
echo "FAIL: fake local restart response was accepted"
exit 1
fi
echo "fake_local_restart rejected"
echo
echo "DEMOTE_DATABASE_RESPONSE_MATRIX_TEST_PASS=1"