8e1ca3
From aca97507cd119ad55e0c3c18ca65087cb5576c82 Mon Sep 17 00:00:00 2001
8e1ca3
From: Sumedh Sidhaye <ssidhaye@redhat.com>
8e1ca3
Date: Mon, 13 Jun 2022 13:49:08 +0530
8e1ca3
Subject: [PATCH] Added a check while removing 'cert_dir'. The teardown method
8e1ca3
 is called even if all the tests are skipped since the required PKI version is
8e1ca3
 not present. The teardown is trying to remove a non-existent directory.
8e1ca3
8e1ca3
Currently the cert_dir attribute is only present if IPA installation was
8e1ca3
done. If IPA was not installed the attribute does not exist.
8e1ca3
In order that the uninstall code finds the attribute a class attribute
8e1ca3
is added.
8e1ca3
8e1ca3
Pagure Issue: https://pagure.io/freeipa/issue/9179
8e1ca3
8e1ca3
Signed-off-by: Sumedh Sidhaye <ssidhaye@redhat.com>
8e1ca3
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
8e1ca3
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
8e1ca3
---
8e1ca3
 ipatests/test_integration/test_caless.py             | 12 +++++++++++-
8e1ca3
 .../test_integration/test_random_serial_numbers.py   |  6 ++++++
8e1ca3
 2 files changed, 17 insertions(+), 1 deletion(-)
8e1ca3
8e1ca3
diff --git a/ipatests/test_integration/test_caless.py b/ipatests/test_integration/test_caless.py
8e1ca3
index 96f477bbe4b0e25184605a80659b5ec6529a2320..4c370f77e84215714e533b1b6ebeb89216319c0f 100644
8e1ca3
--- a/ipatests/test_integration/test_caless.py
8e1ca3
+++ b/ipatests/test_integration/test_caless.py
8e1ca3
@@ -122,6 +122,15 @@ def replica_install_teardown(func):
8e1ca3
 
8e1ca3
 
8e1ca3
 class CALessBase(IntegrationTest):
8e1ca3
+    # The teardown method is called even if all the tests are skipped
8e1ca3
+    # since the required PKI version is not present.
8e1ca3
+    # The teardown is trying to remove a non-existent directory.
8e1ca3
+    # Currently the cert_dir attribute is only present if IPA installation was
8e1ca3
+    # done. If IPA was not installed the attribute does not exist.
8e1ca3
+    # In order that the uninstall code finds the attribute a class attribute
8e1ca3
+    # is added.
8e1ca3
+    cert_dir = None
8e1ca3
+
8e1ca3
     @classmethod
8e1ca3
     def install(cls, mh):
8e1ca3
         cls.cert_dir = tempfile.mkdtemp(prefix="ipatest-")
8e1ca3
@@ -164,7 +173,8 @@ class CALessBase(IntegrationTest):
8e1ca3
     @classmethod
8e1ca3
     def uninstall(cls, mh):
8e1ca3
         # Remove the NSS database
8e1ca3
-        shutil.rmtree(cls.cert_dir)
8e1ca3
+        if cls.cert_dir:
8e1ca3
+            shutil.rmtree(cls.cert_dir)
8e1ca3
         super(CALessBase, cls).uninstall(mh)
8e1ca3
 
8e1ca3
     @classmethod
8e1ca3
diff --git a/ipatests/test_integration/test_random_serial_numbers.py b/ipatests/test_integration/test_random_serial_numbers.py
8e1ca3
index a931c7b562f00f94e10d1e9e891fbf0624d5fd88..c52cfa4ed50e2718791b0844d743fb240d26b365 100644
8e1ca3
--- a/ipatests/test_integration/test_random_serial_numbers.py
8e1ca3
+++ b/ipatests/test_integration/test_random_serial_numbers.py
8e1ca3
@@ -64,3 +64,9 @@ class TestServerCALessToExternalCA_RSN(TestServerCALessToExternalCA):
8e1ca3
         if not pki_supports_RSNv3(mh.master):
8e1ca3
             raise pytest.skip("RNSv3 not supported")
8e1ca3
         super(TestServerCALessToExternalCA_RSN, cls).install(mh)
8e1ca3
+
8e1ca3
+    @classmethod
8e1ca3
+    def uninstall(cls, mh):
8e1ca3
+        if not pki_supports_RSNv3(mh.master):
8e1ca3
+            raise pytest.skip("RSNv3 not supported")
8e1ca3
+        super(TestServerCALessToExternalCA_RSN, cls).uninstall(mh)
8e1ca3
-- 
8e1ca3
2.37.2
8e1ca3