예제 #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 send_request_for_indications(conn, class_name, requested_indications):
    """
    Send an invokemethod to the WBEM server to initiate the indication
    output.  This is a pegasus specific operation. Note also that the
    way Pegasus works today, often the response for this request does not
    get returned until well after the indication flow has started because
    it operates on the same thread as the response.
    """
    try:
        # Send method to pegasus server to create  required number of
        # indications. This is a pegasus specific class and method

        result = conn.InvokeMethod(
            "SendTestIndicationsCount", class_name,
            [('indicationSendCount', Uint32(requested_indications))])

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

    except Error as er:
        print('Error: Indication Method exception %s' % er)
        return False
예제 #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('<PROPERTY NAME="Foo" TYPE="uint32"></PROPERTY>',
                         CIMProperty('Foo', None, type='uint32'))

        self._run_single(
            '<PROPERTY NAME="Foo" TYPE="uint32"><VALUE>1234</VALUE>'
            '</PROPERTY>', CIMProperty('Foo', Uint32(1234)))

        self._run_single(
            '<PROPERTY NAME="Foo" TYPE="uint32">'
            '<QUALIFIER NAME="ASSOCIATION" TYPE="boolean">'
            '<VALUE>TRUE</VALUE></QUALIFIER><VALUE>1234</VALUE></PROPERTY>',
            CIMProperty(
                'Foo',
                Uint32(1234),
                qualifiers={'ASSOCIATION': CIMQualifier('ASSOCIATION', True)}))
예제 #5
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)
예제 #6
0
    def test_all(self):

        self._run_single(CIMClass('CIM_Foo'))
        self._run_single(CIMClass('CIM_Foo', superclass='CIM_bar'))

        self._run_single(CIMClass(
            'CIM_CollectionInSystem',
            qualifiers={'ASSOCIATION':
                        CIMQualifier('ASSOCIATION', True,
                                     overridable=False),

                        'Aggregation':
                        CIMQualifier('Aggregation', True,
                                     overridable=False),
                        'Version':
                        CIMQualifier('Version', '2.6.0',
                                     tosubclass=False,
                                     translatable=False),
                        'Description':
                        CIMQualifier('Description',
                                     'CIM_CollectionInSystem is an ' \
                                     'association used to establish a ' \
                                     'parent-child relationship between a ' \
                                     'collection and an \'owning\' System ' \
                                     'such as an AdminDomain or '\
                                     'ComputerSystem. A single collection '\
                                     'should not have both a ' \
                                     'CollectionInOrganization and a ' \
                                     'CollectionInSystem association.',
                                     translatable=True)},
            properties={'Parent':
                        CIMProperty(
                            'Parent', None, type='reference',
                            reference_class='CIM_System',
                            qualifiers={'Key':
                                        CIMQualifier('Key', True,
                                                     overridable=False),
                                        'Aggregate':
                                        CIMQualifier('Aggregate', True,
                                                     overridable=False),
                                        'Max':
                                        CIMQualifier('Max', Uint32(1))}),
                        'Child':
                        CIMProperty(
                            'Child', None, type='reference',
                            reference_class='CIM_Collection',
                            qualifiers={'Key':
                                        CIMQualifier('Key', True,
                                                     overridable=False)}
                            )
                       }
            ))
예제 #7
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]]))
예제 #8
0
    def execute(self, url_type, timeout, delay):
        """
            Execute a single connect with timeout, followed by invokemethod
            of the method that delays response and test for possible responses.

            Tests for correct response type (good response if the delay is
            less than the timeout and timeout exception if the delay is greater
            than the timeout.  It ignores results where the operation delay
            and timeout are equal since the result could be either timeout
            or good response.
        """
        url = url_type + '://' + self.host
        conn = self.connect(url, timeout=timeout)
        execution_time = None

        if self.debug:
            print('execute url_type=%s timeout=%s delay=%s' %
                  (url_type, timeout, delay))

        err_flag = ""
        opttimer = ElapsedTimer()
        try:
            # Confirm server working with a simple request.
            conn.GetClass('CIM_ManagedElement')
            request_result = 0  # good response
            conn.InvokeMethod(TESTMETHOD, TESTCLASS,
                              [('delayInSeconds', Uint32(delay))])

            execution_time = opttimer.elapsed_sec()

            if delay > timeout:
                err_flag = "Timeout Error: delay gt timeout"
                if self.stop_on_err:
                    self.fail('should not get good response for %delay > %s' %
                              (delay, timeout))
            if delay == timeout:
                err_flag = "Good when timeout matches delay"

        # This exception terminates the test
        except ConnectionError as ce:
            request_result = 2  # Connection error received
            err_flag = "ConnectionError"
            execution_time = opttimer.elapsed_sec()

            self.fail('%s exception %s' % ('Failed ConnectionError)', ce))

        # this exception tests against expected result. It terminates the
        # test only if the timeout is not expected
        except TimeoutError:
            execution_time = opttimer.elapsed_sec()
            err_flag = "TimeoutError"
            execution_time = opttimer.elapsed_sec()
            request_result = 1  # timeout error received
            # error if the operation delay is lt timeout value and we get
            # a timeout
            if delay < timeout:
                err_flag = 'Error. delay < timeout'
                if self.stop_on_err:
                    self.fail('should not get timeout for %delay < %s' %
                              (delay, timeout))
            if delay == timeout:
                err_flag = "Timeout when timeout matches delay"

        # This exception terminates the test if stop_on_err set.
        except Exception as ec:  # pylint: disable=broad-except
            err_flag = "Test Failed.General Exception"
            execution_time = opttimer.elapsed_sec()
            request_result = 2
            if self.stop_on_err:
                self.fail('%s exception %s' % ('Failed(Exception)', ec))

        # generate table entry if verbose. This defines result for this
        # test
        if self.verbose:
            request_result_txt = ['Good Rtn', 'Timeout ', 'Failure']

            print('%-5s %-7s %7d %5d %10.2f  %s' %
                  (url_type, request_result_txt[request_result], timeout,
                   delay, execution_time, err_flag))

        return (True if request_result == 1 else False)
예제 #9
0
 ("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),
      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',
예제 #10
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