From afb9887a408dc7ce4b178f730ea17f7c77f120b9 Mon Sep 17 00:00:00 2001 From: "Gael Chamoulaud (Strider)" Date: Thu, 23 Jan 2020 10:56:35 +0100 Subject: [PATCH] Get validation groups info from groups.yaml file This patch makes the VALIDATION_GROUPS list constants dynamic by getting them from the 'groups.yaml' file. This file comes from tripleo-validations and is present on the Undercloud at the location [1]. [1] => /usr/share/openstack-tripleo-validations Change-Id: Ide8cba32a0ea14086714094291f1a8866b669491 Signed-off-by: Gael Chamoulaud (Strider) --- tripleoclient/constants.py | 10 ------- .../v1/tripleo/test_tripleo_validator.py | 2 +- tripleoclient/utils.py | 29 +++++++++++++++---- tripleoclient/v1/tripleo_validator.py | 11 +++---- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/tripleoclient/constants.py b/tripleoclient/constants.py index cedeece1c..9657b29bd 100644 --- a/tripleoclient/constants.py +++ b/tripleoclient/constants.py @@ -94,16 +94,6 @@ ANSIBLE_TRIPLEO_PLAYBOOKS = \ VALIDATION_GROUPS_INFO = '%s/groups.yaml' % DEFAULT_VALIDATIONS_BASEDIR -VALIDATION_GROUPS = ['no-op', - 'openshift-on-openstack', - 'prep', - 'pre-introspection', - 'pre-deployment', - 'post-deployment', - 'pre-upgrade', - 'post-upgrade'] - - # ctlplane network defaults CTLPLANE_CIDR_DEFAULT = '192.168.24.0/24' CTLPLANE_DHCP_START_DEFAULT = ['192.168.24.5'] diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py b/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py index f9ccd55d0..bd8103dfa 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_validator.py @@ -151,7 +151,7 @@ class TestValidatorGroupInfo(utils.TestCommand): # Get the command object to test self.cmd = tripleo_validator.TripleOValidatorGroupInfo(self.app, None) - @mock.patch('tripleoclient.utils.parse_all_validation_groups_on_disk', + @mock.patch('tripleoclient.utils.prepare_validation_groups_for_display', return_value=GROUPS_LIST) def test_show_group_info(self, mock_validations): arglist = [] diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 72a2043ec..870ca7e22 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -2140,19 +2140,38 @@ def get_validation_parameters(validation): return dict() -def parse_all_validation_groups_on_disk(groups_file_path=None): - results = [] - +def read_validation_groups_file(groups_file_path=None): + """Load groups.yaml file and return a dictionary with its contents""" if not groups_file_path: groups_file_path = constants.VALIDATION_GROUPS_INFO if not os.path.exists(groups_file_path): - return results + return [] with open(groups_file_path, 'r') as grps: contents = yaml.safe_load(grps) - for grp_name, grp_desc in sorted(contents.items()): + return contents + + +def get_validation_group_name_list(): + """Get the validation group name list only""" + results = [] + + groups = read_validation_groups_file() + + if groups and isinstance(dict, groups): + for grp_name in six.viewkeys(groups): + results.append(grp_name) + + return results + + +def prepare_validation_groups_for_display(): + results = [] + groups = read_validation_groups_file() + + for grp_name, grp_desc in sorted(groups.items()): results.append((grp_name, grp_desc[0].get('description'))) return results diff --git a/tripleoclient/v1/tripleo_validator.py b/tripleoclient/v1/tripleo_validator.py index 970d8d71f..0823b9dc4 100644 --- a/tripleoclient/v1/tripleo_validator.py +++ b/tripleoclient/v1/tripleo_validator.py @@ -39,10 +39,12 @@ RESET = "\033[0;0m" FAILED_VALIDATION = "{}FAILED{}".format(RED, RESET) PASSED_VALIDATION = "{}PASSED{}".format(GREEN, RESET) +GROUP_FILE = constants.VALIDATION_GROUPS_INFO + class _CommaListGroupAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): - opts = constants.VALIDATION_GROUPS + opts = oooutils.get_validation_group_name_list() for value in values.split(','): if value not in opts: message = ("Invalid choice: {value} (choose from {choice})" @@ -65,12 +67,11 @@ class TripleOValidatorGroupInfo(command.Lister): return parser def take_action(self, parsed_args): - group_file = constants.VALIDATION_GROUPS_INFO - group = oooutils.parse_all_validation_groups_on_disk(group_file) + group = oooutils.prepare_validation_groups_for_display() if not group: raise exceptions.CommandError( - "Could not find groups information file %s" % group_file) + "Could not find groups information file %s" % GROUP_FILE) group_info = [] for gp in group: @@ -444,7 +445,7 @@ class TripleOValidatorRun(command.Command): else: for pb in parsed_args.validation_name: - if pb not in constants.VALIDATION_GROUPS: + if pb not in oooutils.get_validation_group_name_list(): playbooks.append(pb + '.yaml') else: raise exceptions.CommandError(