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

# HG changeset patch # User Zhengang Li <lizg@cn.ibm.com> # Date 1208313255 -28800 # Node ID e252990b0c7e4fe0cfdb3e43c035f56d52548dbe # Parent 137e5079c73fcbfc70e6654cee0b3c3eb3c6acd2 [TEST] #3 Add -d to duplicate error output to stderr This gives us the capability to output the error messages to screen. .#3: - Fix the bug that ignore bugs if no -d is specified. .#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 e252990b0c7e lib/CimTest/Globals.py --- a/lib/CimTest/Globals.py Fri Apr 11 16:58:23 2008 +0530 +++ b/lib/CimTest/Globals.py Wed Apr 16 10:34:15 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==True) from VirtLib.utils import setup_ssh_key from XenKvmLib.test_doms import destroy_and_undefine_all setup_ssh_key() diff -r 137e5079c73f -r e252990b0c7e 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 Wed Apr 16 10:34:15 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)

zli@linux.vnet.ibm.com wrote:
.#3: - Fix the bug that ignore bugs if no -d is specified.
@@ -119,6 +134,7 @@ def do_main(types=['Xen'], p=parser): else: def do_try(): try: + log_param(options.debug==True) This is the only line .#3 changed. The parser doesn't assign a 'False' value to options.debug if no -d is specified.
So we have three case: 1. log_param() in test case, debug is 'None' 2. log_param(debug) in do_try(), and -d is specified, debug is 'True' 3. log_param(debug) in do_try(), and no -d is specified, debug is 'False'
from VirtLib.utils import setup_ssh_key from XenKvmLib.test_doms import destroy_and_undefine_all setup_ssh_key()
-- - Zhengang

Zhengang Li wrote:
zli@linux.vnet.ibm.com wrote:
.#3: - Fix the bug that ignore bugs if no -d is specified.
@@ -119,6 +134,7 @@ def do_main(types=['Xen'], p=parser): else: def do_try(): try: + log_param(options.debug==True) This is the only line .#3 changed. The parser doesn't assign a 'False' value to options.debug if no -d is specified.
So we have three case: 1. log_param() in test case, debug is 'None' 2. log_param(debug) in do_try(), and -d is specified, debug is 'True' 3. log_param(debug) in do_try(), and no -d is specified, debug is 'False'
Excellent - thanks Zhengang! I've pushed this in. Sorry to make you re-work this so many times. I think this will be handy when running a single test. I use cimtest for spot checking things here and there, so having the option to print the log will save me a few keystrokes. =) I hope others find it useful. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Kaitlin Rupert
-
Zhengang Li
-
zli@linux.vnet.ibm.com