Handle demotion gate transport failures safely
This commit is contained in:
@@ -3,9 +3,59 @@ set -euo pipefail
|
||||
|
||||
ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
|
||||
FILE="$ROOT/ocf/loxthelion/managed-container.d/applications/postgresql/native_peers.sh"
|
||||
FAKE="$(mktemp)"
|
||||
|
||||
grep -q 'MC_DEMOTE_DATABASE_GATE' "$FILE"
|
||||
grep -q 'gate rejected demotion' "$FILE"
|
||||
grep -q 'if ! mc_pg_demote_database_shadow' "$FILE"
|
||||
cleanup()
|
||||
{
|
||||
rm -f "$FAKE"
|
||||
}
|
||||
|
||||
echo "DEMOTE_DATABASE_GATE_TEST_PASS=1"
|
||||
trap cleanup EXIT
|
||||
|
||||
ocf_log()
|
||||
{
|
||||
:
|
||||
}
|
||||
|
||||
export OCF_RESOURCE_INSTANCE=postgresql-ha
|
||||
export MC_PROXY_CLIENT="$FAKE"
|
||||
|
||||
cat > "$FAKE" <<'EOF'
|
||||
import json
|
||||
print(json.dumps({
|
||||
"ocf_rc": 1,
|
||||
"ready": False,
|
||||
"mutation": False,
|
||||
}))
|
||||
EOF
|
||||
chmod 0755 "$FAKE"
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
. "$FILE"
|
||||
|
||||
unset MC_DEMOTE_DATABASE_GATE
|
||||
mc_pg_demote_database_shadow
|
||||
|
||||
export MC_DEMOTE_DATABASE_GATE=true
|
||||
|
||||
if mc_pg_demote_database_shadow; then
|
||||
echo "FAIL: mismatch was not gated"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat > "$FAKE" <<'EOF'
|
||||
raise SystemExit(10)
|
||||
EOF
|
||||
chmod 0755 "$FAKE"
|
||||
|
||||
unset MC_DEMOTE_DATABASE_GATE
|
||||
mc_pg_demote_database_shadow
|
||||
|
||||
export MC_DEMOTE_DATABASE_GATE=true
|
||||
|
||||
if mc_pg_demote_database_shadow; then
|
||||
echo "FAIL: transport failure was not gated"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "DEMOTE_DATABASE_GATE_RUNTIME_TEST_PASS=1"
|
||||
|
||||
Reference in New Issue
Block a user