With this patch applied integration tests pass and in-tree tests are
gracefully skipped.

@mkubik, It is not possible to put the decorator to util.py as per our
discussion, because it uses tasks, so tasks must be imported. But tasks
already import util, which leads to circular imports. So I've put it to
tasks.py

-- 
Oleg Fayans
Quality Engineer
FreeIPA team
RedHat.
From 2f3d460c0b29d65491a47528802d067ccb9757d8 Mon Sep 17 00:00:00 2001
From: Oleg Fayans <ofay...@redhat.com>
Date: Wed, 16 Mar 2016 09:42:58 +0100
Subject: [PATCH] rewrote a misprocessed teardown_method method as a custom
 decorator

https://fedorahosted.org/freeipa/ticket/5736
teardown_method is a standard pytest method used to put any code to be executed
after each test method is executed. Wile trated correctly by our integration
tests, this method is misinterpreted by in-tree tests in the followiong way:
in-tree tests try to execute it even if all the test methods are skipped due to
test resources being not configured. This causes the tests, that otherwise would
have been skipped, to fail
---
 ipatests/test_integration/tasks.py                 | 22 ++++++++++++++++++++++
 .../test_integration/test_replica_promotion.py     | 18 +++++-------------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/ipatests/test_integration/tasks.py b/ipatests/test_integration/tasks.py
index 1d6846a05f0e8af13953257b360cf2152b401bfa..31b13729723798947aea7fc30c873898c5f3b447 100644
--- a/ipatests/test_integration/tasks.py
+++ b/ipatests/test_integration/tasks.py
@@ -1153,3 +1153,25 @@ def uninstall_replica(master, replica):
                         "-p", master.config.dirman_password,
                         replica.hostname], raiseonerr=False)
     uninstall_master(replica)
+
+
+def dereplicafy(func):
+    """
+    dereplicafy decorator, applied to any test method in integration tests
+    uninstalls all replicas and clients in the topology leaving only master
+    configured
+    """
+    def wrapped(*args):
+        func(*args)
+        for host in args[0].replicas:
+            uninstall_replica(args[0].master, host)
+            uninstall_client(host)
+            result = args[0].master.run_command(
+                ["ipa", "host-del", "--updatedns", host.hostname],
+                raiseonerr=False)
+            # Workaround for 5627
+            if "host not found" in result.stderr_text:
+                args[0].master.run_command(["ipa",
+                                            "host-del",
+                                            host.hostname], raiseonerr=False)
+    return wrapped
diff --git a/ipatests/test_integration/test_replica_promotion.py b/ipatests/test_integration/test_replica_promotion.py
index 45bfdd22e79845f7f091ce2c75a7148dc1963dba..059a4af346f185ff9538e2d30bfb1a055d5e6d8f 100644
--- a/ipatests/test_integration/test_replica_promotion.py
+++ b/ipatests/test_integration/test_replica_promotion.py
@@ -4,6 +4,7 @@ from ipatests.test_integration.test_caless import assert_error
 from ipalib.constants import DOMAIN_LEVEL_0
 from ipalib.constants import DOMAIN_LEVEL_1
 from ipalib.constants import DOMAIN_SUFFIX_NAME
+from ipatests.test_integration.tasks import dereplicafy
 
 
 class ReplicaPromotionBase(IntegrationTest):
@@ -12,19 +13,7 @@ class ReplicaPromotionBase(IntegrationTest):
     def install(cls, mh):
         tasks.install_master(cls.master, domain_level=cls.domain_level)
 
-    def teardown_method(self, method):
-        for host in self.replicas:
-            tasks.uninstall_replica(self.master, host)
-            tasks.uninstall_client(host)
-            result = self.master.run_command(
-                ["ipa", "host-del", "--updatedns", host.hostname],
-                raiseonerr=False)
-            # Workaround for 5627
-            if "host not found" in result.stderr_text:
-                self.master.run_command(["ipa",
-                                         "host-del",
-                                         host.hostname], raiseonerr=False)
-
+    @dereplicafy
     def test_kra_install_master(self):
         result1 = tasks.install_kra(self.master,
                                     first_instance=True,
@@ -43,6 +32,7 @@ class TestReplicaPromotionLevel0(ReplicaPromotionBase):
     num_replicas = 1
     domain_level = DOMAIN_LEVEL_0
 
+    @dereplicafy
     def test_promotion_disabled(self):
         """
         Testcase:
@@ -60,6 +50,7 @@ class TestReplicaPromotionLevel0(ReplicaPromotionBase):
                      'You must provide a file generated by ipa-replica-prepare'
                      ' to create a replica when the domain is at level 0', 1)
 
+    @dereplicafy
     def test_backup_restore(self):
         """
         TestCase:
@@ -168,6 +159,7 @@ class TestReplicaPromotionLevel1(ReplicaPromotionBase):
     num_replicas = 1
     domain_level = DOMAIN_LEVEL_1
 
+    @dereplicafy
     def test_replica_prepare_disabled(self):
         replica = self.replicas[0]
         args = ['ipa-replica-prepare',
-- 
1.8.3.1

-- 
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