Files
freeipa/ipatests/test_xmlrpc/test_hostgroup_plugin.py
T

316 lines
9.8 KiB
Python
Raw Normal View History

2009-06-24 15:12:27 +02:00
# Authors:
# Rob Crittenden <rcritten@redhat.com>
# Pavel Zuna <pzuna@redhat.com>
#
# Copyright (C) 2008, 2009 Red Hat
2009-06-24 15:12:27 +02:00
# see file 'COPYING' for use and warranty information
#
2010-12-09 13:59:11 +01:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
2009-06-24 15:12:27 +02:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2010-12-09 13:59:11 +01:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-06-24 15:12:27 +02:00
"""
Test the `ipalib.plugins.hostgroup` module.
2009-06-24 15:12:27 +02:00
"""
from ipalib import api, errors
2013-05-21 13:40:27 +02:00
from ipatests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid
from ipatests.test_xmlrpc import objectclasses
2012-05-13 07:36:35 -04:00
from ipapython.dn import DN
import pytest
2009-12-17 06:16:18 -07:00
hostgroup1 = u'testhostgroup1'
dn1 = DN(('cn',hostgroup1),('cn','hostgroups'),('cn','accounts'),
api.env.basedn)
2012-05-04 10:25:42 +02:00
hostgroup_single = u'a'
dn_single = DN(('cn',hostgroup_single),('cn','hostgroups'),('cn','accounts'),
api.env.basedn)
fqdn1 = u'testhost1.%s' % api.env.domain
host_dn1 = DN(('fqdn',fqdn1),('cn','computers'),('cn','accounts'),
api.env.basedn)
invalidhostgroup1 = u'@invalid'
@pytest.mark.tier1
class test_hostgroup(Declarative):
cleanup_commands = [
2009-12-17 06:16:18 -07:00
('hostgroup_del', [hostgroup1], {}),
('host_del', [fqdn1], {}),
]
tests=[
dict(
2009-12-17 06:16:18 -07:00
desc='Try to retrieve non-existent %r' % hostgroup1,
command=('hostgroup_show', [hostgroup1], {}),
2012-03-27 09:27:11 -04:00
expected=errors.NotFound(
reason=u'%s: host group not found' % hostgroup1),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Try to update non-existent %r' % hostgroup1,
command=('hostgroup_mod', [hostgroup1],
dict(description=u'Updated hostgroup 1')
),
2012-03-27 09:27:11 -04:00
expected=errors.NotFound(
reason=u'%s: host group not found' % hostgroup1),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Try to delete non-existent %r' % hostgroup1,
command=('hostgroup_del', [hostgroup1], {}),
2012-03-27 09:27:11 -04:00
expected=errors.NotFound(
reason=u'%s: host group not found' % hostgroup1),
),
dict(
desc='Test an invalid hostgroup name %r' % invalidhostgroup1,
command=('hostgroup_add', [invalidhostgroup1], dict(description=u'Test')),
2012-03-27 09:27:11 -04:00
expected=errors.ValidationError(name='hostgroup_name',
error=u'may only include letters, numbers, _, -, and .'),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Create %r' % hostgroup1,
command=('hostgroup_add', [hostgroup1],
dict(description=u'Test hostgroup 1')
),
expected=dict(
2009-12-17 06:16:18 -07:00
value=hostgroup1,
summary=u'Added hostgroup "testhostgroup1"',
result=dict(
2012-05-13 07:36:35 -04:00
dn=dn1,
2009-12-17 06:16:18 -07:00
cn=[hostgroup1],
objectclass=objectclasses.hostgroup,
2009-12-17 06:16:18 -07:00
description=[u'Test hostgroup 1'],
ipauniqueid=[fuzzy_uuid],
2012-05-13 07:36:35 -04:00
mepmanagedentry=[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'),
api.env.basedn)],
),
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Try to create duplicate %r' % hostgroup1,
command=('hostgroup_add', [hostgroup1],
dict(description=u'Test hostgroup 1')
),
2012-03-27 09:27:11 -04:00
expected=errors.DuplicateEntry(message=
u'host group with name "%s" already exists' % hostgroup1),
),
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(
2012-05-13 07:36:35 -04:00
dn=host_dn1,
2009-12-17 06:16:18 -07:00
fqdn=[fqdn1],
description=[u'Test host 1'],
l=[u'Undisclosed location 1'],
2009-12-17 06:16:18 -07:00
krbprincipalname=[u'host/%s@%s' % (fqdn1, api.env.realm)],
objectclass=objectclasses.host,
2009-12-17 06:16:18 -07:00
ipauniqueid=[fuzzy_uuid],
2010-11-10 16:47:29 -05:00
managedby_host=[fqdn1],
has_keytab=False,
has_password=False,
),
),
),
dict(
2009-12-17 06:16:18 -07:00
desc=u'Add host %r to %r' % (fqdn1, hostgroup1),
command=(
2009-12-17 06:16:18 -07:00
'hostgroup_add_member', [hostgroup1], dict(host=fqdn1)
),
expected=dict(
completed=1,
failed=dict(
member=dict(
host=tuple(),
hostgroup=tuple(),
),
),
result={
2012-05-13 07:36:35 -04:00
'dn': dn1,
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
'member_host': [fqdn1],
},
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Retrieve %r' % hostgroup1,
command=('hostgroup_show', [hostgroup1], {}),
expected=dict(
2009-12-17 06:16:18 -07:00
value=hostgroup1,
summary=None,
result={
2012-05-13 07:36:35 -04:00
'dn': dn1,
'member_host': [u'testhost1.%s' % api.env.domain],
2009-12-17 06:16:18 -07:00
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
},
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Search for %r' % hostgroup1,
command=('hostgroup_find', [], dict(cn=hostgroup1)),
expected=dict(
count=1,
truncated=False,
summary=u'1 hostgroup matched',
2009-12-17 06:16:18 -07:00
result=[
{
2012-05-13 07:36:35 -04:00
'dn': dn1,
'member_host': [u'testhost1.%s' % api.env.domain],
2009-12-17 06:16:18 -07:00
'cn': [hostgroup1],
'description': [u'Test hostgroup 1'],
},
2009-12-17 06:16:18 -07:00
],
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Update %r' % hostgroup1,
command=('hostgroup_mod', [hostgroup1],
dict(description=u'Updated hostgroup 1')
),
expected=dict(
2009-12-17 06:16:18 -07:00
value=hostgroup1,
summary=u'Modified hostgroup "testhostgroup1"',
result=dict(
cn=[hostgroup1],
2009-12-17 06:16:18 -07:00
description=[u'Updated hostgroup 1'],
member_host=[u'testhost1.%s' % api.env.domain],
),
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Retrieve %r to verify update' % hostgroup1,
command=('hostgroup_show', [hostgroup1], {}),
expected=dict(
2009-12-17 06:16:18 -07:00
value=hostgroup1,
summary=None,
result={
2012-05-13 07:36:35 -04:00
'dn': dn1,
'member_host': [u'testhost1.%s' % api.env.domain],
2009-12-17 06:16:18 -07:00
'cn': [hostgroup1],
'description': [u'Updated hostgroup 1'],
},
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Remove host %r from %r' % (fqdn1, hostgroup1),
command=('hostgroup_remove_member', [hostgroup1],
dict(host=fqdn1)
),
expected=dict(
failed=dict(
member=dict(
host=tuple(),
hostgroup=tuple(),
),
),
completed=1,
result={
2012-05-13 07:36:35 -04:00
'dn': dn1,
'cn': [hostgroup1],
'description': [u'Updated hostgroup 1'],
},
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Delete %r' % hostgroup1,
command=('hostgroup_del', [hostgroup1], {}),
expected=dict(
value=[hostgroup1],
summary=u'Deleted hostgroup "testhostgroup1"',
result=dict(failed=[]),
),
),
2012-05-04 10:25:42 +02:00
dict(
desc='Create hostgroup with name containing only one letter: %r' % hostgroup_single,
command=('hostgroup_add', [hostgroup_single],
dict(description=u'Test hostgroup with single letter in name')
),
expected=dict(
value=hostgroup_single,
summary=u'Added hostgroup "a"',
result=dict(
2012-05-13 07:36:35 -04:00
dn=dn_single,
2012-05-04 10:25:42 +02:00
cn=[hostgroup_single],
objectclass=objectclasses.hostgroup,
description=[u'Test hostgroup with single letter in name'],
ipauniqueid=[fuzzy_uuid],
2012-05-13 07:36:35 -04:00
mepmanagedentry=[DN(('cn',hostgroup_single),('cn','ng'),('cn','alt'),
api.env.basedn)],
2012-05-04 10:25:42 +02:00
),
),
),
dict(
desc='Delete %r' % hostgroup_single,
command=('hostgroup_del', [hostgroup_single], {}),
expected=dict(
value=[hostgroup_single],
2012-05-04 10:25:42 +02:00
summary=u'Deleted hostgroup "a"',
result=dict(failed=[]),
2012-05-04 10:25:42 +02:00
),
),
dict(
2009-12-17 06:16:18 -07:00
desc='Delete host %r' % fqdn1,
command=('host_del', [fqdn1], {}),
expected=dict(
value=[fqdn1],
summary=u'Deleted host "%s"' % fqdn1,
result=dict(failed=[]),
),
)
]