From 8cccb7775b71a777099846e2a3a5abb95b57998f Mon Sep 17 00:00:00 2001 From: shylesh Date: Thu, 16 May 2024 16:04:17 +0530 Subject: [PATCH] Download subctl downstream if not present (#9657) * Download subctl downstream if not present * Address review comments * Address review comments: Update subctl version for rhel9 * Fix subctl download issue * fix /bin/subctl path issues --------- Signed-off-by: Shylesh Kumar Mohan --- conf/ocsci/submariner_downstream.yaml | 1 + ocs_ci/deployment/acm.py | 46 +++++++++++++++++++ ocs_ci/ocs/constants.py | 1 + .../disaster-recovery/regional-dr/conftest.py | 18 ++++++++ 4 files changed, 66 insertions(+) diff --git a/conf/ocsci/submariner_downstream.yaml b/conf/ocsci/submariner_downstream.yaml index 0f3bf371188..9021d0e0233 100644 --- a/conf/ocsci/submariner_downstream.yaml +++ b/conf/ocsci/submariner_downstream.yaml @@ -1,2 +1,3 @@ ENV_DATA: submariner_source: "downstream" + subctl_version: "subctl-rhel9:v0.17" diff --git a/ocs_ci/deployment/acm.py b/ocs_ci/deployment/acm.py index ca6936b7787..852f71f9926 100644 --- a/ocs_ci/deployment/acm.py +++ b/ocs_ci/deployment/acm.py @@ -7,14 +7,17 @@ import tempfile import shutil import requests +import time import semantic_version +import platform from ocs_ci.framework import config from ocs_ci.ocs import constants from ocs_ci.ocs.exceptions import ( CommandFailed, DRPrimaryNotFoundException, + UnsupportedPlatformError, ) from ocs_ci.utility import templating from ocs_ci.ocs.utils import get_non_acm_cluster_config @@ -157,6 +160,49 @@ def download_binary(self): os.path.expanduser("~/.local/bin/subctl"), os.path.join(config.RUN["bin_dir"], "subctl"), ) + elif self.source == "downstream": + self.download_downstream_binary() + + def download_downstream_binary(self): + """ + Download downstream subctl binary + + Raises: + UnsupportedPlatformError : If current platform has no supported subctl binary + """ + + subctl_ver = config.ENV_DATA["subctl_version"] + version_str = subctl_ver.split(":")[1] + pull_secret_path = os.path.join(constants.DATA_DIR, "pull-secret") + processor = platform.processor() + arch = platform.machine() + if arch == "x86_64" and processor == "x86_64": + binary_pltfrm = "amd64" + elif arch == "arm64" and processor == "arm": + binary_pltfrm = "arm64" + else: + raise UnsupportedPlatformError( + "Not a supported architecture for subctl binary" + ) + cmd = ( + f"oc image extract --filter-by-os linux/{binary_pltfrm} --registry-config " + f"{pull_secret_path} {constants.SUBCTL_DOWNSTREAM_URL}{subctl_ver} " + f'--path="/dist/subctl-{version_str}*-linux-{binary_pltfrm}.tar.xz":/tmp --confirm' + ) + run_cmd(cmd) + # Wait till image extract happens and subctl dir appears + time.sleep(30) + decompress = ( + f"tar -C /tmp/ -xf /tmp/subctl-{version_str}*-linux-{binary_pltfrm}.tar.xz" + ) + run_cmd(decompress) + target_dir = os.path.expanduser("./bin") + install_cmd = ( + f"install -m744 /tmp/subctl-{version_str}*/subctl-{version_str}*-linux-{binary_pltfrm} " + f"{target_dir} " + ) + run_cmd(install_cmd, shell=True) + run_cmd(f"mv {target_dir}/subctl-* {target_dir}/subctl", shell=True) def submariner_configure_upstream(self): """ diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index db92cb36e06..8f4220fe604 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -2257,6 +2257,7 @@ "&rows_per_page=25&delta=1296000&contains=submariner-operator-bundle-container-v" ) SUBMARINER_BREW_REPO = "brew.registry.redhat.io/rh-osbs/iib" +SUBCTL_DOWNSTREAM_URL = "registry.redhat.io/rhacm2/" # Multicluster related diff --git a/tests/functional/disaster-recovery/regional-dr/conftest.py b/tests/functional/disaster-recovery/regional-dr/conftest.py index cf88477c31c..d35c1019db7 100644 --- a/tests/functional/disaster-recovery/regional-dr/conftest.py +++ b/tests/functional/disaster-recovery/regional-dr/conftest.py @@ -1,6 +1,11 @@ import logging +import pytest + from ocs_ci.framework import config from ocs_ci.ocs import constants +from ocs_ci.deployment import acm +from ocs_ci.utility.utils import run_cmd +from ocs_ci.ocs.exceptions import CommandFailed log = logging.getLogger(__name__) @@ -20,3 +25,16 @@ def pytest_collection_modifyitems(items): f"Test {item} is removed from the collected items. Test runs only on RDR clusters" ) items.remove(item) + + +@pytest.fixture(autouse=True) +def check_subctl_cli(): + # Check whether subctl cli is present + if config.MULTICLUSER.get("multicluster_mode") != constants.RDR_MODE: + return + try: + run_cmd("./bin/subctl") + except (CommandFailed, FileNotFoundError): + log.debug("subctl binary not found, downloading now...") + submariner = acm.Submariner() + submariner.download_binary()