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
|
|
|
|
#
|
2010-12-09 06:59:11 -06: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 08:12:27 -05: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 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test, raises_exact
|
|
|
|
from ipatests.test_xmlrpc.tracker.hostgroup_plugin import HostGroupTracker
|
|
|
|
from ipatests.test_xmlrpc.tracker.host_plugin import HostTracker
|
|
|
|
from ipalib import errors
|
|
|
|
import pytest
|
2009-12-15 14:36:14 -06:00
|
|
|
|
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def hostgroup(request):
|
|
|
|
tracker = HostGroupTracker(name=u'hostgroup')
|
|
|
|
return tracker.make_fixture(request)
|
2009-12-15 14:36:14 -06:00
|
|
|
|
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def hostgroup_invalid(request):
|
|
|
|
tracker = HostGroupTracker(name=u'@invalid')
|
|
|
|
return tracker.make_fixture(request)
|
2009-12-15 14:36:14 -06:00
|
|
|
|
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def hostgroup_single(request):
|
|
|
|
tracker = HostGroupTracker(name=u'a')
|
|
|
|
return tracker.make_fixture(request)
|
2009-12-15 14:36:14 -06:00
|
|
|
|
2012-05-04 03:25:42 -05:00
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def host(request):
|
|
|
|
tracker = HostTracker(name=u'host')
|
|
|
|
return tracker.make_fixture(request)
|
2012-05-04 03:25:42 -05:00
|
|
|
|
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
class TestNonexistentHostGroup(XMLRPC_test):
|
|
|
|
def test_retrieve_nonexistent(self, hostgroup):
|
|
|
|
""" Try to retrieve non-existent hostgroup """
|
|
|
|
hostgroup.ensure_missing()
|
|
|
|
command = hostgroup.make_retrieve_command()
|
|
|
|
with raises_exact(errors.NotFound(
|
|
|
|
reason=u'%s: host group not found' % hostgroup.cn)):
|
|
|
|
command()
|
2012-05-04 03:25:42 -05:00
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
def test_update_nonexistent(self, hostgroup):
|
|
|
|
""" Try to update non-existent hostgroup """
|
|
|
|
hostgroup.ensure_missing()
|
|
|
|
command = hostgroup.make_update_command(
|
|
|
|
dict(description=u'Updated hostgroup 1')
|
2009-12-15 14:36:14 -06:00
|
|
|
)
|
2015-12-18 08:25:21 -06:00
|
|
|
with raises_exact(errors.NotFound(
|
|
|
|
reason=u'%s: host group not found' % hostgroup.cn)):
|
|
|
|
command()
|
|
|
|
|
|
|
|
def test_delete_nonexistent(self, hostgroup):
|
|
|
|
""" Try to delete non-existent hostgroup """
|
|
|
|
hostgroup.ensure_missing()
|
|
|
|
command = hostgroup.make_delete_command()
|
|
|
|
with raises_exact(errors.NotFound(
|
|
|
|
reason=u'%s: host group not found' % hostgroup.cn)):
|
|
|
|
command()
|
|
|
|
|
|
|
|
|
|
|
|
class TestHostGroup(XMLRPC_test):
|
|
|
|
def test_invalid_name(self, hostgroup_invalid):
|
|
|
|
""" Test an invalid hostgroup name """
|
|
|
|
hostgroup_invalid.ensure_missing()
|
|
|
|
command = hostgroup_invalid.make_create_command()
|
|
|
|
with raises_exact(errors.ValidationError(
|
|
|
|
name='hostgroup_name',
|
|
|
|
error=u'may only include letters, numbers, _, -, and .')):
|
|
|
|
command()
|
|
|
|
|
|
|
|
def test_create_hostgroup(self, hostgroup):
|
|
|
|
""" Create hostgroup """
|
|
|
|
hostgroup.create()
|
|
|
|
|
|
|
|
def test_create_duplicate_hostgroup(self, hostgroup):
|
|
|
|
""" Try to create duplicate hostgroup """
|
|
|
|
hostgroup.ensure_exists()
|
|
|
|
command = hostgroup.make_create_command()
|
|
|
|
with raises_exact(errors.DuplicateEntry(
|
|
|
|
message=u'host group with name "%s" already exists' %
|
|
|
|
hostgroup.cn)):
|
|
|
|
command()
|
|
|
|
|
|
|
|
def test_create_host_add_to_hostgroup(self, hostgroup, host):
|
|
|
|
""" Check that host can be added to hostgroup """
|
|
|
|
host.create()
|
|
|
|
hostgroup.add_member(dict(host=host.fqdn))
|
|
|
|
hostgroup.retrieve()
|
|
|
|
|
|
|
|
def test_search_for_hostgroup(self, hostgroup):
|
|
|
|
""" Search for hostgroup """
|
|
|
|
hostgroup.ensure_exists()
|
|
|
|
hostgroup.find()
|
|
|
|
|
2016-05-19 06:50:38 -05:00
|
|
|
def test_search_for_hostgroup_with_all(self, hostgroup):
|
|
|
|
""" Search for hostgroup """
|
|
|
|
hostgroup.ensure_exists()
|
|
|
|
hostgroup.find(all=True)
|
|
|
|
|
2015-12-18 08:25:21 -06:00
|
|
|
def test_update_hostgroup(self, hostgroup):
|
|
|
|
""" Update description of hostgroup and verify """
|
|
|
|
hostgroup.ensure_exists()
|
|
|
|
hostgroup.update(dict(description=u'Updated hostgroup 1'))
|
|
|
|
hostgroup.retrieve()
|
|
|
|
|
|
|
|
def test_remove_host_from_hostgroup(self, hostgroup, host):
|
|
|
|
""" Remove host from hostgroup """
|
|
|
|
hostgroup.ensure_exists()
|
|
|
|
hostgroup.remove_member(dict(host=host.fqdn))
|
|
|
|
|
|
|
|
def test_delete_hostgroup(self, hostgroup):
|
|
|
|
""" Delete hostgroup """
|
|
|
|
hostgroup.ensure_exists()
|
|
|
|
hostgroup.delete()
|
|
|
|
|
|
|
|
def test_one_letter_hostgroup(self, hostgroup_single):
|
|
|
|
""" Create hostgroup with name containing only one letter """
|
|
|
|
hostgroup_single.create()
|
|
|
|
hostgroup_single.delete()
|