Skip to content

Commit

Permalink
Merge pull request #181 from thegreyd/fix_rhcos_kernel
Browse files Browse the repository at this point in the history
Fix art-bot what kernel is in rhcos cmd
  • Loading branch information
openshift-merge-bot[bot] authored Apr 25, 2024
2 parents 1a17a53 + 98d0dc4 commit f1f4460
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 41 deletions.
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.error('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:
rpms.append(f"kernel-rt-core.{labels['com.coreos.rpm.kernel-rt-core']}")

return {
'name': 'rhcos',
'rpms': rpms,
Expand Down
53 changes: 24 additions & 29 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,36 @@ 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)

# 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
build_id = None
# TODO: use artcommonlib to do all of this
# Hardcode rhcos tags 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_1 = "machine-os-content"
rhcos_tag_2 = "rhel-coreos"
rc, stdout, stderr = exectools.cmd_gather(f"oc adm release info {release_img_pullspec} --image-for {rhcos_tag_1}")
if rc:
rc, stdout, stderr = exectools.cmd_gather(f"oc adm release info {release_img_pullspec} --image-for {rhcos_tag_2}")
if rc:
logger.error('Failed to get RHCOS image for %s: %s', release_img_pullspec, 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

0 comments on commit f1f4460

Please sign in to comment.