Skip to content

Commit

Permalink
tests: Add test case for check_ok()
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Prabhu <[email protected]>
  • Loading branch information
spuiuk committed Feb 9, 2022
1 parent 05aad8a commit 631a0f3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_ctdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,40 @@ def _fake_ctdb_script(pnn, recmaster):
assert not status.is_leader()
assert "pnn" in caplog.records[-2].getMessage()
assert "recmaster" in caplog.records[-1].getMessage()


def test_check_ok(tmp_path):
import os

datapath = tmp_path / "_ctdb"
datapath.mkdir()

fake_ctdb = [
"#!/bin/sh",
'if [ "$1$TESTFAIL" == "nodestatus" ]',
"then exit 0;",
"else exit 1;",
"fi",
]
fake_ctdb_script = datapath / "ctdb.sh"
with open(fake_ctdb_script, "w") as fh:
fh.write("\n".join(fake_ctdb))
fh.write("\n")
os.chmod(fake_ctdb_script, 0x0755)

# simulate nodestatus == OK
pid = os.fork()
if pid == 0:
ctdb.check_ok(cmd=sambacc.samba_cmds.SambaCommand(fake_ctdb_script))
else:
_, status = os.waitpid(pid, 0)
assert status == 0

# simulate nodestatus != OK
pid = os.fork()
if pid == 0:
os.environ["TESTFAIL"] = "yes"
ctdb.check_ok(cmd=sambacc.samba_cmds.SambaCommand(fake_ctdb_script))
else:
_, status = os.waitpid(pid, 0)
assert status != 0

0 comments on commit 631a0f3

Please sign in to comment.