[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Pki-devel] [PATCH] 822-823 Added upgrade script to fix deployment descriptors.



An upgrade script has been added to fix missing deployment
descriptors or deployment descriptors that are pointing to
non-existent or empty folders.

The RPM spec has been modified to move the upgrade script into
the correct folder for RHEL.

https://fedorahosted.org/pki/ticket/2439

--
Endi S. Dewata
>From 25172687c60f9683333e981fb2e4116f60c81725 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata redhat com>
Date: Wed, 24 Aug 2016 18:42:05 +0200
Subject: [PATCH] Added upgrade script to fix deployment descriptors.

An upgrade script has been added to fix missing deployment
descriptors or deployment descriptors that are pointing to
non-existent or empty folders.

https://fedorahosted.org/pki/ticket/2439
---
 .../upgrade/10.3.5/03-FixDeploymentDescriptor      | 110 +++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 base/server/upgrade/10.3.5/03-FixDeploymentDescriptor

diff --git a/base/server/upgrade/10.3.5/03-FixDeploymentDescriptor b/base/server/upgrade/10.3.5/03-FixDeploymentDescriptor
new file mode 100644
index 0000000000000000000000000000000000000000..1f721f237e6b3840c6d44e349f985e8bc4c8a48f
--- /dev/null
+++ b/base/server/upgrade/10.3.5/03-FixDeploymentDescriptor
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+# Authors:
+#     Endi S. Dewata <edewata redhat com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright (C) 2016 Red Hat, Inc.
+# All rights reserved.
+
+from __future__ import absolute_import
+from lxml import etree
+import os
+import shutil
+
+import pki.server.upgrade
+
+
+class FixDeploymentDescriptor(pki.server.upgrade.PKIServerUpgradeScriptlet):
+
+    def __init__(self):
+        super(FixDeploymentDescriptor, self).__init__()
+        self.message = 'Fix deployment descriptor'
+        self.parser = etree.XMLParser(remove_blank_text=True)
+
+    def upgrade_instance(self, instance):
+
+        self.fix_webapp(instance, 'ROOT.xml')
+        self.fix_webapp(instance, 'pki#admin.xml')
+        self.fix_webapp(instance, 'pki#js.xml')
+
+        self.fix_theme(instance, 'pki.xml')
+
+    def fix_webapp(self, instance, context_xml):
+
+        source_xml = pki.SHARE_DIR + '/server/conf/Catalina/localhost/' + context_xml
+        target_xml = instance.conf_dir + '/Catalina/localhost/' + context_xml
+
+        # if deployment descriptor doesn't exist, install the default
+        if not os.path.exists(target_xml):
+            self.copy_file(instance, source_xml, target_xml)
+            return
+
+        # get docBase from deployment descriptor
+        document = etree.parse(target_xml, self.parser)
+        context = document.getroot()
+        docBase = context.get('docBase')
+
+        # if docBase is absolute and pointing to non-empty folder, ignore
+        if docBase.startswith('/') and \
+                os.path.exists(docBase) and \
+                os.listdir(docBase):
+            return
+
+        # if docBase is relative and pointing to non-empty folder, ignore
+        if not docBase.startswith('/') and \
+                os.path.exists(instance.base_dir + '/webapps/' + docBase) and \
+                os.listdir(instance.base_dir + '/webapps/' + docBase):
+            return
+
+        # docBase is pointing to non-existent/empty folder, replace with default
+        self.copy_file(instance, source_xml, target_xml)
+
+    def fix_theme(self, instance, context_xml):
+
+        source_xml = pki.SHARE_DIR + '/server/conf/Catalina/localhost/' + context_xml
+        target_xml = instance.conf_dir + '/Catalina/localhost/' + context_xml
+
+        # if deployment descriptor doesn't exist, ignore (no theme)
+        if not os.path.exists(target_xml):
+            return
+
+        # get docBase from deployment descriptor
+        document = etree.parse(target_xml, self.parser)
+        context = document.getroot()
+        docBase = context.get('docBase')
+
+        # if docBase is absolute and pointing to non-empty folder, ignore
+        if docBase.startswith('/') and \
+                os.path.exists(docBase) and \
+                os.listdir(docBase):
+            return
+
+        # if docBase is relative and pointing to non-empty folder, ignore
+        if not docBase.startswith('/') and \
+                os.path.exists(instance.base_dir + '/webapps/' + docBase) and \
+                os.listdir(instance.base_dir + '/webapps/' + docBase):
+            return
+
+        # docBase is pointing to non-existent/empty folder
+
+        # if theme package is installed, replace deployment descriptor
+        if os.path.exists(pki.SHARE_DIR + '/common-ui'):
+            self.copy_file(instance, source_xml, target_xml)
+
+    def copy_file(self, instance, source, target):
+
+        self.backup(target)
+        shutil.copyfile(source, target)
+        os.chown(target, instance.uid, instance.gid)
-- 
2.5.5

>From 711012bc06976949930223c0e083311400e7ef22 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata redhat com>
Date: Thu, 25 Aug 2016 16:41:51 +0200
Subject: [PATCH] Updated RPM spec for RHEL.

The RPM spec has been modified to move the upgrade script into
the correct folder for RHEL.

https://fedorahosted.org/pki/ticket/2439
---
 specs/pki-core.spec | 1 +
 1 file changed, 1 insertion(+)

diff --git a/specs/pki-core.spec b/specs/pki-core.spec
index 015de1b1a0a406b082cf9a58ca9ce66c4a9f022c..76ef0440fe275b6e7a95eba2a47e5048ef1d1144 100644
--- a/specs/pki-core.spec
+++ b/specs/pki-core.spec
@@ -925,6 +925,7 @@ fi
 %if 0%{?rhel}
 mv %{buildroot}%{_datadir}/pki/server/upgrade/10.3.5/01-FixServerLibrary %{buildroot}%{_datadir}/pki/server/upgrade/10.3.3/02-FixServerLibrary
 mv %{buildroot}%{_datadir}/pki/server/upgrade/10.3.5/02-FixSELinuxContexts %{buildroot}%{_datadir}/pki/server/upgrade/10.3.3/03-FixSELinuxContexts
+mv %{buildroot}%{_datadir}/pki/server/upgrade/10.3.5/03-FixDeploymentDescriptor %{buildroot}%{_datadir}/pki/server/upgrade/10.3.3/04-FixDeploymentDescriptor
 /bin/rm -rf %{buildroot}%{_datadir}/pki/server/upgrade/10.3.4
 /bin/rm -rf %{buildroot}%{_datadir}/pki/server/upgrade/10.3.5
 %endif
-- 
2.5.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]