From 2f2f5a6d3a9648c73829efa559da7d859aadd421 Mon Sep 17 00:00:00 2001 From: Daniel Osypenko Date: Wed, 10 Apr 2024 16:08:33 +0300 Subject: [PATCH] hypershift upstream Fix 0.1 Signed-off-by: Daniel Osypenko --- ocs_ci/deployment/cnv.py | 24 +++++++++++- ocs_ci/deployment/helpers/hypershift_base.py | 19 ---------- ocs_ci/deployment/hosted_cluster.py | 40 +++++++++++--------- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/ocs_ci/deployment/cnv.py b/ocs_ci/deployment/cnv.py index 34ce6aa685da..23470e31e36f 100644 --- a/ocs_ci/deployment/cnv.py +++ b/ocs_ci/deployment/cnv.py @@ -23,7 +23,10 @@ ) from ocs_ci.utility import templating from ocs_ci.ocs import constants -from ocs_ci.utility.utils import run_cmd +from ocs_ci.utility.utils import ( + run_cmd, + exec_cmd, +) from ocs_ci.ocs import exceptions from ocs_ci.ocs.resources.catalog_source import CatalogSource from ocs_ci.ocs.resources.install_plan import wait_for_install_plan_and_approve @@ -612,3 +615,22 @@ def deploy_cnv(self, check_cnv_deployed=False, check_cnv_ready=False): self.enable_software_emulation() # Download and extract the virtctl binary to bin_dir self.download_and_extract_virtctl_binary() + + def disable_multicluster_engine(self): + """ + Disable multicluster engine on cluster + """ + logger.info("Disabling multicluster engine") + cmd = ( + "oc patch mce multiclusterengine " + '-p \'{"spec":{"overrides":{"components":[' + '{"enabled":false, "name":"hypershift"},' + '{"enabled":false, "name":"hypershift-local-hosting"}, ' + '{"enabled":false, "name":"local-cluster"}' + "]}}}' --type=merge" + ) + cmd_res = exec_cmd(cmd, shell=True) + if cmd_res.returncode != 0: + logger.error(f"Failed to disable multicluster engine\n{cmd_res.stderr}") + return + logger.info(cmd_res.stdout.decode("utf-8").splitlines()) diff --git a/ocs_ci/deployment/helpers/hypershift_base.py b/ocs_ci/deployment/helpers/hypershift_base.py index 499454b56f08..ce2cab789974 100644 --- a/ocs_ci/deployment/helpers/hypershift_base.py +++ b/ocs_ci/deployment/helpers/hypershift_base.py @@ -593,25 +593,6 @@ def get_mce_version(self): logger.info(f"Multicluster engine version: {cmd_res.stdout.decode('utf-8')}") return cmd_res.stdout.decode("utf-8") - def disable_multicluster_engine(self): - """ - Disable multicluster engine on cluster - """ - logger.info("Disabling multicluster engine") - cmd = ( - "oc patch mce multiclusterengine " - '-p \'{"spec":{"overrides":{"components":[' - '{"enabled":false, "name":"hypershift"},' - '{"enabled":false, "name":"hypershift-local-hosting"}, ' - '{"enabled":false, "name":"local-cluster"}' - "]}}}' --type=merge" - ) - cmd_res = exec_cmd(cmd, shell=True) - if cmd_res.returncode != 0: - logger.error(f"Failed to disable multicluster engine\n{cmd_res.stderr}") - return - logger.info(cmd_res.stdout.decode("utf-8").splitlines()) - def install_hypershift_upstream_on_cluster(self): """ Install hypershift on the cluster diff --git a/ocs_ci/deployment/hosted_cluster.py b/ocs_ci/deployment/hosted_cluster.py index b77372642bd2..5f8a6c16b9e5 100644 --- a/ocs_ci/deployment/hosted_cluster.py +++ b/ocs_ci/deployment/hosted_cluster.py @@ -31,11 +31,15 @@ from ocs_ci.ocs.resources.pod import ( wait_for_pods_to_be_in_statuses_concurrently, ) -from ocs_ci.ocs.version import get_ocp_version from ocs_ci.utility import templating from ocs_ci.utility.managedservice import generate_onboarding_token from ocs_ci.utility.retry import retry -from ocs_ci.utility.utils import exec_cmd, TimeoutSampler, get_latest_release_version +from ocs_ci.utility.utils import ( + exec_cmd, + TimeoutSampler, + get_ocp_version, + get_latest_release_version, +) from ocs_ci.utility.version import get_semantic_version logger = logging.getLogger(__name__) @@ -75,22 +79,6 @@ def do_deploy(self): due to n-1 logic we are assuming that desired CNV version <= OCP version """ - provider_ocp_version = str( - get_semantic_version(get_ocp_version(), only_major_minor=True) - ) - latest_released_ocp_version = str( - get_semantic_version(get_latest_release_version(), only_major_minor=True) - ) - - if provider_ocp_version > latest_released_ocp_version: - try: - self.disable_multicluster_engine() - self.install_hypershift_upstream_on_cluster() - except CommandFailed as e: - raise AssertionError( - f"Failed to install Hypershift on the cluster: {e}" - ) - # stage 1 deploy multiple hosted OCP clusters cluster_names = self.deploy_hosted_ocp_clusters() @@ -357,6 +345,22 @@ def deploy_dependencies( if download_hcp_binary: self.update_hcp_binary() + provider_ocp_version = str( + get_semantic_version(get_ocp_version(), only_major_minor=True) + ) + latest_released_ocp_version = str( + get_semantic_version(get_latest_release_version(), only_major_minor=True) + ) + + if provider_ocp_version > latest_released_ocp_version: + try: + self.disable_multicluster_engine() + self.install_hypershift_upstream_on_cluster() + except CommandFailed as e: + raise AssertionError( + f"Failed to install Hypershift on the cluster: {e}" + ) + class HostedODF(HypershiftHostedOCP): def __init__(self, name: str):