Esempio n. 1
0
def make_properties(number, property_profile):
    """
    Construct and return a list of CIMProperty objects for use on CIM classes,
    that has the specified number of properties according to the specified
    property profile.
    """

    props = []
    for _ in range(0, number):
        pname = random_name(property_profile.name_len)
        ptype, pvalue = random_type_value(property_profile.value_profile)
        if random.random() > property_profile.value_ratio:
            pvalue = None
        pquals = []
        if property_profile.description_len:
            pquals.append(
                CIMQualifier('Description',
                             type='string',
                             value=random_string(
                                 property_profile.description_len)))
        if property_profile.qualifier_set_profile:
            qset = random.choice(
                property_profile.qualifier_set_profile.qualifier_sets)
            for j, qname in enumerate(qset.names):
                qtype = qset.types[j]
                _, qvalue = random_type_value(qset.values, type=qtype)
                pquals.append(CIMQualifier(qname, type=qtype, value=qvalue))
        prop = CIMProperty(pname, type=ptype, value=pvalue, qualifiers=pquals)
        props.append(prop)
    return props
Esempio n. 2
0
    def setup_for_parameter(self, server, integer_type, is_array, valuemap,
                            values):
        # pylint: disable=redefined-outer-name
        """
        Return a new ValueMapping object that is set up for a CIM parameter
        with the specified data type and valuemap and values qualifiers.
        """
        test_parm = CIMParameter(PARMNAME,
                                 type=integer_type,
                                 is_array=is_array)
        if valuemap is not None:
            test_parm.qualifiers['ValueMap'] = \
                CIMQualifier('ValueMap', valuemap, 'string')
        if values is not None:
            test_parm.qualifiers['Values'] = \
                CIMQualifier('Values', values, 'string')
        test_meth = CIMMethod(METHNAME, return_type='string')
        test_meth.parameters[PARMNAME] = test_parm
        test_class = CIMClass(CLASSNAME)
        test_class.methods[METHNAME] = test_meth
        self.conn.GetClass = Mock(return_value=test_class)

        vm = ValueMapping.for_parameter(server, NAMESPACE, CLASSNAME, METHNAME,
                                        PARMNAME)
        return vm
Esempio n. 3
0
    def test_all(self):

        # Single-valued parameters

        self._run_single(CIMParameter('Param', 'string'))

        self._run_single(CIMParameter('Param', 'string',
                                      qualifiers={'Key': CIMQualifier('Key',
                                                                      True)}))

        # Reference parameters

        self._run_single(CIMParameter('RefParam', 'reference'))

        self._run_single(CIMParameter('RefParam', 'reference',
                                      reference_class='CIM_Foo'))

        self._run_single(CIMParameter('RefParam', 'reference',
                                      reference_class='CIM_Foo',
                                      qualifiers={'Key': CIMQualifier('Key',
                                                                      True)}))

        # Array parameters

        self._run_single(CIMParameter('Array', 'string', is_array=True))

        self._run_single(CIMParameter('Array', 'string', is_array=True,
                                      array_size=10))

        self._run_single(CIMParameter('Array', 'string', is_array=True,
                                      array_size=10,
                                      qualifiers={'Key': CIMQualifier('Key',
                                                                      True)}))

        # Reference array parameters

        self._run_single(CIMParameter('RefArray', 'reference',
                                      is_array=True))

        self._run_single(CIMParameter('RefArray', 'reference',
                                      is_array=True,
                                      reference_class='CIM_Foo'))

        self._run_single(CIMParameter('RefArray', 'reference',
                                      is_array=True,
                                      reference_class='CIM_Foo',
                                      array_size=10))

        self._run_single(CIMParameter('RefArray', 'reference',
                                      is_array=True,
                                      reference_class='CIM_Foo',
                                      array_size=10,
                                      qualifiers={'Key': CIMQualifier('Key',
                                                                      True)}))
Esempio n. 4
0
 def setup_for_property(self, valuemap, values):
     """
     Set up a test class with a ValueMap/Values qualified property,
     and mock the GetClass() method to return that test class.
     """
     test_prop = CIMProperty(PROPNAME, None, 'uint8')
     test_prop.qualifiers['ValueMap'] = \
         CIMQualifier('ValueMap', valuemap, 'string')
     test_prop.qualifiers['Values'] = \
         CIMQualifier('Values', values, 'string')
     test_class = CIMClass(CLASSNAME)
     test_class.properties[PROPNAME] = test_prop
     self.conn.GetClass = Mock(return_value=test_class)
Esempio n. 5
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]]))
Esempio n. 6
0
def test_leaks_CIMClass_qualifier():
    """
    Test function with a CIMClass object that has one qualifier.
    """
    _ = CIMClass('CIM_Foo', qualifiers=[
        CIMQualifier('Q1', value='q'),
    ])
Esempio n. 7
0
 def test_reference_properties(self):
     """Test 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)}))
Esempio n. 8
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)}))
Esempio n. 9
0
    def setup_for_method(self, server, type_, valuemap, values):
        """
        Return a new ValueMapping object that is set up for a CIM method
        with the specified data type and valuemap and values qualifiers.
        """
        test_meth = CIMMethod(METHNAME, return_type=type_)
        if valuemap is not None:
            test_meth.qualifiers['ValueMap'] = \
                CIMQualifier('ValueMap', valuemap, 'string')
        if values is not None:
            test_meth.qualifiers['Values'] = \
                CIMQualifier('Values', values, 'string')
        test_class = CIMClass(CLASSNAME)
        test_class.methods[METHNAME] = test_meth
        self.conn.GetClass = Mock(return_value=test_class)

        vm = ValueMapping.for_method(server, NAMESPACE, CLASSNAME, METHNAME)
        return vm
Esempio n. 10
0
 def test_single_valued(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)}))
Esempio n. 11
0
    def setup_for_property(self, server, type_, valuemap, values):
        """
        Return a new ValueMapping object that is set up for a CIM property
        with the specified data type and valuemap and values qualifiers.
        """
        test_prop = CIMProperty(PROPNAME, value=None, type=type_)
        if valuemap is not None:
            test_prop.qualifiers['ValueMap'] = \
                CIMQualifier('ValueMap', valuemap, 'string')
        if values is not None:
            test_prop.qualifiers['Values'] = \
                CIMQualifier('Values', values, 'string')
        test_class = CIMClass(CLASSNAME)
        test_class.properties[PROPNAME] = test_prop
        self.conn.GetClass = Mock(return_value=test_class)

        vm = ValueMapping.for_property(server, NAMESPACE, CLASSNAME, PROPNAME)
        return vm
Esempio n. 12
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)}
                            )
                       }
            ))
Esempio n. 13
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]))
def build_classes():
    """
    Function that builds and returns a single class: CIM_Foo that will to be
     used as a test class for the mock class tests.
    """
    # build the key properties
    qkey = {'Key': CIMQualifier('Key', True)}
    dkey = {'Description': CIMQualifier('Description', 'blah blah')}

    # build the CIMClass with properties and methods.
    c = CIMClass('CIM_FooDirLoad',
                 qualifiers=dkey,
                 properties={
                     'InstanceID':
                     CIMProperty('InstanceID',
                                 None,
                                 qualifiers=qkey,
                                 type='string',
                                 class_origin='CIM_Foo',
                                 propagated=False)
                 },
                 methods={
                     'Delete':
                     CIMMethod('Delete',
                               'uint32',
                               qualifiers=dkey,
                               class_origin='CIM_Foo',
                               propagated=False),
                     'Fuzzy':
                     CIMMethod('Fuzzy',
                               'string',
                               qualifiers=dkey,
                               class_origin='CIM_Foo',
                               propagated=False)
                 })
    # add the objects to the mock repository
    CONN.add_cimobjects(c)  # noqa: F821
Esempio n. 15
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)}))
Esempio n. 16
0
    def build_elementconformstoprofile_inst(self, conn, profile_path,
                                            element_path):
        """
        Build an instance of CIM_ElementConformsToProfile and insert into
        repository
        """
        class_name = 'CIM_ElementConformsToProfile'
        element_conforms_dict = {
            'ConformantStandard': profile_path,
            'ManagedElement': element_path
        }

        # TODO modify this when issue #1540  (resolve qualifiers)fixed
        # inst = self.inst_from_classname(conn, class_name,
        #                                namespace=self.interop_ns,
        #                                property_values=element_conforms_dict,
        #                                include_missing_properties=False,
        #                                include_path=True)
        cls = conn.GetClass(class_name,
                            namespace=self.interop_ns,
                            LocalOnly=False,
                            IncludeQualifiers=True,
                            IncludeClassOrigin=True)

        for pvalue in cls.properties.values():
            if pvalue.type == 'reference':
                if "key" not in pvalue.qualifiers:
                    pvalue.qualifiers['Key'] = \
                        CIMQualifier('Key', True, propagated=True)

        inst = CIMInstance.from_class(cls,
                                      namespace=self.interop_ns,
                                      property_values=element_conforms_dict,
                                      include_missing_properties=False,
                                      include_path=True)
        # TODO end of temp code

        conn.add_cimobjects(inst, namespace=self.interop_ns)

        assert conn.EnumerateInstances(class_name, namespace=self.interop_ns)
        assert conn.GetInstance(inst.path)
Esempio n. 17
0
def test_leaks_CIMQualifier_minimal():
    """
    Test function with a minimal CIMQualifier object.
    """
    _ = CIMQualifier('Q1', value='bla')
Esempio n. 18
0
from __future__ import absolute_import

import pytest

from ..utils.pytest_extensions import simplified_test_function

# pylint: disable=wrong-import-position, wrong-import-order, invalid-name
from ...utils import import_installed
pywbem = import_installed('pywbem')
from pywbem import CIMProperty, CIMMethod, CIMParameter, CIMQualifier, \
    siunit_obj, siunit  # noqa: E402
# pylint: enable=wrong-import-position, wrong-import-order, invalid-name

# Some qualifier objects used for test cases
TEST_QUAL_PUNIT1_BYTE = CIMQualifier('PUnit', value='byte')
TEST_QUAL_PUNIT2_BYTE = CIMQualifier('pUnIt', value='byte')
TEST_QUAL_UNITS1_BYTES = CIMQualifier('Units', value='Bytes')
TEST_QUAL_UNITS2_BYTES = CIMQualifier('uNiTs', value='Bytes')
TEST_QUAL_UNITS_METERS = CIMQualifier('Units', value='Meters')

TESTCASES_SIUNIT_OBJ = [

    # Testcases for siunit_obj(), that test general behavior.

    # Each list item is a testcase tuple with these items:
    # * desc: Short testcase description.
    # * kwargs: Keyword arguments for the test function:
    #   * in_kwargs: Keyword arguments for siunit().
    #   * exp_result: Expected return value of siunit(), or None.
    # * exp_exc_types: Expected exception type(s), or None.
Esempio n. 19
0
    def build_referenced_profile_insts(self, server, referenced_profiles):
        """
        Build and install in repository the referemced profile instances
        defined by the referemces parameter. A dictionary of tuples where each
        tuple contains Antecedent and Dependent reference in terms of the
        profile name as a tuple (org, name, version).

        Parameters:
          conn:
          profiles (dict of tuples where each tuple defines the antecedent
          and dependent)
        """
        class_name = 'CIM_ReferencedProfile'
        for profile_name in referenced_profiles:
            antecedent = profile_name[0]
            dependent = profile_name[1]
            antecedent_inst = server.get_selected_profiles(
                registered_org=antecedent[0],
                registered_name=antecedent[1],
                registered_version=antecedent[2])
            dependent_inst = server.get_selected_profiles(
                registered_org=dependent[0],
                registered_name=dependent[1],
                registered_version=dependent[2])

            assert len(antecedent_inst) == 1, \
                "Antecedent: {0}".format(antecedent)
            assert len(dependent_inst) == 1, \
                "Dependent: {0}".format(dependent)

            ref_profile_dict = {
                'Antecedent': antecedent_inst[0].path,
                'Dependent': dependent_inst[0].path
            }

            # TODO replace the setting of key qualifier with the commented
            # code with #issue 1540 is fixed, i.e the key qualifier is
            # included in the class.
            # inst = self.inst_from_classname(server.conn, class_name,
            #                                namespace=self.interop_ns,
            #                                property_values=ref_profile_dict,
            #                                include_missing_properties=False,
            #                                include_path=True)

            cls = server.conn.GetClass(class_name,
                                       namespace=self.interop_ns,
                                       LocalOnly=False,
                                       IncludeQualifiers=True,
                                       IncludeClassOrigin=True,
                                       PropertyList=None)

            for pvalue in cls.properties.values():
                if pvalue.type == 'reference':
                    if "key" not in pvalue.qualifiers:
                        pvalue.qualifiers['Key'] = \
                            CIMQualifier('Key', True, propagated=True)

            inst = CIMInstance.from_class(cls,
                                          namespace=self.interop_ns,
                                          property_values=ref_profile_dict,
                                          include_missing_properties=False,
                                          include_path=True)
            # TODO end of code to drop for #1540 fix

            server.conn.add_cimobjects(inst, namespace=self.interop_ns)

            assert server.conn.EnumerateInstances(class_name,
                                                  namespace=self.interop_ns)
            assert server.conn.GetInstance(inst.path)
Esempio n. 20
0
    #   * inst_kwargs: Single inst def or list of class def
    # * exp_exc_types: Expected exception type(s), or None.
    # * exp_warn_types: Expected warning type(s), or None.
    # * condition: Boolean condition for testcase to run, or 'pdb' for debugger

    (
        "Test with a class",
        dict(
            init_args=[CIMClass],
            cls_kwargs=dict(
                classname='CIM_Foo',
                properties=[
                    CIMProperty(
                        'P1', None, type='string',
                        qualifiers=[
                            CIMQualifier('Key', value=True)
                        ]
                    ),
                    CIMProperty('P2', value='Cheese'),
                ]
            ),
            inst_kwargs=None,
            qual_kwargs=None,
        ),
        None, None, True
    ),
    (
        "Test with an instance. Note the class used to build instance path",
        dict(
            init_args=[CIMInstance],
            cls_kwargs=dict(