summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2012-02-01 16:33:54 +0100
committerMartin Kosek <mkosek@redhat.com>2012-02-03 16:06:08 +0100
commit16d17f48dfc81f47d91696d8678699f88f10ae4c (patch)
tree5800e0d9c1c3d272c9bc144619f1690e659e9530
parenta79a27a568f85cec2c7f1a213042230156848ace (diff)
downloadfreeipa.git-16d17f48dfc81f47d91696d8678699f88f10ae4c.tar.gz
freeipa.git-16d17f48dfc81f47d91696d8678699f88f10ae4c.tar.xz
freeipa.git-16d17f48dfc81f47d91696d8678699f88f10ae4c.zip
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
-rw-r--r--ipalib/plugins/netgroup.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/ipalib/plugins/netgroup.py b/ipalib/plugins/netgroup.py
index d8c3c470..149936dc 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