diff options
author | Rob Crittenden <rcritten@redhat.com> | 2010-10-27 12:07:53 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2010-10-28 17:47:20 -0400 |
commit | 3c795f3251bd0354d56e2b50042ee04cee7cd21f (patch) | |
tree | 2b52ddf89754c8375290343cdc51563c147346fd /ipalib/plugins | |
parent | 7486ead6c910d13ae4d7cbae6fae738ce2bf47eb (diff) | |
download | freeipa-3c795f3251bd0354d56e2b50042ee04cee7cd21f.tar.gz freeipa-3c795f3251bd0354d56e2b50042ee04cee7cd21f.tar.xz freeipa-3c795f3251bd0354d56e2b50042ee04cee7cd21f.zip |
Return reason for failure when updating group membership fails.
We used to return a list of dns that failed to be added. We now return
a list of tuples instead. The tuple looks like (dn, reason) where reason
is the exception that was returned.
Also made the label we use for failures to be singular instead of plural
since we now print them out individually instead of as comma-separated.
ticket 270
Diffstat (limited to 'ipalib/plugins')
-rw-r--r-- | ipalib/plugins/baseldap.py | 26 | ||||
-rw-r--r-- | ipalib/plugins/netgroup.py | 18 |
2 files changed, 26 insertions, 18 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index f764efbb7..f3aa09d3e 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -117,6 +117,12 @@ global_output_params = ( Str('externalhost?', label=_('External host'), ), + Str('memberhost', + label=_('Failed hosts/hostgroups'), + ), + Str('memberuser', + label=_('Failed users/groups'), + ), ) @@ -818,7 +824,7 @@ class LDAPModMember(LDAPQuery): name = to_cli(ldap_obj_name) doc = self.member_param_doc % ldap_obj.object_name_plural yield List('%s?' % name, cli_name='%ss' % name, doc=doc, - label=ldap_obj.object_name_plural) + label=ldap_obj.object_name) def get_member_dns(self, **options): dns = {} @@ -835,8 +841,8 @@ class LDAPModMember(LDAPQuery): ldap_obj = self.api.Object[ldap_obj_name] try: dns[attr][ldap_obj_name].append(ldap_obj.get_dn(name)) - except errors.PublicError: - failed[attr][ldap_obj_name].append(name) + except errors.PublicError, e: + failed[attr][ldap_obj_name].append((name, unicode(e))) return (dns, failed) @@ -884,10 +890,11 @@ class LDAPAddMember(LDAPModMember): continue try: ldap.add_entry_to_group(m_dn, dn, attr) - except errors.PublicError: + except errors.PublicError, e: ldap_obj = self.api.Object[ldap_obj_name] - failed[attr][ldap_obj_name].append( - ldap_obj.get_primary_key_from_dn(m_dn) + failed[attr][ldap_obj_name].append(( + ldap_obj.get_primary_key_from_dn(m_dn), + unicode(e),) ) else: completed += 1 @@ -985,10 +992,11 @@ class LDAPRemoveMember(LDAPModMember): continue try: ldap.remove_entry_from_group(m_dn, dn, attr) - except errors.PublicError: + except errors.PublicError, e: ldap_obj = self.api.Object[ldap_obj_name] - failed[attr][ldap_obj_name].append( - ldap_obj.get_primary_key_from_dn(m_dn) + failed[attr][ldap_obj_name].append(( + ldap_obj.get_primary_key_from_dn(m_dn), + unicode(e),) ) else: completed += 1 diff --git a/ipalib/plugins/netgroup.py b/ipalib/plugins/netgroup.py index 3b714213a..28647b963 100644 --- a/ipalib/plugins/netgroup.py +++ b/ipalib/plugins/netgroup.py @@ -156,13 +156,13 @@ class netgroup_add_member(LDAPAddMember): external_hosts = entry_attrs_.get('externalhost', []) failed_hosts = [] for host in failed['memberhost']['host']: - host = host.lower() - host_dn = self.api.Object['host'].get_dn(host) - if host not in external_hosts and host_dn not in members: - external_hosts.append(host) + hostname = host[0].lower() + host_dn = self.api.Object['host'].get_dn(hostname) + if hostname not in external_hosts and host_dn not in members: + external_hosts.append(hostname) completed_external += 1 else: - failed_hosts.append(host) + failed_hosts.append(hostname) if completed_external: try: ldap.update_entry(dn, {'externalhost': external_hosts}) @@ -190,12 +190,12 @@ class netgroup_remove_member(LDAPRemoveMember): failed_hosts = [] completed_external = 0 for host in failed['memberhost']['host']: - host = host.lower() - if host in external_hosts: - external_hosts.remove(host) + hostname = host[0].lower() + if hostname in external_hosts: + external_hosts.remove(hostname) completed_external += 1 else: - failed_hosts.append(host) + failed_hosts.append(hostname) if completed_external: try: ldap.update_entry(dn, {'externalhost': external_hosts}) |