Handle PostgreSQL self-restart demotion preflight
This commit is contained in:
@@ -137,3 +137,56 @@ assert result["reason"] == "successor_unreachable"
|
||||
print("successor_unreachable rejected")
|
||||
|
||||
print("DEMOTE_DATABASE_FAILURE_TEST_PASS=1")
|
||||
|
||||
print()
|
||||
print("===== SELF-RESTART DATABASE GATE =====")
|
||||
|
||||
plugin.monitor = lambda config, runtime_state: {
|
||||
"ha": {"ocf_rc": plugin.OCF_RUNNING_PROMOTED},
|
||||
"primary": {"current_wal_lsn": "14/1C07A920"},
|
||||
}
|
||||
|
||||
self_restart_state = {
|
||||
"postgresql": {
|
||||
"notification": {
|
||||
"type": "pre",
|
||||
"operation": "demote",
|
||||
"demote_uname": "david-prodesk",
|
||||
"promote_uname": "david-prodesk",
|
||||
"promoted_uname": "david-prodesk",
|
||||
"unpromoted_uname": "david-eve",
|
||||
"received_at": time.time(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
connect_called = False
|
||||
|
||||
def must_not_connect(**kwargs):
|
||||
global connect_called
|
||||
connect_called = True
|
||||
raise AssertionError(
|
||||
"self-restart demotion must not probe a remote successor"
|
||||
)
|
||||
|
||||
plugin.psycopg2.connect = must_not_connect
|
||||
|
||||
result = plugin.demote_database(
|
||||
config,
|
||||
self_restart_state,
|
||||
{},
|
||||
)
|
||||
|
||||
assert result["ocf_rc"] == 0
|
||||
assert result["ready"] is True
|
||||
assert result["mutation"] is False
|
||||
assert result["final_handoff_required"] is False
|
||||
assert result["handoff_mode"] == "local_restart"
|
||||
assert result["reason"] == "local_restart_demotion_ready"
|
||||
assert result["successor_node"] == "david-prodesk"
|
||||
assert result["checks"]["local_primary"] is True
|
||||
assert result["checks"]["remote_handoff_required"] is False
|
||||
assert connect_called is False
|
||||
|
||||
print("self_restart_database accepted")
|
||||
print("remote_probe_skipped accepted")
|
||||
|
||||
Reference in New Issue
Block a user