def ModifyInstance(self, modified_instance, IncludeQualifiers=None): # pylint: disable=invalid-name """ Modification of CIM_IndicationSubscription instance allowed only for selected properties. See the documentation in CommonMethodsMixin.validate_modify_instance for parameter documentation. """ # NOTE: The choice of modifiable properties is just to support tests # and may not reflect user needs since profile definition is # flexible modifiable_properties = [ 'SubscriptionInfo', 'SubscriptionState', 'SubscriptionDuration' ] # Validates the modify instance but does not change any properties. # If not valid, it generates exception self.validate_modify_instance( modified_instance, modifiable_properties=modifiable_properties, IncludeQualifiers=IncludeQualifiers) if modified_instance['SubscriptionDuration']: modified_instance['SubscriptionTimeRemaining'] = \ modified_instance['SubscriptionDuration'] if modified_instance['SubscriptionDuration']: modified_instance['SubscriptionTimeRemaining'] = \ modified_instance['SubscriptionDuration'] modified_instance['TimeOfLastStateChange'] = CIMDateTime.now() return super(CIMIndicationSubscriptionProvider, self).ModifyInstance(modified_instance, IncludeQualifiers=IncludeQualifiers)
def test_invoke_method(self): """ Emulates call to invokemethod to test parameter processing. Currently creates the pywbem_request component. Each test emulated a single cim operation with fixed data to create the input for the yaml, create the yaml, and test the result """ obj_name = self.create_ciminstancename() params = [ ('StringParam', 'Spotty'), ('Uint8', Uint8(1)), ('Sint8', Sint8(2)), ('Uint16', Uint16(3)), ('Sint16', Sint16(3)), ('Uint32', Uint32(4)), ('Sint32', Sint32(5)), ('Uint64', Uint64(6)), ('Sint64', Sint64(7)), ('Real32', Real32(8)), ('Real64', Real64(9)), ('Bool', True), ('DTN', CIMDateTime.now()), # ('DTI', timedelta(60)), ('Ref', obj_name) ] self.test_recorder.stage_pywbem_args(method='InvokeMethod', MethodName='Blah', ObjectName=obj_name, Params=params) method_result_tuple = None method_exception = None self.test_recorder.stage_pywbem_result(method_result_tuple, method_exception) self.test_recorder.record_staged() # reload the yaml to test created values test_yaml = self.loadYamlFile() test_yaml = test_yaml[0] pywbem_request = test_yaml['pywbem_request'] self.assertEqual(pywbem_request['url'], 'http://acme.com:80') operation = pywbem_request['operation'] self.assertEqual(operation['pywbem_method'], 'InvokeMethod') self.assertEqual(operation['MethodName'], 'Blah') param_dict = dict(params) self.assertEqual(len(param_dict), 14) self.assertEqual(param_dict['StringParam'], 'Spotty') self.assertEqual(param_dict['Uint8'], 1) self.assertEqual(param_dict['Bool'], True) # test other parameters ref = param_dict['Ref'] self.assertEqual(ref, obj_name)
def test_all(self): # Invoke on classname try: self.cimcall( self.conn.InvokeMethod, 'FooMethod', TEST_CLASS) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise # Invoke on an InstanceName inst_names = self.cimcall(self.conn.EnumerateInstanceNames, TEST_CLASS) self.assertTrue(len(inst_names) >= 1) name = inst_names[0] # Pick the first returned instance try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', name) except CIMError as ce: if ce.args[0] not in (CIM_ERR_METHOD_NOT_AVAILABLE, CIM_ERR_METHOD_NOT_FOUND): raise # Test remote instance name name2 = name.copy() name2.host = 'woot.com' name2.namespace = 'root/cimv2' try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', name) except CIMError as ce: if ce.args[0] not in (CIM_ERR_METHOD_NOT_AVAILABLE, CIM_ERR_METHOD_NOT_FOUND): raise # Call with all possible parameter types try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', TEST_CLASS, String='Spotty', Uint8=Uint8(1), Sint8=Sint8(2), Uint16=Uint16(3), Sint16=Sint16(3), Uint32=Uint32(4), Sint32=Sint32(5), Uint64=Uint64(6), Sint64=Sint64(7), Real32=Real32(8), Real64=Real64(9), Bool=True, Date1=CIMDateTime.now(), Date2=timedelta(60), Ref=name) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise # Call with non-empty arrays try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', TEST_CLASS, StringArray='Spotty', Uint8Array=[Uint8(1)], Sint8Array=[Sint8(2)], Uint16Array=[Uint16(3)], Sint16Array=[Sint16(3)], Uint32Array=[Uint32(4)], Sint32Array=[Sint32(5)], Uint64Array=[Uint64(6)], Sint64Array=[Sint64(7)], Real32Array=[Real32(8)], Real64Array=[Real64(9)], BoolArray=[False, True], Date1Array=[CIMDateTime.now(), CIMDateTime.now()], Date2Array=[timedelta(0), timedelta(60)], RefArray=[name, name]) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise # Call with new Params arg try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', TEST_CLASS, [('Spam', Uint16(1)), ('Ham', Uint16(2))], # Params Drink=Uint16(3), # begin of **params Beer=Uint16(4)) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise
def CreateInstance(self, namespace, new_instance): # pylint: disable=invalid-name """ Create an instance of the CIM_IndicationFilter class in an Interop namespace of the CIM repository, and if not yet existing create the new namespace in the CIM repository. See `~pywbem_mock.InstanceWriteProvider.CreateInstance` for documentation of validation and description of input parameters, noting extra conditions for this provider as described below: Parameters: namespace (:term:`string`): Must be a valid Interop namespace. new_instance (:class:`~pywbem.CIMInstance`): The following applies regarding its properties: * The 'Filter' and 'Handler' reference properties must exist. * If 'SubscriptionDuration' exists, 'SubscriptionTimeRemaining' will be set. * 'CreationClassName' property: This property is required and its value must match the class name of the new instance. Raises: :exc:`~pywbem.CIMError`: (CIM_ERR_INVALID_PARAMETER) if namespace is not the Interop namespace in the CIM repository or the Name property does not exist or the other properties cannot be added to the instance. """ self.parameter_is_interop(namespace, new_instance.classname) required_properties = ["Filter", "Handler"] self.validate_required_properties_exist(new_instance, namespace, required_properties) # Add missing properties that the might come from CIM_IndicationService new_instance['SubscriptionStartTime'] = CIMDateTime.now() new_instance['TimeOfLastStateChange'] = CIMDateTime.now() # Conditionally add the following properties set_property(new_instance, 'OnFatalErrorPolicy', Uint16(2)) set_property(new_instance, 'RepeatNotificationPolicy', Uint16(2)) set_property(new_instance, 'SubscriptionState', Uint16(2)) if 'SubscriptionDuration' in new_instance: new_instance['SubscriptionTimeRemaining'] = \ new_instance['SubscriptionDuration'] else: new_instance['SubscriptionDuration'] = CIMProperty( 'SubscriptionDuration', None, type='uint64') set_property(new_instance, 'SubscriptionInfo', CIMProperty('SubscriptionInfo', None, type='string')) set_property(new_instance, 'Description', "Pywbem mock CIMIndicationSubscriptionProvider instance") # Create the CIM instance for the new namespace in the CIM repository, # by delegating to the default provider method. return super(CIMIndicationSubscriptionProvider, self).CreateInstance(namespace, new_instance)
def test_all(self): # Invoke on classname try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', TEST_CLASS) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise # Invoke on an InstanceName inst_names = self.cimcall(self.conn.EnumerateInstanceNames, TEST_CLASS) self.assertTrue(len(inst_names) >= 1) name = inst_names[0] # Pick the first returned instance try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', name) except CIMError as ce: if ce.args[0] not in (CIM_ERR_METHOD_NOT_AVAILABLE, CIM_ERR_METHOD_NOT_FOUND): raise # Test remote instance name name2 = name.copy() name2.host = 'woot.com' name2.namespace = 'root/cimv2' try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', name) except CIMError as ce: if ce.args[0] not in (CIM_ERR_METHOD_NOT_AVAILABLE, CIM_ERR_METHOD_NOT_FOUND): raise # Call with all possible parameter types try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', TEST_CLASS, String='Spotty', Uint8=Uint8(1), Sint8=Sint8(2), Uint16=Uint16(3), Sint16=Sint16(3), Uint32=Uint32(4), Sint32=Sint32(5), Uint64=Uint64(6), Sint64=Sint64(7), Real32=Real32(8), Real64=Real64(9), Bool=True, Date1=CIMDateTime.now(), Date2=timedelta(60), Ref=name) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise # Call with non-empty arrays try: self.cimcall(self.conn.InvokeMethod, 'FooMethod', TEST_CLASS, StringArray='Spotty', Uint8Array=[Uint8(1)], Sint8Array=[Sint8(2)], Uint16Array=[Uint16(3)], Sint16Array=[Sint16(3)], Uint32Array=[Uint32(4)], Sint32Array=[Sint32(5)], Uint64Array=[Uint64(6)], Sint64Array=[Sint64(7)], Real32Array=[Real32(8)], Real64Array=[Real64(9)], BoolArray=[False, True], Date1Array=[CIMDateTime.now(), CIMDateTime.now()], Date2Array=[timedelta(0), timedelta(60)], RefArray=[name, name]) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise # Call with new Params arg try: self.cimcall( self.conn.InvokeMethod, 'FooMethod', TEST_CLASS, [('Spam', Uint16(1)), ('Ham', Uint16(2))], # Params Drink=Uint16(3), # begin of **params Beer=Uint16(4)) except CIMError as ce: if ce.args[0] != CIM_ERR_METHOD_NOT_AVAILABLE: raise