Skip to content

Commit

Permalink
Merge pull request #121 from xenserver/extract-include_inventory-into…
Browse files Browse the repository at this point in the history
…-def

Prepare `release/yangtze` for backporting #51 (collect up-to-date RRDs)
  • Loading branch information
liulinC authored Sep 10, 2024
2 parents 19aaa6b + ac73d58 commit 23dd201
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion tests/unit/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def assert_mock_bugtool_plugin_output(temporary_directory, subdir, names):
expected_names = [
subdir + "/etc/group",
subdir + "/etc/passwd.tar",
subdir + "/inventory.xml",
subdir + "/ls-l-%etc.out",
subdir + "/proc/self/status",
subdir + "/proc/sys/fs/epoll/max_user_watches",
Expand All @@ -30,6 +31,7 @@ def assert_mock_bugtool_plugin_output(temporary_directory, subdir, names):
extracted = "%s/%s/" % (temporary_directory, subdir)

# Will be refactored to be more easy in a separate commit soon:
assert_valid_inventory_schema(parse(extracted + "inventory.xml"))
with open(extracted + "proc_version.out") as proc_version:
assert proc_version.read()[:14] == "Linux version "
with open(extracted + "ls-l-%etc.out") as etc:
Expand All @@ -52,7 +54,7 @@ def assert_mock_bugtool_plugin_output(temporary_directory, subdir, names):


def minimal_bugtool(bugtool, dom0_template, archive, subdir, mocker):
"""Load the plugins from dom0_template and collect the specified data"""
"""Load the plugins from the template and include the generated inventory"""

mocker.patch("xen-bugtool.time.strftime", return_value="time.strftime")
# Load the mock plugin from dom0_template and process the plugin's caps:
Expand All @@ -65,6 +67,7 @@ def minimal_bugtool(bugtool, dom0_template, archive, subdir, mocker):
# Mock the 2nd argument of the ls -l /etc to collect it using dom0_template:
bugtool.data["ls -l /etc"]["cmd_args"][2] = dom0_template + "/etc"
bugtool.collect_data(subdir, archive)
bugtool.include_inventory(archive, subdir)
archive.close()


Expand Down
11 changes: 8 additions & 3 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,13 @@ def func_output(cap, label, func):
if cap in entries:
data[label] = {'cap': cap, 'func': func}


def include_inventory(archive, subdir):
inventory = {'cap': None, 'output': StringIOmtime(no_unicode(make_inventory(data, subdir)))}
archive.add_path_with_data(construct_filename(subdir, 'inventory.xml', inventory),
StringIOmtime(no_unicode(make_inventory(data, subdir))))


def collect_data(subdir, archive):
process_lists = {}

Expand Down Expand Up @@ -1183,9 +1190,7 @@ exclude those logs from the archive.
collect_data(subdir, archive)

# include inventory
inventory = {'cap': None, 'output': StringIOmtime(no_unicode(make_inventory(data, subdir)))}
archive.add_path_with_data(construct_filename(subdir, 'inventory.xml', inventory),
StringIOmtime(no_unicode(make_inventory(data, subdir))))
include_inventory(archive, subdir)

if archive.close():
res = 0
Expand Down

0 comments on commit 23dd201

Please sign in to comment.