mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-26 16:16:31 -06:00
Tests: Fix for failing location tests
Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
parent
926462d335
commit
eec440b2d5
@ -10,7 +10,7 @@ from ipatests.test_xmlrpc.tracker.location_plugin import LocationTracker
|
||||
from ipatests.test_xmlrpc.tracker.server_plugin import ServerTracker
|
||||
from ipatests.test_xmlrpc.xmlrpc_test import (
|
||||
XMLRPC_test,
|
||||
raises_exact,
|
||||
raises_exact
|
||||
)
|
||||
from ipapython.dnsutil import DNSName
|
||||
|
||||
@ -30,13 +30,13 @@ def location_invalid(request):
|
||||
@pytest.fixture(scope='class')
|
||||
def location_absolute(request):
|
||||
tracker = LocationTracker(u'invalid.absolute.')
|
||||
return tracker.make_fixture(request)
|
||||
return tracker
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def server(request):
|
||||
tracker = ServerTracker(api.env.host)
|
||||
return tracker
|
||||
return tracker.make_fixture_clean_location(request)
|
||||
|
||||
|
||||
@pytest.mark.tier1
|
||||
@ -122,7 +122,18 @@ class TestCRUD(XMLRPC_test):
|
||||
|
||||
|
||||
@pytest.mark.tier1
|
||||
@pytest.mark.skipif(
|
||||
not api.Command.dns_is_enabled()['result'], reason='DNS not configured')
|
||||
class TestLocationsServer(XMLRPC_test):
|
||||
messages = [{
|
||||
u'data': {u'service': u'named-pkcs11.service',
|
||||
u'server': u'%s' % api.env.host},
|
||||
u'message': (u'Service named-pkcs11.service requires restart '
|
||||
u'on IPA server %s to apply configuration '
|
||||
u'changes.' % api.env.host),
|
||||
u'code': 13025,
|
||||
u'type': u'warning',
|
||||
u'name': u'ServiceRestartRequired'}]
|
||||
|
||||
def test_add_nonexistent_location_to_server(self, server):
|
||||
nonexistent_loc = DNSName(u'nonexistent-location')
|
||||
@ -140,13 +151,13 @@ class TestLocationsServer(XMLRPC_test):
|
||||
def test_add_location_to_server(self, location, server):
|
||||
location.ensure_exists()
|
||||
server.update(
|
||||
dict(ipalocation_location=location.idnsname_obj),
|
||||
expected_updates=dict(
|
||||
ipalocation_location=[location.idnsname_obj],
|
||||
)
|
||||
)
|
||||
updates={u'ipalocation_location': location.idnsname_obj},
|
||||
expected_updates={u'ipalocation_location': [location.idnsname_obj],
|
||||
u'enabled_role_servrole': lambda other: True},
|
||||
messages=self.messages)
|
||||
location.add_server_to_location(server.server_name)
|
||||
location.retrieve()
|
||||
location.remove_server_from_location(server.server_name)
|
||||
|
||||
def test_retrieve(self, server):
|
||||
server.retrieve()
|
||||
@ -174,16 +185,15 @@ class TestLocationsServer(XMLRPC_test):
|
||||
|
||||
def test_add_location_to_server_custom_weight(self, location, server):
|
||||
location.ensure_exists()
|
||||
|
||||
server.update(
|
||||
dict(
|
||||
ipalocation_location=location.idnsname_obj,
|
||||
ipaserviceweight=200,
|
||||
),
|
||||
expected_updates=dict(
|
||||
ipalocation_location=[location.idnsname_obj],
|
||||
ipaserviceweight=[u'200'],
|
||||
)
|
||||
)
|
||||
updates={u'ipalocation_location': location.idnsname_obj,
|
||||
u'ipaserviceweight': 200},
|
||||
expected_updates={u'ipalocation_location': [location.idnsname_obj],
|
||||
u'enabled_role_servrole': lambda other: True,
|
||||
u'ipaserviceweight': [u'200']},
|
||||
messages=self.messages)
|
||||
|
||||
# remove invalid data from the previous test
|
||||
location.remove_server_from_location(server.server_name)
|
||||
|
||||
@ -191,10 +201,16 @@ class TestLocationsServer(XMLRPC_test):
|
||||
location.retrieve()
|
||||
|
||||
def test_remove_location_from_server(self, location, server):
|
||||
server.update(dict(ipalocation_location=None))
|
||||
server.update(
|
||||
updates={u'ipalocation_location': None},
|
||||
expected_updates={u'enabled_role_servrole': lambda other: True},
|
||||
messages=self.messages)
|
||||
location.remove_server_from_location(server.server_name)
|
||||
location.retrieve()
|
||||
|
||||
def test_remove_service_weight_from_server(self, location, server):
|
||||
server.update(dict(ipaserviceweight=None))
|
||||
server.update(
|
||||
updates={u'ipaserviceweight': None},
|
||||
expected_updates={u'enabled_role_servrole': lambda other: True},
|
||||
messages=self.messages)
|
||||
location.retrieve()
|
||||
|
@ -17,7 +17,8 @@ if six.PY3:
|
||||
|
||||
class LocationTracker(Tracker):
|
||||
"""Tracker for IPA Location tests"""
|
||||
retrieve_keys = {'idnsname', 'description', 'dn', 'servers_server'}
|
||||
retrieve_keys = {
|
||||
'idnsname', 'description', 'dn', 'servers_server', 'dns_server'}
|
||||
retrieve_all_keys = retrieve_keys | {'objectclass'}
|
||||
create_keys = {'idnsname', 'description', 'dn', 'objectclass'}
|
||||
find_keys = {'idnsname', 'description', 'dn',}
|
||||
@ -130,21 +131,26 @@ class LocationTracker(Tracker):
|
||||
def add_server_to_location(
|
||||
self, server_name, weight=100, relative_weight=u"100.0%"):
|
||||
self.attrs.setdefault('servers_server', []).append(server_name)
|
||||
self.attrs.setdefault('dns_server', []).append(server_name)
|
||||
self.servers[server_name] = {
|
||||
'cn': [server_name],
|
||||
'ipaserviceweight': [unicode(weight)],
|
||||
'service_relative_weight': [relative_weight]
|
||||
'service_relative_weight': [relative_weight],
|
||||
'enabled_role_servrole': lambda other: True
|
||||
}
|
||||
|
||||
def remove_server_from_location(self, server_name):
|
||||
if 'servers_server' in self.attrs:
|
||||
try:
|
||||
self.attrs['servers_server'].remove(server_name)
|
||||
self.attrs['dns_server'].remove(server_name)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
if not self.attrs['servers_server']:
|
||||
del self.attrs['servers_server']
|
||||
if not self.attrs['dns_server']:
|
||||
del self.attrs['dns_server']
|
||||
try:
|
||||
del self.servers[server_name]
|
||||
except KeyError:
|
||||
|
@ -3,6 +3,7 @@
|
||||
#
|
||||
from __future__ import absolute_import
|
||||
|
||||
from ipalib import errors
|
||||
from ipapython.dn import DN
|
||||
from ipatests.util import assert_deepequal
|
||||
from ipatests.test_xmlrpc.tracker.base import Tracker
|
||||
@ -13,7 +14,7 @@ class ServerTracker(Tracker):
|
||||
retrieve_keys = {
|
||||
'cn', 'dn', 'ipamaxdomainlevel', 'ipamindomainlevel',
|
||||
'iparepltopomanagedsuffix_topologysuffix', 'ipalocation_location',
|
||||
'ipaserviceweight',
|
||||
'ipaserviceweight', 'enabled_role_servrole'
|
||||
}
|
||||
retrieve_all_keys = retrieve_keys | {'objectclass'}
|
||||
create_keys = retrieve_keys | {'objectclass'}
|
||||
@ -101,10 +102,48 @@ class ServerTracker(Tracker):
|
||||
result=[],
|
||||
), result)
|
||||
|
||||
def check_update(self, result, extra_keys=()):
|
||||
def check_update(self, result, extra_keys=(), messages=None):
|
||||
"""Check `server-update` command result"""
|
||||
assert_deepequal(dict(
|
||||
expected = dict(
|
||||
value=self.server_name,
|
||||
summary=u'Modified IPA server "{server}"'.format(server=self.name),
|
||||
summary=u'Modified IPA server "{server}"'.format(
|
||||
server=self.name),
|
||||
result=self.filter_attrs(self.update_keys | set(extra_keys))
|
||||
), result)
|
||||
)
|
||||
if messages:
|
||||
expected['messages'] = messages
|
||||
|
||||
assert_deepequal(expected, result)
|
||||
|
||||
def update(self, updates, expected_updates=None, messages=None):
|
||||
if expected_updates is None:
|
||||
expected_updates = {}
|
||||
|
||||
self.ensure_exists()
|
||||
command = self.make_update_command(updates)
|
||||
result = command()
|
||||
self.attrs.update(updates)
|
||||
self.attrs.update(expected_updates)
|
||||
for key, value in self.attrs.items():
|
||||
if value is None:
|
||||
del self.attrs[key]
|
||||
|
||||
self.check_update(
|
||||
result,
|
||||
extra_keys=set(updates.keys()) | set(expected_updates.keys()),
|
||||
messages=messages)
|
||||
|
||||
def make_fixture_clean_location(self, request):
|
||||
command = self.make_update_command({u'ipalocation_location': None})
|
||||
try:
|
||||
command()
|
||||
except errors.EmptyModlist:
|
||||
pass
|
||||
|
||||
def cleanup():
|
||||
try:
|
||||
command()
|
||||
except errors.EmptyModlist:
|
||||
pass
|
||||
request.addfinalizer(cleanup)
|
||||
return self
|
||||
|
Loading…
Reference in New Issue
Block a user