On 05/03/2016 10:33 AM, Martin Basti wrote:
Hello I'm quite confused what is happening in that code, can you explain it more to me? I see duplicated code there.
Sorry, that was just an unnecessary leftover. Fixed patch attached.
The code is expected to remove any certificates that were added to the local host but not to try to remove the host itself.

Lenka


Martin^2

From 6d61205372653353629308df56f950223ac6671f Mon Sep 17 00:00:00 2001
From: Lenka Doudova <ldoud...@redhat.com>
Date: Mon, 2 May 2016 14:04:24 +0200
Subject: [PATCH] Test fix: Cleanup for host certificate

This fix provides means to remove certificates from host that were added during tests, but not removed.

Ticket: https://fedorahosted.org/freeipa/ticket/5839
---
 ipatests/test_xmlrpc/test_host_plugin.py    |  4 ++--
 ipatests/test_xmlrpc/tracker/host_plugin.py | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/ipatests/test_xmlrpc/test_host_plugin.py b/ipatests/test_xmlrpc/test_host_plugin.py
index 47f05a403ddb519f201b11251c2acb71faa9133b..b62ce32a2206b489bdc9cdf32851f6101b004218 100644
--- a/ipatests/test_xmlrpc/test_host_plugin.py
+++ b/ipatests/test_xmlrpc/test_host_plugin.py
@@ -130,9 +130,9 @@ def this_host(request):
     """Fixture for the current master"""
     tracker = HostTracker(name=api.env.host.partition('.')[0],
                           fqdn=api.env.host)
-    # This host is not created/deleted, so don't call make_fixture
     tracker.exists = True
-    return tracker
+    # Fixture ensures that any certificates added to this_host are removed
+    return tracker.make_fixture_certcleanup(request)
 
 
 @pytest.fixture(scope='class')
diff --git a/ipatests/test_xmlrpc/tracker/host_plugin.py b/ipatests/test_xmlrpc/tracker/host_plugin.py
index bf199f4f50820fe27384eea4897b73bd02391c56..9561f57b3e7d45781f3e36230ef53b21a96e30f3 100644
--- a/ipatests/test_xmlrpc/tracker/host_plugin.py
+++ b/ipatests/test_xmlrpc/tracker/host_plugin.py
@@ -10,6 +10,7 @@ from ipatests.test_xmlrpc.tracker.base import Tracker
 from ipatests.test_xmlrpc.xmlrpc_test import fuzzy_uuid
 from ipatests.test_xmlrpc import objectclasses
 from ipatests.util import assert_deepequal
+from ipalib import errors
 
 
 class HostTracker(Tracker):
@@ -152,3 +153,18 @@ class HostTracker(Tracker):
             summary=u'Modified host "%s"' % self.fqdn,
             result=self.filter_attrs(self.update_keys | set(extra_keys))
         ), result)
+
+    def make_fixture_certcleanup(self, request):
+        """ Fixture to cleanup certificate from local host """
+        cleanup_command = self.make_update_command(
+            updates={'usercertificate':''})
+
+        def cleanup():
+            try:
+                cleanup_command()
+            except errors.EmptyModlist:
+                pass
+
+        request.addfinalizer(cleanup)
+
+        return self
-- 
2.5.5

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