Fix a regression in the ShowGroup sub-command
The ShowGroup sub-command was not working anymore due
to a regression introduced by the new CLI next generation
commit[1].
This patch fixes the ShowGroup sub-command by addressing the
following points:
* The ValidationActions.group_information method should take
the absolute path of the groups.yaml file by default.
* Using cliff.lister.Lister base class instead of
cliff.show.ShowOne base class for the ShowGroup class.
Resolves: rhbz#1972155
[1] - 5fad1a4d18
Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Ia5aa3e96e8b5a6634a709ce8677f90108c80dfd3
This commit is contained in:
parent
d6ecf241d1
commit
e265028e40
|
@ -26,12 +26,9 @@ try:
|
|||
except ImportError:
|
||||
JUNIT_XML_FOUND = False
|
||||
|
||||
from validations_libs import constants
|
||||
from validations_libs import utils as v_utils
|
||||
from validations_libs.cli import colors
|
||||
|
||||
GROUP_FILE = constants.VALIDATION_GROUPS_INFO
|
||||
|
||||
|
||||
def print_dict(data):
|
||||
"""Print table from python dict with PrettyTable"""
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# under the License.
|
||||
|
||||
from cliff.show import ShowOne
|
||||
from cliff.lister import Lister
|
||||
|
||||
from validations_libs.validation_actions import ValidationActions
|
||||
from validations_libs import constants
|
||||
|
@ -50,30 +51,26 @@ class Show(ShowOne):
|
|||
return data.keys(), data.values()
|
||||
|
||||
|
||||
class ShowGroup(ShowOne):
|
||||
class ShowGroup(Lister):
|
||||
"""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."))
|
||||
|
||||
parser.add_argument('--group_file', '-g',
|
||||
metavar='<group_name>',
|
||||
dest="group",
|
||||
default=constants.VALIDATION_GROUPS_INFO,
|
||||
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)
|
||||
v_actions = ValidationActions(constants.ANSIBLE_VALIDATION_DIR)
|
||||
return v_actions.group_information(parsed_args.groups)
|
||||
|
||||
|
||||
class ShowParameter(ShowOne):
|
||||
|
|
|
@ -48,21 +48,20 @@ class TestShowGroup(BaseCommand):
|
|||
@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')]
|
||||
arglist = []
|
||||
|
||||
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)
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
|
||||
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')
|
||||
mock_info.group_information.assert_called_once()
|
||||
|
||||
self.assertEqual('foo', group_info)
|
||||
|
||||
|
|
Loading…
Reference in New Issue