Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download subctl downstream unreleased binary #11063

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 60 additions & 15 deletions ocs_ci/deployment/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import requests
import subprocess
import re

import semantic_version
import platform
Expand Down Expand Up @@ -86,8 +87,11 @@ def __init__(self):
self.dr_only_list = []

def deploy(self):
# Download subctl binary in any case.
self.download_binary()
# Download subctl binary in any case except downstream unreleased.
if not (
self.source == "downstream" and self.submariner_release_type == "unreleased"
):
self.download_binary()
if self.source == "upstream":
self.deploy_upstream()
elif self.source == "downstream":
Expand Down Expand Up @@ -166,16 +170,45 @@ def download_binary(self):
elif self.source == "downstream":
self.download_downstream_binary()

def get_submariner_csv_version(self):
"""
Get submariner version from CSV

"""
csv_version_cmd = (
"oc get submariners.submariner.io -n submariner-operator "
"submariner -o jsonpath='{.status.gateways[0].version}'"
)
return run_cmd(csv_version_cmd)

def get_submariner_unreleased_tag(self, subctl_version):
"""
Get downstream unreleased tag to download

"""
cmd = (
f"curl --retry 3 --retry-delay 5 -Ls "
f'"https://datagrepper.engineering.redhat.com/raw?'
f"topic=/topic/VirtualTopic.eng.ci.redhat-container-image.pipeline.complete&"
f'rows_per_page=25&delta=12960000&contains=subctl-container-{subctl_version}"|'
f'jq -r \'[.raw_messages[].msg | select(.pipeline.status=="complete") | '
f"{{nvr: .artifact.nvr, index_image: .artifact.image_tag}}] | .[0]' | "
f"jq -r '.index_image' |cut -d'/' -f3- |cut -d':' -f2-"
)
return run_cmd(cmd, shell=True)

def download_downstream_binary(self):
"""
Download downstream subctl binary
Download downstream subctl binary - released/unreleased

Raises:
UnsupportedPlatformError : If current platform has no supported subctl binary
"""

subctl_ver = config.ENV_DATA["subctl_version"]
version_str = subctl_ver.split(":")[1]
if self.submariner_release_type == "unreleased":
version_str = self.get_submariner_csv_version()
else:
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()
Expand All @@ -187,15 +220,27 @@ def download_downstream_binary(self):
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'
)
version_str_trimmed = None
if self.submariner_release_type == "unreleased":
xy_version = re.match(r"(v\d+\.\d+)", version_str).group(1)
unreleased_tag = self.get_submariner_unreleased_tag(xy_version)
brew_url = "/".join([constants.SUBMARINER_BREW, "rhacm2-subctl-rhel9:"])
cmd = (
f"oc image extract --filter-by-os linux/{binary_pltfrm} "
f"-a {pull_secret_path} {brew_url}{unreleased_tag} "
f'--path="/dist/subctl-{xy_version}*-linux-{binary_pltfrm}.tar.xz":/tmp --confirm'
)
version_str_trimmed = xy_version
else:
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'
)
version_str_trimmed = version_str

run_cmd(cmd)
decompress = (
f"tar -C /tmp/ -xf /tmp/subctl-{version_str}*-linux-{binary_pltfrm}.tar.xz"
)
decompress = f"tar -C /tmp/ -xf /tmp/subctl-{version_str_trimmed}*-linux-{binary_pltfrm}.tar.xz"
p = subprocess.run(decompress, stdout=subprocess.PIPE, shell=True)
if p.returncode:
logger.error("Failed to untar subctl")
Expand All @@ -204,7 +249,7 @@ def download_downstream_binary(self):
logger.info(p.stdout)
target_dir = config.RUN["bin_dir"]
install_cmd = (
f"install -m744 /tmp/subctl-{version_str}*/subctl-{version_str}*-linux-{binary_pltfrm} "
f"install -m744 /tmp/subctl-{version_str_trimmed}*/subctl-{version_str_trimmed}*-linux-{binary_pltfrm} "
f"{target_dir} "
)
run_cmd(install_cmd, shell=True)
Expand Down
4 changes: 3 additions & 1 deletion ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2721,14 +2721,16 @@
SUBMARINER_DOWNSTREAM_UNRELEASED_BUILD_URL = (
"https://datagrepper.engineering.redhat.com/raw?topic=/topic/"
"VirtualTopic.eng.ci.redhat-container-image.pipeline.complete"
"&rows_per_page=25&delta=1296000&contains=submariner-operator-bundle-container-v"
"&rows_per_page=25&delta=12960000&contains=submariner-operator-bundle-container-v"
)
ACM_BREW_BUILD_URL = (
"https://datagrepper.engineering.redhat.com/raw?topic=/topic/"
"VirtualTopic.eng.ci.redhat-container-image.pipeline.complete"
"&rows_per_page=25&delta=1296000&contains=acm"
)
SUBMARINER_BREW_REPO = "brew.registry.redhat.io/rh-osbs/iib"
SUBMARINER_BREW = "brew.registry.redhat.io/rh-osbs"
SUBMARINER_BREW_REPO = "/".join([SUBMARINER_BREW, "iib"])
SUBCTL_DOWNSTREAM_URL = "registry.redhat.io/rhacm2/"
ACM_BREW_REPO = SUBMARINER_BREW_REPO

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def pytest_generate_tests(metafunc):

"""
# For now we are only dealing with multicluster scenarios in this hook
if ocsci_config.multicluster:
if ocsci_config.multicluster and ocsci_config.UPGRADE.get("upgrade", False):
upgrade_parametrizer = get_multicluster_upgrade_parametrizer()
# for various roles which are applicable to current test wrt multicluster, for ex: ACM, primary, secondary etc
roles = None
Expand Down
Loading