From 2e6778142620dc048e3994a664255f0b73f2d1c1 Mon Sep 17 00:00:00 2001 From: oviner Date: Wed, 24 Jul 2024 00:14:35 +0300 Subject: [PATCH] get_dr_operator_versions function Signed-off-by: oviner --- ocs_ci/ocs/resources/ocs.py | 52 ++++------------------------ ocs_ci/ocs/utils.py | 67 +++++++++++++++++++++++++++++++++++-- tests/conftest.py | 59 +++----------------------------- 3 files changed, 76 insertions(+), 102 deletions(-) diff --git a/ocs_ci/ocs/resources/ocs.py b/ocs_ci/ocs/resources/ocs.py index ef60fb26caf..168e5592eac 100644 --- a/ocs_ci/ocs/resources/ocs.py +++ b/ocs_ci/ocs/resources/ocs.py @@ -17,15 +17,7 @@ from ocs_ci.ocs.exceptions import CSVNotFound from ocs_ci.utility import templating, utils from ocs_ci.utility.version import get_semantic_ocs_version_from_config, VERSION_4_9 -from ocs_ci.utility.version import ( - get_dr_hub_operator_version, - get_ocp_dr_cluster_operator_version, - get_odf_multicluster_orchestrator_version, - get_ocp_gitops_operator_version, - get_submariner_operator_version, - get_volsync_operator_version, -) -from ocs_ci.utility.utils import get_oadp_version, get_acm_version + log = logging.getLogger(__name__) @@ -213,43 +205,11 @@ def get_version_info(namespace=None): csv_name = package_manifest.get_current_csv(channel) csv_pre = CSV(resource_name=csv_name, namespace=namespace) info = get_images(csv_pre.get()) - from ocs_ci.ocs.utils import is_dr_scenario - - if is_dr_scenario(): - with config.RunWithAcmConfigContext(): - acm_operator_version = get_acm_version() - if acm_operator_version: - info["acm_version"] = acm_operator_version - ocp_dr_hub_operator_version = get_dr_hub_operator_version() - if ocp_dr_hub_operator_version: - info["dr_hub_version"] = ocp_dr_hub_operator_version - odf_multicluster_orchestrator_version = ( - get_odf_multicluster_orchestrator_version() - ) - if odf_multicluster_orchestrator_version: - info[ - "odf_multicluster_orchestrator_version" - ] = odf_multicluster_orchestrator_version - gitops_operator_version = get_ocp_gitops_operator_version() - if gitops_operator_version: - info["gitops_version"] = gitops_operator_version - with config.RunWithPrimaryConfigContext(): - oadp_operator_version = get_oadp_version() - if oadp_operator_version: - info["oadp_version"] = oadp_operator_version - ocp_dr_cluster_operator_version = get_ocp_dr_cluster_operator_version() - if ocp_dr_cluster_operator_version: - info["ocp_dr_cluster_version"] = ocp_dr_cluster_operator_version - gitops_operator_version = get_ocp_gitops_operator_version() - if gitops_operator_version: - info["gitops_version"] = gitops_operator_version - volsync_operator_version = get_volsync_operator_version() - if volsync_operator_version: - info["volsync_version"] = volsync_operator_version - submariner_operator_version = get_submariner_operator_version() - if submariner_operator_version: - info["submariner_version"] = submariner_operator_version - return info + from ocs_ci.ocs.utils import get_dr_operator_versions + + dr_operator_versions = get_dr_operator_versions() + versions = {**info, **dr_operator_versions} + return versions def get_ocs_csv(): diff --git a/ocs_ci/ocs/utils.py b/ocs_ci/ocs/utils.py index 8ae455ae545..c8ff18022ed 100644 --- a/ocs_ci/ocs/utils.py +++ b/ocs_ci/ocs/utils.py @@ -31,7 +31,21 @@ from ocs_ci.utility import templating, version from ocs_ci.utility.prometheus import PrometheusAPI from ocs_ci.utility.retry import retry -from ocs_ci.utility.utils import create_directory_path, mirror_image, run_cmd +from ocs_ci.utility.utils import ( + create_directory_path, + mirror_image, + run_cmd, + get_oadp_version, + get_acm_version, +) +from ocs_ci.utility.version import ( + get_dr_hub_operator_version, + get_ocp_dr_cluster_operator_version, + get_odf_multicluster_orchestrator_version, + get_ocp_gitops_operator_version, + get_submariner_operator_version, + get_volsync_operator_version, +) log = logging.getLogger(__name__) @@ -1691,4 +1705,53 @@ def is_dr_scenario(): bool: return True if it is rdr or mdr setup otherwise False """ - return ocsci_config.MULTICLUSTER["multicluster_mode"] in ("metro-dr", "regional-dr") + return ocsci_config.MULTICLUSTER.get("multicluster_mode") in ( + "metro-dr", + "regional-dr", + ) + + +def get_dr_operator_versions(): + """ + Get all DR operator versions on hub and primary clusters + + Returns: + dict: return operator name as key and version as value + + """ + versions_dic = dict() + if is_dr_scenario(): + with ocsci_config.RunWithAcmConfigContext(): + acm_operator_version = get_acm_version() + if acm_operator_version: + versions_dic["acm_version"] = acm_operator_version + ocp_dr_hub_operator_version = get_dr_hub_operator_version() + if ocp_dr_hub_operator_version: + versions_dic["dr_hub_version"] = ocp_dr_hub_operator_version + odf_multicluster_orchestrator_version = ( + get_odf_multicluster_orchestrator_version() + ) + if odf_multicluster_orchestrator_version: + versions_dic[ + "odf_multicluster_orchestrator_version" + ] = odf_multicluster_orchestrator_version + gitops_operator_version = get_ocp_gitops_operator_version() + if gitops_operator_version: + versions_dic["gitops_version"] = gitops_operator_version + with ocsci_config.RunWithPrimaryConfigContext(): + oadp_operator_version = get_oadp_version() + if oadp_operator_version: + versions_dic["oadp_version"] = oadp_operator_version + ocp_dr_cluster_operator_version = get_ocp_dr_cluster_operator_version() + if ocp_dr_cluster_operator_version: + versions_dic["ocp_dr_cluster_version"] = ocp_dr_cluster_operator_version + gitops_operator_version = get_ocp_gitops_operator_version() + if gitops_operator_version: + versions_dic["gitops_version"] = gitops_operator_version + volsync_operator_version = get_volsync_operator_version() + if volsync_operator_version: + versions_dic["volsync_version"] = volsync_operator_version + submariner_operator_version = get_submariner_operator_version() + if submariner_operator_version: + versions_dic["submariner_version"] = submariner_operator_version + return versions_dic diff --git a/tests/conftest.py b/tests/conftest.py index 6540b5ffca6..fc60f2ecd2d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -65,7 +65,7 @@ setup_ceph_toolbox, collect_ocs_logs, collect_pod_container_rpm_package, - is_dr_scenario, + get_dr_operator_versions, ) from ocs_ci.ocs.resources.deployment import Deployment from ocs_ci.ocs.resources.job import get_job_obj @@ -147,8 +147,6 @@ skipif_ui_not_support, run_cmd, ceph_health_check_multi_storagecluster_external, - get_oadp_version, - get_acm_version, ) from ocs_ci.helpers import helpers, dr_helpers from ocs_ci.helpers.helpers import ( @@ -174,14 +172,7 @@ ) from ocs_ci.ocs.longevity import start_app_workload from ocs_ci.utility.decorators import switch_to_default_cluster_index_at_last -from ocs_ci.utility.version import ( - get_dr_hub_operator_version, - get_ocp_dr_cluster_operator_version, - get_odf_multicluster_orchestrator_version, - get_ocp_gitops_operator_version, - get_submariner_operator_version, - get_volsync_operator_version, -) + log = logging.getLogger(__name__) @@ -1603,49 +1594,9 @@ def additional_testsuite_properties(record_testsuite_property, pytestconfig): # add markers as separated property markers = ocsci_config.RUN["cli_params"].get("-m", "").replace(" ", "-") record_testsuite_property("rp_markers", markers) - if is_dr_scenario(): - with ocsci_config.RunWithAcmConfigContext(): - acm_operator_version = get_acm_version() - if acm_operator_version: - record_testsuite_property("rp_acm_version", acm_operator_version) - ocp_dr_hub_operator_version = get_dr_hub_operator_version() - if ocp_dr_hub_operator_version: - record_testsuite_property( - "rp_dr_hub_version", ocp_dr_hub_operator_version - ) - odf_multicluster_orchestrator_version = ( - get_odf_multicluster_orchestrator_version() - ) - if odf_multicluster_orchestrator_version: - record_testsuite_property( - "rp_odf_multicluster_orchestrator_version", - odf_multicluster_orchestrator_version, - ) - gitops_operator_version = get_ocp_gitops_operator_version() - if gitops_operator_version: - record_testsuite_property("rp_gitops_version", gitops_operator_version) - with ocsci_config.RunWithPrimaryConfigContext(): - oadp_operator_version = get_oadp_version() - if oadp_operator_version: - record_testsuite_property("rp_oadp_version", oadp_operator_version) - ocp_dr_cluster_operator_version = get_ocp_dr_cluster_operator_version() - if ocp_dr_cluster_operator_version: - record_testsuite_property( - "rp_ocp_dr_cluster_version", ocp_dr_cluster_operator_version - ) - gitops_operator_version = get_ocp_gitops_operator_version() - if gitops_operator_version: - record_testsuite_property("rp_gitops_version", gitops_operator_version) - volsync_operator_version = get_volsync_operator_version() - if volsync_operator_version: - record_testsuite_property( - "rp_volsync_version", volsync_operator_version - ) - submariner_operator_version = get_submariner_operator_version() - if submariner_operator_version: - record_testsuite_property( - "rp_submariner_version", submariner_operator_version - ) + dr_operator_versions = get_dr_operator_versions() + for dr_operator_name, dr_operator_version in dr_operator_versions.items(): + record_testsuite_property(f"rp_{dr_operator_name}", dr_operator_version) @pytest.fixture(scope="session")