Skip to content

Commit

Permalink
Add functions to choose the right parameter tuples based on roles
Browse files Browse the repository at this point in the history
Signed-off-by: Shylesh Kumar Mohan <[email protected]>
  • Loading branch information
shylesh committed Nov 7, 2023
1 parent e7d43e1 commit 7c8eb3d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2343,4 +2343,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"]
14 changes: 14 additions & 0 deletions ocs_ci/ocs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 42 additions & 13 deletions ocs_ci/utility/multicluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

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,
)
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
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ecosystem/upgrade/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c8eb3d

Please sign in to comment.