Ejemplo n.º 1
0
def set_provider_parameters(conn, count, size):
    """Set the provider parameters with InvokeMethod"""
    try:
        result = conn.InvokeMethod("Set", TEST_CLASSNAME,
                                   [('ResponseCount', Uint64(count)),
                                    ('Size', Uint64(size))])

        if result[0] != 0:
            print('SendTestIndicationCount Method error. Nonzero return=%s' %
                  result[0])
            return False
        return True

    except Error as er:
        print('Error: Invoke Method exception %s' % er)
        raise
Ejemplo n.º 2
0
    def create_ciminstance(self):
        """
        Create a sample instance with multiple properties and
        property types.
        """
        class TZ(tzinfo):
            """'Simplistic tsinfo subclass for this test"""
            def utcoffset(self, dt):  # pylint: disable=unused-argument
                return timedelta(minutes=-399)

        dt = datetime(year=2016,
                      month=3,
                      day=31,
                      hour=19,
                      minute=30,
                      second=40,
                      microsecond=654321,
                      tzinfo=MinutesFromUTC(120))
        cim_dt = CIMDateTime(dt)
        props_input = {
            'S1':
            b'Ham',
            'Bool':
            True,
            'UI8':
            Uint8(42),
            'UI16':
            Uint16(4216),
            'UI32':
            Uint32(4232),
            'UI64':
            Uint64(4264),
            'SI8':
            Sint8(-42),
            'SI16':
            Sint16(-4216),
            'SI32':
            Sint32(-4232),
            'SI64':
            Sint64(-4264),
            'R32':
            Real32(42.0),
            'R64':
            Real64(42.64),
            'DTI':
            CIMDateTime(timedelta(10, 49, 20)),
            'DTF':
            cim_dt,
            'DTP':
            CIMDateTime(datetime(2014, 9, 22, 10, 49, 20, 524789,
                                 tzinfo=TZ())),
        }
        # TODO python 2.7 will not write the following unicode character
        # For the moment, only add this property in python 3 test
        if six.PY3:
            props_input['S2'] = u'H\u00E4m'  # U+00E4 = lower case a umlaut

        inst = CIMInstance('CIM_Foo', props_input)
        return inst
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def test_inst_to_yaml_array_props(self):
        """Test  property with array toyaml"""
        str_data = "The pink fox jumped over the big blue dog"
        dt = datetime(2014, 9, 22, 10, 49, 20, 524789)
        array_props = {
            'MyString':
            str_data,
            'MyUint8Array': [Uint8(1), Uint8(2)],
            'MySint8Array': [Sint8(1), Sint8(2)],
            'MyUint64Array':
            [Uint64(123456789),
             Uint64(123456789),
             Uint64(123456789)],
            'MyUint32Array': [Uint32(9999), Uint32(9999)],
            'MyDateTimeArray': [dt, dt, dt],
            'MyStrLongArray': [str_data, str_data, str_data]
        }
        inst = CIMInstance('CIM_FooArray', array_props)
        test_yaml = self.test_recorder.toyaml(inst)

        self.assertEqual(test_yaml['pywbem_object'], 'CIMInstance')
        self.assertEqual(test_yaml['classname'], 'CIM_FooArray')
        properties = test_yaml['properties']
        my_string = properties['MyString']
        self.assertEqual(my_string['name'], 'MyString')
        self.assertEqual(my_string['type'], 'string')
        self.assertEqual(my_string['value'], str_data)

        my_uint8array = properties['MyUint8Array']
        self.assertEqual(my_uint8array['name'], 'MyUint8Array')
        self.assertEqual(my_uint8array['type'], 'uint8')
        self.assertEqual(my_uint8array['value'], [Uint8(1), Uint8(2)])

        my_sint8array = properties['MySint8Array']
        self.assertEqual(my_sint8array['name'], 'MySint8Array')
        self.assertEqual(my_sint8array['type'], 'sint8')
        self.assertEqual(my_sint8array['value'], [Sint8(1), Sint8(2)])

        my_sint64array = properties['MyUint64Array']
        self.assertEqual(my_sint64array['name'], 'MyUint64Array')
        self.assertEqual(my_sint64array['type'], 'uint64')
        self.assertEqual(
            my_sint64array['value'],
            [Uint64(123456789),
             Uint64(123456789),
             Uint64(123456789)])

        my_datetimearray = properties['MyDateTimeArray']
        self.assertEqual(my_datetimearray['name'], 'MyDateTimeArray')
        self.assertEqual(my_datetimearray['type'], 'datetime')
        cim_dt = str(CIMDateTime(dt))
        self.assertEqual(my_datetimearray['value'], [cim_dt, cim_dt, cim_dt])
Ejemplo n.º 5
0
     obj=Uint8(42),
     exp_type_name=u'uint8',
 ), None, None, True),
 ("Object is a Uint16 number",
  dict(
      obj=Uint16(42),
      exp_type_name=u'uint16',
  ), None, None, True),
 ("Object is a Uint32 number",
  dict(
      obj=Uint32(42),
      exp_type_name=u'uint32',
  ), None, None, True),
 ("Object is a Uint64 number",
  dict(
      obj=Uint64(42),
      exp_type_name=u'uint64',
  ), None, None, True),
 ("Object is a Sint8 number", dict(
     obj=Sint8(42),
     exp_type_name=u'sint8',
 ), None, None, True),
 ("Object is a Sint16 number",
  dict(
      obj=Sint16(42),
      exp_type_name=u'sint16',
  ), None, None, True),
 ("Object is a Sint32 number",
  dict(
      obj=Sint32(42),
      exp_type_name=u'sint32',
Ejemplo n.º 6
0
    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