Add read-only PostgreSQL notification target action
This commit is contained in:
Executable
+80
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
import time
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
fake_psycopg2 = types.ModuleType("psycopg2")
|
||||
fake_psycopg2.Error = Exception
|
||||
fake_psycopg2.OperationalError = OSError
|
||||
|
||||
fake_extras = types.ModuleType("psycopg2.extras")
|
||||
fake_extras.RealDictCursor = object
|
||||
fake_psycopg2.extras = fake_extras
|
||||
|
||||
sys.modules["psycopg2"] = fake_psycopg2
|
||||
sys.modules["psycopg2.extras"] = fake_extras
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"postgresql_plugin",
|
||||
Path("plugins/postgresql/plugin.py"),
|
||||
)
|
||||
plugin = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(plugin)
|
||||
|
||||
|
||||
def require(condition, message):
|
||||
if not condition:
|
||||
raise SystemExit("FAIL: " + message)
|
||||
|
||||
|
||||
print("===== NOTIFY TARGET ACTION =====")
|
||||
|
||||
config = {
|
||||
"PACEMAKER_NODE_NAME": "david-macbookpro",
|
||||
}
|
||||
|
||||
runtime_state = {
|
||||
"postgresql": {
|
||||
"notification": {
|
||||
"operation": "demote",
|
||||
"demote_uname": "david-macbookpro",
|
||||
"promote_uname": "david-prodesk",
|
||||
"received_at": time.time(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
result = plugin.notify_target(config, runtime_state, {})
|
||||
require(result["ocf_rc"] == 0, "fresh target query failed")
|
||||
require(result["target"] is True, "local demote target was not detected")
|
||||
print("matching_target accepted")
|
||||
|
||||
config["PACEMAKER_NODE_NAME"] = "david-eve"
|
||||
result = plugin.notify_target(config, runtime_state, {})
|
||||
require(result["target"] is False, "mismatched target was accepted")
|
||||
print("mismatched_target rejected")
|
||||
|
||||
runtime_state["postgresql"]["notification"]["received_at"] = (
|
||||
time.time() - 121
|
||||
)
|
||||
result = plugin.notify_target(
|
||||
{"PACEMAKER_NODE_NAME": "david-macbookpro"},
|
||||
runtime_state,
|
||||
{},
|
||||
)
|
||||
require(result["reason"] == "notification_stale", "stale notification accepted")
|
||||
print("stale_notification rejected")
|
||||
|
||||
result = plugin.notify_target(
|
||||
{"PACEMAKER_NODE_NAME": "david-macbookpro"},
|
||||
{},
|
||||
{},
|
||||
)
|
||||
require(result["reason"] == "notification_missing", "missing notification accepted")
|
||||
print("missing_notification rejected")
|
||||
|
||||
print()
|
||||
print("NOTIFY_TARGET_TEST_PASS=1")
|
||||
Reference in New Issue
Block a user