From 7b51f732646a3166ce9b4f51a0bfa02c3a377143 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mon, 13 Apr 2026 11:58:48 -0700 Subject: [PATCH] setup_repos: use Koji client library for build arch check Now I've remembered how to use the Koji client library, it turns out it's actually cleaner and easier to do the 'what arches was this package built for?' check that way after all. Signed-off-by: Adam Williamson --- data/setup_repos.py | 51 +++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/data/setup_repos.py b/data/setup_repos.py index 8a9a794a..bde44e74 100755 --- a/data/setup_repos.py +++ b/data/setup_repos.py @@ -37,6 +37,8 @@ import shutil import subprocess import sys +import koji + # these are variables to make testing this script easier...change them # to /tmp for testing WORKAROUNDS_DIR = "/mnt/workarounds_repo" @@ -74,7 +76,7 @@ async def download_item(item, arch, targetdir): Download something - a build or task (with koji) or an update (with bodhi). """ - print(f"Downloading item {item}") + print(f"Downloading item {item} for arch {arch}") if item.isdigit(): # this will be a task ID cmd = ("koji", "download-task", f"--arch={arch}", "--arch=noarch", item) @@ -88,30 +90,39 @@ async def download_item(item, arch, targetdir): # https://forge.fedoraproject.org/quality/os-autoinst-distri-fedora/issues/510 # we don't bother on the other paths as they're less important, # this is the one used to download real updates + ksess = koji.ClientSession("https://koji.fedoraproject.org/kojihub") tries = 5 - stdout = "" - retcode = 0 + builtarches = set() while tries: - (retcode, stdout, _) = await run_command("koji", "buildinfo", item) - if retcode: + try: + kbuild = await asyncio.to_thread(ksess.getBuild, item) or {} + kbid = kbuild.get("build_id") + if kbid: + rpms = await asyncio.to_thread(ksess.listRPMs, kbid) + builtarches = {dc["arch"] for dc in rpms} + # drop these so the set will be empty if there are + # only noarch packages + builtarches.discard("src") + builtarches.discard("noarch") + break + else: + print(f"Warning: Koji build ID discovery for {item} failed") + break + except Exception as err: # pylint: disable=broad-exception-caught tries -= 1 + print("Warning: arch check attempt failed...") + print(err) + print(f"Tries remaining: {tries}") if tries: await asyncio.sleep(2) - else: - break - # if that didn't work we'll default to downloading to be safe - if stdout and not retcode: - lines = stdout.splitlines() - foundarches = set() - knownarches = ["x86_64", "aarch64", "s390x", "ppc64le", "riscv64", "i686"] - for line in lines: - for checkarch in knownarches: - if f".{checkarch}.rpm" in line: - foundarches.add(checkarch) - # no foundarches means it's a noarch-only package, which is fine - if foundarches and arch not in foundarches: - print(f"{item} not built for {arch}, skipping!") - return False + else: + print(f"Warning: arch check failed, default to downloading {item} for {arch}") + break + # if there's anything in builtarches here, the package was + # built for at least one arch besides noarch, so we'll check + if builtarches and arch not in builtarches: + print(f"{item} not built for {arch}, skipping!") + return False # do the download and check for failure tries = 5