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
This commit is contained in:
Emilien Macchi 2019-12-16 11:17:28 -05:00
parent 03ccf4ba9b
commit 9e8f79ccf3

View File

@ -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):