Skip to content

Commit

Permalink
Fix invoke method interface. I misunderstood the Params vs params and
Browse files Browse the repository at this point in the history
did not incorporate it all.
  • Loading branch information
KSchopmeyer committed Jan 23, 2018
1 parent 43d7a4d commit a722e2d
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 76 deletions.
49 changes: 29 additions & 20 deletions pywbem_mock/_wbemconnection_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def _display(dest, text):
f.close()


def method_callback_interface(conn, objectname, methodname, params):
# pylint: disable=unused-argument
def method_callback_interface(conn, objectname, methodname, Params, **params):
# pylint: disable=unused-argument, invalid-name
"""
**Experimental:** *New in pywbem 0.12 as experimental.*
Expand Down Expand Up @@ -137,7 +137,7 @@ class and methodname is received. This method will be called
a single callback function to be used as the responder
for multiple methods.
params (:term:`py:iterable` of tuples of name,value):
Params (:term:`py:iterable` of tuples of name,value):
Input parameters from the InvokeMethod Params input.
An iterable of input parameters for the CIM method.
Expand All @@ -151,6 +151,16 @@ class and methodname is received. This method will be called
* value (:term:`CIM data type`):
Parameter value
Keyword Arguments:
: Each keyword parameter represents a single input parameter for the
CIM method, with:
* key (:term:`string`):
Parameter name (case independent)
* value (:term:`CIM data type`):
Parameter value
Returns:
* The user written callback method must return a tuple
Expand Down Expand Up @@ -601,16 +611,15 @@ def add_method_callback(self, classname, methodname, method_callback,
if namespace is None:
namespace = self.default_namespace

if not self.methods:
if namespace not in self.methods:
self.methods[namespace] = NocaseDict()

if classname not in self.methods[namespace]:
self.methods[namespace][classname] = NocaseDict()

# Test if dictionary entry already exists. If not, create it
try:
self.methods[namespace][classname][methodname] = method_callback
except KeyError:
mth = NocaseDict(NocaseDict({methodname: method_callback}))
self.methods[namespace][classname] = NocaseDict({methodname: mth})
if methodname in self.methods[namespace][classname]:
raise ValueError("Duplicate method specification")
self.methods[namespace][classname][methodname] = method_callback

def display_repository(self, namespaces=None, dest=None, summary=False,
output_format='mof'):
Expand Down Expand Up @@ -738,6 +747,7 @@ def _display_objects(obj_type, objects_repo, namespace, cmt_begin, cmt_end,
elif obj_type == 'Methods':
try:
methods = objects_repo[namespace]

except KeyError:
return

Expand Down Expand Up @@ -869,11 +879,10 @@ def _mock_methodcall(self, methodname, localobject, Params=None, **params):
'response_params_rqd=%s\nparams=%s',
methodname, localobject, Params, params)

result = self._fake_invokemethod(methodname,
localobject,
Params=Params,
result = self._fake_invokemethod(methodname, localobject, Params,
**params)
# sleep for defined number of seconds

# Sleep for defined number of seconds
if self._response_delay:
time.sleep(self._response_delay)

Expand Down Expand Up @@ -2803,8 +2812,7 @@ def _fake_closeenumeration(self, namespace, **params):
#
#####################################################################

def _fake_invokemethod(self, methodname, objectname, Params=None,
**params):
def _fake_invokemethod(self, methodname, objectname, Params, **params):
# pylint: disable=invalid-name
"""
Implements a mock WBEM server responder for
Expand Down Expand Up @@ -2861,7 +2869,7 @@ def _fake_invokemethod(self, methodname, objectname, Params=None,
try:
methods = methodsrepo[target_class]
except KeyError:
raise CIMError(CIM_ERR_NOT_FOUND, 'Class %s for Method %s in'
raise CIMError(CIM_ERR_NOT_FOUND, 'Class %s for Method %s in '
'namespace %s not '
'registered in repo' %
(localobject.classname, methodname, namespace))
Expand All @@ -2880,9 +2888,10 @@ def _fake_invokemethod(self, methodname, objectname, Params=None,

# Call the registered method and catch exceptions.
try:
result = bound_method(self, methodname, localobject, params=Params)
result = bound_method(self, methodname, localobject, Params,
**params)

# TODO Test return: assert isinstance(result, (list, tuple))
assert isinstance(result, (list, tuple))

# Map output params to NocaseDict to be compatible with return
# from _methodcall
Expand All @@ -2903,5 +2912,5 @@ def _fake_invokemethod(self, methodname, objectname, Params=None,
raise CIMError(CIM_ERR_FAILED, 'Exception failure of invoked '
'method %s in namespace %s with '
'input localobject %r, parameters '
'%s. Exception: %r\nTraceback\n%s' %
'%r. Exception: %r\nTraceback\n%s' %
(methodname, namespace, localobject, params, ex, tb))

0 comments on commit a722e2d

Please sign in to comment.