diff --git a/tests/unit/test_fs_funcs.py b/tests/unit/test_fs_funcs.py new file mode 100644 index 00000000..06130e45 --- /dev/null +++ b/tests/unit/test_fs_funcs.py @@ -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" diff --git a/xen-bugtool b/xen-bugtool index eb1c2bf2..49189890 100755 --- a/xen-bugtool +++ b/xen-bugtool @@ -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 = {} @@ -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',