示例#1
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])
示例#2
0
 def test_property_arrays(self):
     """Property arrays"""
     self._run_single(CIMProperty('Foo', ['a', 'b', 'c']))
     self._run_single(CIMProperty('Foo', None, type='string', is_array=True))
     self._run_single(CIMProperty('Foo', [Uint8(x) for x in [1, 2, 3]],
                                  qualifiers={'Key': CIMQualifier('Key',
                                                                  True)}))
示例#3
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
示例#4
0
    def test_all(self):

        self._run_single(CIMInstance('CIM_Foo'))

        self._run_single(
            CIMInstance(
                'CIM_Foo', {
                    'string': 'string',
                    'uint8': Uint8(0),
                    'uint8array': [Uint8(1), Uint8(2)],
                    'ref': CIMInstanceName('CIM_Bar')
                }))

        self._run_single(
            CIMInstance('CIM_Foo', {'InstanceID': '1234'},
                        path=CIMInstanceName('CIM_Foo',
                                             {'InstanceID': '1234'})))
示例#5
0
    def test_one_cimtype(self):
        valuemap = ['1']
        values = ['one']
        self.setup_for_property(valuemap, values)

        vm = ValueMapping.for_property(self.server, NAMESPACE, CLASSNAME,
                                       PROPNAME)

        self.assertEqual(vm.tovalues(Uint8(1)), 'one')
示例#6
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)
示例#7
0
    def test_all(self):

        # Single-valued properties

        self._run_single(CIMProperty('Spotty', 'Foot'))
        self._run_single(CIMProperty('Age', Uint16(32)))
        self._run_single(CIMProperty('Foo', '', type='string'))
        self._run_single(CIMProperty('Foo', None, type='string'))
        self._run_single(
            CIMProperty('Age',
                        None,
                        type='uint16',
                        qualifiers={'Key': CIMQualifier('Key', True)}))

        # Property arrays

        self._run_single(CIMProperty('Foo', ['a', 'b', 'c']))
        self._run_single(CIMProperty('Foo', None, type='string',
                                     is_array=True))
        self._run_single(
            CIMProperty('Foo', [Uint8(x) for x in [1, 2, 3]],
                        qualifiers={'Key': CIMQualifier('Key', True)}))

        # Reference properties

        self._run_single(CIMProperty('Foo', None, type='reference'))
        self._run_single(CIMProperty('Foo', CIMInstanceName('CIM_Foo')))
        self._run_single(
            CIMProperty('Foo',
                        CIMInstanceName('CIM_Foo'),
                        qualifiers={'Key': CIMQualifier('Key', True)}))

        # EmbeddedObject properties

        inst = CIMInstance('Foo_Class', {'one': Uint8(1), 'two': Uint8(2)})
        self._run_single(CIMProperty('Foo', inst))
        self._run_single(CIMProperty('Foo', [inst]))
示例#8
0
    def test_all(self):

        self._run_single(
            '<QUALIFIER NAME="ASSOCIATION" TYPE="boolean"><VALUE>TRUE</VALUE>'
            '</QUALIFIER>', CIMQualifier('ASSOCIATION', True))

        self._run_single(
            '<QUALIFIER NAME="Age" TYPE="uint32"><VALUE>1234</VALUE>'
            '</QUALIFIER>', CIMQualifier('Age', Uint32(1234)))

        self._run_single(
            '<QUALIFIER NAME="List" TYPE="uint8"><VALUE.ARRAY><VALUE>1</VALUE>'
            '<VALUE>2</VALUE><VALUE>3</VALUE><VALUE>4</VALUE></VALUE.ARRAY>'
            '</QUALIFIER>',
            CIMQualifier('List', [Uint8(i) for i in [1, 2, 3, 4]]))
示例#9
0
TESTCASES_PERF_EQ = [

    # Testcases for performance tests for equality tests

    # Each list item is a testcase tuple with these items:
    # * desc: Short testcase description.
    # * obj1: Object #1 for equality test.
    # * obj2: Object #2 for equality test.
    (
        "CIMInstanceName with two keybindings, last one different",
        CIMInstanceName(
            'CIM_Foo',
            keybindings=dict(
                Chicken='Ham',
                Beans=Uint8(42),
            ),
        ),
        CIMInstanceName(
            'CIM_Foo',
            keybindings=dict(
                Chicken='Ham',
                Beans=Uint8(43),
            ),
        ),
    ),
    (
        "CIMClass with 10 properties, last one different",
        CIMClass(
            'CIM_Foo',
            properties=[
示例#10
0
    ("Object is a unicode string", dict(
        obj=u"abc",
        exp_type_name=u'string',
    ), None, None, True),
    ("Object is a byte string", dict(
        obj=b"abc",
        exp_type_name=u'string',
    ), None, None, True),

    # Integer tests
    ("Object is an integer", dict(
        obj=42,
        exp_type_name=None,
    ), TypeError, None, True),
    ("Object is a Uint8 number", dict(
        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),
示例#11
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
示例#12
0
 def test_embeddedobject_properties(self):
     """Test EmbeddedObject properties"""
     inst = CIMInstance('Foo_Class',
                        {'one': Uint8(1), 'two': Uint8(2)})
     self._run_single(CIMProperty('Foo', inst))
     self._run_single(CIMProperty('Foo', [inst]))