Author SHA1 Message Date
Lyncoln 3937de82dc Accept validated PostgreSQL self-restart demotion 2026-09-18 09:43:41 -04:00
4 changed files with 139 additions and 8 deletions
+3 -2
View File
@@ -2,7 +2,7 @@
5aa02fa065d1dba55486838fa4f0cd8eba982edaaf73cdc7d818223a09cbadc6 ocf/loxthelion/managed-container 5aa02fa065d1dba55486838fa4f0cd8eba982edaaf73cdc7d818223a09cbadc6 ocf/loxthelion/managed-container
10932919c4339b553c7c9dbf30b45a917c51c0a08f362e12678003d58b12fa82 ocf/loxthelion/managed-container.d/applications/postgresql/auth.sh 10932919c4339b553c7c9dbf30b45a917c51c0a08f362e12678003d58b12fa82 ocf/loxthelion/managed-container.d/applications/postgresql/auth.sh
61d64b4a3a15c354f101ef34c5dc0425723f4204207d359b5377d2b9f04f6b23 ocf/loxthelion/managed-container.d/applications/postgresql/demote.sh 61d64b4a3a15c354f101ef34c5dc0425723f4204207d359b5377d2b9f04f6b23 ocf/loxthelion/managed-container.d/applications/postgresql/demote.sh
e111dfe454a6e1edd80edc0c303119e045e7c88fe77b69a2745e58a022d0d317 ocf/loxthelion/managed-container.d/applications/postgresql/native_peers.sh 86bb5bacd27e4082a7f753108c1f5d5e777ff04fba8699d62ed148c17224abdf ocf/loxthelion/managed-container.d/applications/postgresql/native_peers.sh
bcfde96b98f4727a8c97d42a39b7c6ec925b1b89d17ef67cc58eb7bd67afbfae ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh bcfde96b98f4727a8c97d42a39b7c6ec925b1b89d17ef67cc58eb7bd67afbfae ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh
957a5a72ed277d0216e070abb80733483be3d421b9fa488e27fdd75bb2919548 ocf/loxthelion/managed-container.d/applications/postgresql/peer_config.sh 957a5a72ed277d0216e070abb80733483be3d421b9fa488e27fdd75bb2919548 ocf/loxthelion/managed-container.d/applications/postgresql/peer_config.sh
286d282565239bdb600563bac116575f3f56580e06f8f8df86c1a0fd0af96f07 ocf/loxthelion/managed-container.d/applications/postgresql/plugin.sh 286d282565239bdb600563bac116575f3f56580e06f8f8df86c1a0fd0af96f07 ocf/loxthelion/managed-container.d/applications/postgresql/plugin.sh
@@ -23,9 +23,10 @@ a42bb59a058ffeb59c1baa96e403856910bbbaea98f9104ff93daf4b5970c780 postgres-host/
957a5a72ed277d0216e070abb80733483be3d421b9fa488e27fdd75bb2919548 postgres-host/postgres-ha-peer-config.sh 957a5a72ed277d0216e070abb80733483be3d421b9fa488e27fdd75bb2919548 postgres-host/postgres-ha-peer-config.sh
deb09e3ae40629f43b262ba4f9a7ebf59a1dca3da9d8c94478f670aea28bd0e1 quadlet/postgres.container deb09e3ae40629f43b262ba4f9a7ebf59a1dca3da9d8c94478f670aea28bd0e1 quadlet/postgres.container
04a125068677bbee6e71d313ca9d95d35faa32851b79de781cd7b9f466561445 quadlet/postgres.env.example 04a125068677bbee6e71d313ca9d95d35faa32851b79de781cd7b9f466561445 quadlet/postgres.env.example
186c2350d1f4eaddd756fbc680319ce2bfb7ee3462cf1d421f549ba8ccca8d24 tests/run-all.sh ad248df2911e87fbe456c095f4e30dd54b2da52c9e2efa0619d3a2bf16a0f30c tests/run-all.sh
a373c0560391a2d8f63c3ba31609ab16b219d9b532b4ab9f8aea6dc45de10555 tests/test-demote-database-gate.sh a373c0560391a2d8f63c3ba31609ab16b219d9b532b4ab9f8aea6dc45de10555 tests/test-demote-database-gate.sh
688eeb756c7f346e7e55acc555004ba12b48bc7c3d309073658d5e84a6e5e348 tests/test-demote-database-parameter.sh 688eeb756c7f346e7e55acc555004ba12b48bc7c3d309073658d5e84a6e5e348 tests/test-demote-database-parameter.sh
a3b3b2dad6bfdab8ffc7b3cabc6e1b9f188ff743fcadf073e5e8bdcf1827b2b9 tests/test-demote-database-response-matrix.sh
22d3eb56e8cd3ae1a58e2616f44abd3818f79d7e5df55c1c158e36dca7c77f42 tests/test-demote-database-shadow.sh 22d3eb56e8cd3ae1a58e2616f44abd3818f79d7e5df55c1c158e36dca7c77f42 tests/test-demote-database-shadow.sh
5e5d4fdd2b6c7e0b8b146de7aad06c1f96b221a10fec525b00d40e0d85709fb0 tests/test-entrypoint-structure.sh 5e5d4fdd2b6c7e0b8b146de7aad06c1f96b221a10fec525b00d40e0d85709fb0 tests/test-entrypoint-structure.sh
2faee72cf2fdcbfa667c3e1c2a7aabc053b96a9b8127ff7440ddb717fd2dc314 tests/test-notify-daemon-shadow.sh 2faee72cf2fdcbfa667c3e1c2a7aabc053b96a9b8127ff7440ddb717fd2dc314 tests/test-notify-daemon-shadow.sh
@@ -71,12 +71,23 @@ import os
response = json.loads(os.environ["MC_DAEMON_RESPONSE"]) response = json.loads(os.environ["MC_DAEMON_RESPONSE"])
if ( common_valid = (
response.get("ocf_rc") != 0 response.get("ocf_rc") == 0
or response.get("ready") is not True and response.get("ready") is True
or response.get("mutation") is not False and response.get("mutation") is False
or response.get("final_handoff_required") is not True )
):
peer_handoff = (
response.get("final_handoff_required") is True
)
local_restart = (
response.get("final_handoff_required") is False
and response.get("handoff_mode") == "local_restart"
and response.get("reason") == "local_restart_demotion_ready"
)
if not common_valid or not (peer_handoff or local_restart):
raise SystemExit(1) raise SystemExit(1)
'; then '; then
ocf_log info \ ocf_log info \
+1
View File
@@ -27,6 +27,7 @@ python3 ./tests/test-proxy-client-parameters.py
./tests/test-notify-daemon-shadow.sh ./tests/test-notify-daemon-shadow.sh
./tests/test-notify-target-shadow.sh ./tests/test-notify-target-shadow.sh
./tests/test-demote-database-shadow.sh ./tests/test-demote-database-shadow.sh
./tests/test-demote-database-response-matrix.sh
./tests/test-promote-database-shadow.sh ./tests/test-promote-database-shadow.sh
./tests/test-demote-database-gate.sh ./tests/test-demote-database-gate.sh
./tests/test-promote-database-gate.sh ./tests/test-promote-database-gate.sh
+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"