Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : 0.9-fixes
---------------------------------------------------------------
commit c8bf5b777fd7fef21c00ed48a5bbb68fa3b29bad
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Dec 2 10:40:58 2013 +0100
extend connect() error messages
---------------------------------------------------------------
cli/lmi/shell/LMIConnection.py | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index da7cef9..6d228bf 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -137,7 +137,8 @@ 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")
@@ -154,8 +155,9 @@ 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():
- logger.error("Not connected to %s, wrong username/password or
certificate", uri)
+ (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)
@@ -289,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)
@@ -302,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):
"""