From 9248b0307f0fd723689c895f8a826e250ff2db58 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Wed, 28 Nov 2012 18:59:06 -0500
Subject: [PATCH] Replaced links of scriptlets with lists.

Previously the deployment tools used symbolic links to determine the
scriplets to execute and their order. The code has been changed such
that now the scriplets are listed as parameters (spawn_scriplets and
destroy_scriplets) in the configuration file.

Ticket #403
---
 base/deploy/CMakeLists.txt        | 122 --------------------------------------
 base/deploy/config/deployment.cfg |  25 ++++++++
 base/deploy/src/pkidestroy        |  21 ++-----
 base/deploy/src/pkispawn          |  21 ++-----
 specs/pki-core.spec               |  14 -----
 5 files changed, 35 insertions(+), 168 deletions(-)

diff --git a/base/deploy/CMakeLists.txt b/base/deploy/CMakeLists.txt
index 26abe5346fcec05e6efb0b117eddc1f17eef6dda..3848bd4993a9e862c3d758f85d0ed48d775d45f0 100644
--- a/base/deploy/CMakeLists.txt
+++ b/base/deploy/CMakeLists.txt
@@ -117,125 +117,3 @@ install(
 # install empty directories
 install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${VAR_INSTALL_DIR}/lock/pki)")
 install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${VAR_INSTALL_DIR}/run/pki)")
-
-# install subsystem directories for pkispawn and pkidestroy
-foreach(PKI_SUBSYSTEM ${PKI_SUBSYSTEMS})
-    install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${PKI_SUBSYSTEM})")
-    install(CODE "file(MAKE_DIRECTORY \$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${PKI_SUBSYSTEM})")
-endforeach(PKI_SUBSYSTEM ${PKI_SUBSYSTEMS})
-
-# generate and install shared ordered 'scriptlet' symbolic links
-# for CA, KRA, OCSP, and TKS for pkispawn
-foreach(TOMCAT_SUBSYSTEM ${TOMCAT_SUBSYSTEMS})
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/initialization.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/000_initialization\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/infrastructure_layout.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/010_infrastructure_layout\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/instance_layout.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/020_instance_layout\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/subsystem_layout.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/030_subsystem_layout\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/selinux_setup.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/035_selinux_setup\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/webapp_deployment.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/040_webapp_deployment\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/slot_substitution.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/050_slot_substitution\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/security_databases.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/060_security_databases\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/configuration.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/070_configuration\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/finalization.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/spawn/${TOMCAT_SUBSYSTEM}/999_finalization\")"
-    )
-endforeach(TOMCAT_SUBSYSTEM ${TOMCAT_SUBSYSTEMS})
-
-# generate and install shared ordered 'scriptlet' symbolic links
-# for RA, and TPS for pkispawn
-
-# generate and install shared ordered 'scriptlet' symbolic links
-# for CA, KRA, OCSP, and TKS for pkidestroy
-foreach(TOMCAT_SUBSYSTEM ${TOMCAT_SUBSYSTEMS})
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/initialization.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/000_initialization\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/configuration.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/930_configuration\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/webapp_deployment.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/940_webapp_deployment\")"
-    )
-#   install(CODE "execute_process(COMMAND
-#       ${CMAKE_COMMAND} -E create_symlink
-#       \"${PYTHON_SITE_PACKAGES}/pki/deployment/slot_substitution.py\"
-#       \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/950_slot_substitution\")"
-#   )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/subsystem_layout.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/960_subsystem_layout\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/security_databases.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/970_security_databases\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/instance_layout.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/980_instance_layout\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/selinux_setup.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/985_selinux_setup\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/infrastructure_layout.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/990_infrastructure_layout\")"
-    )
-    install(CODE "execute_process(COMMAND
-        ${CMAKE_COMMAND} -E create_symlink
-        \"${PYTHON_SITE_PACKAGES}/pki/deployment/finalization.py\"
-        \"\$ENV{DESTDIR}${DATA_INSTALL_DIR}/deployment/destroy/${TOMCAT_SUBSYSTEM}/999_finalization\")"
-    )
-endforeach(TOMCAT_SUBSYSTEM ${TOMCAT_SUBSYSTEMS})
-
-# generate and install shared ordered 'scriptlet' symbolic links
-# for RA, and TPS for pkidestroy
diff --git a/base/deploy/config/deployment.cfg b/base/deploy/config/deployment.cfg
index 133d4e9931a4b92ca0d240651e8e0eb40ab49169..278df62d393b7bf75d49a9ce9c0501bf1d75d5e3 100644
--- a/base/deploy/config/deployment.cfg
+++ b/base/deploy/config/deployment.cfg
@@ -22,6 +22,31 @@ sensitive_parameters=
     pki_security_domain_password
     pki_token_password
 
+# The spawn_scriplets contains a list of scriplets to be executed by pkispawn.
+spawn_scriplets=
+    initialization
+    infrastructure_layout
+    instance_layout
+    subsystem_layout
+    selinux_setup
+    webapp_deployment
+    slot_substitution
+    security_databases
+    configuration
+    finalization
+
+# The destroy_scriplets contains a list of scriplets to be executed by pkidestroy.
+destroy_scriplets=
+    initialization
+    configuration
+    webapp_deployment
+    subsystem_layout
+    security_databases
+    instance_layout
+    selinux_setup
+    infrastructure_layout
+    finalization
+
 ###############################################################################
 ##  Common Configuration:                                                    ##
 ##                                                                           ##
diff --git a/base/deploy/src/pkidestroy b/base/deploy/src/pkidestroy
index 88a47308ff5c8f6dae06cee110e0873e8ccb38ac..4e8bca9d1a1c4edd4caf2ed7dd192969106b7e89 100755
--- a/base/deploy/src/pkidestroy
+++ b/base/deploy/src/pkidestroy
@@ -153,24 +153,13 @@ def main(argv):
     config.pki_log.debug(pkilogging.format(config.pki_master_dict),
                          extra=config.PKI_INDENTATION_LEVEL_0)
 
-    # Remove the specified PKI subsystem.
-    pki_scriptlets_path = "/usr/share/pki/deployment/destroy" +\
-                          "/" + config.pki_subsystem.lower()
-    if not os.path.exists(pki_scriptlets_path) or\
-       not os.path.isdir(pki_scriptlets_path):
-        config.pki_log.error(log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1,
-                             pki_scriptlets_path,
-                             extra=config.PKI_INDENTATION_LEVEL_0)
-        sys.exit(1)
-    pki_subsystem_scriptlets = os.listdir(pki_scriptlets_path)
-    pki_subsystem_scriptlets.sort()
-
-    # Process the various "scriptlets" for the specified PKI subsystem.
+    # Process the various "scriptlets" to remove the specified PKI subsystem.
+    pki_subsystem_scriptlets = config.pki_master_dict['destroy_scriplets'].split()
     rv = 0
     for pki_scriptlet in pki_subsystem_scriptlets:
-        scriptlet = __import__("pki.deployment" +\
-                               "." + pki_scriptlet[4:],
-                               fromlist = [pki_scriptlet[4:]])
+        scriptlet = __import__("pki.deployment." +
+                               pki_scriptlet,
+                               fromlist = [pki_scriptlet])
         instance = scriptlet.PkiScriptlet()
         rv = instance.destroy()
         if rv != 0:
diff --git a/base/deploy/src/pkispawn b/base/deploy/src/pkispawn
index 8031bbdf5f8d5ab2e7c159daefde8afc9941185e..1adbf05fa058296b067aeec7e1084746bbc08ce1 100755
--- a/base/deploy/src/pkispawn
+++ b/base/deploy/src/pkispawn
@@ -167,24 +167,13 @@ def main(argv):
     config.pki_log.debug(pkilogging.format(config.pki_master_dict),
                          extra=config.PKI_INDENTATION_LEVEL_0)
 
-    # Install and configure the specified PKI subsystem.
-    pki_scriptlets_path = "/usr/share/pki/deployment/spawn" +\
-                          "/" + config.pki_subsystem.lower()
-    if not os.path.exists(pki_scriptlets_path) or\
-       not os.path.isdir(pki_scriptlets_path):
-        config.pki_log.error(log.PKI_DIRECTORY_MISSING_OR_NOT_A_DIRECTORY_1,
-                             pki_scriptlets_path,
-                             extra=config.PKI_INDENTATION_LEVEL_0)
-        sys.exit(1)
-    pki_subsystem_scriptlets = os.listdir(pki_scriptlets_path)
-    pki_subsystem_scriptlets.sort()
-
-    # Process the various "scriptlets" for the specified PKI subsystem.
+    # Process the various "scriptlets" to create the specified PKI subsystem.
+    pki_subsystem_scriptlets = config.pki_master_dict['spawn_scriplets'].split()
     rv = 0
     for pki_scriptlet in pki_subsystem_scriptlets:
-        scriptlet = __import__("pki.deployment" +\
-                               "." + pki_scriptlet[4:],
-                               fromlist = [pki_scriptlet[4:]])
+        scriptlet = __import__("pki.deployment." +
+                               pki_scriptlet,
+                               fromlist = [pki_scriptlet])
         instance = scriptlet.PkiScriptlet()
         rv = instance.spawn()
         if rv != 0:
diff --git a/specs/pki-core.spec b/specs/pki-core.spec
index e9234529a7dabf4bc6a5a3d75612f9bc786bc06b..d0cdfcb2f13073ce9f4076e2d3c7c1711ea781cf 100644
--- a/specs/pki-core.spec
+++ b/specs/pki-core.spec
@@ -817,20 +817,6 @@ fi
 %{python_sitelib}/pki/deployment/
 %dir %{_datadir}/pki/deployment
 %{_datadir}/pki/deployment/config/
-%dir %{_datadir}/pki/deployment/spawn
-%{_datadir}/pki/deployment/spawn/ca/
-%{_datadir}/pki/deployment/spawn/kra/
-%{_datadir}/pki/deployment/spawn/ocsp/
-%{_datadir}/pki/deployment/spawn/ra/
-%{_datadir}/pki/deployment/spawn/tks/
-%{_datadir}/pki/deployment/spawn/tps/
-%dir %{_datadir}/pki/deployment/destroy
-%{_datadir}/pki/deployment/destroy/ca/
-%{_datadir}/pki/deployment/destroy/kra/
-%{_datadir}/pki/deployment/destroy/ocsp/
-%{_datadir}/pki/deployment/destroy/ra/
-%{_datadir}/pki/deployment/destroy/tks/
-%{_datadir}/pki/deployment/destroy/tps/
 %dir %{_datadir}/pki/scripts
 %{_datadir}/pki/scripts/operations
 %dir %{_localstatedir}/lock/pki
-- 
1.7.12.1

