Skip to content

Commit

Permalink
Add tests/unit/test_load_plugins.py and fix load_plugins()
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardkaindl committed Dec 17, 2023
1 parent 5747829 commit 62ef058
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ max-returns=11

# Maximum number of statements in function / method body.
# defaults to: max-statements=50
# xen-bugtool:main() is currently at 376, but it has a dedicated pylint disable comment now:
# max-statements=376
max-statements=52

[FORMAT]

Expand Down
52 changes: 52 additions & 0 deletions tests/unit/test_load_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Regression tests for bugtool.load_plugins()"""


def test_load_plugins(bugtool, dom0_template):
"""Assert () returning arrays of the in the dom0-template"""

# Use the plugins found in the dom0_template "/etc/xensource/bugtool":
bugtool.PLUGIN_DIR = dom0_template + "/etc/xensource/bugtool"
# Only process the xapi bugtool plugin:
bugtool.entries = ["xapi"]
# Reset the predefined caps and cap_sizes, so we can check the plugin code:
# bugtool.caps = {}
# bugtool.cap_sizes = {}
# Load the xapi plugin:
bugtool.load_plugins(just_capabilities=False)
# Assert the set of properties of the created xapi capability:
assert bugtool.caps["xapi"] == (
"xapi",
"yes",
-1,
16384,
-1,
60,
"text/plain",
True,
False,
9,
)
# Assert the size of the created xapi capability:
assert bugtool.cap_sizes["xapi"] == 0
print(bugtool.data)
# Assert the entries added to the bugtool.data dict:
assert bugtool.data == {
"ls -l /proc/sys/dev/tty": {
"cap": "xapi",
"cmd_args": ["ls", "-l", "/proc/sys/dev/tty"],
"filter": None,
},
"/proc/sys/dev/tty": {
"cap": "xapi",
"filename": "/proc/sys/dev/tty",
},
"/proc/sys/dev/tty/ldisc_autoload": {
"cap": "xapi",
"filename": "/proc/sys/dev/tty/ldisc_autoload",
},
"tty": {
"cap": "xapi",
"cmd_args": "ls /proc/sys/dev/tty",
"filter": None,
},
}
6 changes: 4 additions & 2 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,15 @@ def dir_list(cap, path_list, recursive = False):
flags = '-lR'

pl = []
map(lambda x: pl.extend(glob.glob(x)), path_list)
list(map(lambda x: pl.extend(glob.glob(x)), path_list))

for p in pl:
cmd_output(cap, [LS, flags, p])

def file_output(cap, path_list):
if cap in entries:
pl = []
map(lambda x: pl.extend(glob.glob(x)), path_list)
list(map(lambda x: pl.extend(glob.glob(x)), path_list))

for p in pl:
try:
Expand Down Expand Up @@ -1594,6 +1594,8 @@ def load_plugins(just_capabilities = False):
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc += node.data
if sys.version_info > (3, 0):
return rc
return rc.encode()

def getBoolAttr(el, attr, default = False):
Expand Down

0 comments on commit 62ef058

Please sign in to comment.