pywbem / pywbemtools

A set of tools using pywbem to communicate with WBEM servers
http://pywbemtools.readthedocs.io/en/stable/
Apache License 2.0
12 stars 2 forks source link

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

Open andy-maier opened 2 years ago

andy-maier commented 2 years ago

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 commented 2 years ago

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

KSchopmeyer commented 1 year ago

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 commented 1 year ago

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