From 2a667d94ec1ad8834f79e12b6e55745deca1cd4d Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Wed, 1 Feb 2012 16:33:54 +0100 Subject: Improve netgroup-add error messages These two situations in netgroup-add need to be distinguished: 1) Netgroup cannot be added because a hostgroup with the same name created a colliding managed netgroup 2) Another native netgroup with the same name exists This patch checks the colliding netgroup and raise appropriate error message based on this finding. https://fedorahosted.org/freeipa/ticket/2069 --- ipalib/plugins/netgroup.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ipalib/plugins/netgroup.py b/ipalib/plugins/netgroup.py index d8c3c4707..149936dc4 100644 --- a/ipalib/plugins/netgroup.py +++ b/ipalib/plugins/netgroup.py @@ -143,13 +143,20 @@ class netgroup_add(LDAPCreate): has_output_params = LDAPCreate.has_output_params + output_params msg_summary = _('Added netgroup "%(value)s"') + + msg_collision = _(u'hostgroup with name "%s" already exists. ' \ + u'Hostgroups and netgroups share a common namespace') + def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options): entry_attrs.setdefault('nisdomainname', self.api.env.domain) try: - # check duplicity with netgroups first to provide proper error - netgroup = api.Command['netgroup_show'](keys[-1]) - self.obj.handle_duplicate_entry(*keys) + dn = self.obj.get_dn(keys[-1]) + (dn_, netgroup) = ldap.get_entry(dn, ['objectclass']) + if 'mepManagedEntry' in netgroup.get('objectclass', []): + raise errors.DuplicateEntry(message=unicode(self.msg_collision % keys[-1])) + else: + self.obj.handle_duplicate_entry(*keys) except errors.NotFound: pass @@ -158,10 +165,7 @@ class netgroup_add(LDAPCreate): # make sure that we don't create a collision if the plugin is # (temporarily) disabled netgroup = api.Command['hostgroup_show'](keys[-1]) - raise errors.DuplicateEntry(message=unicode(_(\ - u'hostgroup with name "%s" already exists. ' \ - u'Hostgroups and netgroups share a common namespace'\ - ) % keys[-1])) + raise errors.DuplicateEntry(message=unicode(self.msg_collision % keys[-1])) except errors.NotFound: pass -- cgit