Skip to content

Commit

Permalink
Add mock bugtool plugin and test it being loaded by load_plugins()
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardkaindl committed Dec 22, 2023
1 parent c06992e commit 0c43534
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ 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
# For the Python3 fix for bugtool.load_plugins():
max-statements=52

[FORMAT]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<capability pii="yes" max_size="16384" max_time="60" mime="text/plain" checked="true"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<collect>
<list>/etc</list>
<files>/proc/self/status</files>
<directory pattern=".*ax_user_watches">/proc/sys/fs/epoll</directory>
<command label="proc_version">cat /proc/version</command>
</collect>
48 changes: 48 additions & 0 deletions tests/unit/test_load_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""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 mock bugtool plugin:
bugtool.entries = ["mock"]
# Load the mock plugin:
bugtool.load_plugins(just_capabilities=False)
# Assert the set of properties of the created mock capability:
assert bugtool.caps["mock"] == (
"mock",
"yes",
-1,
16384,
-1,
60,
"text/plain",
True,
False,
9,
)
# Assert the size of the created mock capability:
assert bugtool.cap_sizes["mock"] == 0
# Assert the entries added to the bugtool.data dict:
assert bugtool.data == {
"ls -l /etc": {
"cap": "mock",
"cmd_args": ["ls", "-l", "/etc"],
"filter": None,
},
"/proc/self/status": {
"cap": "mock",
"filename": "/proc/self/status",
},
"/proc/sys/fs/epoll/max_user_watches": {
"cap": "mock",
"filename": "/proc/sys/fs/epoll/max_user_watches",
},
"proc_version": {
"cap": "mock",
"cmd_args": "cat /proc/version",
"filter": None,
},
}
8 changes: 6 additions & 2 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,17 @@ def dir_list(cap, path_list, recursive = False):
flags = '-lR'

pl = []
map(lambda x: pl.extend(glob.glob(x)), path_list)
for path in path_list:
pl.extend(glob.glob(path))

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)
for path in path_list:
pl.extend(glob.glob(path))

for p in pl:
try:
Expand Down Expand Up @@ -1593,6 +1595,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 0c43534

Please sign in to comment.