From 61b6e8737a269358a6f67d970c00d4581d08f620 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Thu, 22 Apr 2021 18:03:17 -0400 Subject: [PATCH] Handle exceptions in finally clause The "finally" clause for overcloud deploy is updated to handle exceptions raised by statements so that later code in the block will be assured of executing. Change-Id: I7a94e0f72ed42b70468a361536bfbf88d158dc14 Signed-off-by: James Slagle --- tripleoclient/v1/overcloud_deploy.py | 61 +++++++++++++++++++--------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index 10b47e153..cf78f871d 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -1188,17 +1188,30 @@ class DeployOvercloud(command.Command): working_dir=self.working_dir ) finally: - # Run postconfig on create or force. Use force to makes sure - # endpoints are created with deploy reruns and upgrades - if (stack_create or parsed_args.force_postconfig - and not parsed_args.skip_postconfig): - self._deploy_postconfig(stack, parsed_args) + try: + # Run postconfig on create or force + if (stack_create or parsed_args.force_postconfig + and not parsed_args.skip_postconfig): + self._deploy_postconfig(stack, parsed_args) + except Exception as e: + self.log.error('Exception during postconfig') + self.log.error(e) - # Copy clouds.yaml to the cloud user directory - user = \ - getpwuid(os.stat(constants.CLOUD_HOME_DIR).st_uid).pw_name - utils.copy_clouds_yaml(user) - utils.create_tempest_deployer_input(output_dir=self.working_dir) + try: + # Copy clouds.yaml to the cloud user directory + user = \ + getpwuid(os.stat(constants.CLOUD_HOME_DIR).st_uid).pw_name + utils.copy_clouds_yaml(user) + except Exception as e: + self.log.error('Exception creating clouds.yaml') + self.log.error(e) + + try: + utils.create_tempest_deployer_input( + output_dir=self.working_dir) + except Exception as e: + self.log.error('Exception creating tempest configuration.') + self.log.error(e) try: if (parsed_args.heat_type != 'installed' and @@ -1224,17 +1237,25 @@ class DeployOvercloud(command.Command): rcpath, old_rcpath)) print("Overcloud Deployed {0}".format(deploy_message)) - if parsed_args.heat_type != 'installed': - self.log.info("Stopping ephemeral heat.") - utils.kill_heat(self.heat_launcher) - utils.rm_heat(self.heat_launcher, backup_db=True) + try: + if parsed_args.heat_type != 'installed': + self.log.info("Stopping ephemeral heat.") + utils.kill_heat(self.heat_launcher) + utils.rm_heat(self.heat_launcher, backup_db=True) + except Exception as e: + self.log.error('Exception stopping ephemeral Heat') + self.log.error(e) - if parsed_args.output_dir: - ansible_dir = config_download_dir - else: - ansible_dir = None - utils.archive_deploy_artifacts(self.log, parsed_args.stack, - self.working_dir, ansible_dir) + try: + if parsed_args.output_dir: + ansible_dir = config_download_dir + else: + ansible_dir = None + utils.archive_deploy_artifacts(self.log, parsed_args.stack, + self.working_dir, ansible_dir) + except Exception as e: + self.log.error('Exception archiving deploy artifacts') + self.log.error(e) if deploy_status == 'DEPLOY_FAILED': raise(deploy_trace)