Accept validated PostgreSQL self-restart demotion
This commit is contained in:
@@ -27,6 +27,7 @@ python3 ./tests/test-proxy-client-parameters.py
|
||||
./tests/test-notify-daemon-shadow.sh
|
||||
./tests/test-notify-target-shadow.sh
|
||||
./tests/test-demote-database-shadow.sh
|
||||
./tests/test-demote-database-response-matrix.sh
|
||||
./tests/test-promote-database-shadow.sh
|
||||
./tests/test-demote-database-gate.sh
|
||||
./tests/test-promote-database-gate.sh
|
||||
|
||||
+118
@@ -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"
|
||||
Reference in New Issue
Block a user