89cb6d
From ca073d46b6bfbd3644d6ed8e022482756f510257 Mon Sep 17 00:00:00 2001
89cb6d
From: Florence Blanc-Renaud <flo@redhat.com>
89cb6d
Date: Thu, 14 Jan 2021 09:44:30 +0100
89cb6d
Subject: [PATCH] ipatest: fix
89cb6d
 test_upgrade.py::TestUpgrade::()::test_kra_detection
89cb6d
89cb6d
Modify the test scenario in order to be independant from PKI
89cb6d
behavior. The aim of the test is to ensure that the KRA
89cb6d
detection is not based on the presence of the directory
89cb6d
/var/lib/pki/pki-tomcat/kra/.
89cb6d
Previously the test was calling ipa-server-upgrade but this cmd
89cb6d
may fail even with the kra detection fix because of an issue in
89cb6d
pki (https://github.com/dogtagpki/pki/issues/3397).
89cb6d
Instead of exercising the whole ipa-server-upgrade command, the
89cb6d
test now checks the output of the API kra.is_installed() to validate
89cb6d
KRA detection mechanism.
89cb6d
89cb6d
Fixes: https://pagure.io/freeipa/issue/8653
89cb6d
Related: https://pagure.io/freeipa/issue/8596
89cb6d
89cb6d
Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
89cb6d
Reviewed-By: Francois Cami <fcami@redhat.com>
89cb6d
Reviewed-By: Francois Cami <fcami@redhat.com>
89cb6d
---
89cb6d
 ipatests/test_integration/test_upgrade.py | 32 ++++++++++++++---------
89cb6d
 1 file changed, 20 insertions(+), 12 deletions(-)
89cb6d
89cb6d
diff --git a/ipatests/test_integration/test_upgrade.py b/ipatests/test_integration/test_upgrade.py
89cb6d
index c866b28dda6efdd10ccd1bee42253ccb6e1285be..06509b8d31b2a042df8452ca818ece95e419fbd6 100644
89cb6d
--- a/ipatests/test_integration/test_upgrade.py
89cb6d
+++ b/ipatests/test_integration/test_upgrade.py
89cb6d
@@ -10,7 +10,6 @@ from __future__ import absolute_import
89cb6d
 import base64
89cb6d
 import os
89cb6d
 from cryptography.hazmat.primitives import serialization
89cb6d
-import pytest
89cb6d
 
89cb6d
 from ipaplatform.paths import paths
89cb6d
 from ipapython.dn import DN
89cb6d
@@ -70,22 +69,31 @@ class TestUpgrade(IntegrationTest):
89cb6d
         Test for https://pagure.io/freeipa/issue/8596
89cb6d
         When the directory /var/lib/pki/pki-tomcat/kra/ exists, the upgrade
89cb6d
         wrongly assumes that KRA component is installed and crashes.
89cb6d
-        The test creates an empty dir and calls ipa-server-upgrade
89cb6d
+        The test creates an empty dir and calls kra.is_installed()
89cb6d
         to make sure that KRA detection is not based on the directory
89cb6d
         presence.
89cb6d
+        Note: because of issue https://github.com/dogtagpki/pki/issues/3397
89cb6d
+        ipa-server-upgrade fails even with the kra detection fix. That's
89cb6d
+        why the test does not exercise the whole ipa-server-upgrade command
89cb6d
+        but only the KRA detection part.
89cb6d
         """
89cb6d
-        # Skip test if pki 10.10.0 is installed
89cb6d
-        # because of https://github.com/dogtagpki/pki/issues/3397
89cb6d
-        # pki fails to start if empty dir /var/lib/pki/pki-tomcat/kra exists
89cb6d
-        if tasks.get_pki_version(self.master) \
89cb6d
-           == tasks.parse_version('10.10.0'):
89cb6d
-            pytest.skip("Skip test with pki 10.10.0")
89cb6d
-
89cb6d
         kra_path = os.path.join(paths.VAR_LIB_PKI_TOMCAT_DIR, "kra")
89cb6d
         try:
89cb6d
             self.master.run_command(["mkdir", "-p", kra_path])
89cb6d
-            result = self.master.run_command(['ipa-server-upgrade'])
89cb6d
-            err_msg = 'Upgrade failed with no such entry'
89cb6d
-            assert err_msg not in result.stderr_text
89cb6d
+            script = (
89cb6d
+                "from ipalib import api; "
89cb6d
+                "from ipaserver.install import krainstance; "
89cb6d
+                "api.bootstrap(); "
89cb6d
+                "api.finalize(); "
89cb6d
+                "kra = krainstance.KRAInstance(api.env.realm); "
89cb6d
+                "print(kra.is_installed())"
89cb6d
+            )
89cb6d
+
89cb6d
+            result = self.master.run_command(['python3', '-c', script],
89cb6d
+                                             raiseonerr=False)
89cb6d
+            if result.returncode != 0:
89cb6d
+                # Retry with python instead of python3
89cb6d
+                result = self.master.run_command(['python', '-c', script])
89cb6d
+            assert "False" in result.stdout_text
89cb6d
         finally:
89cb6d
             self.master.run_command(["rmdir", kra_path])
89cb6d
-- 
89cb6d
2.26.2
89cb6d