This was spawned by another recent patch I pushed that showed netgroups
that a hostgroup is a member of. We want to suppress the automatic
netgroup that is created with hostgroups.
rob
>From f4020dffa0f7ebd289063a2e519e21123456890a Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcrit...@redhat.com>
Date: Tue, 30 Aug 2011 18:38:22 -0400
Subject: [PATCH 2/2] Suppress managed netgroups from showing as memberof hostgroups.
By design these managed netgroups are not supposed to show unless you
specifically want to see them.
https://fedorahosted.org/freeipa/ticket/1738
---
ipalib/plugins/hostgroup.py | 49 ++++++++++++++++++++++++++--
tests/test_xmlrpc/test_hostgroup_plugin.py | 7 ----
tests/test_xmlrpc/test_nesting.py | 5 ---
tests/test_xmlrpc/test_netgroup_plugin.py | 1 -
4 files changed, 46 insertions(+), 16 deletions(-)
diff --git a/ipalib/plugins/hostgroup.py b/ipalib/plugins/hostgroup.py
index d75f381e0250c1709d1497db8fe9bac501f4a0be..6a091e2d0d2490beeff041eb1eae282170370363 100644
--- a/ipalib/plugins/hostgroup.py
+++ b/ipalib/plugins/hostgroup.py
@@ -20,6 +20,7 @@
from ipalib.plugins.baseldap import *
from ipalib import api, Int, _, ngettext
+from ipalib.dn import DN
__doc__ = _("""
Groups of hosts.
@@ -88,6 +89,24 @@ class hostgroup(LDAPObject):
),
)
+ def suppress_netgroup_memberof(self, dn, entry_attrs):
+ """
+ We don't want to show managed netgroups so remove them from the
+ memberOf list.
+ """
+ if 'memberof' in entry_attrs:
+ hgdn = DN(dn)
+ for member in entry_attrs['memberof']:
+ ngdn = DN(member)
+ if ngdn['cn'] == hgdn['cn']:
+ try:
+ netgroup = api.Command['netgroup_show'](ngdn['cn'], all=True)['result']
+ if self.has_objectclass(netgroup['objectclass'], 'mepmanagedentry'):
+ entry_attrs['memberof'].remove(member)
+ return
+ except NotFound:
+ pass
+
api.register(hostgroup)
@@ -97,9 +116,11 @@ class hostgroup_add(LDAPCreate):
msg_summary = _('Added hostgroup "%(value)s"')
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
- if self.api.env.wait_for_attr:
- newentry = wait_for_value(ldap, dn, 'objectclass', 'mepOriginEntry')
- entry_from_entry(entry_attrs, newentry)
+ # Always wait for the associated netgroup to be created so we can
+ # be sure to ignore it in memberOf
+ newentry = wait_for_value(ldap, dn, 'objectclass', 'mepOriginEntry')
+ entry_from_entry(entry_attrs, newentry)
+ self.obj.suppress_netgroup_memberof(dn, entry_attrs)
return dn
@@ -120,6 +141,10 @@ class hostgroup_mod(LDAPUpdate):
msg_summary = _('Modified hostgroup "%(value)s"')
+ def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+ self.obj.suppress_netgroup_memberof(dn, entry_attrs)
+ return dn
+
api.register(hostgroup_mod)
@@ -131,22 +156,40 @@ class hostgroup_find(LDAPSearch):
'%(count)d hostgroup matched', '%(count)d hostgroups matched', 0
)
+ def post_callback(self, ldap, entries, truncated, *args, **options):
+ for entry in entries:
+ (dn, entry_attrs) = entry
+ self.obj.suppress_netgroup_memberof(dn, entry_attrs)
+ return dn
+
api.register(hostgroup_find)
class hostgroup_show(LDAPRetrieve):
__doc__ = _('Display information about a hostgroup.')
+ def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+ self.obj.suppress_netgroup_memberof( dn, entry_attrs)
+ return dn
+
api.register(hostgroup_show)
class hostgroup_add_member(LDAPAddMember):
__doc__ = _('Add members to a hostgroup.')
+ def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
+ self.obj.suppress_netgroup_memberof(dn, entry_attrs)
+ return (completed, dn)
+
api.register(hostgroup_add_member)
class hostgroup_remove_member(LDAPRemoveMember):
__doc__ = _('Remove members from a hostgroup.')
+ def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
+ self.obj.suppress_netgroup_memberof(dn, entry_attrs)
+ return (completed, dn)
+
api.register(hostgroup_remove_member)
diff --git a/tests/test_xmlrpc/test_hostgroup_plugin.py b/tests/test_xmlrpc/test_hostgroup_plugin.py
index 6c3b0a41e93eb97bf56edb687bacd626f0888db0..e0d115854e1f437da04cae797eb67e4b82230850 100644
--- a/tests/test_xmlrpc/test_hostgroup_plugin.py
+++ b/tests/test_xmlrpc/test_hostgroup_plugin.py
@@ -83,7 +83,6 @@ class test_hostgroup(Declarative):
objectclass=objectclasses.hostgroup,
description=[u'Test hostgroup 1'],
ipauniqueid=[fuzzy_uuid],
- memberof_netgroup=[hostgroup1],
mepmanagedentry=lambda x: [DN(i) for i in x] == \
[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'),
api.env.basedn)],
@@ -147,7 +146,6 @@ class test_hostgroup(Declarative):
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
'member_host': [fqdn1],
- 'memberof_netgroup': [hostgroup1],
},
),
),
@@ -164,7 +162,6 @@ class test_hostgroup(Declarative):
'member_host': [u'testhost1.%s' % api.env.domain],
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
- 'memberof_netgroup': [hostgroup1],
},
),
),
@@ -183,7 +180,6 @@ class test_hostgroup(Declarative):
'member_host': [u'testhost1.%s' % api.env.domain],
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
- 'memberof_netgroup': [hostgroup1],
},
],
),
@@ -202,7 +198,6 @@ class test_hostgroup(Declarative):
cn=[hostgroup1],
description=[u'Updated hostgroup 1'],
member_host=[u'testhost1.%s' % api.env.domain],
- memberof_netgroup=[hostgroup1],
),
),
),
@@ -219,7 +214,6 @@ class test_hostgroup(Declarative):
'member_host': [u'testhost1.%s' % api.env.domain],
'cn': [hostgroup1],
'description': [u'Updated hostgroup 1'],
- 'memberof_netgroup': [hostgroup1],
},
),
),
@@ -242,7 +236,6 @@ class test_hostgroup(Declarative):
'dn': lambda x: DN(x) == dn1,
'cn': [hostgroup1],
'description': [u'Updated hostgroup 1'],
- 'memberof_netgroup': [hostgroup1],
},
),
),
diff --git a/tests/test_xmlrpc/test_nesting.py b/tests/test_xmlrpc/test_nesting.py
index 31525cd261c7fef1a737947585c11a2305bfd32a..cb2d1d0b29fefabb6eea4e4acd9c3ffe855db78e 100644
--- a/tests/test_xmlrpc/test_nesting.py
+++ b/tests/test_xmlrpc/test_nesting.py
@@ -705,7 +705,6 @@ class test_nesting(Declarative):
objectclass=objectclasses.hostgroup,
description=[u'Test hostgroup 1'],
ipauniqueid=[fuzzy_uuid],
- memberof_netgroup=[hostgroup1],
mepmanagedentry=lambda x: [DN(i) for i in x] == \
[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'),
api.env.basedn)],
@@ -728,7 +727,6 @@ class test_nesting(Declarative):
objectclass=objectclasses.hostgroup,
description=[u'Test hostgroup 2'],
ipauniqueid=[fuzzy_uuid],
- memberof_netgroup=[hostgroup2],
mepmanagedentry=lambda x: [DN(i) for i in x] == \
[DN(('cn',hostgroup2),('cn','ng'),('cn','alt'),
api.env.basedn)],
@@ -755,7 +753,6 @@ class test_nesting(Declarative):
'cn': [hostgroup2],
'description': [u'Test hostgroup 2'],
'member_host': [fqdn1],
- 'memberof_netgroup': [hostgroup2],
},
),
),
@@ -779,7 +776,6 @@ class test_nesting(Declarative):
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
'member_hostgroup': [hostgroup2],
- 'memberof_netgroup': [hostgroup1],
},
),
),
@@ -795,7 +791,6 @@ class test_nesting(Declarative):
'dn': lambda x: DN(x) == hgdn1,
'memberindirect_host': [u'testhost1.%s' % api.env.domain],
'member_hostgroup': [hostgroup2],
- 'memberof_netgroup': [hostgroup1],
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
},
diff --git a/tests/test_xmlrpc/test_netgroup_plugin.py b/tests/test_xmlrpc/test_netgroup_plugin.py
index f28c667ac0a277f4c1191e19990e09554d5c0718..9194b549260a569ae777090a33d68b7e3339ead2 100644
--- a/tests/test_xmlrpc/test_netgroup_plugin.py
+++ b/tests/test_xmlrpc/test_netgroup_plugin.py
@@ -188,7 +188,6 @@ class test_netgroup(Declarative):
cn=[hostgroup1],
objectclass=objectclasses.hostgroup,
description=[u'Test hostgroup 1'],
- memberof_netgroup=[hostgroup1],
mepmanagedentry=lambda x: [DN(i) for i in x] == \
[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'),
api.env.basedn)],
--
1.7.4
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel