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

Fix art-bot what kernel is in rhcos cmd #181

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 4 additions & 12 deletions artbotlib/kernel_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ async def non_rhcos_kernel_info(self, image):

async def rhcos_kernel_info(self):
rpms = []

# Fetch release info from Release Controller to get RHCOS build ID
rhcos_build_id = await rhcos.get_rhcos_build_id_from_release(self.release_img, self.arch)
pullspec, _ = buildinfo.get_img_pullspec(self.release_img)
rhcos_build_id = await rhcos.get_rhcos_build_id_from_pullspec(pullspec)
if not rhcos_build_id:
self.logger.error('Couldn\'t find release %s on RC', self.release_img)
self.so.say(f'Couldn\'t find release `{self.release_img}` on Release Controller')
self.logger.warning('Failed to fetch RHCOS info for %s', self.release_img)
self.so.say(f'Failed to fetch RHCOS info for {self.release_img}')
return None

# Fetch RHCOS build metadata
Expand All @@ -81,13 +80,6 @@ async def rhcos_kernel_info(self):
kernel_core = [pkg for pkg in pkg_list if 'kernel-core' in pkg][0]
rpms.append(f'kernel-core.{".".join(kernel_core[2:])}')

# Get kernel-rt-core from build labels, if available
build_info, pullspec, _ = await buildinfo.get_image_info(
self.so, 'machine-os-content', self.release_img)
labels = build_info['config']['config']['Labels']
if 'com.coreos.rpm.kernel-rt-core' in labels:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These no longer exist

rpms.append(f"kernel-rt-core.{labels['com.coreos.rpm.kernel-rt-core']}")

return {
'name': 'rhcos',
'rpms': rpms,
Expand Down
48 changes: 20 additions & 28 deletions artbotlib/rhcos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import json

from artbotlib import constants
from artbotlib import exectools
from artcommonlib.rhcos import get_build_id_from_rhcos_pullspec

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -83,43 +85,33 @@ def build_metadata(self, build_id, arch):
raise


async def get_rhcos_build_id_from_release(release_img: str, arch: str) -> str:
async def get_rhcos_build_id_from_pullspec(release_img_pullspec: str) -> str:
"""
Given a nightly or release, return the associated RHCOS build id

:param release_img: e.g. 4.12.0-0.nightly-2022-12-20-034740, 4.10.10
:param arch: one in {'amd64', 'arm64', 'ppc64le', 's390x'}
:param release_img_pullspec: e.g. registry.ci.openshift.org/ocp/release:4.12.0-0.nightly-2022-12-20-034740
:return: e.g. 412.86.202212170457-0
"""

logger.info('Retrieving rhcos build ID for %s', release_img)
build_id = None
# TODO: use artcommonlib to do all of this
# Hardcode rhcos_tag for now
# this comes from https://github.com/openshift-eng/ocp-build-data/blob/cc6a68a3446f2e80dddbaa9210897ed2812cb103/group.yml#L71C13-L71C24
# we have logic in artcommonlib.rhcos to do all of this, so do not repeat it here
rhcos_tag = "rhel-coreos"

# Make sure only the release tag is being used
release_img = release_img.replace(f"{constants.NIGHTLY_REGISTRY}:", '')
release_img = release_img.replace(f"{constants.QUAY_REGISTRY}:", '')

# Arch shouldn't be in the name
rhcos_arch = constants.RC_ARCH_TO_RHCOS_ARCH[arch]
release_img = release_img.replace(f'-{rhcos_arch}', '')

async with aiohttp.ClientSession() as session:
url = f'{constants.RELEASE_CONTROLLER_URL.substitute(arch=arch)}/releasetag/{release_img}/json'
logger.info('Fetching URL %s', url)

async with session.get(url) as resp:
try:
release_info = await resp.json()
except aiohttp.client_exceptions.ContentTypeError:
logger.warning('Failed fetching url %s', url)
return None
rc, stdout, stderr = exectools.cmd_gather(f"oc adm release info {release_img_pullspec} --image-for {rhcos_tag}")
if rc:
logger.error('oc failed with rc %s: %s', rc, stderr)
return None
pullspec = stdout.split('\n')[0]

try:
release_info = release_info['displayVersions']['machine-os']['Version']
logger.info('Retrieved release info: %s', release_info)
return release_info
except KeyError:
logger.error('Failed retrieving release info')
raise
build_id = get_build_id_from_rhcos_pullspec(pullspec)
except Exception as e:
logger.error('Failed to fetch RHCOS build id from pullspec %s: %s', pullspec, e)

return build_id


def rhcos_build_urls(ocp_version, build_id, arch="x86_64"):
Expand Down
Loading