Browse Source

New optional param for log path

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Id31a7ce2dfc4d9a132fea7d600e8beb8adc0739b
changes/70/789770/2
Jiri Podivin 1 month ago
parent
commit
e2d11be677
2 changed files with 40 additions and 14 deletions
  1. +11
    -1
      validations_libs/cli/run.py
  2. +29
    -13
      validations_libs/tests/cli/test_run.py

+ 11
- 1
validations_libs/cli/run.py View File

@ -79,6 +79,15 @@ class Run(Command):
"will override the other(s)")
)
parser.add_argument(
'--validation-log-dir',
dest='log_path',
default=constants.VALIDATIONS_LOG_BASEDIR,
help=(
"Path where the log files and artifacts will be located. "),
metavar='<LOG-DIR>'
)
extra_vars_group = parser.add_mutually_exclusive_group(required=False)
extra_vars_group.add_argument(
'--extra-vars',
@ -158,7 +167,8 @@ class Run(Command):
validation_name=parsed_args.validation_name,
extra_env_vars=parsed_args.extra_env_vars,
quiet=True,
ssh_user=parsed_args.ssh_user)
ssh_user=parsed_args.ssh_user,
log_path=parsed_args.log_path)
except RuntimeError as e:
raise RuntimeError(e)


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

@ -56,13 +56,15 @@ class TestRun(BaseCommand):
self.assertRaises(Exception, self.check_parser, self.cmd,
arglist, verifylist)
@mock.patch('validations_libs.constants.VALIDATIONS_LOG_BASEDIR')
@mock.patch('validations_libs.cli.common.print_dict')
@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_vars(self, mock_run, mock_user, mock_print):
def test_run_command_extra_vars(self, mock_run, mock_user, mock_print,
mock_log_dir):
run_called_args = {
'inventory': 'localhost',
'limit_hosts': None,
@ -73,7 +75,8 @@ class TestRun(BaseCommand):
'validation_name': ['foo'],
'extra_env_vars': None,
'quiet': True,
'ssh_user': 'doe'}
'ssh_user': 'doe',
'log_path': mock_log_dir}
arglist = ['--validation', 'foo',
'--extra-vars', 'key=value']
@ -84,6 +87,7 @@ class TestRun(BaseCommand):
self.cmd.take_action(parsed_args)
mock_run.assert_called_with(**run_called_args)
@mock.patch('validations_libs.constants.VALIDATIONS_LOG_BASEDIR')
@mock.patch('validations_libs.cli.common.print_dict')
@mock.patch('getpass.getuser',
return_value='doe')
@ -91,7 +95,7 @@ class TestRun(BaseCommand):
'run_validations',
return_value=fakes.FAKE_SUCCESS_RUN)
def test_run_command_extra_vars_twice(self, mock_run, mock_user,
mock_print):
mock_print, mock_log_dir):
run_called_args = {
'inventory': 'localhost',
'limit_hosts': None,
@ -102,7 +106,8 @@ class TestRun(BaseCommand):
'validation_name': ['foo'],
'extra_env_vars': None,
'quiet': True,
'ssh_user': 'doe'}
'ssh_user': 'doe',
'log_path': mock_log_dir}
arglist = ['--validation', 'foo',
'--extra-vars', 'key=value1',
@ -124,6 +129,7 @@ class TestRun(BaseCommand):
self.assertRaises(Exception, self.check_parser, self.cmd,
arglist, verifylist)
@mock.patch('validations_libs.constants.VALIDATIONS_LOG_BASEDIR')
@mock.patch('yaml.safe_load', return_value={'key': 'value'})
@mock.patch('six.moves.builtins.open')
@mock.patch('getpass.getuser',
@ -132,7 +138,8 @@ class TestRun(BaseCommand):
'run_validations',
return_value=fakes.FAKE_SUCCESS_RUN)
def test_run_command_extra_vars_file(self, mock_run, mock_user, mock_open,
mock_yaml):
mock_yaml, mock_log_dir):
run_called_args = {
'inventory': 'localhost',
'limit_hosts': None,
@ -143,7 +150,8 @@ class TestRun(BaseCommand):
'validation_name': ['foo'],
'extra_env_vars': None,
'quiet': True,
'ssh_user': 'doe'}
'ssh_user': 'doe',
'log_path': mock_log_dir}
arglist = ['--validation', 'foo',
'--extra-vars-file', '/foo/vars.yaml']
@ -154,12 +162,13 @@ class TestRun(BaseCommand):
self.cmd.take_action(parsed_args)
mock_run.assert_called_with(**run_called_args)
@mock.patch('validations_libs.constants.VALIDATIONS_LOG_BASEDIR')
@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(self, mock_run, mock_user):
def test_run_command_extra_env_vars(self, mock_run, mock_user, mock_log_dir):
run_called_args = {
'inventory': 'localhost',
'limit_hosts': None,
@ -170,7 +179,8 @@ class TestRun(BaseCommand):
'validation_name': ['foo'],
'extra_env_vars': {'key': 'value'},
'quiet': True,
'ssh_user': 'doe'}
'ssh_user': 'doe',
'log_path': mock_log_dir}
arglist = ['--validation', 'foo',
'--extra-env-vars', 'key=value']
@ -181,12 +191,13 @@ class TestRun(BaseCommand):
self.cmd.take_action(parsed_args)
mock_run.assert_called_with(**run_called_args)
@mock.patch('validations_libs.constants.VALIDATIONS_LOG_BASEDIR')
@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_twice(self, mock_run, mock_user):
def test_run_command_extra_env_vars_twice(self, mock_run, mock_user, mock_log_dir):
run_called_args = {
'inventory': 'localhost',
'limit_hosts': None,
@ -197,7 +208,8 @@ class TestRun(BaseCommand):
'validation_name': ['foo'],
'extra_env_vars': {'key': 'value2'},
'quiet': True,
'ssh_user': 'doe'}
'ssh_user': 'doe',
'log_path': mock_log_dir}
arglist = ['--validation', 'foo',
'--extra-env-vars', 'key=value1',
@ -209,13 +221,16 @@ class TestRun(BaseCommand):
self.cmd.take_action(parsed_args)
mock_run.assert_called_with(**run_called_args)
@mock.patch('validations_libs.constants.VALIDATIONS_LOG_BASEDIR')
@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_and_extra_vars(self, mock_run,
mock_user):
def test_run_command_extra_env_vars_and_extra_vars(self,
mock_run,
mock_user,
mock_log_dir):
run_called_args = {
'inventory': 'localhost',
'limit_hosts': None,
@ -226,7 +241,8 @@ class TestRun(BaseCommand):
'validation_name': ['foo'],
'extra_env_vars': {'key2': 'value2'},
'quiet': True,
'ssh_user': 'doe'}
'ssh_user': 'doe',
'log_path': mock_log_dir}
arglist = ['--validation', 'foo',
'--extra-vars', 'key=value',


Loading…
Cancel
Save