Skip to content

Commit

Permalink
add recent z-stream release resolution from ohsnap
Browse files Browse the repository at this point in the history
  • Loading branch information
rplevka authored and ogajduse committed Mar 15, 2023
1 parent 087ace9 commit 5f0fdac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion robottelo/host_helpers/contenthost_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _dogfood_helper(self, product, release, snap, repo=None):
def download_repofile(self, product=None, release=None, snap=''):
"""Downloads the tools/client, capsule, or satellite repos on the machine"""
product, release, snap, v_major, _ = self._dogfood_helper(product, release, snap)
url = dogfood_repofile_url(settings.ohsnap.host, product, release, v_major, snap)
url = dogfood_repofile_url(settings.ohsnap, product, release, v_major, snap)
self.execute(f'curl -o /etc/yum.repos.d/dogfood.repo {url}')

def dogfood_repository(self, repo=None, product=None, release=None, snap=''):
Expand Down
2 changes: 1 addition & 1 deletion robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_sat_version():
try:
sat_version = Satellite().version
except (AuthenticationError, ContentHostError, BoxKeyError):
if str(sat_version := settings.server.version.get('release')) == 'stream':
if sat_version := str(settings.server.version.get('release')) == 'stream':
sat_version = str(settings.robottelo.get('satellite_version'))
if not sat_version:
sat_version = SATELLITE_VERSION
Expand Down
40 changes: 31 additions & 9 deletions robottelo/utils/ohsnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def ohsnap_response_hook(r, *args, **kwargs):
r.raise_for_status()


def ohsnap_repo_url(ohsnap_repo_host, request_type, product, release, os_release, snap=''):
def ohsnap_repo_url(ohsnap, request_type, product, release, os_release, snap=''):
"""Returns a URL pointing to Ohsnap "repo_file" or "repositories" API endpoint"""
if request_type not in ['repo_file', 'repositories']:
raise InvalidArgumentError('Type must be one of "repo_file" or "repositories"')
Expand All @@ -37,19 +37,41 @@ def ohsnap_repo_url(ohsnap_repo_host, request_type, product, release, os_release
logger.warning(
'The snap version was not provided. Snap number will not be used in the URL.'
)
release = release.split('.')
if len(release) == 2:
release.append('0')
release = '.'.join(release[:3]) # keep only major.minor.patch
if len(release.split('.')) == 2:
logger.warning(
f'.z version component not provided in the release ({release}),'
f' fetching the recent z-stream from ohsnap'
)
res, _ = wait_for(
lambda: requests.get(
f'{ohsnap.host}/api/streams',
hooks={'response': ohsnap_response_hook},
),
handle_exception=True,
raise_original=True,
timeout=ohsnap.request_retry.timeout,
delay=ohsnap.request_retry.delay,
)
logger.debug(f'List of releases returned by Ohsnap: {res.json()}')
# filter the stream for our release and set it only if it has at least 1 snap
if (streams := [stream for stream in res.json() if stream['id'] == release]) and len(
streams[0]['release_ids']
) > 0:
# get the recent snap id (last in the list)
release = streams[0]['release_ids'][-1]
else:
logger.warning(f'Ohsnap returned no releases for the given stream: {release}')

release = '.'.join(release.split('.')[:3]) # keep only major.minor.patch
logger.debug(f'Release string after processing: {release}')
return (
f'{ohsnap_repo_host}/api/releases/'
f'{ohsnap.host}/api/releases/'
f'{release}{snap}/el{Version(str(os_release)).major}/{product}/{request_type}'
)


def dogfood_repofile_url(ohsnap_repo_host, product, release, os_release, snap=''):
return ohsnap_repo_url(ohsnap_repo_host, 'repo_file', product, release, os_release, snap)
def dogfood_repofile_url(ohsnap, product, release, os_release, snap=''):
return ohsnap_repo_url(ohsnap, 'repo_file', product, release, os_release, snap)


def dogfood_repository(
Expand All @@ -59,7 +81,7 @@ def dogfood_repository(
arch = arch or constants.DEFAULT_ARCHITECTURE
res, _ = wait_for(
lambda: requests.get(
ohsnap_repo_url(ohsnap.host, 'repositories', product, release, os_release, snap),
ohsnap_repo_url(ohsnap, 'repositories', product, release, os_release, snap),
hooks={'response': ohsnap_response_hook},
),
handle_exception=True,
Expand Down

0 comments on commit 5f0fdac

Please sign in to comment.