From patchwork Sun Aug 9 23:57:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 40320 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n79NvTkA006847 for ; Sun, 9 Aug 2009 23:57:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752873AbZHIX5S (ORCPT ); Sun, 9 Aug 2009 19:57:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753296AbZHIX5S (ORCPT ); Sun, 9 Aug 2009 19:57:18 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45161 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751677AbZHIX5R (ORCPT ); Sun, 9 Aug 2009 19:57:17 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n79NvGdZ008999; Sun, 9 Aug 2009 19:57:16 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n79NvFb4018617; Sun, 9 Aug 2009 19:57:15 -0400 Received: from localhost.localdomain (vpn-10-35.bos.redhat.com [10.16.10.35]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n79NvCVq008326; Sun, 9 Aug 2009 19:57:13 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, mgoldish@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: Make kvm_config.py to use autotest logging Date: Sun, 9 Aug 2009 20:57:11 -0300 Message-Id: <1249862231-7082-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make kvm_config.py be able to use the autotest logging infrastructure even in stand alone mode. This way we get the ability of having selective debug mode, and just use the cleaner logging.[debuglevel]('message') syntax instead of resorting to hardcoded [LEVEL] strings in any message. Also, make kvm_config use the optparse library to get options. Script usage: Usage: kvm_config.py [options] Options: -h, --help show this help message and exit -f, --file path to a config file that will be parsed. If not specified, will parse kvm_tests.cfg located inside the kvm test dir. --verbose include debug messages in console output Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/control | 4 +- client/tests/kvm/kvm_config.py | 58 ++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/client/tests/kvm/control b/client/tests/kvm/control index 5c5d424..f894bf9 100644 --- a/client/tests/kvm/control +++ b/client/tests/kvm/control @@ -73,12 +73,12 @@ params = { "name": "kvm_install", "shortname": "kvm_install", "type": "kvm_install", - "mode": "release", + #"mode": "release", #"mode": "snapshot", #"mode": "localtar", #"mode": "localsrc", #"mode": "git", - #"mode": "noinstall", + "mode": "noinstall", ## Are we going to load modules built by this test? ## Defaults to 'yes', so if you are going to provide only userspace code to diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py index 7ff7a07..3237276 100755 --- a/client/tests/kvm/kvm_config.py +++ b/client/tests/kvm/kvm_config.py @@ -1,7 +1,8 @@ #!/usr/bin/python -import re, os, sys, StringIO +import logging, re, os, sys, StringIO, optparse import common from autotest_lib.client.common_lib import error +from autotest_lib.client.common_lib import logging_config, logging_manager """ KVM configuration file utility functions. @@ -9,6 +10,13 @@ KVM configuration file utility functions. @copyright: Red Hat 2008-2009 """ + +class KvmLoggingConfig(logging_config.LoggingConfig): + def configure_logging(self, results_dir=None, verbose=False): + super(KvmLoggingConfig, self).configure_logging(use_console=True, + verbose=verbose) + + class config: """ Parse an input file or string that follows the KVM Test Config File format @@ -22,7 +30,8 @@ class config: """ Initialize the list and optionally parse filename. - @param filename: Path of the file that will be taken + @param filename: Path of the file that will be taken. + @param debug: Whether to turn debugging output. """ self.list = [{"name": "", "shortname": "", "depend": []}] self.debug = debug @@ -31,15 +40,6 @@ class config: self.parse_file(filename) - def set_debug(self, debug=False): - """ - Enable or disable debugging output. - - @param debug: Whether debug is enabled (True) or disabled (False). - """ - self.debug = debug - - def parse_file(self, filename): """ Parse filename, return the resulting list and store it in .list. If @@ -413,11 +413,11 @@ class config: if self.debug and not restricted: self.__debug_print("", "Leaving file %s" % words[1]) else: - print ("WARNING: Cannot include %s -- " - "file not found" % filename) + logging.warning("Cannot include %s -- file not found", + filename) else: - print ("WARNING: Cannot include %s because no file is " - "currently open" % words[1]) + logging.warning("Cannot include %s because no file is " + "currently open", words[1]) # Parse multi-line exceptions # (the block is parsed for each dict separately) @@ -462,7 +462,7 @@ class config: str = "%-50s ---> %s" % (str1, str2) else: str = str1 - print str + logging.debug(str) def __modify_list_variants(self, list, name, dep_list, add_to_shortname): @@ -515,16 +515,30 @@ class config: if __name__ == "__main__": - if len(sys.argv) >= 2: - filename = sys.argv[1] - else: + parser = optparse.OptionParser() + parser.add_option('-f', '--file', dest="filename", action='store_true', + help='path to a config file that will be parsed. ' + 'If not specified, will parse kvm_tests.cfg ' + 'located inside the kvm test dir.') + parser.add_option('--verbose', dest="debug", action='store_true', + help='include debug messages in console output') + + options, args = parser.parse_args() + filename = options.filename + debug = options.debug + + if not filename: filename = os.path.join(os.path.dirname(sys.argv[0]), "kvm_tests.cfg") - list = config(filename, debug=True).get_list() + + # Here we configure the stand alone program to use the autotest + # logging system. + logging_manager.configure_logging(KvmLoggingConfig(), verbose=debug) + list = config(filename, debug=debug).get_list() i = 0 for dict in list: - print "Dictionary #%d:" % i + logging.info("Dictionary #%d:", i) keys = dict.keys() keys.sort() for key in keys: - print " %s = %s" % (key, dict[key]) + logging.info(" %s = %s", key, dict[key]) i += 1