Merge "Raise exception if result is empty"
This commit is contained in:
commit
2c799ebe69
@ -162,13 +162,14 @@ class Run(Command):
|
||||
except RuntimeError as e:
|
||||
raise RuntimeError(e)
|
||||
|
||||
_rc = None
|
||||
if results:
|
||||
_rc = any([1 for r in results if r['Status'] == 'FAILED'])
|
||||
|
||||
_rc = any([r for r in results if r['Status'] == 'FAILED'])
|
||||
if parsed_args.output_log:
|
||||
common.write_output(parsed_args.output_log, results)
|
||||
common.print_dict(results)
|
||||
|
||||
if _rc:
|
||||
raise RuntimeError("One or more validations have failed.")
|
||||
else:
|
||||
msg = ("No validation has been run, please check "
|
||||
"log in the Ansible working directory.")
|
||||
raise RuntimeError(msg)
|
||||
|
@ -37,8 +37,7 @@ class TestRun(BaseCommand):
|
||||
verifylist = [('validation_name', ['foo'])]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.assertEqual(result, None)
|
||||
self.assertRaises(RuntimeError, self.cmd.take_action, parsed_args)
|
||||
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'run_validations',
|
||||
@ -267,6 +266,29 @@ class TestRun(BaseCommand):
|
||||
'quiet': True,
|
||||
'ssh_user': 'doe'}
|
||||
|
||||
arglist = ['--validation', 'foo']
|
||||
verifylist = [('validation_name', ['foo'])]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(RuntimeError, self.cmd.take_action, parsed_args)
|
||||
|
||||
@mock.patch('getpass.getuser',
|
||||
return_value='doe')
|
||||
@mock.patch('validations_libs.validation_actions.ValidationActions.'
|
||||
'run_validations',
|
||||
return_value=[])
|
||||
def test_run_command_no_validation(self, mock_run, mock_user):
|
||||
run_called_args = {
|
||||
'inventory': 'localhost',
|
||||
'limit_hosts': None,
|
||||
'group': [],
|
||||
'extra_vars': {'key': 'value'},
|
||||
'validations_dir': '/usr/share/ansible/validation-playbooks',
|
||||
'base_dir': '/usr/share/ansible/',
|
||||
'validation_name': ['foo'],
|
||||
'extra_env_vars': {'key2': 'value2'},
|
||||
'quiet': True,
|
||||
'ssh_user': 'doe'}
|
||||
|
||||
arglist = ['--validation', 'foo']
|
||||
verifylist = [('validation_name', ['foo'])]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user