From 21587064f07c3d08f41da6e5a7aa357e90438637 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 17 Jul 2023 19:12:19 -0500 Subject: [PATCH] Remove PKIDeployer.tomcat_instance_subsystems() The PKIDeployer.tomcat_instance_subsystems() has been replaced with PKIServer.get_subsystems(). --- .../python/pki/server/deployment/__init__.py | 20 +++---------------- .../deployment/scriptlets/instance_layout.py | 8 ++++---- .../scriptlets/security_databases.py | 8 ++++---- .../deployment/scriptlets/selinux_setup.py | 16 +++++++++------ 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/base/server/python/pki/server/deployment/__init__.py b/base/server/python/pki/server/deployment/__init__.py index 86640dca1ca..86793fad8e4 100644 --- a/base/server/python/pki/server/deployment/__init__.py +++ b/base/server/python/pki/server/deployment/__init__.py @@ -417,20 +417,6 @@ def get_key_params(self, cert_id): return (key_type, key_size, curve, hash_alg) - def tomcat_instance_subsystems(self): - - # Return list of PKI subsystems in the specified tomcat instance - - rv = [] - - for subsystem in config.PKI_SUBSYSTEMS: - - path = os.path.join(self.mdict['pki_instance_path'], subsystem.lower()) - if os.path.exists(path) and os.path.isdir(path): - rv.append(subsystem) - - return rv - def verify_subsystem_exists(self, instance): subsystem_path = os.path.join( @@ -2241,7 +2227,7 @@ def setup_system_certs(self, nssdb, subsystem): system_certs = {} clone = self.configuration_file.clone - tomcat_instance_subsystems = len(self.tomcat_instance_subsystems()) + num_subsystems = len(subsystem.instance.get_subsystems()) external = config.str2bool(self.mdict['pki_external']) or \ config.str2bool(self.mdict['pki_existing']) or \ @@ -2260,11 +2246,11 @@ def setup_system_certs(self, nssdb, subsystem): logger.info('%s cert is already set up', tag) continue - if tag == 'sslserver' and tomcat_instance_subsystems > 1: + if tag == 'sslserver' and num_subsystems > 1: logger.info('sslserver cert is already set up') continue - if tag == 'subsystem' and tomcat_instance_subsystems > 1: + if tag == 'subsystem' and num_subsystems > 1: logger.info('subsystem cert is already set up') continue diff --git a/base/server/python/pki/server/deployment/scriptlets/instance_layout.py b/base/server/python/pki/server/deployment/scriptlets/instance_layout.py index ab4e412d4b6..44fbeec84e2 100644 --- a/base/server/python/pki/server/deployment/scriptlets/instance_layout.py +++ b/base/server/python/pki/server/deployment/scriptlets/instance_layout.py @@ -119,7 +119,7 @@ def spawn(self, deployer): instance.store_passwords() # if this is not the first subsystem, skip - if len(deployer.tomcat_instance_subsystems()) > 0: + if instance.get_subsystems(): logger.info('Installing %s instance', deployer.mdict['pki_instance_name']) return @@ -278,12 +278,12 @@ def spawn(self, deployer): def destroy(self, deployer): + instance = self.instance + # if this is not the last subsystem, skip - if len(deployer.tomcat_instance_subsystems()) > 0: + if instance.get_subsystems(): return - instance = self.instance - logger.info('Removing %s instance', deployer.mdict['pki_instance_name']) logger.info('Removing %s', deployer.systemd.systemd_link) diff --git a/base/server/python/pki/server/deployment/scriptlets/security_databases.py b/base/server/python/pki/server/deployment/scriptlets/security_databases.py index 7c621d5d23f..24c9fa4228a 100644 --- a/base/server/python/pki/server/deployment/scriptlets/security_databases.py +++ b/base/server/python/pki/server/deployment/scriptlets/security_databases.py @@ -229,7 +229,7 @@ def spawn(self, deployer): # installing a non-CA subsystem on a fresh system. instance.copyfile(ca_cert_path, destination) - if len(deployer.tomcat_instance_subsystems()) < 2: + if len(instance.get_subsystems()) == 1: # Check to see if a secure connection is being used for the DS if deployer.ds_url.scheme == 'ldaps': @@ -535,12 +535,12 @@ def update_external_certs_conf(self, external_path, deployer): def destroy(self, deployer): + instance = self.instance + # if this is not the last subsystem, skip - if len(deployer.tomcat_instance_subsystems()) > 0: + if instance.get_subsystems(): return - instance = self.instance - if deployer.directory.exists(deployer.mdict['pki_client_dir']): logger.info('Removing %s', deployer.mdict['pki_client_dir']) pki.util.rmtree(deployer.mdict['pki_client_dir'], diff --git a/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py b/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py index 60acc570179..ae74b7810f4 100644 --- a/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py +++ b/base/server/python/pki/server/deployment/scriptlets/selinux_setup.py @@ -55,6 +55,8 @@ def spawn(self, deployer): logger.info('SELinux disabled') return + instance = self.instance + logger.info('Creating SELinux contexts') # A maximum of 10 tries to create the SELinux contexts @@ -65,16 +67,16 @@ def spawn(self, deployer): # check first if any transactions are required if len(ports) == 0 and deployer.mdict['pki_instance_name'] == \ config.PKI_DEPLOYMENT_DEFAULT_TOMCAT_INSTANCE_NAME: - deployer.restore_selinux_contexts(self.instance) + deployer.restore_selinux_contexts(instance) return # add SELinux contexts when adding the first subsystem - if len(deployer.tomcat_instance_subsystems()) == 1: + if len(instance.get_subsystems()) == 1: if deployer.mdict['pki_instance_name'] != \ config.PKI_DEPLOYMENT_DEFAULT_TOMCAT_INSTANCE_NAME: - deployer.create_selinux_contexts(self.instance) + deployer.create_selinux_contexts(instance) - deployer.restore_selinux_contexts(self.instance) + deployer.restore_selinux_contexts(instance) break except ValueError as e: @@ -101,6 +103,8 @@ def destroy(self, deployer): config.PKI_DEPLOYMENT_DEFAULT_TOMCAT_INSTANCE_NAME): return + instance = self.instance + logger.info('Removing SELinux contexts') # A maximum of 10 tries to delete the SELinux contexts @@ -108,10 +112,10 @@ def destroy(self, deployer): for counter in range(1, max_tries): try: # remove SELinux contexts when removing the last subsystem - if len(deployer.tomcat_instance_subsystems()) == 0: + if not instance.get_subsystems(): if deployer.mdict['pki_instance_name'] != \ config.PKI_DEPLOYMENT_DEFAULT_TOMCAT_INSTANCE_NAME: - deployer.remove_selinux_contexts(self.instance) + deployer.remove_selinux_contexts(instance) break except ValueError as e: