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

# HG changeset patch # User Zhengang Li <lizg@cn.ibm.com> # Date 1207811341 -28800 # Node ID 28d173f24fb60cbbe230b7a67de97cb26aaa95dc # Parent 19ff9c851ed8cb76b74d158a4c439dfa5f4ccb50 [TEST] Add -d to duplicate error output to stderr This gives us the capability to output the error messages to screen. The default value is set to false, where error messages will only be saved in the 'vsmtest.log' file. Signed-off-by: Zhengang Li <lizg@cn.ibm.com> diff -r 19ff9c851ed8 -r 28d173f24fb6 lib/CimTest/Globals.py --- a/lib/CimTest/Globals.py Wed Apr 09 18:00:14 2008 +0530 +++ b/lib/CimTest/Globals.py Thu Apr 10 15:09:01 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="Print the output to stderr") if not CIM_NS: CIM_NS = "root/cimv2" @@ -85,11 +87,14 @@ if not CIM_IP: if not CIM_IP: CIM_IP = "localhost" -def log_param(): +def log_param(debug=False): logger.setLevel(logging.DEBUG) #create console handler and set level to debug ch = logging.StreamHandler() - ch.setLevel(int(CIM_LEVEL)) + 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) @@ -98,6 +103,7 @@ def log_param(): \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 logger.addHandler(fh) @@ -119,6 +125,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 19ff9c851ed8 -r 28d173f24fb6 suites/libvirt-cim/main.py --- a/suites/libvirt-cim/main.py Wed Apr 09 18:00:14 2008 +0530 +++ b/suites/libvirt-cim/main.py Thu Apr 10 15:09:01 2008 +0800 @@ -49,6 +49,9 @@ 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="Print the output to stderr") + TEST_SUITE = 'cimtest' @@ -110,14 +113,19 @@ def main(): if options.clean: remove_old_logs(options.group) + if options.debug: + debug_param = "-d" + else: + debug_param = "" + 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, debug_param) status, output = commands.getstatusoutput(cmd) os_status = os.WEXITSTATUS(status)

zli@linux.vnet.ibm.com wrote:
@@ -119,6 +125,7 @@ def do_main(types=['Xen'], p=parser): else: def do_try(): try: + log_param(options.debug) log_param() is invoked here. It doesn't hurt to leave the invoke in every test cases. But we don't have to add that in future test cases.
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:
@@ -119,6 +125,7 @@ def do_main(types=['Xen'], p=parser): else: def do_try(): try: + log_param(options.debug) log_param() is invoked here. It doesn't hurt to leave the invoke in every test cases. But we don't have to add that in future test cases.
from VirtLib.utils import setup_ssh_key from XenKvmLib.test_doms import destroy_and_undefine_all setup_ssh_key()
Excellent - do_try() just gets better in my book. ;) Would like to see some review comments on this patch. I have no complaints, but I'm interested in hearing whether people think this is useful. Thanks! -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

def do_try(): try: + log_param(options.debug)
log_param() is invoked here. It doesn't hurt to leave the invoke in every test cases. But we don't have to add that in future test cases.
Excellent - do_try() just gets better in my book. ;)
Would like to see some review comments on this patch. I have no complaints, but I'm interested in hearing whether people think this is useful.
Thanks!
Ah.. my mistake.. I didn't notice this at first. Including log_param() in both the test case itself and do_try() causes the messages to be written to the log twice. However, I like the idea of calling log_param() once in do_try() and not having to worry about calling it in each test case. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
def do_try(): try: + log_param(options.debug)
log_param() is invoked here. It doesn't hurt to leave the invoke in every test cases. But we don't have to add that in future test cases.
Excellent - do_try() just gets better in my book. ;)
Would like to see some review comments on this patch. I have no complaints, but I'm interested in hearing whether people think this is useful.
Thanks!
Ah.. my mistake.. I didn't notice this at first. Including log_param() in both the test case itself and do_try() causes the messages to be written to the log twice. How about this: def log_param(debug=None): if debug == None: return else: original log_param() body
This way, we don't have to worry about twice logging, and give us time to remove the log_param() in the testcases. And after all log_param() is removed from the testcases, we can revert the log_param() to the state without a 'debug==None' check.
However, I like the idea of calling log_param() once in do_try() and not having to worry about calling it in each test case.
-- - Zhengang

Zhengang Li wrote:
Kaitlin Rupert wrote:
def do_try(): try: + log_param(options.debug)
log_param() is invoked here. It doesn't hurt to leave the invoke in every test cases. But we don't have to add that in future test cases.
Excellent - do_try() just gets better in my book. ;)
Would like to see some review comments on this patch. I have no complaints, but I'm interested in hearing whether people think this is useful.
Thanks!
Ah.. my mistake.. I didn't notice this at first. Including log_param() in both the test case itself and do_try() causes the messages to be written to the log twice. How about this: def log_param(debug=None): if debug == None: return else: original log_param() body
This way, we don't have to worry about twice logging, and give us time to remove the log_param() in the testcases. And after all log_param() is removed from the testcases, we can revert the log_param() to the state without a 'debug==None' check.
Sorry Zhengang, I thought I'd responded to this already. Yes, I think this is a good approach. Can you modify your original patch and resend? Also, can you add a FIXME comment as well? I am keeping track of such FIXME issues, but adding the comment makes it easier to search for later on. Thanks! -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Kaitlin Rupert
-
Zhengang Li
-
zli@linux.vnet.ibm.com