Skip to content

Use newly replaced leader admin command for ctdb #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sambacc/ctdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,9 @@ def __enter__(self) -> CLILeaderStatus:
_logger.error(f"command {pnn_cmd!r} failed: {err!r}")
except FileNotFoundError:
_logger.error(f"ctdb command ({pnn_cmd!r}) not found")
# recmaster = <ctdb recmaster>
recmaster_cmd = samba_cmds.ctdb["recmaster"]
# recmaster = <ctdb recmaster|leader>
admin_cmd = samba_cmds.ctdb_leader_admin_cmd()
recmaster_cmd = samba_cmds.ctdb[admin_cmd]
try:
out = subprocess.check_output(list(recmaster_cmd))
recmaster = out.decode("utf8").strip()
Expand Down
9 changes: 9 additions & 0 deletions sambacc/samba_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

# Known flags for SAMBA_SPECIFICS env variable
_DAEMON_CLI_STDOUT_OPT: str = "daemon_cli_debug_output"
_CTDB_LEADER_ADMIN_CMD: str = "ctdb_leader_admin_command"


def get_samba_specifics() -> typing.Set[str]:
Expand All @@ -52,6 +53,14 @@ def _daemon_stdout_opt(daemon: str) -> str:
return opt


def ctdb_leader_admin_cmd() -> str:
leader_cmd = "recmaster"
opt_lst = get_samba_specifics()
if _CTDB_LEADER_ADMIN_CMD in opt_lst:
leader_cmd = "leader"
return leader_cmd


def set_global_prefix(lst: list[str]) -> None:
_GLOBAL_PREFIX[:] = lst

Expand Down
10 changes: 6 additions & 4 deletions tests/test_ctdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,15 @@ def test_cli_leader_locator(tmpdir, monkeypatch, caplog):
caplog.set_level(logging.INFO)
fake_ctdb = tmpdir / "fake_ctdb.sh"
monkeypatch.setattr(sambacc.samba_cmds, "_GLOBAL_PREFIX", [fake_ctdb])
monkeypatch.setenv("SAMBA_SPECIFICS", "ctdb_leader_admin_command")
ldr_admin_cmd = sambacc.samba_cmds.ctdb_leader_admin_cmd()

def _fake_ctdb_script(pnn, recmaster):
with open(fake_ctdb, "w") as fh:
fh.write("#!/bin/sh\n")
fh.write("case $2 in\n")
fh.write(f"pnn) {pnn};;\n")
fh.write(f"recmaster) {recmaster};;\n")
fh.write(f"{ldr_admin_cmd}) {recmaster};;\n")
fh.write("esac\n")
fh.write("exit 5\n")
os.chmod(fake_ctdb, 0o700)
Expand All @@ -551,18 +553,18 @@ def _fake_ctdb_script(pnn, recmaster):
with ctdb.CLILeaderLocator() as status:
assert not status.is_leader()
assert "pnn" in caplog.records[-1].getMessage()
assert "recmaster" not in caplog.records[-1].getMessage()
assert "['" + ldr_admin_cmd + "']" not in caplog.records[-1].getMessage()
_fake_ctdb_script(pnn="echo 1; exit 0", recmaster="exit 1")
with ctdb.CLILeaderLocator() as status:
assert not status.is_leader()
assert "pnn" not in caplog.records[-1].getMessage()
assert "recmaster" in caplog.records[-1].getMessage()
assert "['" + ldr_admin_cmd + "']" in caplog.records[-1].getMessage()

os.unlink(fake_ctdb)
with ctdb.CLILeaderLocator() as status:
assert not status.is_leader()
assert "pnn" in caplog.records[-2].getMessage()
assert "recmaster" in caplog.records[-1].getMessage()
assert "['" + ldr_admin_cmd + "']" in caplog.records[-1].getMessage()


def test_check_nodestatus(tmp_path):
Expand Down