On 05/03/2016 12:15 PM, Martin Basti wrote:


On 03.05.2016 11:18, Lenka Doudova wrote:


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

Looks better, please follow proper naming of patches according how to format patch guide. I propose following (Patch attached) changes. It looks weird to me to return self object

Martin

Ok, fixed patch attached.

Thanks,
Lenka
From 46a8fdc91918bfbb2bc9f231581fcb767bc635f5 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    |  3 ++-
 ipatests/test_xmlrpc/tracker/host_plugin.py | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/ipatests/test_xmlrpc/test_host_plugin.py b/ipatests/test_xmlrpc/test_host_plugin.py
index 47f05a403ddb519f201b11251c2acb71faa9133b..85fec423ed530727a20b52534f7568f24e918efa 100644
--- a/ipatests/test_xmlrpc/test_host_plugin.py
+++ b/ipatests/test_xmlrpc/test_host_plugin.py
@@ -130,8 +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
+    # Finalizer ensures that any certificates added to this_host are removed
+    tracker.add_finalizer_certcleanup(request)
     return tracker
 
 
diff --git a/ipatests/test_xmlrpc/tracker/host_plugin.py b/ipatests/test_xmlrpc/tracker/host_plugin.py
index bf199f4f50820fe27384eea4897b73bd02391c56..5e7bd55302ccac942fe740a5e3e15ad828dcb9d1 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,16 @@ class HostTracker(Tracker):
             summary=u'Modified host "%s"' % self.fqdn,
             result=self.filter_attrs(self.update_keys | set(extra_keys))
         ), result)
+
+    def add_finalizer_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)
-- 
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