Fix HTML report generation
PATCH 1/3 tools/html_report: Make html report generation autotest generic
In reply to Lucas Meneghel RodriguesThe html report tool was a bit too tied to KVM autotest, and that was not necessary. Turn it into a generic module that can be used by any autotest job, encapsulate the main worker function into autotest API so we don't need to exec it in a subshell, fix naming of the report and CSS details.
--- client/tools/html_report.py | 85 ++++++++++++++++++++++++------------------- 1 files changed, 47 insertions(+), 38 deletions(-)
client/tools/html_report.py +47 -38
@@ -27,7 +27,6 @@ body { text-decoration:none; font:bold 2em/2em Arial, Helvetica, sans-serif; text-transform:none; - text-shadow: 2px 2px 2px #555; text-align: left; color:#555555; border-bottom: 1px solid #555555;
@@ -37,7 +36,6 @@ body { text-decoration:none; font:bold 16px Arial, Helvetica, sans-serif; text-transform:uppercase; - text-shadow: 2px 2px 2px #555; text-align: left; color:#555555; margin-bottom:0;
@@ -1388,7 +1386,7 @@ def make_html_file(metadata, results, tag, host, output_file_name, dirname): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> -<title>KVM Autotest Results</title> +<title>Autotest job execution results</title> <style type="text/css"> %s </style>
@@ -1414,7 +1412,7 @@ return true; output = sys.stdout # create html page print >> output, html_prefix - print >> output, '<h2 id=\"page_title\">KVM Autotest Execution Report</h2>' + print >> output, '<h2 id=\"page_title\">Autotest job execution report</h2>' # formating date and time to print t = datetime.datetime.now()
@@ -1446,7 +1444,8 @@ return true; print >> output, '<tr><td>DATE</td><td>:</td><td>%s</td></tr>' % now.ctime() print >> output, '<tr><td>STATS</td><td>:</td><td>%s</td></tr>'% stat_str print >> output, '<tr><td></td><td></td><td></td></tr>' - print >> output, '<tr><td>KVM VERSION</td><td>:</td><td>%s</td></tr>' % kvm_ver_str + if kvm_ver_str: + print >> output, '<tr><td>KVM VERSION</td><td>:</td><td>%s</td></tr>' % kvm_ver_str print >> output, '</table>'
@@ -1556,7 +1555,7 @@ def parse_result(dirname, line): # assign actual values rx = re.compile('^(\w+)\.(.*)$') m1 = rx.findall(parts[3]) - result['testcase'] = m1[0][1] + result['testcase'] = str(tag) result['title'] = str(tag) result['status'] = parts[1] if result['status'] != 'GOOD':
@@ -1648,9 +1647,50 @@ def get_kvm_version(result_dir): kvm_version = get_keyval_value(result_dir, "kvm_version") kvm_userspace_version = get_keyval_value(result_dir, "kvm_userspace_version") + if kvm_version == "Unknown" or kvm_userspace_version == "Unknown": + return None return "Kernel: %s<br>Userspace: %s" % (kvm_version, kvm_userspace_version) +def create_report(dirname, html_path=None, output_file_name=None): + res_dir = os.path.abspath(dirname) + tag = res_dir + status_file_name = dirname + '/status' + sysinfo_dir = dirname + '/sysinfo' + host = get_info_file('%s/hostname' % sysinfo_dir) + rx = re.compile('^\s+[END|START].*$') + # create the results set dict + results_data = [] + if os.path.exists(status_file_name): + f = open(status_file_name, "r") + lines = f.readlines() + f.close() + for line in lines: + if rx.match(line): + result_dict = parse_result(dirname, line) + if result_dict: + results_data.append(result_dict) + # create the meta info dict + metalist = { + 'uname': get_info_file('%s/uname' % sysinfo_dir), + 'cpuinfo':get_info_file('%s/cpuinfo' % sysinfo_dir), + 'meminfo':get_info_file('%s/meminfo' % sysinfo_dir), + 'df':get_info_file('%s/df' % sysinfo_dir), + 'modules':get_info_file('%s/modules' % sysinfo_dir), + 'gcc':get_info_file('%s/gcc_--version' % sysinfo_dir), + 'dmidecode':get_info_file('%s/dmidecode' % sysinfo_dir), + 'dmesg':get_info_file('%s/dmesg' % sysinfo_dir), + 'kvmver':get_kvm_version(dirname) + } + + if html_path is None: + html_path = dirname + if output_file_name is None: + output_file_name = os.path.join(dirname, 'job_report.html') + make_html_file(metalist, results_data, tag, host, output_file_name, + html_path) + + def main(argv): dirname = None output_file_name = None
@@ -1682,38 +1722,7 @@ def main(argv): if dirname: if os.path.isdir(dirname): # TBD: replace it with a validation of # autotest result dir - res_dir = os.path.abspath(dirname) - tag = res_dir - status_file_name = dirname + '/status' - sysinfo_dir = dirname + '/sysinfo' - host = get_info_file('%s/hostname' % sysinfo_dir) - rx = re.compile('^\s+[END|START].*$') - # create the results set dict - results_data = [] - if os.path.exists(status_file_name): - f = open(status_file_name, "r") - lines = f.readlines() - f.close() - for line in lines: - if rx.match(line): - result_dict = parse_result(dirname, line) - if result_dict: - results_data.append(result_dict) - # create the meta info dict - metalist = { - 'uname': get_info_file('%s/uname' % sysinfo_dir), - 'cpuinfo':get_info_file('%s/cpuinfo' % sysinfo_dir), - 'meminfo':get_info_file('%s/meminfo' % sysinfo_dir), - 'df':get_info_file('%s/df' % sysinfo_dir), - 'modules':get_info_file('%s/modules' % sysinfo_dir), - 'gcc':get_info_file('%s/gcc_--version' % sysinfo_dir), - 'dmidecode':get_info_file('%s/dmidecode' % sysinfo_dir), - 'dmesg':get_info_file('%s/dmesg' % sysinfo_dir), - 'kvmver':get_kvm_version(dirname) - } - - make_html_file(metalist, results_data, tag, host, output_file_name, - html_path) + create_report(dirname, html_path, output_file_name) sys.exit(0) else: print 'Invalid result directory <%s>' % dirname
Signature · 1 line
1.7.4.4
PATCH 2/3 virt.virt_utils: Get rid of create_report function
In reply to Lucas Meneghel RodriguesAs it has been transfered to the html_report module itself.
--- client/virt/virt_utils.py | 12 ------------ 1 files changed, 0 insertions(+), 12 deletions(-)
client/virt/virt_utils.py +0 -12
@@ -1187,18 +1187,6 @@ def run_tests(parser, job): return not failed -def create_report(report_dir, results_dir): - """ - Creates a neatly arranged HTML results report in the results dir. - - @param report_dir: Directory where the report script is located. - @param results_dir: Directory where the results will be output. - """ - reporter = os.path.join(report_dir, 'html_report.py') - html_file = os.path.join(results_dir, 'results.html') - os.system('%s -r %s -f %s -R' % (reporter, results_dir, html_file)) - - def display_attributes(instance): """ Inspects a given class instance attributes and displays them, convenient
Signature · 1 line
1.7.4.4
PATCH 3/3 KVM test: control: Replace create_report function call
In reply to Lucas Meneghel RodriguesFollowing up with the previous changes.
--- client/tests/kvm/control | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
client/tests/kvm/control +2 -1
@@ -23,6 +23,7 @@ For online docs, please refer to http://www.linux-kvm.org/page/KVM-Autotest import sys, os, logging from autotest_lib.client.common_lib import cartesian_config from autotest_lib.client.virt import virt_utils +from autotest_lib.client.tools import html_report # set English environment (command output might be localized, need to be safe) os.environ['LANG'] = 'en_US.UTF-8'
@@ -69,4 +70,4 @@ parser.parse_string(str) virt_utils.run_tests(parser, job) # Generate a nice HTML report inside the job's results dir -virt_utils.create_report(kvm_test_dir, job.resultdir) +html_report.create_report(job.resultdir)
Signature · 1 line
1.7.4.4
cover Fix HTML report generation
Made HTML report generation generic and useable by any autotest client job, fixed up some bugs in HTML report code. Now it'll be easier to browse and visualize results without the autotest web interface.
Lucas Meneghel Rodrigues (3):
tools/html_report: Make html report generation autotest generic virt.virt_utils: Get rid of create_report function KVM test: control: Replace create_report function call
client/tests/kvm/control | 3 +- client/tools/html_report.py | 85 ++++++++++++++++++++++++------------------- client/virt/virt_utils.py | 12 ------ 3 files changed, 49 insertions(+), 51 deletions(-)
Signature · 1 line
1.7.4.4