diff mbox

[1/3] tools/html_report: Make html report generation autotest generic

Message ID 1304017734-15836-2-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues April 28, 2011, 7:08 p.m. UTC
The 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.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tools/html_report.py |   85 ++++++++++++++++++++++++-------------------
 1 files changed, 47 insertions(+), 38 deletions(-)
diff mbox

Patch

diff --git a/client/tools/html_report.py b/client/tools/html_report.py
index 8b4b109..1b1584c 100755
--- a/client/tools/html_report.py
+++ b/client/tools/html_report.py
@@ -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