report dn in errors from get_pivot_attribute()

This commit is contained in:
Benjamin Dauvergne 2016-09-05 13:58:08 +02:00
parent 9192c509b3
commit 5bb324180c
1 changed files with 6 additions and 6 deletions

View File

@ -138,7 +138,7 @@ class Synchronize(object):
def massage_dn(self, old_dn):
return old_dn[:-len(self.source_dn)] + self.target_dn
def get_pivot_attribute(self, entry):
def get_pivot_attribute(self, dn, entry):
'''Find a pivot attribute value for an LDAP entry'''
for objc, attr in self.pivot_attributes:
entry['objectclass'] = map(istr, entry['objectclass'])
@ -146,12 +146,12 @@ class Synchronize(object):
try:
value = entry[attr]
except KeyError:
raise Exception('entry missing pivot attribute %s: %s' % (attr, entry))
raise Exception('entry %s missing pivot attribute %s: %s' % (dn, attr, entry))
break
else:
raise Exception('entry has unknown objectclasses %s' % entry['objectclass'])
raise Exception('entry %s has unknown objectclasses %s' % (dn, entry['objectclass']))
if len(value) != 1:
raise Exception('entry pivot attribute %s must have only one value' % attr)
raise Exception('entry %s pivot attribute %s must have only one value' % (dn, attr))
if attr in self.case_insensitive_attribute:
value = map(istr, value)
return objc, attr, value[0]
@ -175,7 +175,7 @@ class Synchronize(object):
out_filters = []
# Transform input entries into filters
for dn, entry in entries:
objectclass, attr, value = self.get_pivot_attribute(entry)
objectclass, attr, value = self.get_pivot_attribute(dn, entry)
in_dns.append(((attr, value), (dn, entry)))
filter_tpl = '(&(objectclass=%%s)(%s=%%s))' % attr
out_filters.append(
@ -184,7 +184,7 @@ class Synchronize(object):
# Get existing output entries
out_dns = {}
for dn, entry in self.get_target_entries(filterstr=out_filter, attributes=self.attributes):
objectclass, attr, value = self.get_pivot_attribute(entry)
objectclass, attr, value = self.get_pivot_attribute(dn, entry)
out_dns[(attr, value)] = dn, entry
for pivot, (source_dn, entry) in in_dns:
target_dn = self.massage_dn(source_dn)