Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit 9941a6c1a264ce80ff8bd6e4fff0d832cad21402 Author: Peter Hatina phatina@redhat.com Date: Mon Jun 24 10:33:29 2013 +0200
fix return value from LmiBaseClient::_get_instance_name() when filtering with non-key property
cli-tools/lmi/lmi_client_base.py | 18 ++++++++++++++---- cli-tools/lmi/lmi_client_shell.py | 1 + 2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/cli-tools/lmi/lmi_client_base.py b/cli-tools/lmi/lmi_client_base.py index 89e0206..f90a46a 100644 --- a/cli-tools/lmi/lmi_client_base.py +++ b/cli-tools/lmi/lmi_client_base.py @@ -22,11 +22,17 @@ _RValue = collections.namedtuple('RValue', ["rval", "rparams", "errorstr"]) class LmiReturnValueError(Exception): """Raised, when there is a mandatory argument missing"""
-def raise_or_dump_exception(e): +class LmiFilterError(Exception): + """Raised, when there is a filter error present""" + +def raise_or_dump_exception(e = None): if not LmiBaseClient._get_use_exceptions(): return (et, ei, tb) = sys.exc_info() - raise et, ei, tb + if e is None: + raise et, ei, tb + else: + raise type(e), e, tb
class LmiReturnValue(_RValue): def __getattr__(self, name): @@ -111,14 +117,18 @@ class LmiBaseClient(object): kwargs.pop("Value") try: inst_name_list = self._cliconn.EnumerateInstanceNames(class_name, namespace, **kwargs) + if filter_value: + inst_name_list = filter(lambda n: n[filter_key] == filter_value, inst_name_list) + except KeyError, e: + errorstr = "Can not filter by '%s'" % filter_key + raise_or_dump_exception(LmiFilterError(errorstr)) + return LmiReturnValue(rval = None, errorstr = errorstr) except pywbem.cim_operations.CIMError, e: raise_or_dump_exception(e) return LmiReturnValue(rval = None, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: raise_or_dump_exception(e) return LmiReturnValue(rval = None, errorstr = e.args[0]) - if filter_value: - inst_name_list = filter(lambda n: not filter_key in n or n[filter_key] == filter_value, inst_name_list) return LmiReturnValue(rval = inst_name_list)
def _get_instance(self, path, **kwargs): diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index a9fffc6..1583a97 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -545,6 +545,7 @@ class _LmiClass(BaseObject): return [] return map(lambda inst: _LmiInstance(self._client, self, inst), instance_list)
+ # NOTE: filtering is done only by key properties def first_instance(self, **kwargs): inst_name = self.first_instance_name(**kwargs) if not inst_name:
cura-tools-devel@lists.fedorahosted.org