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 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
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