Message ID | 529841156.1662861249756355515.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Sat, Aug 8, 2009 at 3:32 PM, Michael Goldish<mgoldish@redhat.com> wrote: > How can we set the verbosity level for stand-alone execution, e.g. > enable/disable debug output when running ./kvm_config.py kvm_tests.cfg? On the main program execution we could add a OptionParser instance that parses a --verbose flag, and we pass verbose to the logging system config statement logging_manager.configure_logging(KvmLoggingConfig(), verbose=True) I will re-write the patch with that, thanks! > ----- Original Message ----- > From: "Lucas Meneghel Rodrigues" <lmr@redhat.com> > To: autotest@test.kernel.org > Cc: kvm@vger.kernel.org, mgoldish@redhat.com, "Lucas Meneghel Rodrigues" <lmr@redhat.com> > Sent: Saturday, August 8, 2009 8:37:14 PM (GMT+0200) Auto-Detected > Subject: [PATCH] KVM test: Make kvm_config.py to use autotest logging > > 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 <lmr@redhat.com> > --- > Â 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 > -- > 1.6.2.5 > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest >
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