From 86fecb340d644cf7199289a66af75202b0e25dc2 Mon Sep 17 00:00:00 2001 From: William Brown Date: Sep 07 2020 03:57:01 +0000 Subject: Improve resolver --- diff --git a/src/lib389/lib389/migrate/openldap/config.py b/src/lib389/lib389/migrate/openldap/config.py index 10f0d3a..c15ca67 100644 --- a/src/lib389/lib389/migrate/openldap/config.py +++ b/src/lib389/lib389/migrate/openldap/config.py @@ -194,7 +194,7 @@ NOT checking -> desc {self.desc} -> {ds_obj.desc} obsolete {self.obsolete} -> {ds_obj.obsolete}""") - def inconsistent(self, ds_obj): + def inconsistent(self, ds_obj, resolver): assert self.oid == ds_obj.oid # names if self.name_set != set([n.lower() for n in ds_obj.names]): @@ -205,15 +205,16 @@ obsolete {self.obsolete} -> {ds_obj.obsolete}""") self.log.debug("Inconsistent kind") self.debug_full(ds_obj) return True + if set([s.lower() for s in self.sup]) != set([s.lower() for s in ds_obj.sup]): self.log.debug("Inconsistent superior declaration") self.debug_full(ds_obj) return True - if set([s.lower() for s in self.must]) != set([s.lower() for s in ds_obj.must]): + if set([resolver.resolve(s) for s in self.must]) != set([resolver.resolve(s) for s in ds_obj.must]): self.log.debug("Inconsistent Must Set") self.debug_full(ds_obj) return True - if set([s.lower() for s in self.may]) != set([s.lower() for s in ds_obj.may]): + if set([resolver.resolve(s) for s in self.may]) != set([resolver.resolve(s) for s in ds_obj.may]): self.log.debug("Inconsistent May Set") self.debug_full(ds_obj) return True diff --git a/src/lib389/lib389/migrate/plan.py b/src/lib389/lib389/migrate/plan.py index 42dd601..2927dc9 100644 --- a/src/lib389/lib389/migrate/plan.py +++ b/src/lib389/lib389/migrate/plan.py @@ -7,7 +7,7 @@ # --- END COPYRIGHT BLOCK --- # -from lib389.schema import Schema +from lib389.schema import Schema, Resolver from lib389.backend import Backends from lib389.migrate.openldap.config import olOverlayType @@ -225,6 +225,8 @@ class Migration(object): schema_attrs = schema.get_attributetypes() schema_objects = schema.get_objectclasses() + resolver = Resolver(schema_attrs) + # Examine schema attrs for attr in self.olconfig.schema.attrs: # If we have been instructed to ignore this oid, skip. @@ -259,7 +261,7 @@ class Migration(object): elif len(overlaps) == 1: # We need to possibly adjust the objectClass as it exists ds_obj = overlaps[0] - if obj.inconsistent(ds_obj): + if obj.inconsistent(ds_obj, resolver): self.plan.append(SchemaClassInconsistent(obj, ds_obj)) else: # This should be an impossible state. diff --git a/src/lib389/lib389/schema.py b/src/lib389/lib389/schema.py index 00443ff..6a9b05f 100755 --- a/src/lib389/lib389/schema.py +++ b/src/lib389/lib389/schema.py @@ -784,3 +784,18 @@ class SchemaLegacy(object): return dump_json(result) else: return (attributetype, must, may) + +class Resolver(object): + def __init__(self, schema_attrs): + self.attr_map = {} + for attr in schema_attrs: + for name in attr.names: + self.attr_map[name.lower()] = attr + # done + + def resolve(self, attr_in): + attr_in_l = attr_in.lower() + if attr_in_l in self.attr_map: + return self.attr_map[attr_in_l].names[0] + else: + return attr_in_l