Merge "Add handler for exception raising"

This commit is contained in:
Zuul 2020-02-26 22:12:06 +00:00 committed by Gerrit Code Review
commit 4fc6009f37
4 changed files with 13 additions and 4 deletions

View File

@ -44,7 +44,6 @@ from tripleoclient.tests import fakes
from six.moves.configparser import ConfigParser
from six.moves.urllib import error as url_error
from ansible_runner import AnsibleRunnerException
from ansible_runner import Runner
@ -84,7 +83,7 @@ class TestRunAnsiblePlaybook(TestCase):
def test_subprocess_error(self, mock_dump_artifact,
mock_run, mock_mkdirs, mock_exists,
mock_mkstemp):
with self.assertRaises(AnsibleRunnerException):
with self.assertRaises(RuntimeError):
utils.run_ansible_playbook(
'existing.yaml',
'localhost,',

View File

@ -212,7 +212,8 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
plan='overcloud', gathering_policy='smart',
extra_env_variables=None, parallel_run=False,
callback_whitelist=None, ansible_cfg=None,
ansible_timeout=30, reproduce_command=False):
ansible_timeout=30, reproduce_command=False,
fail_on_rc=True):
"""Simple wrapper for ansible-playbook.
:param playbook: Playbook filename.
@ -296,6 +297,11 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
playbook command which is helpful for debugging
and retry purposes.
:type reproduce_command: Boolean
:param fail_on_rc: Enable or disable raising an exception whenever the
return code from the playbook execution results in a
non 0 exit code. The default is True.
:type fail_on_rc: Boolean
"""
def _playbook_check(play):
@ -609,7 +615,9 @@ def run_ansible_playbook(playbook, inventory, workdir, playbook_dir=None,
if not quiet:
LOG.error(err_msg)
raise ansible_runner.AnsibleRunnerException(err_msg)
if fail_on_rc:
raise RuntimeError(err_msg)
LOG.info(
'Ansible execution success. playbook: {}'.format(

View File

@ -1320,6 +1320,7 @@ class Deploy(command.Command):
),
workdir=self.ansible_dir,
extra_env_variables=extra_env_var,
fail_on_rc=False,
**operation
)[0]
except Exception as e:

View File

@ -95,6 +95,7 @@ def _check_diskspace(upgrade=False):
connection='local',
output_callback='validation_output',
playbook_dir=constants.ANSIBLE_VALIDATION_DIR,
fail_on_rc=False,
**playbook_args
)
if rc != 0: