Skip to content

Commit

Permalink
Fix issue in pywbem_mock with incorrect error response to invokemethod
Browse files Browse the repository at this point in the history
We need to return something like NOT_SUPPORTED when there are no methods
in the methods repo. The code was returning NOT_FOUND.  This was causing
issues with the get_central_instances test.
  • Loading branch information
KSchopmeyer committed Mar 29, 2018
1 parent 3afe1fe commit 0713ce5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pywbem_mock/_wbemconnection_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,8 @@ def _fake_createclass(self, namespace, **params):

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

if new_class.classname in self.classes[namespace]:
raise CIMError(CIM_ERR_ALREADY_EXISTS,
Expand Down Expand Up @@ -1829,6 +1831,8 @@ def _fake_createinstance(self, namespace, **params):
self.instances[namespace].append(new_instance)
except KeyError:
self.instances[namespace] = [new_instance]
if namespace not in self.methods:
self.methods[namespace] = NocaseDict()

# Create instance returns model path, path relative to namespace
return self._make_tuple([new_instance.path.copy()])
Expand Down Expand Up @@ -2913,9 +2917,21 @@ def _fake_invokemethod(self, methodname, objectname, Params, **params):
namespace = localobject.namespace
try:
methodsrepo = self._get_methods_repo(namespace)
except CIMError as ce:
# If invoke indicates method repo not built, create it.
if ce.status_code == CIM_ERR_INVALID_NAMESPACE:
if namespace in self.classes or \
namespace in self.instances:
raise CIMError(CIM_ERR_NOT_SUPPORTED,
'Method %s in namespace %s not registered '
'in repository' %
(methodname, namespace))
else:
raise
except KeyError:
raise CIMError(CIM_ERR_NOT_FOUND, 'Method %s in namespace %s not '
'registered in repository' %
raise CIMError(CIM_ERR_NOT_SUPPORTED,
'Method %s in namespace %s not registered in '
'repository' %
(methodname, namespace))

# find the methods entry corresponding to classname. It must be in
Expand Down

0 comments on commit 0713ce5

Please sign in to comment.