[PATCH] [TEST] #2 Add -d to duplicate error output to stderr

# HG changeset patch # User Zhengang Li <lizg@cn.ibm.com> # Date 1208226308 -28800 # Node ID a22ea10d1e46adfcd2e878328c1746b5c618230b # Parent 137e5079c73fcbfc70e6654cee0b3c3eb3c6acd2 [TEST] #2 Add -d to duplicate error output to stderr This gives us the capability to output the error messages to screen. .#2: - Added a temp work around to avoid duplicated logging to file. - Update some indent (8 spaces -> 4 spaces, line cut, commenting) Signed-off-by: Zhengang Li <lizg@cn.ibm.com> diff -r 137e5079c73f -r a22ea10d1e46 lib/CimTest/Globals.py --- a/lib/CimTest/Globals.py Fri Apr 11 16:58:23 2008 +0530 +++ b/lib/CimTest/Globals.py Tue Apr 15 10:25:08 2008 +0800 @@ -68,6 +68,8 @@ parser.add_option("-v", "--virt", dest=" parser.add_option("-v", "--virt", dest="virt", type="choice", choices=platform_sup, default="Xen", help="Virt type, select from: 'Xen' & 'KVM' & 'XenFV', default: Xen") +parser.add_option("-d", "--debug-output", action="store_true", dest="debug", + help="Duplicate the output to stderr") if not CIM_NS: CIM_NS = "root/cimv2" @@ -85,29 +87,42 @@ if not CIM_IP: if not CIM_IP: CIM_IP = "localhost" -def log_param(): +def log_param(debug=None): + #FIXME debug=None is a temporary work around to avoid duplicate + # logging in vsmtest.log because we have log_param in both the + # do_main decorator and the test case's main function. + # We can safely delete the if branch here after all test cases + # have removed the log_param invoke. + if debug == None: + return + else: logger.setLevel(logging.DEBUG) -#create console handler and set level to debug + #create console handler and set level to debug ch = logging.StreamHandler() - ch.setLevel(int(CIM_LEVEL)) -#create file handler and set level to debug + if debug: + ch.setLevel(logging.ERROR) + else: + ch.setLevel(int(CIM_LEVEL)) + #create file handler and set level to debug fh = logging.FileHandler("vsmtest.log") fh.setLevel(logging.DEBUG) -#create formatter - formatter = logging.Formatter("%(asctime)s:%(name)s:%(levelname)s \ -\t- %(message)s", datefmt="%a, %d %b %Y %H:%M:%S") -#add formatter to handlers + #create formatter + formatter = logging.Formatter(\ + "%(asctime)s:%(name)s:%(levelname)s \t- %(message)s", + datefmt="%a, %d %b %Y %H:%M:%S") + #add formatter to handlers fh.setFormatter(formatter) + formatter = logging.Formatter("%(levelname)s \t- %(message)s") ch.setFormatter(formatter) -#add handlers to logger + #add handlers to logger logger.addHandler(fh) logger.addHandler(ch) -#Print header + #Print header logger.info("====%s Log====", CIM_TC) def log_bug(bug_num): - logger.info("Known Bug:%s" % bug_num) - print "Bug:<%s>" % bug_num + logger.info("Known Bug:%s" % bug_num) + print "Bug:<%s>" % bug_num def do_main(types=['Xen'], p=parser): def do_type(f): @@ -119,6 +134,7 @@ def do_main(types=['Xen'], p=parser): else: def do_try(): try: + log_param(options.debug) from VirtLib.utils import setup_ssh_key from XenKvmLib.test_doms import destroy_and_undefine_all setup_ssh_key() diff -r 137e5079c73f -r a22ea10d1e46 suites/libvirt-cim/main.py --- a/suites/libvirt-cim/main.py Fri Apr 11 16:58:23 2008 +0530 +++ b/suites/libvirt-cim/main.py Tue Apr 15 10:25:08 2008 +0800 @@ -49,6 +49,8 @@ parser.add_option("-v", "--virt", dest=" parser.add_option("-v", "--virt", dest="virt", type="choice", choices=platform_sup, default="Xen", help="Virt type, select from 'Xen' & 'KVM' & 'XenFV'(default: Xen). ") +parser.add_option("-d", "--debug-output", action="store_true", dest="debug", + help="Duplicate the output to stderr") TEST_SUITE = 'cimtest' @@ -110,14 +112,19 @@ def main(): if options.clean: remove_old_logs(options.group) + if options.debug: + dbg = "-d" + else: + dbg = "" + print "Testing " + options.virt + " hypervisor" for test in test_list: t_path = os.path.join(TEST_SUITE, test['group']) os.environ['CIM_TC'] = test['test'] - cmd = "cd %s && python %s -i %s -v %s" % \ - (t_path, test['test'], options.ip, options.virt) + cmd = "cd %s && python %s -i %s -v %s %s" % \ + (t_path, test['test'], options.ip, options.virt, dbg) status, output = commands.getstatusoutput(cmd) os_status = os.WEXITSTATUS(status)

-def log_param(): +def log_param(debug=None): + #FIXME debug=None is a temporary work around to avoid duplicate + # logging in vsmtest.log because we have log_param in both the + # do_main decorator and the test case's main function. + # We can safely delete the if branch here after all test cases + # have removed the log_param invoke. + if debug == None: + return + else:
For some reason, if -d isn't supplied, nothing is written to the log. I went back and looked at what I tested yesterday - I used debug=False and if debug == False (instead of using None). Although, I noticed in the mail you send, you'd suggested using None. Do you see the same behavior? Also, thanks for the cleanup - looks much better. =) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
For some reason, if -d isn't supplied, nothing is written to the log.
I went back and looked at what I tested yesterday - I used debug=False and if debug == False (instead of using None). Although, I noticed in the mail you send, you'd suggested using None.
Do you see the same behavior? Yes, just found that. New patch is on the way.
Also, thanks for the cleanup - looks much better. =)
-- - Zhengang
participants (3)
-
Kaitlin Rupert
-
Zhengang Li
-
zli@linux.vnet.ibm.com