Skip to content

Commit b6c19e4

Browse files
committed
src/konflux-rpm-lockfile: use coreos-pool URLs only
Until now, we tackled the DNF5 issue [1] by prioritizing the URL location of the repo 'coreos-pool' when multiple repo were found for the say locked NEVRA. But, if that locked NEVRA has only one URL location coming from the fedora repos i.e: fedora, fedora-updates, then the repoquery command returns a broken URL location for ppc64le and s390x arches because of the DNF5 issue. It returns the URL from the first item defined in baseurl, whereas the resolution worked with the second item i.e fedora-secondary repo where the RPMs for ppc64le and s390x are available. This patch fixes this issue with another approach wich consists of using coreos-pool URLs only. For each non coreos-pool URL we extract the NEVRA and arch to construct the URL into the canonical koji path structure. As soon as the 'bump-lockfile' commit is merged, the coreos-koji-tagger will tag to 'coreos-pool'. So it's safe to craft the URL prior its availability. One downside is a possible race condition between the koji tag operation and the CI/CD system building hermetically. The other downside is that the `rpms.lock.yaml` changes cannot be tested locally as this relies on remote koji tagging operation. But, as it's consumed for Konflux only now, I'd say it's ok. [1] rpm-software-management/dnf5#2466
1 parent 7a80e77 commit b6c19e4

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

src/konflux-rpm-lockfile

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,51 @@ import os
66
import sys
77
import subprocess
88
import yaml
9+
import re
910

1011
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
1112
from cosalib.cmdlib import get_basearch
1213

1314

15+
def use_koji_url_only(url_list):
16+
"""
17+
Returns a list of package URLs to point only to our koji coreos-pool.
18+
If a URL is not a coreos-pool one, then we extract the arch and NEVRA from
19+
it and we construct the new one into the canonical koji path structure.
20+
"""
21+
koji_url_base = "https://kojipkgs.fedoraproject.org/repos-dist/coreos-pool"
22+
updated_list = []
23+
for url in url_list:
24+
if koji_url_base in url:
25+
updated_list.append(url)
26+
continue
27+
nevra = url.split("/")[-1]
28+
arch = extract_arch_from_url(url)
29+
koji_url_base_with_arch = koji_url_base + f"/latest/{arch}/Packages"
30+
new_url = "/".join([koji_url_base_with_arch,
31+
nevra[0].lower(),
32+
nevra])
33+
updated_list.append(new_url)
34+
return updated_list
35+
36+
37+
def extract_arch_from_url(url):
38+
"""
39+
Extracts the arch value from the URL.
40+
"""
41+
arches = ['x86_64', 'aarch64', 'ppc64le', 's390x']
42+
# using word boundaries (\b) to ensure we match a full architecture name.
43+
# this means the chars immediately surrounding the arch string must be
44+
# non-word characters e.g: "/"
45+
architecture_pattern = re.compile(
46+
r'\b(' + '|'.join(re.escape(a) for a in arches) + r')\b')
47+
match = architecture_pattern.search(url)
48+
if match:
49+
return match.group(1)
50+
else:
51+
return None
52+
53+
1454
def format_packages_with_repoid(pkgs, repos):
1555
"""
1656
Takes a list of package URLs and repos and returns a list
@@ -118,10 +158,6 @@ def query_packages_location(locks, repoquery_args):
118158
continue
119159
name, url = line.split(' ')
120160
# Prioritize the url from fedora-coreos-pool
121-
# there is a bug in dnf here where the url returned is incorrect when the
122-
# repofile have more than one baseurl, which causes ppc64le and s390x
123-
# urls comming from fedora and fedora-updates to be invalid
124-
# See https://github.com/rpm-software-management/dnf5/issues/2466
125161
existing_url = processed_urls.get(name, None)
126162
if 'coreos-pool' in url or not existing_url:
127163
processed_urls[name] = url
@@ -201,6 +237,8 @@ def generate_main(args):
201237
# we have to specify both --arch and --forcearch to get both result for $arch and $noarch
202238
arch_args = ['--forcearch', arch, '--arch', arch, '--arch', 'noarch']
203239
pkg_urls = query_packages_location(locks, repoquery_args + arch_args)
240+
# we only want coreos-pool URLs
241+
pkg_urls = use_koji_url_only(pkg_urls)
204242
packages.append({'arch': arch, 'packages': pkg_urls})
205243

206244
lockfile = write_hermeto_lockfile(packages, repos)

0 commit comments

Comments
 (0)