fix: verify current distribution metadata

This commit is contained in:
Kevin Yue committed 2026-11-19 03:39:45 +08:00
1 parent 287d0cc6af
commit 1c34c52707
3 files changed
+29 -15

No files matched your search

+19 -8
View File
@@ -39,14 +39,6 @@ class RepositoryTests(unittest.TestCase):
with self.assertRaises(publication.Pending):
publication.rpm_packages("https://repo")
def test_copr_same_version_from_another_build_does_not_pass(self):
primary = ET.fromstring('''<metadata xmlns="http://linux.duke.edu/metadata/common"><package>
<name>globalprotect-openconnect</name><arch>x86_64</arch><version ver="3.0.1" rel="1.fc44"/>
<location href="011106217-globalprotect-openconnect/package.rpm"/></package></metadata>''')
with patch.object(publication, "rpm_packages", return_value=primary):
params = ("https://repo", "globalprotect-openconnect", "3.0.1", "x86_64", lambda release: True)
self.assertTrue(publication.rpm_present(*params, build_id=11106217))
self.assertFalse(publication.rpm_present(*params, build_id=11106218))
class LaunchpadTests(unittest.TestCase):
@@ -138,6 +130,25 @@ class OBSTests(unittest.TestCase):
class CoprTests(unittest.TestCase):
def test_migrated_repository_matches_exact_build_manifest(self):
checker = publication.Copr(arguments(build_id=42))
build = {"ownername": "yuezk", "projectname": "globalprotect-openconnect",
"state": "succeeded", "source_package": {"name": "globalprotect-openconnect", "version": "3.0.1-1"},
"chroots": ["fedora-44-x86_64"], "repo_url": "https://repo"}
status = {"state": "succeeded", "result_url": "https://results/42/"}
package = {"name": "globalprotect-openconnect", "version": "3.0.1", "release": "1.fc44", "arch": "x86_64"}
primary = ET.fromstring('''<metadata xmlns="http://linux.duke.edu/metadata/common"><package>
<name>globalprotect-openconnect</name><arch>x86_64</arch><version ver="3.0.1" rel="1.fc44"/>
<location href="Packages/g/globalprotect-openconnect-3.0.1-1.fc44.x86_64.rpm"/></package></metadata>''')
with patch.object(publication, "api", side_effect=[build, status, {"packages": [package]}]), \
patch.object(publication, "rpm_packages", return_value=primary):
self.assertIn("1 targets built and published", checker.check())
package["release"] = "1.fc45"
with patch.object(publication, "api", side_effect=[build, status, {"packages": [package]}]), \
patch.object(publication, "rpm_packages", return_value=primary):
with self.assertRaisesRegex(publication.Pending, "Waiting for Copr build 42"):
checker.check()
def test_unselected_chroot_cannot_be_hidden_by_verification(self):
checker = publication.Copr(arguments(build_id=42, chroots=["fedora-44-x86_64"]))
build = {"ownername": "yuezk", "projectname": "globalprotect-openconnect",
+10 -6
View File
@@ -84,17 +84,14 @@ def rpm_packages(base_url):
return ET.fromstring(unpack(content, location))
def rpm_present(base_url, package, version, arch, release_matches, build_id=None):
def rpm_present(base_url, package, version, arch, release_matches):
namespace = {"rpm": "http://linux.duke.edu/metadata/common"}
for entry in rpm_packages(base_url).findall("rpm:package", namespace):
info = entry.find("rpm:version", namespace)
location = entry.find("rpm:location", namespace).get("href")
if (entry.findtext("rpm:name", namespaces=namespace) != package or
entry.findtext("rpm:arch", namespaces=namespace) != arch or
info.get("ver") != version or not release_matches(info.get("rel", ""))):
continue
if build_id is not None and not re.search(rf"(?:^|/)0*{build_id}-", location):
continue
return True
return False
@@ -254,9 +251,16 @@ class Copr:
raise Pending(f"Copr {chroot}: {status['state']}; {link}")
base = build["repo_url"].rstrip("/") + "/" + chroot
arch = chroot.rsplit("-", 1)[1]
packages = api(urljoin(status["result_url"], "results.json"))["packages"]
package = next((item for item in packages
if item["name"] == args.package and item["version"] == args.version
and item["arch"] == arch
and (item["release"] == args.revision
or item["release"].startswith(args.revision + "."))), None)
if package is None:
raise Failed(f"Copr build {args.build_id} has no requested package for {chroot}")
if not rpm_present(base, args.package, args.version, arch,
lambda release: release == args.revision or release.startswith(args.revision + "."),
build_id=args.build_id):
lambda release: release == package["release"]):
raise Pending(f"Waiting for Copr build {args.build_id} in {base}")
return f"Copr build {args.build_id}: {len(build['chroots'])} targets built and published; {link}"