-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #504, Changes to pywbemcli required for pywbem 1.0.0
compatibility. A number of changes were required to make pywbemcli compatible with both pywbem pre version 1.0 and the incompatible differences in pywbem 1.0.0. Generally these are issues in the tests and not in pywbemcli itself. Changed the tests so that we create variables PYWBEM_0 and PYWBEM_1 in a common file and use these variables to modify tests. Modified a number of tests to account for the fact that the returned url for many tests now includes the port in addition to the host. Modified the invokemethod test code to create the user-defined test provider required by pywbem version 1 Since the pywbem 1 invokemethod server responder is completely different that the pywbem 0 version, two different InvokeMethod test driver python files are for the invoke method tests are defined. This applies to both the simple_mock_invokemethod.py code and the all_types_method_mock.py code 1. Changed name of original file to append _V0 to the name 2 Created corresponding _V1.py as the user-defined provider for InvokeMethod tests. 3. Added if statement to each test file that tests invokemethod to use the correct file. 4. Created new test for testing url invalid port for pywbem 1.
- Loading branch information
1 parent
4889e13
commit f39ee84
Showing
13 changed files
with
402 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
mock_pywbem test script that installs a method callback to be executed. This is | ||
based on the CIM_Foo class in the simple_mock_model.mof test file | ||
""" | ||
|
||
import six | ||
from pywbem_mock import MethodProvider | ||
|
||
from pywbem import CIM_ERR_METHOD_NOT_AVAILABLE, CIMError, CIM_ERR_NOT_FOUND | ||
|
||
# test that GLOBALS exist | ||
assert "CONN" in globals() | ||
assert 'SERVER' in globals() | ||
assert 'VERBOSE' in globals() | ||
global CONN # pylint: disable=global-at-module-level | ||
|
||
|
||
class CIM_AllTypesMethodProvider(MethodProvider): | ||
""" | ||
User test provider for InvokeMethod using CIM_Foo and method1. | ||
This is basis for testing passing of input parameters correctly and | ||
generating some exceptions. It uses only one input parameter where the | ||
value defines the test and one return parameter that provides data from the | ||
provider, normally the value of the parameter defined with the input | ||
parameter. Test for existence of method named method1 | ||
""" | ||
|
||
provider_classnames = 'PyWBEM_AllTypes' | ||
|
||
def __init__(self, cimrepository): | ||
super(CIM_AllTypesMethodProvider, self).__init__(cimrepository) | ||
|
||
def InvokeMethod(self, namespace, MethodName, ObjectName, Params): | ||
""" | ||
Simplistic test method. Validates methodname, objectname, Params | ||
and returns rtn value 0 and one parameter | ||
The parameters and return for Invoke method are defined in | ||
:meth:`~pywbem_mock.MethodProvider.InvokeMethod` | ||
""" | ||
# validate namespace using method in BaseProvider | ||
self.validate_namespace(namespace) | ||
|
||
# get classname and validate. This provider uses only one class | ||
if isinstance(ObjectName, six.string_types): | ||
classname = ObjectName | ||
else: | ||
classname = ObjectName.classname | ||
|
||
assert classname.lower() == self.provider_classnames.lower() | ||
|
||
if MethodName != 'AllTypesMethod': | ||
raise CIMError(CIM_ERR_METHOD_NOT_AVAILABLE) | ||
|
||
# Test if class exists. | ||
if not self.class_exists(namespace, classname): | ||
raise CIMError( | ||
CIM_ERR_NOT_FOUND, | ||
"class {0} does not exist in CIM repository, " | ||
"namespace {1}".format(classname, namespace)) | ||
|
||
# Return the input parameters and returnvalue == 0 | ||
return (0, Params) | ||
|
||
|
||
# Add the the callback to the mock repository | ||
# pylint: disable=undefined-variable | ||
CONN.register_provider( # noqa: F821 | ||
CIM_AllTypesMethodProvider(CONN.cimrepository), # noqa: F821 | ||
CONN.default_namespace, # noqa: F821 | ||
verbose=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
""" | ||
mock_pywbem test script that installs a a method provider for the class | ||
CIM_Foo | ||
""" | ||
|
||
import six | ||
from pywbem_mock import MethodProvider | ||
|
||
from pywbem import CIM_ERR_METHOD_NOT_AVAILABLE, CIMError, CIM_ERR_NOT_FOUND, \ | ||
CIMInstanceName | ||
|
||
# test that GLOBALS exist | ||
assert "CONN" in globals() | ||
assert 'SERVER' in globals() | ||
assert 'VERBOSE' in globals() | ||
global CONN # pylint: disable=global-at-module-level | ||
|
||
|
||
class CIM_FooMethodProvider(MethodProvider): | ||
""" | ||
User test provider for InvokeMethod using CIM_Foo and method1. | ||
This is basis for testing passing of input parameters correctly and | ||
generating some exceptions. It uses only one input parameter where the | ||
value defines the test and one return parameter that provides data from the | ||
provider, normally the value of the parameter defined with the input | ||
parameter. Test for existence of method named method1 | ||
""" | ||
|
||
provider_classnames = 'CIM_Foo' | ||
|
||
def __init__(self, cimrepository): | ||
super(CIM_FooMethodProvider, self).__init__(cimrepository) | ||
|
||
def InvokeMethod(self, namespace, MethodName, ObjectName, Params): | ||
""" | ||
Simplistic test method. Validates methodname, objectname, Params | ||
and returns rtn value 0 and one parameter | ||
The parameters and return for Invoke method are defined in | ||
:meth:`~pywbem_mock.MethodProvider.InvokeMethod` | ||
""" | ||
# validate namespace using method in BaseProvider | ||
self.validate_namespace(namespace) | ||
|
||
# get classname and validate. This provider uses only one class | ||
if isinstance(ObjectName, six.string_types): | ||
classname = ObjectName | ||
else: | ||
classname = ObjectName.classname | ||
assert classname.lower() == 'cim_foo' | ||
|
||
# Test if class exists. | ||
if not self.class_exists(namespace, classname): | ||
raise CIMError( | ||
CIM_ERR_NOT_FOUND, | ||
"class {0} does not exist in CIM repository, " | ||
"namespace {1}".format(classname, namespace)) | ||
|
||
if isinstance(ObjectName, CIMInstanceName): | ||
instance_store = self.cimrepository.get_instance_store(namespace) | ||
inst = self.find_instance(ObjectName, instance_store, copy=False) | ||
if inst is None: | ||
raise CIMError( | ||
CIM_ERR_NOT_FOUND, | ||
"Instance {0} does not exist in CIM repository, " | ||
"namespace {1}".format(ObjectName, namespace)) | ||
# This method expects a single parameter input | ||
|
||
return_params = [] | ||
if MethodName.lower() == 'fuzzy': | ||
if Params: | ||
if 'TestInOutParameter' in Params: | ||
return_params.append(Params['TestInOutParameter']) | ||
|
||
if 'TestRef' in Params: | ||
return_params.append(Params['TestRef']) | ||
|
||
return_value = Params.get('OutputRtnValue', 0) | ||
|
||
return (return_value, return_params) | ||
|
||
raise CIMError(CIM_ERR_METHOD_NOT_AVAILABLE) | ||
|
||
|
||
# Add the the callback to the mock repository | ||
# pylint: disable=undefined-variable | ||
CONN.register_provider(CIM_FooMethodProvider(CONN.cimrepository), # noqa: F821 | ||
CONN.default_namespace, # noqa: F821 | ||
verbose=False) |
Oops, something went wrong.