89cb6d
From 4fd1ae18e326ab69d9e22886784ea6b1057ef2a6 Mon Sep 17 00:00:00 2001
89cb6d
From: Florence Blanc-Renaud <flo@redhat.com>
89cb6d
Date: Wed, 25 Nov 2020 09:53:54 +0100
89cb6d
Subject: [PATCH] Improve PKI subsystem detection
89cb6d
89cb6d
The dogtaginstance.is_installed() method currently relies on
89cb6d
the presence of the directory /var/lib/pki/pki-tomcat/{ca|kra},
89cb6d
even if it is empty.
89cb6d
An unwanted consequence is ipa-server-upgrade wrongly assuming the KRA
89cb6d
is installed and crashing when trying to upgrade a not-installed
89cb6d
component.
89cb6d
89cb6d
The fix relies on the command "pki-server subsystem-show {ca|kra}" to
89cb6d
detect if a subsystem is installed. The command does not require PKI
89cb6d
to be running (hence can be called anytime) and is delivered by
89cb6d
the pki-server package which is already required by ipa server pkg.
89cb6d
89cb6d
Fixes: https://pagure.io/freeipa/issue/8596
89cb6d
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
89cb6d
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
89cb6d
Reviewed-By: Alexander Bokovoy <abbra@users.noreply.github.com>
89cb6d
---
89cb6d
 ipaserver/install/dogtaginstance.py | 10 ++++++++--
89cb6d
 1 file changed, 8 insertions(+), 2 deletions(-)
89cb6d
89cb6d
diff --git a/ipaserver/install/dogtaginstance.py b/ipaserver/install/dogtaginstance.py
89cb6d
index a84368344f5d03fdaab401d35af6156b628cf485..7f26696850c85d35c06f6690dc83bb9073844eb1 100644
89cb6d
--- a/ipaserver/install/dogtaginstance.py
89cb6d
+++ b/ipaserver/install/dogtaginstance.py
89cb6d
@@ -148,8 +148,14 @@ class DogtagInstance(service.Service):
89cb6d
 
89cb6d
         Returns True/False
89cb6d
         """
89cb6d
-        return os.path.exists(os.path.join(
89cb6d
-            paths.VAR_LIB_PKI_TOMCAT_DIR, self.subsystem.lower()))
89cb6d
+        try:
89cb6d
+            result = ipautil.run(
89cb6d
+                ['pki-server', 'subsystem-show', self.subsystem.lower()],
89cb6d
+                capture_output=True)
89cb6d
+            # parse the command output
89cb6d
+            return 'Enabled: True' in result.output
89cb6d
+        except ipautil.CalledProcessError:
89cb6d
+            return False
89cb6d
 
89cb6d
     def spawn_instance(self, cfg_file, nolog_list=()):
89cb6d
         """
89cb6d
-- 
89cb6d
2.26.2
89cb6d