From 3965beff1be71ee9ce268813dd7d7f4c03ea841e Mon Sep 17 00:00:00 2001 From: Shylesh Kumar Mohan Date: Fri, 27 Oct 2023 13:05:43 +0100 Subject: [PATCH] Add functions to choose the right parameter tuples based on roles Signed-off-by: Shylesh Kumar Mohan --- ocs_ci/ocs/constants.py | 2 +- ocs_ci/ocs/utils.py | 14 +++++++ ocs_ci/utility/multicluster.py | 55 +++++++++++++++++++------ tests/conftest.py | 9 +++- tests/ecosystem/upgrade/test_upgrade.py | 2 +- 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 67e14e425fd5..45c41e30b1c0 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -2320,4 +2320,4 @@ HTML_REPORT_TEMPLATE_DIR = "ocs_ci/templates/html_reports/" # MDR multicluster roles -MDR_ROLES = ["ActiveACM", "PassiveACM", "Primary_odf", "Secondary_odf"] +MDR_ROLES = ["ActiveACM", "PassiveACM", "PrimaryODF", "SecondaryODF"] diff --git a/ocs_ci/ocs/utils.py b/ocs_ci/ocs/utils.py index d84e557ff124..ea97b717a38a 100644 --- a/ocs_ci/ocs/utils.py +++ b/ocs_ci/ocs/utils.py @@ -1524,6 +1524,20 @@ def get_non_acm_cluster_config(): return non_acm_list +def get_non_acm_cluster_indexes(): + """ + Get config index of all non-acm clusters + + Returns: + list: of integer indexes of non-acm clusters + + """ + non_acm_indexes = list() + for cluster in get_non_acm_cluster_config(): + non_acm_indexes.append(cluster.MULTICLUSTER["multicluster_index"]) + return non_acm_indexes + + def get_all_acm_indexes(): """ Get indexes fro all ACM clusters diff --git a/ocs_ci/utility/multicluster.py b/ocs_ci/utility/multicluster.py index e2da836dbb69..e08abff25886 100644 --- a/ocs_ci/utility/multicluster.py +++ b/ocs_ci/utility/multicluster.py @@ -5,6 +5,7 @@ from ocs_ci.framework import config as ocsci_config from ocs_ci.ocs.utils import ( + get_non_acm_cluster_indexes, get_primary_cluster_index, get_active_acm_index, get_all_acm_indexes, @@ -12,7 +13,7 @@ from ocs_ci.ocs.constants import MDR_ROLES -class MutliClusterUpgradeParametrize(object): +class MultiClusterUpgradeParametrize(object): """ This base class abstracts upgrade parametrization for multicluster scenarios: MDR, RDR and Managed service @@ -87,7 +88,7 @@ def get_zone_info(self): return list(zones) -class MDRClusterUpgradeParametrize(MutliClusterUpgradeParametrize): +class MDRClusterUpgradeParametrize(MultiClusterUpgradeParametrize): """ This child class handles MDR upgrade scenario specific pytest parametrization @@ -103,6 +104,10 @@ def __init__(self): self.generate_zone_ranks() self.generate_role_ranks() self.generate_config_index_map() + # Reverse mapping of cluster's index to its role + self.index_to_role = { + index: role for role, index in self.roles_to_config_index_map.items() + } self.generate_role_to_param_tuple_map() self.generate_zone_role_map() @@ -117,25 +122,25 @@ def generate_config_index_map(self): if cluster_index == get_active_acm_index(): self.roles_to_config_index_map["ActiveACM"] = cluster_index elif cluster_index == get_primary_cluster_index(): - self.roles_to_config_index_map["Primary_odf"] = cluster_index + self.roles_to_config_index_map["PrimaryODF"] = cluster_index elif cluster_index in get_all_acm_indexes(): # We would have already ruled out the ActiveACM in the first 'if' self.roles_to_config_index_map["PassiveACM"] = cluster_index else: # Only option left is secondary odf - self.roles_to_config_index_map["Secondary_odf"] = cluster_index + self.roles_to_config_index_map["SecondaryODF"] = cluster_index def generate_role_ranks(self): """ - Based on current roles for MDR : ActiveACM:1, PassiceACM:1, Primary:2, Secondary: 2 + Based on current roles for MDR : ActiveACM:1, PassiceACM:1, PrimaryODF:2, SecondaryODF: 2 """ # For now we will stick to this convention self.role_ranks = { "ActiveACM": 1, "PassiveACM": 1, - "Primary_odf": 2, - "Secondary_odf": 2, + "PrimaryODF": 2, + "SecondaryODF": 2, } def generate_zone_role_map(self): @@ -170,13 +175,37 @@ def get_pytest_params_tuple(self, role): Parmeter tuples looks like (zone_rank, role_rank, config_index) for a given role """ - param_list = list() - if role == "all": - for t in self.roles_to_param_tuples.values(): - param_list.append(t) - param_list + param_list = None + if role.startswith("mdr-all"): + param_list = self.get_mdr_all_param_tuples(role) else: - param_list.append(self.roles_to_param_tuples[role]) + param_list = [self.roles_to_param_tuples[role]] + return param_list + + def get_mdr_all_param_tuples(self, role): + if "mdr-all-ocp" in role: + return self.get_all_roles_to_param_tuples() + elif "mdr-all-odf" in role: + return self.get_all_odf_roles_to_param_tuple() + elif "mdr-all-acm" in role: + return self.get_all_acm_roles_to_param_tuple() + + def get_all_acm_roles_to_param_tuple(self): + params_list = list() + for i in get_all_acm_indexes(): + params_list.append(self.roles_to_param_tuples[self.index_to_role[i]]) + return params_list + + def get_all_odf_roles_to_param_tuple(self): + params_list = list() + for i in get_non_acm_cluster_indexes(): + params_list.append(self.roles_to_param_tuples[self.index_to_role[i]]) + return params_list + + def get_all_roles_to_param_tuples(self): + param_list = list() + for t in self.roles_to_param_tuples.values(): + param_list.append(t) return param_list def get_roles(self, metafunc): diff --git a/tests/conftest.py b/tests/conftest.py index 33fce69828ac..dc614e473c1e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -121,7 +121,7 @@ from ocs_ci.utility.retry import retry from ocs_ci.utility.multicluster import ( get_multicluster_upgrade_parametrizer, - MutliClusterUpgradeParametrize, + MultiClusterUpgradeParametrize, ) from ocs_ci.utility.uninstall_openshift_logging import uninstall_cluster_logging from ocs_ci.utility.utils import ( @@ -416,7 +416,7 @@ def pytest_collection_modifyitems(session, config, items): if ( list( set([i.name for i in item.iter_markers()]).intersection( - (MutliClusterUpgradeParametrize.MULTICLUSTER_UPGRADE_MARKERS) + (MultiClusterUpgradeParametrize.MULTICLUSTER_UPGRADE_MARKERS) ) ) and ocsci_config.multicluster_scenario @@ -431,6 +431,11 @@ def pytest_collection_modifyitems(session, config, items): # fetch already marked 'order' value if m.name == "run": val = m.kwargs.get("order") + # Sum of the base order value along with + # zone in which the cluster is and the cluster's role rank + # determines the order in which tests need to be executed + # Lower the sum, higher the rank hence it gets prioritized early + # in the test execution sequence newval = val + zone_rank + role_rank markers_update.append((pytest.mark.order, newval)) break diff --git a/tests/ecosystem/upgrade/test_upgrade.py b/tests/ecosystem/upgrade/test_upgrade.py index 0365614e3fd0..da15d594b81a 100644 --- a/tests/ecosystem/upgrade/test_upgrade.py +++ b/tests/ecosystem/upgrade/test_upgrade.py @@ -64,7 +64,7 @@ def test_osd_reboot(teardown): @purple_squad @ocs_upgrade @polarion_id(get_polarion_id(upgrade=True)) -@multicluster_roles(["mdr_all_ocs"]) +@multicluster_roles(["mdr_all_odf"]) def test_upgrade(): """ Tests upgrade procedure of OCS cluster