87 lines
1.8 KiB
Python
Executable File
87 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import importlib.util
|
|
import sys
|
|
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
|
|
|
|
plugin_path = Path("plugins/postgresql/plugin.py")
|
|
|
|
spec = importlib.util.spec_from_file_location(
|
|
"postgresql_plugin",
|
|
plugin_path,
|
|
)
|
|
plugin = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(plugin)
|
|
|
|
|
|
def require(condition, message):
|
|
if not condition:
|
|
raise SystemExit("FAIL: " + message)
|
|
|
|
|
|
print("===== DAEMON NOTIFY ACTION =====")
|
|
|
|
runtime_state = {}
|
|
|
|
parameters = {
|
|
"type": "pre",
|
|
"operation": "demote",
|
|
"promote_uname": "david-eve",
|
|
"demote_uname": "david-prodesk",
|
|
"promoted_uname": "david-prodesk",
|
|
"unpromoted_uname": "david-eve david-macbookpro",
|
|
}
|
|
|
|
response = plugin.notify(
|
|
{},
|
|
runtime_state,
|
|
parameters,
|
|
)
|
|
|
|
require(
|
|
response["ocf_rc"] == plugin.OCF_SUCCESS,
|
|
"notify did not return OCF_SUCCESS",
|
|
)
|
|
require(
|
|
response["state"]["operation"] == "demote",
|
|
"notify operation was not preserved",
|
|
)
|
|
require(
|
|
runtime_state["postgresql"]["notification"]
|
|
== response["state"],
|
|
"notify state was not retained",
|
|
)
|
|
print("valid_notify accepted")
|
|
print("notify_state retained")
|
|
|
|
for invalid in (
|
|
[],
|
|
{"type": None},
|
|
{"operation": "demote\n"},
|
|
):
|
|
try:
|
|
plugin.notify({}, {}, invalid)
|
|
except ValueError:
|
|
continue
|
|
|
|
raise SystemExit(
|
|
"FAIL: invalid notify parameters were accepted"
|
|
)
|
|
|
|
print("invalid_notify rejected")
|
|
print()
|
|
print("NOTIFY_ACTION_TEST_PASS=1")
|