def list_objectclasses(inst, basedn, log, args): log = log.getChild('list_objectclasses') schema = Schema(inst) if args is not None and args.json: print(dump_json(schema.get_objectclasses(json=True), indent=4)) else: for oc in schema.get_objectclasses(): print(oc)
def _gen_schema_plan(self): if self.olschema is None: return # Get the server schema so that we can query it repeatedly. schema = Schema(self.inst) schema_attrs = schema.get_attributetypes() schema_objects = schema.get_objectclasses() resolver = Resolver(schema_attrs) # Examine schema attrs for attr in self.olschema.attrs: # If we have been instructed to ignore this oid, skip. if attr.oid in self._schema_oid_do_not_migrate: continue if attr.oid in self._schema_oid_unsupported: self.plan.append(SchemaAttributeUnsupported(attr)) continue # For the attr, find if anything has a name overlap in any capacity. # overlaps = [ (names, ds_attr) for (names, ds_attr) in schema_attr_names if len(names.intersection(attr.name_set)) > 0] overlaps = [ ds_attr for ds_attr in schema_attrs if ds_attr.oid == attr.oid ] if len(overlaps) == 0: # We need to add attr self.plan.append(SchemaAttributeCreate(attr)) elif len(overlaps) == 1: # We need to possibly adjust attr ds_attr = overlaps[0] # We need to have a way to compare the two. if attr.inconsistent(ds_attr): self.plan.append(SchemaAttributeInconsistent( attr, ds_attr)) else: # Ambiguous attr, the admin must intervene to migrate it. self.plan.append(SchemaAttributeAmbiguous(attr, overlaps)) # Examine schema classes for obj in self.olschema.classes: # If we have been instructed to ignore this oid, skip. if obj.oid in self._schema_oid_do_not_migrate: continue if obj.oid in self._schema_oid_unsupported: self.plan.append(SchemaClassUnsupported(obj)) continue # For the attr, find if anything has a name overlap in any capacity. overlaps = [ ds_obj for ds_obj in schema_objects if ds_obj.oid == obj.oid ] if len(overlaps) == 0: # We need to add attr self.plan.append(SchemaClassCreate(obj)) elif len(overlaps) == 1: # We need to possibly adjust the objectClass as it exists ds_obj = overlaps[0] if obj.inconsistent(ds_obj, resolver): self.plan.append(SchemaClassInconsistent(obj, ds_obj)) else: # This should be an impossible state. raise Exception('impossible state')
def list_all(inst, basedn, log, args): log = log.getChild('list_all') schema = Schema(inst) json = False if args is not None and args.json: json = True objectclass_elems = schema.get_objectclasses(json=json) attributetype_elems = schema.get_attributetypes(json=json) matchingrule_elems = schema.get_matchingrules(json=json) if json: print( dump_json( { 'type': 'schema', 'objectclasses': objectclass_elems, 'attributetypes': attributetype_elems, 'matchingrules': matchingrule_elems }, indent=4)) else: separator_line = "".join(["-" for _ in range(50)]) print("Objectclasses:\n", separator_line) for oc in objectclass_elems: print(oc) print("AttributeTypes:\n", separator_line) for at in attributetype_elems: print(at) print("MathingRules:\n", separator_line) for mr in matchingrule_elems: print(mr)
def test_x_origin(topo): """ Test that the various forms of X-ORIGIN are handled correctly :id: 995acc60-243b-45b0-9c1c-12bbe6a2882d :setup: Standalone Instance :steps: 1. Create schema file with specific/unique formats for X-ORIGIN 2. Reload the schema file (schema reload task) 3. List all attributes without error 4. Confirm the expected results :expectedresults: 1. Success 2. Success 3. Success 4. Success """ # Create a custom schema file so we can tests specific formats schema_file_name = topo.standalone.schemadir + '/98test.ldif' schema_file = open(schema_file_name, "w") testschema = ( "dn: cn=schema\n" + "attributetypes: ( 8.9.10.11.12.13.16 NAME 'testattr' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'USER_DEFINED' )\n" + "attributetypes: ( 8.9.10.11.12.13.17 NAME 'testattrtwo' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN ( 'USER_DEFINED' 'should be not ignored!!' ) )\n" ) schema_file.write(testschema) schema_file.close() # Reload the schema myschema = Schema(topo.standalone) task = myschema.reload() assert task.exists() task.wait() assert task.get_exit_code() == 0 # Now search attrs and make sure there are no errors myschema.get_attributetypes() myschema.get_objectclasses() # Check we have X-ORIGIN as expected assert " 'USER_DEFINED' " in str(myschema.query_attributetype("testattr")) assert " 'USER_DEFINED' " in str( myschema.query_attributetype("testattrtwo"))