mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Refactor test_nesting, create HostGroupTracker
Reviewed-By: Milan Kubik <mkubik@redhat.com>
This commit is contained in:
committed by
Martin Basti
parent
7febe569ce
commit
ab3f652dc1
@@ -20,193 +20,93 @@
|
||||
Test group nesting and indirect members
|
||||
"""
|
||||
|
||||
from ipalib import api
|
||||
from ipatests.test_xmlrpc import objectclasses
|
||||
from ipatests.test_xmlrpc.xmlrpc_test import (Declarative, fuzzy_digits,
|
||||
fuzzy_uuid)
|
||||
from ipapython.dn import DN
|
||||
from ipatests.test_xmlrpc.test_user_plugin import get_user_result
|
||||
from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test
|
||||
from ipatests.test_xmlrpc.tracker.user_plugin import UserTracker
|
||||
from ipatests.test_xmlrpc.tracker.group_plugin import GroupTracker
|
||||
from ipatests.test_xmlrpc.tracker.host_plugin import HostTracker
|
||||
from ipatests.test_xmlrpc.tracker.hostgroup_plugin import HostGroupTracker
|
||||
import pytest
|
||||
|
||||
group1 = u'testgroup1'
|
||||
group2 = u'testgroup2'
|
||||
group3 = u'testgroup3'
|
||||
group4 = u'testgroup4'
|
||||
user1 = u'tuser1'
|
||||
user2 = u'tuser2'
|
||||
user3 = u'tuser3'
|
||||
user4 = u'tuser4'
|
||||
|
||||
hostgroup1 = u'testhostgroup1'
|
||||
hgdn1 = DN(('cn',hostgroup1),('cn','hostgroups'),('cn','accounts'),
|
||||
api.env.basedn)
|
||||
hostgroup2 = u'testhostgroup2'
|
||||
hgdn2 = DN(('cn',hostgroup2),('cn','hostgroups'),('cn','accounts'),
|
||||
api.env.basedn)
|
||||
@pytest.fixture(scope='class')
|
||||
def user1(request):
|
||||
tracker = UserTracker(name=u'tuser1', givenname=u'Test1', sn=u'User1')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
fqdn1 = u'testhost1.%s' % api.env.domain
|
||||
host_dn1 = DN(('fqdn',fqdn1),('cn','computers'),('cn','accounts'),
|
||||
api.env.basedn)
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def user2(request):
|
||||
tracker = UserTracker(name=u'tuser2', givenname=u'Test2', sn=u'User2')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def user3(request):
|
||||
tracker = UserTracker(name=u'tuser3', givenname=u'Test3', sn=u'User3')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def user4(request):
|
||||
tracker = UserTracker(name=u'tuser4', givenname=u'Test4', sn=u'User4')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def group1(request):
|
||||
tracker = GroupTracker(name=u'testgroup1', description=u'Test desc1')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def group2(request):
|
||||
tracker = GroupTracker(name=u'testgroup2', description=u'Test desc2')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def group3(request):
|
||||
tracker = GroupTracker(name=u'testgroup3', description=u'Test desc3')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def group4(request):
|
||||
tracker = GroupTracker(name=u'testgroup4', description=u'Test desc4')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def host1(request):
|
||||
tracker = HostTracker(name=u'host1')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def hostgroup1(request):
|
||||
tracker = HostGroupTracker(name=u'hostgroup1')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def hostgroup2(request):
|
||||
tracker = HostGroupTracker(name=u'hostgroup2')
|
||||
return tracker.make_fixture(request)
|
||||
|
||||
|
||||
@pytest.mark.tier1
|
||||
class test_nesting(Declarative):
|
||||
cleanup_commands = [
|
||||
('group_del', [group1], {}),
|
||||
('group_del', [group2], {}),
|
||||
('group_del', [group3], {}),
|
||||
('group_del', [group4], {}),
|
||||
('user_del', [user1], {}),
|
||||
('user_del', [user2], {}),
|
||||
('user_del', [user3], {}),
|
||||
('user_del', [user4], {}),
|
||||
('host_del', [fqdn1], {}),
|
||||
('hostgroup_del', [hostgroup1], {}),
|
||||
('hostgroup_del', [hostgroup2], {}),
|
||||
]
|
||||
|
||||
tests = [
|
||||
|
||||
################
|
||||
# create group1:
|
||||
|
||||
dict(
|
||||
desc='Create %r' % group1,
|
||||
command=(
|
||||
'group_add', [group1], dict(description=u'Test desc 1')
|
||||
),
|
||||
expected=dict(
|
||||
value=group1,
|
||||
summary=u'Added group "testgroup1"',
|
||||
result=dict(
|
||||
cn=[group1],
|
||||
description=[u'Test desc 1'],
|
||||
objectclass=objectclasses.group + [u'posixgroup'],
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
gidnumber=[fuzzy_digits],
|
||||
dn=DN(('cn','testgroup1'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
################
|
||||
# create group2:
|
||||
dict(
|
||||
desc='Create %r' % group2,
|
||||
command=(
|
||||
'group_add', [group2], dict(description=u'Test desc 2')
|
||||
),
|
||||
expected=dict(
|
||||
value=group2,
|
||||
summary=u'Added group "testgroup2"',
|
||||
result=dict(
|
||||
cn=[group2],
|
||||
description=[u'Test desc 2'],
|
||||
gidnumber=[fuzzy_digits],
|
||||
objectclass=objectclasses.group + [u'posixgroup'],
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
dn=DN(('cn','testgroup2'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % group3,
|
||||
command=(
|
||||
'group_add', [group3], dict(description=u'Test desc 3')
|
||||
),
|
||||
expected=dict(
|
||||
value=group3,
|
||||
summary=u'Added group "testgroup3"',
|
||||
result=dict(
|
||||
cn=[group3],
|
||||
description=[u'Test desc 3'],
|
||||
gidnumber=[fuzzy_digits],
|
||||
objectclass=objectclasses.group + [u'posixgroup'],
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
dn=DN(('cn','testgroup3'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % group4,
|
||||
command=(
|
||||
'group_add', [group4], dict(description=u'Test desc 4')
|
||||
),
|
||||
expected=dict(
|
||||
value=group4,
|
||||
summary=u'Added group "testgroup4"',
|
||||
result=dict(
|
||||
cn=[group4],
|
||||
description=[u'Test desc 4'],
|
||||
gidnumber=[fuzzy_digits],
|
||||
objectclass=objectclasses.group + [u'posixgroup'],
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
dn=DN(('cn','testgroup4'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % user1,
|
||||
command=(
|
||||
'user_add', [user1], dict(givenname=u'Test', sn=u'User1')
|
||||
),
|
||||
expected=dict(
|
||||
value=user1,
|
||||
summary=u'Added user "%s"' % user1,
|
||||
result=get_user_result(user1, u'Test', u'User1', 'add'),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % user2,
|
||||
command=(
|
||||
'user_add', [user2], dict(givenname=u'Test', sn=u'User2')
|
||||
),
|
||||
expected=dict(
|
||||
value=user2,
|
||||
summary=u'Added user "%s"' % user2,
|
||||
result=get_user_result(user2, u'Test', u'User2', 'add'),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % user3,
|
||||
command=(
|
||||
'user_add', [user3], dict(givenname=u'Test', sn=u'User3')
|
||||
),
|
||||
expected=dict(
|
||||
value=user3,
|
||||
summary=u'Added user "%s"' % user3,
|
||||
result=get_user_result(user3, u'Test', u'User3', 'add'),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % user4,
|
||||
command=(
|
||||
'user_add', [user4], dict(givenname=u'Test', sn=u'User4')
|
||||
),
|
||||
expected=dict(
|
||||
value=user4,
|
||||
summary=u'Added user "%s"' % user4,
|
||||
result=get_user_result(user4, u'Test', u'User4', 'add'),
|
||||
),
|
||||
),
|
||||
|
||||
class TestNestingUserGroups(XMLRPC_test):
|
||||
def test_create_groups_and_users(self, group1, group2, group3, group4,
|
||||
user1, user2, user3, user4):
|
||||
""" Create groups and users """
|
||||
group1.ensure_exists()
|
||||
group2.ensure_exists()
|
||||
group3.ensure_exists()
|
||||
group4.ensure_exists()
|
||||
user1.ensure_exists()
|
||||
user2.ensure_exists()
|
||||
user3.ensure_exists()
|
||||
user4.ensure_exists()
|
||||
|
||||
###############
|
||||
# member stuff
|
||||
@@ -253,449 +153,69 @@ class test_nesting(Declarative):
|
||||
# Note that tuser1 is an indirect member of g1 both through
|
||||
# g2 and g4. It should appear just once in the list.
|
||||
|
||||
dict(
|
||||
desc='Add a group member %r to %r' % (group2, group1),
|
||||
command=(
|
||||
'group_add_member', [group1], dict(group=group2)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group1),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_group': (group2,),
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group1],
|
||||
'description': [u'Test desc 1'],
|
||||
},
|
||||
),
|
||||
),
|
||||
def test_add_group_members_to_groups(self, group1, group2, group3):
|
||||
""" Add group1 two members: group2 and group3 """
|
||||
group1.add_member(dict(group=group2.cn))
|
||||
group2.attrs.update(memberof_group=[group1.cn])
|
||||
group1.add_member(dict(group=group3.cn))
|
||||
group3.attrs.update(memberof_group=[group1.cn])
|
||||
|
||||
def test_add_user_members_to_groups(self, user1, user2, user3, user4,
|
||||
group1, group2, group3, group4):
|
||||
""" Add user1 and user2 to group1, add user3 and group4 to group3,
|
||||
add user1 and user4 to group4 """
|
||||
group2.add_member(dict(user=user1.uid))
|
||||
group2.add_member(dict(user=user2.uid))
|
||||
group3.add_member(dict(user=user3.uid))
|
||||
group3.add_member(dict(group=group4.cn))
|
||||
group4.attrs.update(
|
||||
memberof_group=[group3.cn],
|
||||
memberofindirect_group=[group1.cn]
|
||||
)
|
||||
group4.add_member(dict(user=user1.uid))
|
||||
group4.add_member(dict(user=user4.uid))
|
||||
group1.attrs.update(
|
||||
memberindirect_user=[user1.uid, user2.uid, user3.uid, user4.uid],
|
||||
memberindirect_group=[group4.cn]
|
||||
)
|
||||
group3.attrs.update(
|
||||
memberindirect_user=[u'tuser4', u'tuser1']
|
||||
)
|
||||
|
||||
def test_retrieve_group_group(self, group1, group2, group3, group4):
|
||||
""" Retrieve all test groups (1-4) """
|
||||
group1.retrieve()
|
||||
group2.retrieve()
|
||||
group3.retrieve()
|
||||
group4.retrieve()
|
||||
|
||||
|
||||
dict(
|
||||
desc='Add a group member %r to %r' % (group3, group1),
|
||||
command=(
|
||||
'group_add_member', [group1], dict(group=group3)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group1),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_group': [group2, group3,],
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group1],
|
||||
'description': [u'Test desc 1'],
|
||||
},
|
||||
),
|
||||
),
|
||||
@pytest.mark.tier1
|
||||
class TestNestingHostGroups(XMLRPC_test):
|
||||
def test_create_hostgroups(self, host1, hostgroup1, hostgroup2):
|
||||
""" Create a host and two hostgroups """
|
||||
host1.ensure_exists()
|
||||
hostgroup1.ensure_exists()
|
||||
hostgroup2.ensure_exists()
|
||||
|
||||
def test_nest_hostgroups(self, host1, hostgroup1, hostgroup2):
|
||||
""" Add host1 to hostgroup2, add hostgroup2 to hostgroup1 """
|
||||
hostgroup2.add_member(dict(host=host1.fqdn))
|
||||
command = hostgroup1.make_add_member_command(
|
||||
dict(hostgroup=hostgroup2.cn)
|
||||
)
|
||||
hostgroup1.attrs.update(
|
||||
memberindirect_host=hostgroup2.attrs[u'member_host'],
|
||||
member_hostgroup=[hostgroup2.cn]
|
||||
)
|
||||
result = command()
|
||||
hostgroup1.check_add_member(result)
|
||||
host1.attrs.update(
|
||||
memberof_hostgroup=[hostgroup2.cn],
|
||||
memberofindirect_hostgroup=[hostgroup1.cn]
|
||||
)
|
||||
|
||||
dict(
|
||||
desc='Add a user member %r to %r' % (user1, group2),
|
||||
command=(
|
||||
'group_add_member', [group2], dict(user=user1)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group2),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_user': (u'tuser1',),
|
||||
'memberof_group': (u'testgroup1',),
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group2],
|
||||
'description': [u'Test desc 2'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Add a user member %r to %r' % (user2, group2),
|
||||
command=(
|
||||
'group_add_member', [group2], dict(user=user2)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group2),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_user': [user1, user2],
|
||||
'memberof_group': [group1],
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group2],
|
||||
'description': [u'Test desc 2'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Add a user member %r to %r' % (user3, group3),
|
||||
command=(
|
||||
'group_add_member', [group3], dict(user=user3)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group3),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_user': [user3],
|
||||
'memberof_group': [group1],
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group3],
|
||||
'description': [u'Test desc 3'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Add a group member %r to %r' % (group4, group3),
|
||||
command=(
|
||||
'group_add_member', [group3], dict(group=group4)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group3),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_user': [user3],
|
||||
'memberof_group': [group1],
|
||||
'member_group': [group4],
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group3],
|
||||
'description': [u'Test desc 3'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Add a user member %r to %r' % (user1, group4),
|
||||
command=(
|
||||
'group_add_member', [group4], dict(user=user1)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group4),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_user': [user1],
|
||||
'memberof_group': [group3],
|
||||
'memberofindirect_group': [group1],
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group4],
|
||||
'description': [u'Test desc 4'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Add a user member %r to %r' % (user4, group4),
|
||||
command=(
|
||||
'group_add_member', [group4], dict(user=user4)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
group=tuple(),
|
||||
user=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': DN(('cn',group4),('cn','groups'),('cn','accounts'),
|
||||
api.env.basedn),
|
||||
'member_user': [user1, user4],
|
||||
'memberof_group': [group3],
|
||||
'memberofindirect_group': [group1],
|
||||
'gidnumber': [fuzzy_digits],
|
||||
'cn': [group4],
|
||||
'description': [u'Test desc 4'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve group %r' % group1,
|
||||
command=('group_show', [group1], {}),
|
||||
expected=dict(
|
||||
value=group1,
|
||||
summary=None,
|
||||
result=dict(
|
||||
cn=[group1],
|
||||
description=[u'Test desc 1'],
|
||||
gidnumber= [fuzzy_digits],
|
||||
memberindirect_group = [group4],
|
||||
member_group = [group2, group3],
|
||||
memberindirect_user = [user1, user2, user3, user4],
|
||||
dn=DN(('cn','testgroup1'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve group %r' % group2,
|
||||
command=('group_show', [group2], {}),
|
||||
expected=dict(
|
||||
value=group2,
|
||||
summary=None,
|
||||
result=dict(
|
||||
cn=[group2],
|
||||
description=[u'Test desc 2'],
|
||||
gidnumber= [fuzzy_digits],
|
||||
memberof_group = [group1],
|
||||
member_user = [user1, user2],
|
||||
dn=DN(('cn','testgroup2'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve group %r' % group3,
|
||||
command=('group_show', [group3], {}),
|
||||
expected=dict(
|
||||
value=group3,
|
||||
summary=None,
|
||||
result=dict(
|
||||
cn=[group3],
|
||||
description=[u'Test desc 3'],
|
||||
gidnumber= [fuzzy_digits],
|
||||
memberof_group = [group1],
|
||||
member_user = [user3],
|
||||
member_group = [group4],
|
||||
memberindirect_user = [user1, user4],
|
||||
dn=DN(('cn','testgroup3'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve group %r' % group4,
|
||||
command=('group_show', [group4], {}),
|
||||
expected=dict(
|
||||
value=group4,
|
||||
summary=None,
|
||||
result=dict(
|
||||
cn=[group4],
|
||||
description=[u'Test desc 4'],
|
||||
gidnumber= [fuzzy_digits],
|
||||
memberof_group = [group3],
|
||||
member_user = [user1, user4],
|
||||
memberofindirect_group = [group1],
|
||||
dn=DN(('cn','testgroup4'),('cn','groups'),
|
||||
('cn','accounts'),api.env.basedn),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
# Now do something similar with hosts and hostgroups
|
||||
dict(
|
||||
desc='Create host %r' % fqdn1,
|
||||
command=('host_add', [fqdn1],
|
||||
dict(
|
||||
description=u'Test host 1',
|
||||
l=u'Undisclosed location 1',
|
||||
force=True,
|
||||
),
|
||||
),
|
||||
expected=dict(
|
||||
value=fqdn1,
|
||||
summary=u'Added host "%s"' % fqdn1,
|
||||
result=dict(
|
||||
dn=host_dn1,
|
||||
fqdn=[fqdn1],
|
||||
description=[u'Test host 1'],
|
||||
l=[u'Undisclosed location 1'],
|
||||
krbprincipalname=[u'host/%s@%s' % (fqdn1, api.env.realm)],
|
||||
objectclass=objectclasses.host,
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
managedby_host=[fqdn1],
|
||||
has_keytab=False,
|
||||
has_password=False,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % hostgroup1,
|
||||
command=('hostgroup_add', [hostgroup1],
|
||||
dict(description=u'Test hostgroup 1')
|
||||
),
|
||||
expected=dict(
|
||||
value=hostgroup1,
|
||||
summary=u'Added hostgroup "testhostgroup1"',
|
||||
result=dict(
|
||||
dn=hgdn1,
|
||||
cn=[hostgroup1],
|
||||
objectclass=objectclasses.hostgroup,
|
||||
description=[u'Test hostgroup 1'],
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
mepmanagedentry=[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'),
|
||||
api.env.basedn)],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % hostgroup2,
|
||||
command=('hostgroup_add', [hostgroup2],
|
||||
dict(description=u'Test hostgroup 2')
|
||||
),
|
||||
expected=dict(
|
||||
value=hostgroup2,
|
||||
summary=u'Added hostgroup "testhostgroup2"',
|
||||
result=dict(
|
||||
dn=hgdn2,
|
||||
cn=[hostgroup2],
|
||||
objectclass=objectclasses.hostgroup,
|
||||
description=[u'Test hostgroup 2'],
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
mepmanagedentry=[DN(('cn',hostgroup2),('cn','ng'),('cn','alt'),
|
||||
api.env.basedn)],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc=u'Add host %r to %r' % (fqdn1, hostgroup2),
|
||||
command=(
|
||||
'hostgroup_add_member', [hostgroup2], dict(host=fqdn1)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
host=tuple(),
|
||||
hostgroup=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': hgdn2,
|
||||
'cn': [hostgroup2],
|
||||
'description': [u'Test hostgroup 2'],
|
||||
'member_host': [fqdn1],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc=u'Add hostgroup %r to %r' % (hostgroup2, hostgroup1),
|
||||
command=(
|
||||
'hostgroup_add_member', [hostgroup1], dict(hostgroup=hostgroup2)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
host=tuple(),
|
||||
hostgroup=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': hgdn1,
|
||||
'cn': [hostgroup1],
|
||||
'description': [u'Test hostgroup 1'],
|
||||
'member_hostgroup': [hostgroup2],
|
||||
'memberindirect_host': [fqdn1],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve %r' % hostgroup1,
|
||||
command=('hostgroup_show', [hostgroup1], {}),
|
||||
expected=dict(
|
||||
value=hostgroup1,
|
||||
summary=None,
|
||||
result={
|
||||
'dn': hgdn1,
|
||||
'memberindirect_host': [u'testhost1.%s' % api.env.domain],
|
||||
'member_hostgroup': [hostgroup2],
|
||||
'cn': [hostgroup1],
|
||||
'description': [u'Test hostgroup 1'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve %r' % fqdn1,
|
||||
command=('host_show', [fqdn1], {}),
|
||||
expected=dict(
|
||||
value=fqdn1,
|
||||
summary=None,
|
||||
result=dict(
|
||||
dn=host_dn1,
|
||||
fqdn=[fqdn1],
|
||||
description=[u'Test host 1'],
|
||||
l=[u'Undisclosed location 1'],
|
||||
krbprincipalname=[u'host/%s@%s' % (fqdn1, api.env.realm)],
|
||||
has_keytab=False,
|
||||
has_password=False,
|
||||
managedby_host=[fqdn1],
|
||||
memberof_hostgroup = [u'testhostgroup2'],
|
||||
memberofindirect_hostgroup = [u'testhostgroup1'],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
]
|
||||
def test_retrieve_host_hostgroup(self, host1, hostgroup1):
|
||||
""" Retrieve host1 and hostgroup1 """
|
||||
hostgroup1.retrieve()
|
||||
host1.retrieve()
|
||||
|
||||
@@ -12,7 +12,10 @@ from ipatests.util import assert_deepequal, get_group_dn
|
||||
class GroupTracker(Tracker):
|
||||
""" Class for host plugin like tests """
|
||||
retrieve_keys = {u'dn', u'cn', u'gidnumber', u'member_user',
|
||||
u'member_group', u'description'}
|
||||
u'member_group', u'description',
|
||||
u'memberof_group', u'memberofindirect_group',
|
||||
u'memberindirect_group', u'memberindirect_user'}
|
||||
|
||||
retrieve_all_keys = retrieve_keys | {u'ipauniqueid', u'objectclass'}
|
||||
|
||||
create_keys = retrieve_all_keys
|
||||
|
||||
@@ -26,6 +26,7 @@ class HostTracker(Tracker):
|
||||
'serial_number', 'serial_number_hex', 'sha1_fingerprint',
|
||||
'subject', 'usercertificate', 'valid_not_after', 'valid_not_before',
|
||||
'macaddress', 'sshpubkeyfp', 'ipaallowedtoperform_read_keys_user',
|
||||
'memberof_hostgroup', 'memberofindirect_hostgroup',
|
||||
'ipaallowedtoperform_read_keys_group',
|
||||
'ipaallowedtoperform_read_keys_host',
|
||||
'ipaallowedtoperform_read_keys_hostgroup',
|
||||
|
||||
248
ipatests/test_xmlrpc/tracker/hostgroup_plugin.py
Normal file
248
ipatests/test_xmlrpc/tracker/hostgroup_plugin.py
Normal file
@@ -0,0 +1,248 @@
|
||||
#
|
||||
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
|
||||
from ipatests.test_xmlrpc import objectclasses
|
||||
from ipatests.test_xmlrpc.xmlrpc_test import fuzzy_uuid
|
||||
|
||||
from ipatests.test_xmlrpc.tracker.base import Tracker
|
||||
from ipatests.util import assert_deepequal
|
||||
|
||||
from ipalib import api
|
||||
from ipapython.dn import DN
|
||||
|
||||
|
||||
class HostGroupTracker(Tracker):
|
||||
""" Class for tracking hostgroups """
|
||||
retrieve_keys = {u'dn', u'cn', u'member_host', u'description',
|
||||
u'member_hostgroup', u'memberindirect_host'}
|
||||
retrieve_all_keys = retrieve_keys | {u'ipauniqueid', u'objectclass',
|
||||
u'mepmanagedentry'}
|
||||
|
||||
create_keys = retrieve_all_keys
|
||||
update_keys = retrieve_keys - {u'dn'}
|
||||
|
||||
add_member_keys = retrieve_keys | {u'member_host'}
|
||||
|
||||
def __init__(self, name, description=u'HostGroup desc'):
|
||||
super(HostGroupTracker, self).__init__(default_version=None)
|
||||
self.cn = name
|
||||
self.description = description
|
||||
self.dn = DN(('cn', self.cn), ('cn', 'hostgroups'),
|
||||
('cn', 'accounts'), api.env.basedn)
|
||||
|
||||
def make_create_command(self,
|
||||
force=True, *args, **kwargs):
|
||||
""" Make function that creates a hostgroup using 'hostgroup-add' """
|
||||
return self.make_command('hostgroup_add', self.cn,
|
||||
description=self.description,
|
||||
*args, **kwargs)
|
||||
|
||||
def make_delete_command(self):
|
||||
""" Make function that deletes a hostgroup using 'hostgroup-del' """
|
||||
return self.make_command('hostgroup_del', self.cn)
|
||||
|
||||
def make_retrieve_command(self, all=False, raw=False):
|
||||
""" Make function that retrieves a hostgroup using 'hostgroup-show' """
|
||||
return self.make_command('hostgroup_show', self.cn, all=all)
|
||||
|
||||
def make_find_command(self, *args, **kwargs):
|
||||
""" Make function that searches for a hostgroup
|
||||
using 'hostgroup-find' """
|
||||
return self.make_command('hostgroup_find', *args, **kwargs)
|
||||
|
||||
def make_update_command(self, updates):
|
||||
""" Make function that updates a hostgroup using 'hostgroup-mod' """
|
||||
return self.make_command('hostgroup_mod', self.cn, **updates)
|
||||
|
||||
def make_add_member_command(self, options={}):
|
||||
""" Make function that adds a member to a hostgroup """
|
||||
return self.make_command('hostgroup_add_member', self.cn, **options)
|
||||
|
||||
def make_remove_member_command(self, options={}):
|
||||
""" Make function that removes a member from a hostgroup """
|
||||
return self.make_command('hostgroup_remove_member', self.cn, **options)
|
||||
|
||||
def track_create(self):
|
||||
""" Updates expected state for hostgroup creation"""
|
||||
self.attrs = dict(
|
||||
dn=self.dn,
|
||||
mepmanagedentry=[DN(('cn', self.cn), ('cn', 'ng'),
|
||||
('cn', 'alt'), api.env.basedn)],
|
||||
cn=[self.cn],
|
||||
description=[self.description],
|
||||
ipauniqueid=[fuzzy_uuid],
|
||||
objectclass=objectclasses.hostgroup,
|
||||
)
|
||||
self.exists = True
|
||||
|
||||
def add_member(self, options):
|
||||
""" Add a member host to hostgroup and perform check """
|
||||
if u'host' in options:
|
||||
try:
|
||||
self.attrs[u'member_host'] =\
|
||||
self.attrs[u'member_host'] + [options[u'host']]
|
||||
except KeyError as ex:
|
||||
self.attrs[u'member_host'] = [options[u'host']]
|
||||
# search for hosts in the target hostgroup and
|
||||
# add them as memberindirect hosts
|
||||
elif u'hostgroup' in options:
|
||||
try:
|
||||
self.attrs[u'member_hostgroup'] =\
|
||||
self.attrs[u'member_hostgroup'] + [options[u'hostgroup']]
|
||||
except KeyError as ex:
|
||||
self.attrs[u'member_hostgroup'] = [options[u'hostgroup']]
|
||||
|
||||
command = self.make_add_member_command(options)
|
||||
result = command()
|
||||
self.check_add_member(result)
|
||||
|
||||
def remove_member(self, options):
|
||||
""" Remove a member host from hostgroup and perform check """
|
||||
if u'host' in options:
|
||||
self.attrs[u'member_host'].remove(options[u'host'])
|
||||
elif u'hostgroup' in options:
|
||||
self.attrs[u'member_hostgroup'].remove(options[u'hostgroup'])
|
||||
|
||||
try:
|
||||
if not self.attrs[u'member_host']:
|
||||
del self.attrs[u'member_host']
|
||||
except KeyError as ex:
|
||||
pass
|
||||
try:
|
||||
if not self.attrs[u'member_hostgroup']:
|
||||
del self.attrs[u'member_hostgroup']
|
||||
except KeyError as ex:
|
||||
pass
|
||||
|
||||
command = self.make_remove_member_command(options)
|
||||
result = command()
|
||||
self.check_remove_member(result)
|
||||
|
||||
def update(self, updates, expected_updates=None):
|
||||
"""Helper function to update this user and check the result
|
||||
|
||||
Overriding Tracker method for setting self.attrs correctly;
|
||||
* most attributes stores its value in list
|
||||
* the rest can be overridden by expected_updates
|
||||
* allow deleting parametrs if update value is None
|
||||
"""
|
||||
if expected_updates is None:
|
||||
expected_updates = {}
|
||||
|
||||
self.ensure_exists()
|
||||
command = self.make_update_command(updates)
|
||||
result = command()
|
||||
|
||||
for key, value in updates.items():
|
||||
if value is None:
|
||||
del self.attrs[key]
|
||||
else:
|
||||
self.attrs[key] = [value]
|
||||
for key, value in expected_updates.items():
|
||||
if value is None:
|
||||
del self.attrs[key]
|
||||
else:
|
||||
self.attrs[key] = value
|
||||
|
||||
self.check_update(
|
||||
result,
|
||||
extra_keys=set(updates.keys()) | set(expected_updates.keys())
|
||||
)
|
||||
|
||||
def check_create(self, result):
|
||||
""" Checks 'hostgroup_add' command result """
|
||||
assert_deepequal(dict(
|
||||
value=self.cn,
|
||||
summary=u'Added hostgroup "%s"' % self.cn,
|
||||
result=self.filter_attrs(self.create_keys)
|
||||
), result)
|
||||
|
||||
def check_delete(self, result):
|
||||
""" Checks 'hostgroup_del' command result """
|
||||
assert_deepequal(dict(
|
||||
value=[self.cn],
|
||||
summary=u'Deleted hostgroup "%s"' % self.cn,
|
||||
result=dict(failed=[]),
|
||||
), result)
|
||||
|
||||
def check_retrieve(self, result, all=False, raw=False):
|
||||
""" Checks 'hostgroup_show' command result """
|
||||
if all:
|
||||
expected = self.filter_attrs(self.retrieve_all_keys)
|
||||
else:
|
||||
expected = self.filter_attrs(self.retrieve_keys)
|
||||
|
||||
assert_deepequal(dict(
|
||||
value=self.cn,
|
||||
summary=None,
|
||||
result=expected
|
||||
), result)
|
||||
|
||||
def check_find(self, result, all=False, raw=False):
|
||||
""" Checks 'hostgroup_find' command result """
|
||||
if all:
|
||||
expected = self.filter_attrs(self.retrieve_all_keys)
|
||||
else:
|
||||
expected = self.filter_attrs(self.retrieve_keys)
|
||||
|
||||
assert_deepequal(dict(
|
||||
count=1,
|
||||
truncated=False,
|
||||
summary=u'1 hostgroup matched',
|
||||
result=[expected],
|
||||
), result)
|
||||
|
||||
def check_update(self, result, extra_keys={}):
|
||||
""" Checks 'hostgroup_mod' command result """
|
||||
assert_deepequal(dict(
|
||||
value=self.cn,
|
||||
summary=u'Modified hostgroup "%s"' % self.cn,
|
||||
result=self.filter_attrs(self.update_keys | set(extra_keys))
|
||||
), result)
|
||||
|
||||
def check_add_member(self, result):
|
||||
""" Checks 'hostgroup_add_member' command result """
|
||||
assert_deepequal(dict(
|
||||
completed=1,
|
||||
failed={u'member': {u'host': (), u'hostgroup': ()}},
|
||||
result=self.filter_attrs(self.add_member_keys)
|
||||
), result)
|
||||
|
||||
def check_add_member_negative(self, result, options):
|
||||
""" Checks 'hostgroup_add_member' command result
|
||||
when expected result is failure of the operation"""
|
||||
expected = dict(
|
||||
completed=0,
|
||||
failed={u'member': {u'hostgroup': (), u'user': ()}},
|
||||
result=self.filter_attrs(self.add_member_keys)
|
||||
)
|
||||
if u'host' in options:
|
||||
expected[u'failed'][u'member'][u'host'] = [(
|
||||
options[u'host'], u'no such entry')]
|
||||
elif u'hostgroup' in options:
|
||||
expected[u'failed'][u'member'][u'hostgroup'] = [(
|
||||
options[u'hostgroup'], u'no such entry')]
|
||||
|
||||
assert_deepequal(expected, result)
|
||||
|
||||
def check_remove_member_negative(self, result, options):
|
||||
""" Checks 'hostgroup_remove_member' command result
|
||||
when expected result is failure of the operation"""
|
||||
expected = dict(
|
||||
completed=0,
|
||||
failed={u'member': {u'hostgroup': (), u'host': ()}},
|
||||
result=self.filter_attrs(self.add_member_keys)
|
||||
)
|
||||
if u'user' in options:
|
||||
expected[u'failed'][u'member'][u'host'] = [(
|
||||
options[u'user'], u'This entry is not a member')]
|
||||
elif u'hostgroup' in options:
|
||||
expected[u'failed'][u'member'][u'hostgroup'] = [(
|
||||
options[u'hostgroup'], u'This entry is not a member')]
|
||||
|
||||
assert_deepequal(expected, result)
|
||||
|
||||
def check_remove_member(self, result):
|
||||
""" Checks 'hostgroup_remove_member' command result """
|
||||
self.check_add_member(result)
|
||||
Reference in New Issue
Block a user