[Libvirt-cim] [PATCH 3 of 3] [TEST] #2 Add test report generation

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Mon Aug 11 16:21:16 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1218470745 25200
# Node ID d1e8325893b3e68e12b1725e350314aeaf6d2be1
# Parent  a5111986921da879e2dcc57a1529c7f4d902aebf
[TEST] #2 Add test report generation.

Using the --report option, you can generate a report and have it mailed to the address supplied.

How to call using the report option:

./runtests libvirt-cim -i localhost -c -d -v LXC -g VirtualSystemManagementService -t 01_definesystem_name.py --report <my_to_addr at test.com>

The user will need to create a .cimtestrc file in their home directory in the following format:

[email]
relay = my.mail.relay.com
from = Joe User <joe at test.com>

Will need to add revision number support to cimtest and then add the cimtest revision number to the report.

Updates:
  -Refactored reporting related pieces into their own library file

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r a5111986921d -r d1e8325893b3 suites/libvirt-cim/main.py
--- a/suites/libvirt-cim/main.py	Mon Aug 11 09:05:37 2008 -0700
+++ b/suites/libvirt-cim/main.py	Mon Aug 11 09:05:45 2008 -0700
@@ -29,12 +29,13 @@
 sys.path.append('../../lib')
 import TestSuite
 import commands
-from VirtLib import utils
 from VirtLib import groups
 from CimTest.ReturnCodes import PASS, SKIP, XFAIL
 from CimTest.Globals import platform_sup
 sys.path.append('./lib')
 from XenKvmLib.classes import get_typed_class
+import ConfigParser
+from XenKvmLib.reporting import gen_report, send_report 
 
 parser = OptionParser()
 parser.add_option("-i", "--ip", dest="ip", default="localhost",
@@ -54,8 +55,11 @@
                   help="Virt type, select from 'Xen' & 'KVM' & 'XenFV' & 'LXC'(default: Xen). ")
 parser.add_option("-d", "--debug-output", action="store_true", dest="debug",
                   help="Duplicate the output to stderr")
+parser.add_option("--report", dest="report",
+                  help="Send report using mail info: --report=<recipient addr>")
 
 TEST_SUITE = 'cimtest'
+CIMTEST_RCFILE = '%s/.cimtestrc' % os.environ['HOME']
 
 def set_python_path():
     previous_pypath = os.environ.get('PYTHONPATH')
@@ -82,6 +86,28 @@
 
     print "Cleaned log files."
 
+def get_rcfile_vals():
+    if not os.access(CIMTEST_RCFILE, os.R_OK):
+        print "\nCould not access the %s file for this user." % CIMTEST_RCFILE
+        print "Create this file and add the appropriate relay:"
+        print "\tfrom = me at isp.com\n\trelay = my.relay\n"
+        return None, None
+
+    try:
+        conf = ConfigParser.ConfigParser()
+        if not conf.read(CIMTEST_RCFILE):
+            return None, None
+
+        addr = conf.get("email", "from")
+        relay = conf.get("email", "relay")
+
+    except Exception, details:
+        print "\n%s" % details 
+        print "\nPlease verify the format of the %s file\n" % CIMTEST_RCFILE 
+        return None, None
+
+    return addr, relay
+
 def get_version(virt, ip):
     conn = WBEMConnection('http://%s' % ip, 
                           (os.getenv('CIM_USER'), os.getenv('CIM_PASS')),
@@ -101,7 +127,10 @@
 
 def main():
     (options, args) = parser.parse_args()
-
+    to_addr = None
+    from_addr = None
+    relay = None
+    div = "--------------------------------------------------------------------"
 
     if options.test and not options.group:
         parser.print_help()
@@ -114,7 +143,15 @@
         os.environ['CIMOM_PORT'] = str(options.port)
     #
 
-    testsuite = TestSuite.TestSuite()
+    if options.report:
+        from_addr, relay = get_rcfile_vals()
+
+        if from_addr == None or relay == None:
+            return 1
+         
+        to_addr = options.report
+
+    testsuite = TestSuite.TestSuite(log=True)
    
     set_python_path()
 
@@ -139,9 +176,10 @@
 
     revision, changeset = get_version(options.virt, options.ip)
 
-    print "Testing " + options.virt + " hypervisor"
+    print "\nTesting " + options.virt + " hypervisor"
 
-    for test in test_list:
+    for test in test_list: 
+        testsuite.debug(div) 
         t_path = os.path.join(TEST_SUITE, test['group'])
         os.environ['CIM_TC'] = test['test'] 
         cdto = 'cd %s' % t_path
@@ -155,7 +193,16 @@
 
         testsuite.print_results(test['group'], test['test'], os_status)
 
+    testsuite.debug("%s\n" % div) 
     testsuite.finish()
+
+    msg_body, heading = gen_report(revision, changeset, options.virt,
+                                   options.ip, testsuite.log_file)
+
+    if options.report:
+        print "Sending mail from %s to %s using %s relay.\n" % \
+              (from_addr, to_addr, relay)
+        send_report(to_addr, from_addr, relay, msg_body, heading)
 
 if __name__ == '__main__':
     sys.exit(main())




More information about the Libvirt-cim mailing list