Skip to content

Commit 2f89a38

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
tests: add a test case for the ensure_ctdb_port_in_services func
Signed-off-by: John Mulligan <[email protected]>
1 parent 3601e3d commit 2f89a38

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_ctdb.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,34 @@ def test_check_nodestatus(tmp_path):
604604
else:
605605
_, status = os.waitpid(pid, 0)
606606
assert status != 0
607+
608+
609+
def test_ensure_ctdb_port_in_services(tmp_path):
610+
fname = tmp_path / "fake.services"
611+
with open(fname, "w") as fh:
612+
# random snippets from a real /etc/services
613+
print("# this is a comment", file=fh)
614+
print("ftp 21/tcp", file=fh)
615+
print("ftp 21/udp fsp fspd", file=fh)
616+
print("ssh 22/tcp", file=fh)
617+
print("ssh 22/udp", file=fh)
618+
print("telnet 23/tcp", file=fh)
619+
print("telnet 23/udp", file=fh)
620+
print("ctdb 4379/tcp # CTDB", file=fh)
621+
print("ctdb 4379/udp # CTDB", file=fh)
622+
print("roce 4791/udp", file=fh)
623+
print("# a random comment...", file=fh)
624+
print("snss 11171/udp", file=fh)
625+
print("oemcacao-jmxmp 11172/tcp", file=fh)
626+
627+
ctdb.ensure_ctdb_port_in_services(9099, fname)
628+
629+
with open(fname) as fh:
630+
content = fh.read()
631+
assert "ctdb 9099/tcp" in content
632+
assert "ctdb 9099/udp" in content
633+
assert "ctdb 4379/tcp" not in content
634+
assert "ctdb 4379/udp" not in content
635+
# others
636+
assert "ssh 22/tcp" in content
637+
assert "snss 11171/udp" in content

0 commit comments

Comments
 (0)