Skip to content

Commit

Permalink
Add dom0_template fixture, test_module_info, multipathd_topology
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardkaindl committed Dec 21, 2023
1 parent b131ca4 commit 2ab76c7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
2 changes: 2 additions & 0 deletions tests/integration/dom0-template/usr/sbin/modinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "modinfo for $*"
2 changes: 2 additions & 0 deletions tests/integration/dom0-template/usr/sbin/multipathd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo -n "${0##*/}$*"
8 changes: 8 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ def testdir():
return os.path.dirname(__file__)


@pytest.fixture(scope="session")
def dom0_template(testdir):
"""Test fixture to get the directory of the dom0 template and adding it's /usr/sbin to the PATH"""
dom0_rootdir = testdir + "/../integration/dom0-template"
os.environ["PATH"] = dom0_rootdir + "/usr/sbin" # for modinfo, mdadm, etc
return dom0_rootdir


@pytest.fixture(scope="session")
def bugtool(testdir):
"""Test fixture to import the xen-bugtool script as a module for executing unit tests on functions"""
Expand Down
13 changes: 0 additions & 13 deletions tests/unit/test_mdadm_arrays.py

This file was deleted.

3 changes: 3 additions & 0 deletions tests/unit/test_process_output.modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tcp_diag 16384 0 - Live 0xffffffffc05c0000
udp_diag 16384 0 - Live 0xffffffffc059c000
inet_diag 24576 2 tcp_diag,udp_diag, Live 0xffffffffc0533000
19 changes: 19 additions & 0 deletions tests/unit/test_process_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Regression tests for the bugtool helper function mdadm_arrays()"""


def test_mdadm_arrays(bugtool, dom0_template):
"""Assert mdadm_arrays() returning arrays of the mdadm mockup in the dom0-template"""
assert list(bugtool.mdadm_arrays()) == ["/dev/md0", "/dev/md1"]


def test_module_info(bugtool, dom0_template):
"""Assert module_info() returning module names from mockup file in the dom0-template"""

bugtool.PROC_MODULES = __file__.replace(".py", ".modules")
output = bugtool.module_info(bugtool.CAP_KERNEL_INFO)
assert output == "modinfo for tcp_diag\nmodinfo for udp_diag\nmodinfo for inet_diag\n"


def test_multipathd_topology(bugtool, dom0_template):
"""Assert multipathd_topology() returning the output of the faked multipathd tool"""
assert bugtool.multipathd_topology(bugtool.CAP_MULTIPATH) == bugtool.MULTIPATHD + "-k"
12 changes: 9 additions & 3 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -1517,9 +1517,15 @@ def csl_logs(cap):
return output.getvalue()

def multipathd_topology(cap):
pipe = Popen([MULTIPATHD, '-k'], bufsize=1, stdin=PIPE,
stdout=PIPE, stderr=dev_null)
stdout, _ = pipe.communicate('show topology')
pipe = Popen(
[MULTIPATHD, "-k"],
universal_newlines=sys.version_info > (3, 0),
bufsize=1,
stdin=PIPE,
stdout=PIPE,
stderr=dev_null,
)
stdout, _ = pipe.communicate("show topology")

return stdout

Expand Down

0 comments on commit 2ab76c7

Please sign in to comment.