Hi,

attaching patch for failing location tests (ipatests/test_xmlrpc/test_location_plugin.py).


Lenka

From 6fc64ea5574e730c5c4c733e4e1eeb60163f6163 Mon Sep 17 00:00:00 2001
From: Lenka Doudova <ldoud...@redhat.com>
Date: Tue, 21 Jun 2016 15:29:46 +0200
Subject: [PATCH] Tests: Fix for failing location tests

---
 ipatests/test_xmlrpc/test_location_plugin.py    | 54 ++++++++++++++--------
 ipatests/test_xmlrpc/tracker/location_plugin.py | 13 ++++--
 ipatests/test_xmlrpc/tracker/server_plugin.py   | 59 ++++++++++++++++++++++---
 3 files changed, 98 insertions(+), 28 deletions(-)

diff --git a/ipatests/test_xmlrpc/test_location_plugin.py b/ipatests/test_xmlrpc/test_location_plugin.py
index 3f0edfbcf791feea1a9e1b584386215d84b44606..665911fad99673aef36a6ac3a833058c9428fc0e 100644
--- a/ipatests/test_xmlrpc/test_location_plugin.py
+++ b/ipatests/test_xmlrpc/test_location_plugin.py
@@ -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
@@ -123,6 +123,15 @@ class TestCRUD(XMLRPC_test):
 
 @pytest.mark.tier1
 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 +149,14 @@ 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': (
+                                  u'CA server', u'DNS server', u'NTP server')},
+            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 +184,16 @@ 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': (
+                                  u'CA server', u'DNS server', u'NTP server'),
+                              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,18 @@ 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': (
+                              u'CA server', u'DNS server', u'NTP server')},
+            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': (
+                              u'CA server', u'DNS server', u'NTP server')},
+            messages=self.messages)
         location.retrieve()
diff --git a/ipatests/test_xmlrpc/tracker/location_plugin.py b/ipatests/test_xmlrpc/tracker/location_plugin.py
index 3bce6669aed59141c6cddf492afd478bcabff06d..3500a70db3ef52a4e00c2cdbdb6c7b13557efcc9 100644
--- a/ipatests/test_xmlrpc/tracker/location_plugin.py
+++ b/ipatests/test_xmlrpc/tracker/location_plugin.py
@@ -17,12 +17,13 @@ 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',}
     find_all_keys = find_keys | {'objectclass'}
-    update_keys = {'idnsname', 'description'}
+    update_keys = {'idnsname', 'description', u'messages'}
 
     def __init__(self, name, description=u"Location description"):
         super(LocationTracker, self).__init__(default_version=None)
@@ -130,21 +131,27 @@ 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': (
+                u'CA server', u'DNS server', u'NTP server')
         }
 
     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:
diff --git a/ipatests/test_xmlrpc/tracker/server_plugin.py b/ipatests/test_xmlrpc/tracker/server_plugin.py
index 7540f45bf5f222e603fb446f7f2935376cca6be6..adeac368d657d1fe1a2aab5251299022f12155e4 100644
--- a/ipatests/test_xmlrpc/tracker/server_plugin.py
+++ b/ipatests/test_xmlrpc/tracker/server_plugin.py
@@ -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,54 @@ 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(
-            value=self.server_name,
-            summary=u'Modified IPA server "{server}"'.format(server=self.name),
-            result=self.filter_attrs(self.update_keys | set(extra_keys))
-        ), result)
+        if not messages:
+            assert_deepequal(dict(
+                value=self.server_name,
+                summary=u'Modified IPA server "{server}"'.format(
+                    server=self.name),
+                result=self.filter_attrs(self.update_keys | set(extra_keys))
+            ), result)
+        else:
+            assert_deepequal(dict(
+                value=self.server_name,
+                summary=u'Modified IPA server "{server}"'.format(
+                    server=self.name),
+                result=self.filter_attrs(self.update_keys | set(extra_keys)),
+                messages=messages
+            ), 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)
+        self.messages = messages
+        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
-- 
2.7.4

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to