From patchwork Sat Aug 8 17:37:14 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: 40182 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 n78HbRgw007331 for ; Sat, 8 Aug 2009 17:37:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752553AbZHHRhX (ORCPT ); Sat, 8 Aug 2009 13:37:23 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752516AbZHHRhX (ORCPT ); Sat, 8 Aug 2009 13:37:23 -0400 Received: from mx2.redhat.com ([66.187.237.31]:55664 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107AbZHHRhW (ORCPT ); Sat, 8 Aug 2009 13:37:22 -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 n78HbMiv014033; Sat, 8 Aug 2009 13:37:22 -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 n78HbLkF005583; Sat, 8 Aug 2009 13:37:21 -0400 Received: from localhost.localdomain (vpn-10-40.bos.redhat.com [10.16.10.40]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n78HbGPL028559; Sat, 8 Aug 2009 13:37:19 -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: Sat, 8 Aug 2009 14:37:14 -0300 Message-Id: <1249753034-3457-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. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm_config.py | 26 ++++++++++++++++++-------- 1 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py index 7ff7a07..e2cf5be 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 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,12 @@ 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 @@ -413,11 +420,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 +469,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): @@ -519,12 +526,15 @@ if __name__ == "__main__": filename = sys.argv[1] else: filename = os.path.join(os.path.dirname(sys.argv[0]), "kvm_tests.cfg") + # Here we configure the stand alone program to use the autotest + # logging system. + logging_manager.configure_logging(KvmLoggingConfig(), verbose=True) list = config(filename, debug=True).get_list() i = 0 for dict in list: - print "Dictionary #%d:" % i + logging.debug("Dictionary #%d:", i) keys = dict.keys() keys.sort() for key in keys: - print " %s = %s" % (key, dict[key]) + logging.debug(" %s = %s", key, dict[key]) i += 1