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:05:56 +0100
commit2a667d94ec1ad8834f79e12b6e55745deca1cd4d (patch)
tree3777b3788fb2771e0b0193492c471eba2db7d578
parent199d6815d49617b4b438a93ccf99e1e4e32a6221 (diff)
downloadfreeipa-2a667d94ec1ad8834f79e12b6e55745deca1cd4d.tar.gz
freeipa-2a667d94ec1ad8834f79e12b6e55745deca1cd4d.tar.xz
freeipa-2a667d94ec1ad8834f79e12b6e55745deca1cd4d.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 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