On 06/22/2016 08:33 AM, Martin Basti wrote:



On 22.06.2016 07:37, Lenka Doudova wrote:



On 06/21/2016 06:57 PM, Martin Basti wrote:



On 21.06.2016 15:39, Lenka Doudova wrote:
Hi,

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

Lenka




Hello,

1)
+ expected_updates={u'ipalocation_location': [location.idnsname_obj],
+                              u'enabled_role_servrole': (
+ u'CA server', u'DNS server', u'NTP server')},

This depends on services installed on server, so server without DNS will cause test failures. We probably should skip test id DNS isn't installed.
Without DNS installed you get much more different warnings


2)
+    def update(self, updates, expected_updates=None, messages=None):
....
+        self.messages = messages

Why is this needed? I'm puzzled by this

It is defined outside __init__ what is wrong and it is never used.

Hi, thanks for review.
ad 1: will fix
ad 2: the 'messages' key is indeed used, because this key is returned every time a server is attached to/removed from a location. If the 'messages' is not supplied to the result comparison, the test fails (see https://paste.fedoraproject.org/382936/65732411/ for result of test without applied patch).

Lenka

Please point me to the line where ServerTracker.messages is used, I still don't see it. In your fpaste, removed self.messages in that context is TestLocationsServer.messages not ServerTracker.messages

Martin^2

Ah, right you are, my good sir. I fixed both issues, hopefully will be fine now. Fixed patch attached.
Lenka
From c3b34ceaf8f3839c616172817651d9461b870812 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    | 78 +++++++++++++++++++------
 ipatests/test_xmlrpc/tracker/location_plugin.py | 12 +++-
 ipatests/test_xmlrpc/tracker/server_plugin.py   | 58 +++++++++++++++---
 3 files changed, 120 insertions(+), 28 deletions(-)

diff --git a/ipatests/test_xmlrpc/test_location_plugin.py b/ipatests/test_xmlrpc/test_location_plugin.py
index 3f0edfbcf791feea1a9e1b584386215d84b44606..a17e2666643450a54c0c96198cb1f626e9abe49b 100644
--- a/ipatests/test_xmlrpc/test_location_plugin.py
+++ b/ipatests/test_xmlrpc/test_location_plugin.py
@@ -6,6 +6,7 @@ from __future__ import absolute_import
 import pytest
 
 from ipalib import errors, api
+from ipatests.util import Fuzzy
 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 (
@@ -30,13 +31,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,8 +124,34 @@ 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 run_command(self, command_name, **kw):
+        if not api.Backend.rpcclient.isconnected():
+            api.Backend.rpcclient.connect()
+        try:
+            api.Command[command_name](**kw)
+        except errors.NetworkError:
+            raise pytest.skip('%r: Server not available: %r' %
+                              (self.__module__, api.env.xmlrpc_uri))
+
+    def check_dns_configured(self):
+        try:
+            self.run_command('dnszone_add', idnsname=u'testzone.{0}'.format(api.env))
+            self.run_command('dnszone_del', idnsname=u'testzone.{0}'.format(api.env))
+        except errors.NotFound:
+            raise pytest.skip('DNS not configured')
 
     def test_add_nonexistent_location_to_server(self, server):
+        self.check_dns_configured()
         nonexistent_loc = DNSName(u'nonexistent-location')
         command = server.make_update_command(
             updates=dict(
@@ -138,52 +165,59 @@ class TestLocationsServer(XMLRPC_test):
             command()
 
     def test_add_location_to_server(self, location, server):
+        self.check_dns_configured()
+
         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': Fuzzy(type=list)},
+            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):
+        self.check_dns_configured()
         server.retrieve()
 
     def test_retrieve_all(self, server):
+        self.check_dns_configured()
         server.retrieve(all=True)
 
     def test_search_server_with_location(self, location, server):
+        self.check_dns_configured()
         command = server.make_find_command(
             server.server_name, in_location=location.idnsname_obj)
         result = command()
         server.check_find(result)
 
     def test_search_server_with_location_with_all(self, location, server):
+        self.check_dns_configured()
         command = server.make_find_command(
             server.server_name, in_location=location.idnsname_obj, all=True)
         result = command()
         server.check_find(result, all=True)
 
     def test_search_server_without_location(self, location, server):
+        self.check_dns_configured()
         command = server.make_find_command(
             server.server_name, not_in_location=location.idnsname_obj)
         result = command()
         server.check_find_nomatch(result)
 
     def test_add_location_to_server_custom_weight(self, location, server):
+        self.check_dns_configured()
         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': Fuzzy(type=list),
+                              u'ipaserviceweight': [u'200']},
+            messages=self.messages)
+
         # remove invalid data from the previous test
         location.remove_server_from_location(server.server_name)
 
@@ -191,10 +225,18 @@ class TestLocationsServer(XMLRPC_test):
         location.retrieve()
 
     def test_remove_location_from_server(self, location, server):
-        server.update(dict(ipalocation_location=None))
+        self.check_dns_configured()
+        server.update(
+            updates={u'ipalocation_location': None},
+            expected_updates={u'enabled_role_servrole': Fuzzy(type=list)},
+            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))
+        self.check_dns_configured()
+        server.update(
+            updates={u'ipaserviceweight': None},
+            expected_updates={u'enabled_role_servrole': Fuzzy(type=list)},
+            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..728e7d9798431c74a7361f7c092e886f19eed5cd 100644
--- a/ipatests/test_xmlrpc/tracker/location_plugin.py
+++ b/ipatests/test_xmlrpc/tracker/location_plugin.py
@@ -7,7 +7,7 @@ import six
 
 from ipapython.dn import DN
 from ipapython.dnsutil import DNSName
-from ipatests.util import assert_deepequal
+from ipatests.util import assert_deepequal, Fuzzy
 from ipatests.test_xmlrpc.tracker.base import Tracker
 
 
@@ -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': Fuzzy(type=list)
         }
 
     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..1b89cf8fb65f3644534504042eaf6c0387abbb9f 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,53 @@ 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)
+        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