Skip to content

Commit

Permalink
Download subctl downstream if not present (red-hat-storage#9657)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
shylesh authored and amr1ta committed May 27, 2024
1 parent b11548d commit 30ee9e3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/ocsci/submariner_downstream.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ENV_DATA:
submariner_source: "downstream"
subctl_version: "subctl-rhel9:v0.17"
46 changes: 46 additions & 0 deletions ocs_ci/deployment/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,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

Expand Down
18 changes: 18 additions & 0 deletions tests/functional/disaster-recovery/regional-dr/conftest.py
Original file line number Diff line number Diff line change
@@ -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__)

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

0 comments on commit 30ee9e3

Please sign in to comment.