Skip to content

Commit

Permalink
Add test_fs_funcs.py for get_recent_logs() & readKeyValueFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardkaindl committed Dec 22, 2023
1 parent 82b8121 commit c06992e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 19 additions & 0 deletions tests/unit/test_fs_funcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Regression tests for bugtool helper functions like get_recent_logs()"""


def test_get_recent_logs(bugtool):
"""Assert get_recent_logs() returning the most recent file(s)"""

files = ["/proc/1/stat", "/proc/self/stat"] # self/stat is more recent.
# return the files, ordered by their modification time, most recent first:
assert bugtool.get_recent_logs(files, 9) == files
assert bugtool.get_recent_logs([files[1], files[0]], 9) == files
# When verbosity is 1, only return the most recent file:
assert bugtool.get_recent_logs(files, 1) == [files[1]]


def test_read_inventory(bugtool, dom0_template):
"""Assert readKevValueFile() reading the a xensource inventory file"""

inventory = bugtool.readKeyValueFile(dom0_template + bugtool.XENSOURCE_INVENTORY)
assert inventory["PRODUCT_VERSION"] == "8.3.0"
10 changes: 6 additions & 4 deletions xen-bugtool
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ def func_output(cap, label, func):
if cap in entries:
data[label] = {'cap': cap, 'func': func}


def get_recent_logs(logs, verbosity):
logs = sorted([(os.stat(e).st_mtime, e) for e in logs])
return [x[1] for x in (logs[-verbosity:] if verbosity < 9 else logs)]


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

Expand Down Expand Up @@ -1086,10 +1092,6 @@ exclude those logs from the archive.
except:
pass

def get_recent_logs(logs, verbosity):
logs = sorted([(os.stat(e).st_mtime, e) for e in logs])
return map(lambda x: x[1], logs[-verbosity:] if verbosity < 9 else logs)

xenserver_logs = \
[ VAR_LOG_DIR + x for x in
['xensource.log', 'audit.log', 'xenstored-access.log',
Expand Down

0 comments on commit c06992e

Please sign in to comment.