From 9e8f79ccf3f181836c5222336b46be54b68ce571 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Mon, 16 Dec 2019 11:17:28 -0500 Subject: [PATCH] actions/ansible: catch errors when cleaning the work directory If an error happens during the cleaning of the work directory, we now catch the error and return the error to Mistral. Change-Id: Id037525650c9976cd88a8ba2a02b206ec03855aa --- tripleo_common/actions/ansible.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tripleo_common/actions/ansible.py b/tripleo_common/actions/ansible.py index ca675f5ef..5d82f20e7 100644 --- a/tripleo_common/actions/ansible.py +++ b/tripleo_common/actions/ansible.py @@ -324,8 +324,13 @@ class AnsibleAction(actions.Action): "log_path": os.path.join(self.work_dir, 'ansible.log')} finally: # NOTE(flaper87): clean the mess if debug is disabled. - if not self.verbosity and self._remove_work_dir: - shutil.rmtree(self.work_dir) + try: + if not self.verbosity and self._remove_work_dir: + shutil.rmtree(self.work_dir) + except Exception as e: + msg = "An error happened while cleaning work directory: " + e + LOG.error(msg) + return actions.Result(error=msg) class AnsiblePlaybookAction(base.TripleOAction): @@ -663,8 +668,13 @@ class AnsiblePlaybookAction(base.TripleOAction): "log_path": os.path.join(self.work_dir, 'ansible.log')} finally: # NOTE(flaper87): clean the mess if debug is disabled. - if not self.verbosity and self._remove_work_dir: - shutil.rmtree(self.work_dir) + try: + if not self.verbosity and self._remove_work_dir: + shutil.rmtree(self.work_dir) + except Exception as e: + msg = "An error happened while cleaning work directory: " + e + LOG.error(msg) + return actions.Result(error=msg) class AnsibleGenerateInventoryAction(base.TripleOAction):