Test/stages/rpm: add compatibility with RPM 6.0

RPM 6.0 (landed in F43, current rawhide), no longer uses short key ID
for the 'gpg-pubkey' pseudo-package, but to prevent any collision, it
uses full key ID.

This means that we can't consistently just compare the pipeline rpm
stage metadata from the test data with what we get from building the
test manifest. The reason is that we need to keep running the unit test
in upstream and downstream CI pipelines for OSes, which may ship RPM
6.0, but also older RPM version.

Extend the test case to do a special case check for any 'gpg-pubkey'
package in the metadata if the package version length differs between
the test data and data got from building the manifest.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2025-05-19 13:05:45 +02:00 committed by Simon de Vlieger
parent e7b0705c1d
commit f30174d9ba

View file

@ -246,6 +246,35 @@ class TestStages(test.TestBase):
with open(md_path, "r", encoding="utf8") as f:
metadata = json.load(f)
# NB: RPM 6.0 (on F43+) no longer uses short key ids to identify imported GPG keys.
# This means that the gpg-pubkey pseudo-package version differs with RPM 6 vs. older RPM version.
# https://fedoraproject.org/wiki/Changes/RPM-6.0
for pipeline in metadata:
self.assertIn(pipeline, res["metadata"])
test_rpm_pkgs_md = metadata[pipeline]["org.osbuild.rpm"]["packages"]
got_rpm_pkgs_md = res["metadata"][pipeline]["org.osbuild.rpm"]["packages"]
# Iterate over the metadata and do a special check of the 'gpg-pubkey' package
# if it is present and the version is has different length (short key id vs. full key id)
for test_pkg, got_pkg in zip(test_rpm_pkgs_md, got_rpm_pkgs_md):
self.assertEqual(test_pkg["name"], got_pkg["name"])
if test_pkg["name"] != "gpg-pubkey":
continue
if len(test_pkg["version"]) == len(got_pkg["version"]):
continue
test_pkg_version = test_pkg.pop("version")
got_pkg_version = got_pkg.pop("version")
# Ensure that the remaining fields are equal
self.assertEqual(test_pkg, got_pkg)
# Check that the shorter version (the short key id) is a suffix of the longer version.
# Check both ways, since we may eventually use the full key id in the test data, while
# still running the test with an older RPM version (i.e. on RHEL).
if len(test_pkg_version) > len(got_pkg_version):
assert test_pkg_version.endswith(got_pkg_version)
else:
assert got_pkg_version.endswith(test_pkg_version)
self.assertEqual(metadata, res["metadata"])
# cache the downloaded data for the sources by copying