Browse Source

Merge "Disable quiet mode run when using an Ansible Custom Callback"

changes/57/792257/3
Zuul 3 weeks ago
committed by Gerrit Code Review
parent
commit
51564ac80c
2 changed files with 42 additions and 3 deletions
  1. +13
    -3
      validations_libs/cli/run.py
  2. +29
    -0
      validations_libs/tests/cli/test_run.py

+ 13
- 3
validations_libs/cli/run.py View File

@ -141,6 +141,15 @@ class Run(Command):
v_actions = ValidationActions(
validation_path=parsed_args.validation_dir)
# Ansible execution should be quiet while using the validations_json
# default callback and be verbose while passing ANSIBLE_SDTOUT_CALLBACK
# environment variable to Ansible through the --extra-env-vars argument
quiet_mode = True
extra_env_vars = parsed_args.extra_env_vars
if extra_env_vars:
if "ANSIBLE_STDOUT_CALLBACK" in extra_env_vars.keys():
quiet_mode = False
extra_vars = parsed_args.extra_vars
if parsed_args.extra_vars_file:
try:
@ -161,9 +170,10 @@ class Run(Command):
validations_dir=parsed_args.validation_dir,
base_dir=parsed_args.ansible_base_dir,
validation_name=parsed_args.validation_name,
extra_env_vars=parsed_args.extra_env_vars,
quiet=True,
ssh_user=parsed_args.ssh_user)
extra_env_vars=extra_env_vars,
quiet=quiet_mode,
ssh_user=parsed_args.ssh_user,
)
except RuntimeError as e:
raise RuntimeError(e)


+ 29
- 0
validations_libs/tests/cli/test_run.py View File

@ -181,6 +181,35 @@ class TestRun(BaseCommand):
self.cmd.take_action(parsed_args)
mock_run.assert_called_with(**run_called_args)
@mock.patch('getpass.getuser',
return_value='doe')
@mock.patch('validations_libs.validation_actions.ValidationActions.'
'run_validations',
return_value=fakes.FAKE_SUCCESS_RUN)
def test_run_command_extra_env_vars_with_custom_callback(self,
mock_run,
mock_user):
run_called_args = {
'inventory': 'localhost',
'limit_hosts': None,
'group': [],
'extra_vars': None,
'validations_dir': '/usr/share/ansible/validation-playbooks',
'base_dir': '/usr/share/ansible/',
'validation_name': ['foo'],
'extra_env_vars': {'ANSIBLE_STDOUT_CALLBACK': 'default'},
'quiet': False,
'ssh_user': 'doe'}
arglist = ['--validation', 'foo',
'--extra-env-vars', 'ANSIBLE_STDOUT_CALLBACK=default']
verifylist = [('validation_name', ['foo']),
('extra_env_vars', {'ANSIBLE_STDOUT_CALLBACK': 'default'})]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
mock_run.assert_called_with(**run_called_args)
@mock.patch('getpass.getuser',
return_value='doe')
@mock.patch('validations_libs.validation_actions.ValidationActions.'


Loading…
Cancel
Save