Changing group show commmand into a lister.

The CLI group info command now uses preset path
to the validation groups file if no other is supplied.

The default value is set in both CLI and the 'group_information'
method of the ValidationActions class.

Tests adjusted.

Resolves: rhbz#1972155

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Iff12dff9a870e3e3b89e8070bc251401498ea623
This commit is contained in:
Jiri Podivin 2021-06-15 13:38:12 +02:00
parent 4d1df7b0e7
commit 8217d7b360
7 changed files with 96 additions and 74 deletions

View File

@ -42,8 +42,8 @@ console_scripts:
validation.cli:
list = validations_libs.cli.lister:ValidationList
list_groups = validations_libs.cli.lister:GroupsList
show = validations_libs.cli.show:Show
show_group = validations_libs.cli.show:ShowGroup
show_parameter = validations_libs.cli.show:ShowParameter
run = validations_libs.cli.run:Run
history_list = validations_libs.cli.history:ListHistory

View File

@ -50,3 +50,29 @@ class ValidationList(Lister):
v_actions = ValidationActions(validation_path=validation_dir)
return (v_actions.list_validations(group))
class GroupsList(Lister):
"""Validation List group client implementation class"""
def get_parser(self, parser):
"""Argument parser for validation show group"""
parser = super(GroupsList, self).get_parser(parser)
parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks "
"are located."))
parser.add_argument('--groups-file', '-g',
dest="groups_file",
default=constants.VALIDATION_GROUPS_INFO,
help=("Path to the group definition file."))
return parser
def take_action(self, parsed_args):
"""Take validation action"""
# Get parameters:
validation_dir = parsed_args.validation_dir
groups_file = parsed_args.groups_file
v_actions = ValidationActions(validation_path=validation_dir)
return v_actions.group_information(groups_file)

View File

@ -50,32 +50,6 @@ class Show(ShowOne):
return data.keys(), data.values()
class ShowGroup(ShowOne):
"""Validation Show group client implementation class"""
def get_parser(self, parser):
"""Argument parser for validation show group"""
parser = super(ShowGroup, self).get_parser(parser)
parser.add_argument('--validation-dir', dest='validation_dir',
default=constants.ANSIBLE_VALIDATION_DIR,
help=("Path where the validation playbooks "
"are located."))
parser.add_argument('--group', '-g',
metavar='<group_name>',
dest="group",
help=("Show a specific group."))
return parser
def take_action(self, parsed_args):
"""Take validation action"""
# Get parameters:
validation_dir = parsed_args.validation_dir
group = parsed_args.group
v_actions = ValidationActions(validation_path=validation_dir)
return v_actions.group_information(group)
class ShowParameter(ShowOne):
"""Display Validations Parameters"""

View File

@ -65,7 +65,7 @@ class TestList(BaseCommand):
self.assertEqual(result, [])
@mock.patch('validations_libs.utils.parse_all_validations_on_disk',
return_value=fakes.VALIDATIONS_LIST_GROUP)
return_value=fakes.VALIDATIONS_LIST)
def test_list_validations_group(self, mock_list):
arglist = ['--validation-dir', 'foo', '--group', 'prep']
verifylist = [('validation_dir', 'foo'),
@ -76,3 +76,43 @@ class TestList(BaseCommand):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.assertEqual(result, list)
class TestListGroup(BaseCommand):
def setUp(self):
super(TestListGroup, self).setUp()
self.cmd = lister.GroupsList(self.app, None)
@mock.patch('validations_libs.utils.glob.glob', return_value=['foo_valiation.yaml'])
@mock.patch('validations_libs.cli.lister.ValidationActions', autospec=True)
@mock.patch(
'validations_libs.validation.yaml.safe_load',
side_effect=[
fakes.GROUP,
fakes.VALIDATIONS_LIST_GROUP,
fakes.VALIDATIONS_LIST_GROUP,
fakes.VALIDATIONS_LIST_GROUP])
@mock.patch('six.moves.builtins.open', autospec=True)
def test_show_validations_group_info(self, mock_open,
mock_yaml,
mock_actions,
mock_glob):
arglist = ['--groups-file', 'group.yaml']
verifylist = [('groups_file', 'group.yaml')]
mock_info = mock.MagicMock()
mock_info.group_information = mock.MagicMock(return_value='foo')
mock_actions.return_value = mock_info
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
group_info = self.cmd.take_action(parsed_args)
mock_actions.assert_called_once_with(
validation_path=fakes.FAKE_VALIDATIONS_PATH)
mock_info.group_information.assert_called_once_with('group.yaml')
self.assertEqual('foo', group_info)

View File

@ -38,35 +38,6 @@ class TestShow(BaseCommand):
self.cmd.take_action(parsed_args)
class TestShowGroup(BaseCommand):
def setUp(self):
super(TestShowGroup, self).setUp()
self.cmd = show.ShowGroup(self.app, None)
@mock.patch('validations_libs.cli.show.ValidationActions', autospec=True)
@mock.patch('yaml.safe_load', return_value=fakes.GROUP)
@mock.patch('six.moves.builtins.open')
def test_show_validations_group_info(self, mock_open, mock_yaml, mock_actions):
arglist = ['--group', 'group.yaml']
verifylist = [('group', 'group.yaml')]
mock_info = mock.MagicMock()
mock_info.group_information = mock.MagicMock(return_value='foo')
mock_actions.return_value = mock_info
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
group_info = self.cmd.take_action(parsed_args)
mock_actions.assert_called_once_with(
validation_path=fakes.FAKE_VALIDATIONS_PATH)
mock_info.group_information.assert_called_once_with('group.yaml')
self.assertEqual('foo', group_info)
class TestShowParameter(BaseCommand):
def setUp(self):

View File

@ -30,17 +30,28 @@ VALIDATIONS_LIST = [{
}]
VALIDATIONS_LIST_GROUP = [{
'description': 'My Validation Two Description',
'groups': ['prep', 'pre-introspection'],
'id': 'my_val2',
'name': 'My Validation Two Name',
'parameters': {'min_value': 8}
}]
'vars': {
'metadata': {
'description': 'My Validation Two Description',
'groups': ['prep', 'pre-introspection'],
'id': 'my_val2',
'name': 'My Validation Two Name',
'parameters': {'min_value': 8}
}}}]
VALIDATION_LIST_RESULT = (('ID', 'Name', 'Groups'),
[('my_val2', 'My Validation Two Name',
['prep', 'pre-introspection'])])
VALIDATION_LIST_RESULT = (
('ID', 'Name', 'Groups'),
[
(
'my_val1',
'My Validation One Name',
['prep', 'pre-deployment']
),
(
'my_val2',
'My Validation Two Name',
['prep', 'pre-introspection'])])
GROUPS_LIST = [
('group1', 'Group1 description'),

View File

@ -410,7 +410,7 @@ class ValidationActions(object):
vlog = ValidationLogs(log_path)
return vlog.get_results(uuid)
def group_information(self, groups):
def group_information(self, groups=constants.VALIDATION_GROUPS_INFO):
"""Get Information about Validation Groups
This is used to print table from python ``Tuple`` with ``PrettyTable``.
@ -444,16 +444,16 @@ class ValidationActions(object):
('group3', 'Description of group3', 1)])
"""
val_gp = Group(groups)
group = val_gp.get_formated_group
groups = val_gp.get_formated_group
group_info = []
groups_info = []
# Get validations number by groups
for gp in group:
for group in groups:
validations = v_utils.parse_all_validations_on_disk(
self.validation_path, gp[0])
group_info.append((gp[0], gp[1], len(validations)))
column_name = ("Groups", "Description", "Number of Validations")
return (column_name, group_info)
self.validation_path, group[0])
groups_info.append((group[0], group[1], len(validations)))
column_names = ("Groups", "Description", "Number of Validations")
return (column_names, groups_info)
def show_validations_parameters(self, validation=None, group=None,
output_format='json', download_file=None):