Blob Blame History Raw
From ca073d46b6bfbd3644d6ed8e022482756f510257 Mon Sep 17 00:00:00 2001
From: Florence Blanc-Renaud <flo@redhat.com>
Date: Thu, 14 Jan 2021 09:44:30 +0100
Subject: [PATCH] ipatest: fix
 test_upgrade.py::TestUpgrade::()::test_kra_detection

Modify the test scenario in order to be independant from PKI
behavior. The aim of the test is to ensure that the KRA
detection is not based on the presence of the directory
/var/lib/pki/pki-tomcat/kra/.
Previously the test was calling ipa-server-upgrade but this cmd
may fail even with the kra detection fix because of an issue in
pki (https://github.com/dogtagpki/pki/issues/3397).
Instead of exercising the whole ipa-server-upgrade command, the
test now checks the output of the API kra.is_installed() to validate
KRA detection mechanism.

Fixes: https://pagure.io/freeipa/issue/8653
Related: https://pagure.io/freeipa/issue/8596

Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
Reviewed-By: Francois Cami <fcami@redhat.com>
Reviewed-By: Francois Cami <fcami@redhat.com>
---
 ipatests/test_integration/test_upgrade.py | 32 ++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/ipatests/test_integration/test_upgrade.py b/ipatests/test_integration/test_upgrade.py
index c866b28dda6efdd10ccd1bee42253ccb6e1285be..06509b8d31b2a042df8452ca818ece95e419fbd6 100644
--- a/ipatests/test_integration/test_upgrade.py
+++ b/ipatests/test_integration/test_upgrade.py
@@ -10,7 +10,6 @@ from __future__ import absolute_import
 import base64
 import os
 from cryptography.hazmat.primitives import serialization
-import pytest
 
 from ipaplatform.paths import paths
 from ipapython.dn import DN
@@ -70,22 +69,31 @@ class TestUpgrade(IntegrationTest):
         Test for https://pagure.io/freeipa/issue/8596
         When the directory /var/lib/pki/pki-tomcat/kra/ exists, the upgrade
         wrongly assumes that KRA component is installed and crashes.
-        The test creates an empty dir and calls ipa-server-upgrade
+        The test creates an empty dir and calls kra.is_installed()
         to make sure that KRA detection is not based on the directory
         presence.
+        Note: because of issue https://github.com/dogtagpki/pki/issues/3397
+        ipa-server-upgrade fails even with the kra detection fix. That's
+        why the test does not exercise the whole ipa-server-upgrade command
+        but only the KRA detection part.
         """
-        # Skip test if pki 10.10.0 is installed
-        # because of https://github.com/dogtagpki/pki/issues/3397
-        # pki fails to start if empty dir /var/lib/pki/pki-tomcat/kra exists
-        if tasks.get_pki_version(self.master) \
-           == tasks.parse_version('10.10.0'):
-            pytest.skip("Skip test with pki 10.10.0")
-
         kra_path = os.path.join(paths.VAR_LIB_PKI_TOMCAT_DIR, "kra")
         try:
             self.master.run_command(["mkdir", "-p", kra_path])
-            result = self.master.run_command(['ipa-server-upgrade'])
-            err_msg = 'Upgrade failed with no such entry'
-            assert err_msg not in result.stderr_text
+            script = (
+                "from ipalib import api; "
+                "from ipaserver.install import krainstance; "
+                "api.bootstrap(); "
+                "api.finalize(); "
+                "kra = krainstance.KRAInstance(api.env.realm); "
+                "print(kra.is_installed())"
+            )
+
+            result = self.master.run_command(['python3', '-c', script],
+                                             raiseonerr=False)
+            if result.returncode != 0:
+                # Retry with python instead of python3
+                result = self.master.run_command(['python', '-c', script])
+            assert "False" in result.stdout_text
         finally:
             self.master.run_command(["rmdir", kra_path])
-- 
2.26.2