예제 #1
0
def conn():
    """
    Create the FakedWBEMConnection and return it
    """
    # pylint: disable=protected-access
    FakedWBEMConnection._reset_logging_config()
    return FakedWBEMConnection()
예제 #2
0
파일: conftest.py 프로젝트: pywbem/pywbem
def conn():
    """
    Create the FakedWBEMConnection and return it. This includes the
    standard default namespace.
    """
    # pylint: disable=protected-access
    FakedWBEMConnection._reset_logging_config()
    return FakedWBEMConnection()
예제 #3
0
def test_is_interop_namespace(testcase, ns, exp_rtn):
    # pylint: disable=unused-argument
    """
    Test the method _is_interop_namespace() which should return True
    or False depending on whether the tst_ns is a valid interop namespace
    name returns correct result.
    """
    conn = FakedWBEMConnection()

    assert conn.is_interop_namespace(ns) is exp_rtn
    assert conn.is_interop_namespace(ns.upper()) is exp_rtn
예제 #4
0
def test_find_interop_namespace(testcase, deflt, nss, exp_ns):
    # pylint: disable=unused-argument
    """
    Test the method
    """
    conn = FakedWBEMConnection(default_namespace=deflt)

    if nss:
        if isinstance(nss, six.string_types):
            nss = [nss]
        for name in nss:
            conn.add_namespace(name)

    rtnd_ns = conn.find_interop_namespace()

    assert rtnd_ns == exp_ns
예제 #5
0
    def build_classes(self, namespace):
        """
        Build the schema qualifier declarations, and the class objects in the
        repository from a DMTF schema.
        This requires only that the leaf objects be defined in a mof
        include file since the compiler finds the files for qualifiers
        and dependent classes.

        Returns:
            Instance of FakedWBEMConnection object.
        """
        # pylint: disable=protected-access

        FakedWBEMConnection._reset_logging_config()

        # Note: During tests, not needed.  When you run direct from
        # pywbemcli it fails
        try:
            self.conn.add_namespace(namespace)
        except Error as er:
            if er.status_code != CIM_ERR_ALREADY_EXISTS:
                raise

        self.conn.compile_dmtf_schema(
            self.dmtf_schema_ver,
            self.schema_dir,
            class_names=self.server_mock_data['class_names'],
            namespace=namespace,
            verbose=self.verbose)

        for filename in self.pg_schema_files:
            filepath = os.path.join(self.pg_schema_dir, filename)
            self.conn.compile_mof_file(filepath,
                                       namespace=namespace,
                                       search_paths=[self.pg_schema_dir],
                                       verbose=self.verbose)

        # compile the mof defined in the 'class-mof definitions
        for mof in self.server_mock_data['class-mof']:
            self.conn.compile_mof_string(mof,
                                         namespace=namespace,
                                         verbose=self.verbose)
예제 #6
0
def build_repo():
    """Fixture to initialize the mock environment and install classes.
       Definde as a function without the pytest.fixture decorator becasue
       there is no way to include a fixture in the signature of a test
       function that uses simplified_test_function. Simplified_test_function
       reports a parameter count difference because of the extram parameter
       that is the fixture and fixtures may not be included in the testcases.
    """
    schema = install_test_dmtf_schema()
    namespace = "root/cimv2"
    partial_schema = """
        #pragma locale ("en_US")
        #pragma include ("Interop/CIM_ObjectManager.mof")
        #pragma include ("Interop/CIM_RegisteredProfile.mof")
        """

    conn = FakedWBEMConnection(default_namespace=namespace)
    conn.compile_mof_string(partial_schema, namespace=namespace,
                            search_paths=[schema.schema_mof_dir])
    return conn
예제 #7
0
def test_install_namespace_provider(testcase, default_ns, ns):
    """
    Test installation of the namespace provider
    """
    # setup the connection and schema
    conn = FakedWBEMConnection(default_namespace=default_ns)

    skip_if_moftab_regenerated()

    schema = DMTFCIMSchema(DMTF_TEST_SCHEMA_VER,
                           TESTSUITE_SCHEMA_DIR,
                           verbose=False)
    # code to be tested
    conn.install_namespace_provider(ns, schema.schema_pragma_file)

    # Ensure that exceptions raised in the remainder of this function
    # are not mistaken as expected exceptions
    assert testcase.exp_exc_types is None

    # Assert that the defined interop namespace is installed
    assert ns in conn.namespaces

    if default_ns:
        assert default_ns in conn.namespaces

    assert len(conn.EnumerateInstances("CIM_Namespace", ns)) == \
        len(conn.namespaces)

    for namespace in conn.namespaces:
        if namespace != ns:
            assert len(conn.EnumerateClasses(namespace=namespace)) == 0
예제 #8
0
    def build_class_repo(self, default_namespace, url=None):
        """
        Build the schema qualifier and class objects in the repository
        from a DMTF schema.
        This requires only that the leaf objects be defined in a mof
        include file since the compiler finds the files for qualifiers
        and dependent classes.

        Returns:
            Instance of FakedWBEMConnection object.
        """
        # pylint: disable=protected-access

        FakedWBEMConnection._reset_logging_config()
        conn = FakedWBEMConnection(default_namespace=default_namespace,
                                   url=url)

        schema = DMTFCIMSchema(self.dmtf_schema_ver,
                               self.schema_dir,
                               verbose=False)

        conn.compile_schema_classes(self.server_mock_data['class_names'],
                                    schema.schema_pragma_file,
                                    verbose=False)

        for fn in self.tst_schema_files:
            pg_file = os.path.join(self.tst_schema_dir, fn)
            conn.compile_mof_file(pg_file,
                                  namespace=default_namespace,
                                  search_paths=[self.tst_schema_dir],
                                  verbose=False)

        # compile the mof defined in the 'class-mof definitions
        for mof in self.server_mock_data['class-mof']:
            conn.compile_mof_string(mof,
                                    namespace=default_namespace,
                                    verbose=False)

        return conn
예제 #9
0
def tst_random_conn(num_insts, num_props):
    """
    Build a FakedWBEMConnection with a mock environment that contains:
    - the qualifiers needed for the class
    - a class with the specified number of properties of types string, uint32,
      boolean, with one string-typed key property
    - the specified number of instances of that class, with random property
      values

    Returns:
      tuple(FakedWBEMConnection, CIMClass, list(CIMInstance))
    """

    qualifiers_mof = """
Qualifier Description : string = null,
    Scope(any),
    Flavor(EnableOverride, ToSubclass, Translatable);

Qualifier Key : boolean = false,
    Scope(property, reference),
    Flavor(DisableOverride, ToSubclass);

Qualifier MaxLen : uint32 = null,
    Scope(property, method, parameter);

Qualifier MaxValue : sint64 = null,
    Scope(property, method, parameter);

Qualifier MinLen : uint32 = 0,
    Scope(property, method, parameter);

Qualifier MinValue : sint64 = null,
    Scope(property, method, parameter);
    """

    cls = tst_random_class(num_props)
    instances = tst_random_instances(cls, num_insts)

    # Build mock environment (using default namespace)
    conn = FakedWBEMConnection(disable_pull_operations=True)
    conn.compile_mof_string(qualifiers_mof)
    conn.add_cimobjects(cls)
    conn.add_cimobjects(instances)

    return conn, cls, instances
def create_conn(reg_dict):
    """
    Create and return a FakedWBEMConnection object that has the specified
    dependents registered.

    Parameters:
      reg_dict (dict): Dependents to be registered, with:
        Key (string): Path name of mock script; does not need to be normalized.
        Value (list): List of path names of dependent files; do not need to be
          normalized.
    """
    conn = FakedWBEMConnection()
    for ms_path in reg_dict:
        dep_paths = reg_dict[ms_path]
        conn.provider_dependent_registry.add_dependents(ms_path, dep_paths)
    return conn
예제 #11
0
def test_interop_namespace_names():
    """
    Test the method interop_namespace_names. This is a single test
    with no parameters because it is really a static operation.
    """
    conn = FakedWBEMConnection()

    interop_ns = conn.interop_namespace_names

    # get valid set from WBEMServer.
    interop_namespaces = WBEMServer.INTEROP_NAMESPACES

    assert set(interop_ns) == set(interop_namespaces)
    # confirm case interop_ns is case-insensitive iterable
    for name in interop_namespaces:
        assert name.lower() in [ns.lower() for ns in interop_ns]
def test_ProviderDependentRegistry_add_dependents(
        testcase, mock_script, dependents, exp_dependents):
    """
    Test function for ProviderDependentRegistry.add_dependents() and
    iter_dependents().
    """
    conn = FakedWBEMConnection()
    registry = conn.provider_dependent_registry

    # The code to be tested
    registry.add_dependents(mock_script, dependents)

    # The code to be tested
    res_dependents = list(registry.iter_dependents(mock_script))

    # Ensure that exceptions raised in the remainder of this function
    # are not mistaken as expected exceptions
    assert testcase.exp_exc_types is None

    assert res_dependents == exp_dependents
예제 #13
0
def create_registered_conn(providers):
    """
    Create and return a FakedWBEMConnection object that has the specified
    providers registered.

    providers: Providers to be registered.
       providers are specified as tuple(prov_class, cim_class, namespace):
         - prov_class: Python class of provider
         - cim_class: Name of CIM class for the provider
         - namespace: CIM namespace for the provider
    """

    # Build a FakedWBEMConnection that has the required namespaces, classes
    # and registered providers in its provider registry.
    conn = FakedWBEMConnection()
    for item in providers:

        prov_class, cim_class, namespace = item

        # Make sure the namespace exists in the CIM repository
        if namespace not in conn.namespaces:
            conn.add_namespace(namespace)

        # Make sure the CIM class exists in the CIM repository
        class_store = conn.cimrepository.get_class_store(namespace)
        if not class_store.object_exists(cim_class):
            # An empty class is sufficient for this purpose:
            class_obj = CIMClass(cim_class)
            conn.add_cimobjects(class_obj, namespace=namespace)

        # Create the provider object, setting up its provider classes
        prov_class.provider_classnames = cim_class
        prov_obj = prov_class(conn.cimrepository)

        # Register the provider
        conn.register_provider(prov_obj, namespaces=namespace)

    return conn
예제 #14
0
    def build_class_repo(self, default_namespace):
        """
        Build the schema qualifier and class objects in the repository.
        This requires only that the leaf objects be defined in a mof
        include file since the compiler finds the files for qualifiers
        and dependent classes.
        """
        FakedWBEMConnection._reset_logging_config()
        conn = FakedWBEMConnection(default_namespace=default_namespace)
        classnames = [
            'CIM_Namespace', 'CIM_ObjectManager', 'CIM_RegisteredProfile',
            'CIM_ElementConformsToProfile'
        ]

        conn.compile_dmtf_schema(DMTF_TEST_SCHEMA_VER,
                                 TESTSUITE_SCHEMA_DIR,
                                 class_names=classnames,
                                 verbose=False)

        return conn