setup_repos: use Koji client library for build arch check
All checks were successful
All checks were successful
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 <awilliam@redhat.com>
This commit is contained in:
parent
b84f6b0ca4
commit
7b51f73264
1 changed files with 31 additions and 20 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue