From 1f2fbca7d4ed885f7fe9bd2384e9877538e6e2e4 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Thu, 29 Oct 2020 11:23:06 -0400 Subject: [PATCH] Check dnf version before skipping base module conflicts The base module conflict generation was skipped for local builds in 6b2e5be93aad because libdnf wasn't ported to libmodulemd yet - that was done in libdnf-0.45, so only warn and skip for versions of dnf too old to require libdnf-0.45. (Don't just unconditionally skip check/warning in case someone is doing local module builds on RHEL 8.) --- .../scheduler/default_modules.py | 17 ++++++++++++++++- .../scheduler/handlers/modules.py | 11 ++--------- requirements.txt | 1 + tests/test_scheduler/test_default_modules.py | 3 ++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/module_build_service/scheduler/default_modules.py b/module_build_service/scheduler/default_modules.py index 81940063..6846d13e 100644 --- a/module_build_service/scheduler/default_modules.py +++ b/module_build_service/scheduler/default_modules.py @@ -9,6 +9,7 @@ import tempfile import dnf import kobo.rpmlib import koji +import packaging.version import six.moves.xmlrpc_client as xmlrpclib from module_build_service.common import conf, log, models, scm @@ -216,7 +217,7 @@ def _get_rawhide_version(): return build_target["build_tag_name"].partition("-build")[0] -def handle_collisions_with_base_module_rpms(mmd, arches): +def handle_collisions_with_base_module_rpms(mmd, arches, force_for_old_dnf=False): """ Find any RPMs in the buildrequired base modules that collide with the buildrequired modules. @@ -226,8 +227,22 @@ def handle_collisions_with_base_module_rpms(mmd, arches): :param Modulemd.ModuleStream mmd: the modulemd to find the collisions :param list arches: the arches to limit the external repo queries to + :param bool force_for_old_dnf: add the conflicts even if libdnf can't handle them :raise RuntimeError: when a Koji query fails """ + if (not force_for_old_dnf + and packaging.version.parse(dnf.VERSION) < packaging.version.parse('4.2.19')): + # For local builds, we can't use this code unless libdnf uses libmodulemd2 + # (done in libdnf-0.45) - we can't check the libdnf version, so use + # dnf-4.2.19 (which requires libdnf-0.45) as a proxy. + log.warning( + "The necessary conflicts could not be generated due to RHBZ#1693683. " + "Some RPMs from the base modules (%s) may end up being used over modular RPMs. " + "This may result in different behavior than a production build.", + ", ".join(conf.base_module_names) + ) + return + log.info("Finding any buildrequired modules that collide with the RPMs in the base modules") bm_tags = set() non_bm_tags = set() diff --git a/module_build_service/scheduler/handlers/modules.py b/module_build_service/scheduler/handlers/modules.py index f955495a..18ccb40b 100644 --- a/module_build_service/scheduler/handlers/modules.py +++ b/module_build_service/scheduler/handlers/modules.py @@ -207,15 +207,8 @@ def init(msg_id, module_build_id, module_build_state): # Sets xmd["mbs"]["ursine_rpms"] with RPMs from the buildrequired base modules which # conflict with the RPMs from other buildrequired modules. This is done to prefer modular # RPMs over base module RPMs even if their NVR is lower. - if conf.system in ("koji", "test"): - handle_collisions_with_base_module_rpms(mmd, arches) - else: - log.warning( - "The necessary conflicts could not be generated due to RHBZ#1693683. " - "Some RPMs from the base modules (%s) may end up being used over modular RPMs. " - "This may result in different behavior than a production build.", - ", ".join(conf.base_module_names) - ) + handle_collisions_with_base_module_rpms(mmd, arches, + force_for_old_dnf=conf.system in ("koji", "test")) mmd = record_filtered_rpms(mmd) build.modulemd = mmd_to_str(mmd) diff --git a/requirements.txt b/requirements.txt index 9ea96f50..75215f52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,7 @@ koji ldap3 moksha.hub munch +packaging prometheus_client pygobject pyOpenSSL diff --git a/tests/test_scheduler/test_default_modules.py b/tests/test_scheduler/test_default_modules.py index 90fbf78a..7840613d 100644 --- a/tests/test_scheduler/test_default_modules.py +++ b/tests/test_scheduler/test_default_modules.py @@ -291,7 +291,8 @@ def test_handle_collisions_with_base_module_rpms(mock_grft, mock_get_session): } mock_grft.side_effect = [bm_rpms, non_bm_rpms] - default_modules.handle_collisions_with_base_module_rpms(mmd, ["aarch64", "x86_64"]) + default_modules.handle_collisions_with_base_module_rpms(mmd, ["aarch64", "x86_64"], + force_for_old_dnf=True) mock_get_session.assert_called_once() xmd_mbs = mmd.get_xmd()["mbs"]