[openlmi-tools/f19] fix missing log messages in connect()
Peter Hatina
phatina at fedoraproject.org
Mon Dec 2 12:50:26 UTC 2013
commit 96702f9beee0dce0c36845f4118c13b73da2d4f1
Author: Peter Hatina <phatina at redhat.com>
Date: Mon Dec 2 13:14:34 2013 +0100
fix missing log messages in connect()
openlmi-tools-05-fix-log-messages-connect.patch | 127 +++++++++++++++++++++++
openlmi-tools.spec | 7 +-
2 files changed, 133 insertions(+), 1 deletions(-)
---
diff --git a/openlmi-tools-05-fix-log-messages-connect.patch b/openlmi-tools-05-fix-log-messages-connect.patch
new file mode 100644
index 0000000..71938fb
--- /dev/null
+++ b/openlmi-tools-05-fix-log-messages-connect.patch
@@ -0,0 +1,127 @@
+diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
+index 301fa52..7c693c7 100644
+--- a/cli/lmi/shell/LMIConnection.py
++++ b/cli/lmi/shell/LMIConnection.py
+@@ -17,6 +17,7 @@ import os
+ import sys
+ import atexit
+ import pywbem
++import logging
+ import readline
+ import urlparse
+
+@@ -57,8 +58,8 @@ def __lmi_raw_input(prompt, use_echo=True):
+ get_input = raw_input
+ stream = sys.stdout
+ if not sys.stderr.isatty() and not sys.stdout.isatty():
+- LOG.warn('both stdout and stderr are detached from terminal,'
+- ' using stdout for prompt')
++ logging.getLogger("").warn(
++ 'Both stdout and stderr are detached from terminal, using stdout for prompt')
+ if not use_echo:
+ os.system("stty -echo")
+ try:
+@@ -126,6 +127,7 @@ def connect(uri, username="", password="", **kwargs):
+ if kwargs:
+ raise TypeError("connect() got an unexpected keyword arguments: %s" % ", ".join(kwargs.keys()))
+
++ logger = logging.getLogger("")
+ connection = None
+ netloc = urlparse.urlparse(uri).netloc
+ destination = netloc if netloc else uri
+@@ -135,8 +137,11 @@ def connect(uri, username="", password="", **kwargs):
+ connection = LMIConnection(uri, None, None, interactive=interactive,
+ use_cache=use_cache, conn_type=LMIBaseClient.CONN_TYPE_PEGASUS_UDS,
+ verify_server_cert=verify_server_cert)
+- if not connection.verify_credentials():
++ (rval, _, errorstr) = connection.verify_credentials()
++ if not rval:
+ connection = None
++ else:
++ logger.info("Connected via Unix-socket")
+ if connection is None:
+ if interactive and not key_file and not cert_file:
+ try:
+@@ -150,8 +155,12 @@ def connect(uri, username="", password="", **kwargs):
+ connection = LMIConnection(uri, username, password, interactive=interactive,
+ use_cache=use_cache, conn_type=LMIBaseClient.CONN_TYPE_WBEM,
+ key_file=key_file, cert_file=cert_file, verify_server_cert=verify_server_cert)
+- if not connection.verify_credentials():
++ (rval, _, errorstr) = connection.verify_credentials()
++ if not rval:
++ logger.error("Error connecting to %s, %s", uri, errorstr)
+ return None
++ else:
++ logger.info("Connected to %s", uri)
+ return connection
+
+ class LMIConnection(object):
+@@ -282,8 +291,13 @@ class LMIConnection(object):
+ ``CIM_ERR_NOT_FOUND`` set. Otherwise, the should receive
+ :py:exc:`pywbem.AuthError`.
+
+- :returns: True if provided credentials are OK; False otherwise
++ :returns: :py:class:`LMIReturnValue` object with rval set to True, if
++ the user was properly authenticated; False otherwise. In case of any
++ error, rval is set to False and errorstr contains appropriate error
++ string.
++ :rtype: :py:class:`LMIReturnValue`
+ """
++ errorstr = ""
+ try:
+ use_exceptions = lmi_get_use_exceptions()
+ lmi_set_use_exceptions(True)
+@@ -295,13 +309,16 @@ class LMIConnection(object):
+ lmi_set_use_exceptions(use_exceptions)
+ except pywbem.cim_operations.CIMError, e:
+ if e.args[0] == pywbem.cim_constants.CIM_ERR_NOT_FOUND:
+- return True
++ return LMIReturnValue(rval=True)
+ lmi_raise_or_dump_exception(e)
++ errorstr = e.args[1]
+ except pywbem.cim_http.AuthError, e:
+ lmi_raise_or_dump_exception(e)
++ errorstr = e.args[0]
+ except OpenSSL.SSL.Error, e:
+ lmi_raise_or_dump_exception(e)
+- return False
++ errorstr = e.args[0][0][2]
++ return LMIReturnValue(rval=False, errorstr=errorstr)
+
+ def subscribe_indication(self, **kwargs):
+ """
+diff --git a/cli/lmishell b/cli/lmishell
+index e493af5..aaa8f7b 100755
+--- a/cli/lmishell
++++ b/cli/lmishell
+@@ -22,24 +22,23 @@ from lmi.shell import LMIShellOptions
+
+ if __name__ == "__main__":
+ options = LMIShellOptions(sys.argv)
++ logging.basicConfig(format='%(levelname)s: %(message)s')
++ logger = logging.getLogger("")
+ if options.log == LMIShellOptions._LOG_MORE_VERBOSE:
+ # Print out all the log messages to stderr stream
+- logger = logging.getLogger("")
+ logger.setLevel(logging.DEBUG)
+- logger.addHandler(logging.StreamHandler(sys.stderr))
+ elif options.log == LMIShellOptions._LOG_VERBOSE:
+ # Print out only a set of log messages to stderr stream
+- logger = logging.getLogger("")
+ logger.setLevel(logging.INFO)
+- logger.addHandler(logging.StreamHandler(sys.stderr))
+ elif options.log == LMIShellOptions._LOG_QUIET:
+ # Quiet flag seen, drop all the log messages
+- logging.getLogger("").addHandler(logging.NullHandler())
++ handlers = logger.handlers
++ for handler in handlers:
++ logger.removeHandler(handler)
++ logger.addHandler(logging.NullHandler())
+ else:
+ # By default, print error messages to stderr stream
+- logger = logging.getLogger("")
+ logger.setLevel(logging.ERROR)
+- logger.addHandler(logging.StreamHandler(sys.stderr))
+
+ console = LMIConsole()
+ console.set_verify_server_certificate(options.verify_server_cert)
diff --git a/openlmi-tools.spec b/openlmi-tools.spec
index 0ae3c93..777cfdb 100644
--- a/openlmi-tools.spec
+++ b/openlmi-tools.spec
@@ -1,6 +1,6 @@
Name: openlmi-tools
Version: 0.9
-Release: 5%{?dist}
+Release: 6%{?dist}
Summary: Set of CLI tools for Openlmi providers
License: GPLv2+
@@ -10,6 +10,7 @@ Patch0: openlmi-tools-01-python-base-dep.patch
Patch1: openlmi-tools-02-fix-instance-deletion.patch
Patch2: openlmi-tools-03-fix-instance-comparision.patch
Patch3: openlmi-tools-04-fix-passing-method-params.patch
+Patch4: openlmi-tools-05-fix-log-messages-connect.patch
BuildArch: noarch
BuildRequires: automake
@@ -33,6 +34,7 @@ Obsoletes: cura-tools < 0.1-4
%patch1 -p1
%patch2 -p1
%patch3 -p1
+%patch4 -p1
%build
pushd cli
@@ -76,6 +78,9 @@ install -m 644 cli/completion/_lmishell $zsh_comp_dir
%{python_sitelib}/openlmi_tools-*
%changelog
+* Mon Dec 2 2013 Peter Hatina <phatina at redhat.com> - 0.9-6
+- fix missing log messages in connect()
+
* Wed Nov 20 2013 Peter Hatina <phatina at redhat.com> - 0.9-5
- fix passing method params
More information about the scm-commits
mailing list