2009-06-24 08:12:27 -05:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
|
|
|
# Pavel Zuna <pzuna@redhat.com>
|
|
|
|
#
|
2009-12-15 14:36:14 -06:00
|
|
|
# Copyright (C) 2008, 2009 Red Hat
|
2009-06-24 08:12:27 -05:00
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# 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; version 2 only
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2009-12-15 14:36:14 -06:00
|
|
|
|
2009-06-24 08:12:27 -05:00
|
|
|
"""
|
2009-12-15 14:36:14 -06:00
|
|
|
Test the `ipalib.plugins.hostgroup` module.
|
2009-06-24 08:12:27 -05:00
|
|
|
"""
|
|
|
|
|
2009-12-15 14:36:14 -06:00
|
|
|
from ipalib import api, errors
|
2009-12-17 07:16:18 -06:00
|
|
|
from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid
|
2009-12-15 14:36:14 -06:00
|
|
|
from tests.test_xmlrpc import objectclasses
|
|
|
|
|
2009-12-17 07:16:18 -06:00
|
|
|
hostgroup1 = u'testhostgroup1'
|
|
|
|
dn1 = u'cn=%s,cn=hostgroups,cn=accounts,%s' % (hostgroup1, api.env.basedn)
|
2009-12-15 14:36:14 -06:00
|
|
|
|
|
|
|
fqdn1 = u'testhost1.%s' % api.env.domain
|
2009-12-17 07:16:18 -06:00
|
|
|
host_dn1 = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn1, api.env.basedn)
|
2009-12-15 14:36:14 -06:00
|
|
|
|
|
|
|
|
|
|
|
class test_hostgroup(Declarative):
|
|
|
|
|
|
|
|
cleanup_commands = [
|
2009-12-17 07:16:18 -06:00
|
|
|
('hostgroup_del', [hostgroup1], {}),
|
2009-12-15 14:36:14 -06:00
|
|
|
('host_del', [fqdn1], {}),
|
|
|
|
]
|
|
|
|
|
|
|
|
tests=[
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Try to retrieve non-existent %r' % hostgroup1,
|
|
|
|
command=('hostgroup_show', [hostgroup1], {}),
|
2009-12-15 14:36:14 -06:00
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Try to update non-existent %r' % hostgroup1,
|
|
|
|
command=('hostgroup_mod', [hostgroup1],
|
2009-12-15 14:36:14 -06:00
|
|
|
dict(description=u'Updated hostgroup 1')
|
|
|
|
),
|
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Try to delete non-existent %r' % hostgroup1,
|
|
|
|
command=('hostgroup_del', [hostgroup1], {}),
|
2009-12-15 14:36:14 -06:00
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Create %r' % hostgroup1,
|
|
|
|
command=('hostgroup_add', [hostgroup1],
|
2009-12-15 14:36:14 -06:00
|
|
|
dict(description=u'Test hostgroup 1')
|
|
|
|
),
|
|
|
|
expected=dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
value=hostgroup1,
|
2009-12-15 14:36:14 -06:00
|
|
|
summary=u'Added hostgroup "testhostgroup1"',
|
|
|
|
result=dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
dn=dn1,
|
|
|
|
cn=[hostgroup1],
|
2009-12-15 14:36:14 -06:00
|
|
|
objectclass=objectclasses.hostgroup,
|
2009-12-17 07:16:18 -06:00
|
|
|
description=[u'Test hostgroup 1'],
|
|
|
|
ipauniqueid=[fuzzy_uuid],
|
2009-12-15 14:36:14 -06:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Try to create duplicate %r' % hostgroup1,
|
|
|
|
command=('hostgroup_add', [hostgroup1],
|
2009-12-15 14:36:14 -06:00
|
|
|
dict(description=u'Test hostgroup 1')
|
|
|
|
),
|
|
|
|
expected=errors.DuplicateEntry(),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Create host %r' % fqdn1,
|
|
|
|
command=('host_add', [fqdn1],
|
|
|
|
dict(
|
|
|
|
description=u'Test host 1',
|
2010-02-12 15:34:21 -06:00
|
|
|
l=u'Undisclosed location 1',
|
2009-12-15 14:36:14 -06:00
|
|
|
),
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
value=fqdn1,
|
|
|
|
summary=u'Added host "%s"' % fqdn1,
|
|
|
|
result=dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
dn=host_dn1,
|
|
|
|
fqdn=[fqdn1],
|
|
|
|
description=[u'Test host 1'],
|
2010-02-12 15:34:21 -06:00
|
|
|
l=[u'Undisclosed location 1'],
|
2009-12-17 07:16:18 -06:00
|
|
|
krbprincipalname=[u'host/%s@%s' % (fqdn1, api.env.realm)],
|
2009-12-15 14:36:14 -06:00
|
|
|
objectclass=objectclasses.host,
|
2009-12-17 07:16:18 -06:00
|
|
|
ipauniqueid=[fuzzy_uuid],
|
2009-12-15 14:36:14 -06:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc=u'Add host %r to %r' % (fqdn1, hostgroup1),
|
2009-12-15 14:36:14 -06:00
|
|
|
command=(
|
2009-12-17 07:16:18 -06:00
|
|
|
'hostgroup_add_member', [hostgroup1], dict(host=fqdn1)
|
2009-12-15 14:36:14 -06:00
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
completed=1,
|
|
|
|
failed=dict(
|
|
|
|
member=dict(
|
|
|
|
host=tuple(),
|
|
|
|
hostgroup=tuple(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
result={
|
2010-02-12 15:34:21 -06:00
|
|
|
'cn': [hostgroup1],
|
|
|
|
'description': [u'Test hostgroup 1'],
|
|
|
|
'member_host': [fqdn1],
|
2009-12-15 14:36:14 -06:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Retrieve %r' % hostgroup1,
|
|
|
|
command=('hostgroup_show', [hostgroup1], {}),
|
2009-12-15 14:36:14 -06:00
|
|
|
expected=dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
value=hostgroup1,
|
2009-12-15 14:36:14 -06:00
|
|
|
summary=None,
|
|
|
|
result={
|
2009-12-17 07:16:18 -06:00
|
|
|
'dn': dn1,
|
2010-02-12 15:34:21 -06:00
|
|
|
'member_host': [u'testhost1.%s' % api.env.domain],
|
2009-12-17 07:16:18 -06:00
|
|
|
'cn': [hostgroup1],
|
|
|
|
'description': [u'Test hostgroup 1'],
|
2009-12-15 14:36:14 -06:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Search for %r' % hostgroup1,
|
|
|
|
command=('hostgroup_find', [], dict(cn=hostgroup1)),
|
2009-12-15 14:36:14 -06:00
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 hostgroup matched',
|
2009-12-17 07:16:18 -06:00
|
|
|
result=[
|
2009-12-15 14:36:14 -06:00
|
|
|
{
|
2010-02-12 15:34:21 -06:00
|
|
|
#'dn': dn1,
|
|
|
|
'member_host': [u'testhost1.%s' % api.env.domain],
|
2009-12-17 07:16:18 -06:00
|
|
|
'cn': [hostgroup1],
|
|
|
|
'description': [u'Test hostgroup 1'],
|
2009-12-15 14:36:14 -06:00
|
|
|
},
|
2009-12-17 07:16:18 -06:00
|
|
|
],
|
2009-12-15 14:36:14 -06:00
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Update %r' % hostgroup1,
|
|
|
|
command=('hostgroup_mod', [hostgroup1],
|
2009-12-15 14:36:14 -06:00
|
|
|
dict(description=u'Updated hostgroup 1')
|
|
|
|
),
|
|
|
|
expected=dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
value=hostgroup1,
|
2009-12-15 14:36:14 -06:00
|
|
|
summary=u'Modified hostgroup "testhostgroup1"',
|
|
|
|
result=dict(
|
2010-02-12 15:34:21 -06:00
|
|
|
cn=[hostgroup1],
|
2009-12-17 07:16:18 -06:00
|
|
|
description=[u'Updated hostgroup 1'],
|
2010-02-12 15:34:21 -06:00
|
|
|
member_host=[u'testhost1.%s' % api.env.domain],
|
2009-12-15 14:36:14 -06:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Retrieve %r to verify update' % hostgroup1,
|
|
|
|
command=('hostgroup_show', [hostgroup1], {}),
|
2009-12-15 14:36:14 -06:00
|
|
|
expected=dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
value=hostgroup1,
|
2009-12-15 14:36:14 -06:00
|
|
|
summary=None,
|
|
|
|
result={
|
2009-12-17 07:16:18 -06:00
|
|
|
'dn': dn1,
|
2010-02-12 15:34:21 -06:00
|
|
|
'member_host': [u'testhost1.%s' % api.env.domain],
|
2009-12-17 07:16:18 -06:00
|
|
|
'cn': [hostgroup1],
|
|
|
|
'description': [u'Updated hostgroup 1'],
|
2009-12-15 14:36:14 -06:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Remove host %r from %r' % (fqdn1, hostgroup1),
|
|
|
|
command=('hostgroup_remove_member', [hostgroup1],
|
2009-12-15 14:36:14 -06:00
|
|
|
dict(host=fqdn1)
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
failed=dict(
|
|
|
|
member=dict(
|
|
|
|
host=tuple(),
|
|
|
|
hostgroup=tuple(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
completed=1,
|
|
|
|
result={},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Delete %r' % hostgroup1,
|
|
|
|
command=('hostgroup_del', [hostgroup1], {}),
|
2009-12-15 14:36:14 -06:00
|
|
|
expected=dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
value=hostgroup1,
|
2009-12-15 14:36:14 -06:00
|
|
|
summary=u'Deleted hostgroup "testhostgroup1"',
|
|
|
|
result=True,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
2009-12-17 07:16:18 -06:00
|
|
|
desc='Delete host %r' % fqdn1,
|
2009-12-15 14:36:14 -06:00
|
|
|
command=('host_del', [fqdn1], {}),
|
|
|
|
expected=dict(
|
|
|
|
value=fqdn1,
|
|
|
|
summary=u'Deleted host "%s"' % fqdn1,
|
|
|
|
result=True,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|