Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenient function for mock scripts to create interop namespace. #1121

Open
andy-maier opened this issue Dec 28, 2021 · 4 comments
Open

Convenient function for mock scripts to create interop namespace. #1121

andy-maier opened this issue Dec 28, 2021 · 4 comments

Comments

@andy-maier
Copy link
Contributor

No description provided.

@andy-maier
Copy link
Contributor Author

andy-maier commented Mar 15, 2022

Update: The original version of this proposal has been replaced with a better one.

This could be done by adding an add_interop_namespace() method to FakedWBEMConnection, with the appropriate parameters, see below.

Here is the code in a current mock script (simple_interop_mock_script.py) for creating and registering the Interop namespace:

A function definition:

def register_dependents(conn, this_file_path, dependent_file_names):
    """
    Register a dependent file name with the pywbemcli dependent file api.
    This insures that any change to a dependent file will cause the
    script to be recompiled.
    """
    if isinstance(dependent_file_names, six.string_types):
        dependent_file_names = [dependent_file_names]

    for fn in dependent_file_names:
        dep_path = os.path.join(os.path.dirname(this_file_path), fn)
        conn.provider_dependent_registry.add_dependents(this_file_path,
                                                        dep_path)

and code from the main routine:

    # Prepare an Interop namespace and namespace provider

    interop_mof_file = 'mock_interop.mof'
    if INTEROP_NAMESPACE not in conn.cimrepository.namespaces:
        conn.add_namespace(INTEROP_NAMESPACE, verbose=verbose)

    interop_mof_path = os.path.join(
        os.path.dirname(this_file_path), interop_mof_file)
    conn.compile_mof_file(interop_mof_path, namespace=INTEROP_NAMESPACE,
                          verbose=verbose)
    register_dependents(conn, this_file_path, interop_mof_file)

    ns_provider = pywbem_mock.CIMNamespaceProvider(conn.cimrepository)
    conn.register_provider(ns_provider, INTEROP_NAMESPACE, verbose=verbose)

With the proposed function, all of the above would be reduced to the following code in the main routine:

    conn.add_interop_namespace(
        interop_namespace=INTEROP_NAMESPACE,
        interop_mof_path='mock_interop.mof',
        mock_script_path=this_file_path,
        verbose=verbose)

@andy-maier
Copy link
Contributor Author

We need to review the proposal and decide whether we go with it.

@KSchopmeyer
Copy link
Contributor

Comments/DISCUSSION:I think that it should be more general to include:

  1. Getting the classes from a schema rather than just local files i.e. the interop_mof_path

What about building the CIMObjectManager class and instance since it is a requirement for building the interop provider? Should that be a separate method or part of this method?

@andy-maier andy-maier modified the milestones: 1.1.0, 1.2.0 Oct 16, 2022
@andy-maier
Copy link
Contributor Author

We discussed Karl's idea in one of the last meetings, and concluded it should be followed.

@andy-maier andy-maier modified the milestones: 1.2.0, 1.3.0 Nov 29, 2022
@andy-maier andy-maier modified the milestones: 1.3.0, 1.4.0 May 22, 2023
@andy-maier andy-maier removed their assignment May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants