예제 #1
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
예제 #2
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