Skip to content

Commit

Permalink
Test new/replaced ctdb leader admin command
Browse files Browse the repository at this point in the history
Signed-off-by: Anoop C S <anoopcs@samba.org>
  • Loading branch information
anoopcs9 authored and phlogistonjohn committed Sep 20, 2022
1 parent 39cf99a commit b4d2532
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit b4d2532

Please # to comment.