diff --git a/module_build_service/builder/KojiModuleBuilder.py b/module_build_service/builder/KojiModuleBuilder.py index b9063e57..8b095463 100644 --- a/module_build_service/builder/KojiModuleBuilder.py +++ b/module_build_service/builder/KojiModuleBuilder.py @@ -359,6 +359,18 @@ class KojiModuleBuilder(GenericBuilder): ) ) + # These are generated from handle_collisions_with_base_module_rpms and are different than + # the stream collision modules + ursine_rpms = mmd.get_xmd()["mbs"].get("ursine_rpms") + if ursine_rpms: + log.debug("Adding %d ursine RPM(s) to the conflicts", len(ursine_rpms)) + filter_conflicts.append( + "\n# Filter out base module RPMs that overlap with the RPMs in the buildrequired " + "modules" + ) + for ursine_rpm in ursine_rpms: + filter_conflicts.append(KojiModuleBuilder.format_conflicts_line(ursine_rpm)) + spec_content = textwrap.dedent(""" %global dist {disttag} %global modularitylabel {module_name}:{module_stream}:{module_version}:{module_context} diff --git a/module_build_service/scheduler/default_modules.py b/module_build_service/scheduler/default_modules.py index f472b9d2..0e984eea 100644 --- a/module_build_service/scheduler/default_modules.py +++ b/module_build_service/scheduler/default_modules.py @@ -264,14 +264,9 @@ def handle_collisions_with_base_module_rpms(mmd, arches): if rpm_name in name_to_nevras: conflicts = conflicts | name_to_nevras[rpm_name] - if not conflicts: - return - - # Append the conflicting NEVRAs to `ursine_rpms`, so the Conflicts are later generated for them + # Add the conflicting NEVRAs to `ursine_rpms` so the Conflicts are later generated for them # in the KojiModuleBuilder. - if not xmd["mbs"].get("ursine_rpms"): - xmd["mbs"]["ursine_rpms"] = [] - xmd["mbs"]["ursine_rpms"] = list(set(xmd["mbs"]["ursine_rpms"]).union(conflicts)) + xmd["mbs"]["ursine_rpms"] = list(conflicts) mmd.set_xmd(xmd) diff --git a/module_build_service/scheduler/handlers/modules.py b/module_build_service/scheduler/handlers/modules.py index 60e4874c..bed4c797 100644 --- a/module_build_service/scheduler/handlers/modules.py +++ b/module_build_service/scheduler/handlers/modules.py @@ -187,9 +187,9 @@ def init(config, db_session, msg): if conf.system in ["koji", "test"] and not defaults_added: handle_stream_collision_modules(db_session, mmd) - # Extends the xmd["mbs"]["ursine_rpms"] with RPMs from base module which conflict - # with the RPMs from module. We need to prefer modular RPMs over base module RPMs - # even if their NVR is lower. + # 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. handle_collisions_with_base_module_rpms(mmd, arches) mmd = record_filtered_rpms(db_session, mmd) diff --git a/tests/test_builder/test_koji.py b/tests/test_builder/test_koji.py index 1d9d167d..c6ab7c1c 100644 --- a/tests/test_builder/test_koji.py +++ b/tests/test_builder/test_koji.py @@ -969,6 +969,7 @@ class TestGetDistTagSRPM: "ursine_rpms": ["foo-0:1.0-1.fc28", "bar-0:2.0-1.fc28"], }, }, + "ursine_rpms": ["pizza-0:4.0-1.fc32", "spaghetti-0:3.0-1.fc32"], "koji_tag": "module-{name}-{stream}-{version}-{context}".format(**self.module_nsvc), } } @@ -1006,6 +1007,11 @@ class TestGetDistTagSRPM: with open(self.spec_file, "r") as f: content = f.read() + # Stream collision ursine RPMs assert "# modulefoo-s-v-c\n" in content for nevr in ["foo-0:1.0-1.fc28", "bar-0:2.0-1.fc28"]: assert KojiModuleBuilder.format_conflicts_line(nevr) + "\n" in content + + # Conflicting ursine RPMs + for nevr in ["pizza-0:4.0-1.fc32", "spaghetti-0:3.0-1.fc32"]: + assert KojiModuleBuilder.format_conflicts_line(nevr) + "\n" in content diff --git a/tests/test_scheduler/test_default_modules.py b/tests/test_scheduler/test_default_modules.py index 2f7c8696..cae70b94 100644 --- a/tests/test_scheduler/test_default_modules.py +++ b/tests/test_scheduler/test_default_modules.py @@ -222,11 +222,9 @@ def test_get_rawhide_version(mock_koji_builder): assert default_modules._get_rawhide_version() == "f32" -@pytest.mark.parametrize("ursine_rpms", ([], ["httpd-0:2.4-5.el8.x86_64"])) @patch("module_build_service.scheduler.default_modules.KojiModuleBuilder.get_session") @patch("module_build_service.scheduler.default_modules._get_rpms_from_tags") -def test_handle_collisions_with_base_module_rpms( - mock_grft, mock_get_session, ursine_rpms): +def test_handle_collisions_with_base_module_rpms(mock_grft, mock_get_session): """ Test that handle_collisions_with_base_module_rpms will add conflicts for NEVRAs in the modulemd. @@ -236,10 +234,6 @@ def test_handle_collisions_with_base_module_rpms( xmd["mbs"]["buildrequires"]["platform"]["koji_tag"] = "module-el-build" xmd["mbs"]["buildrequires"]["python"] = {"koji_tag": "module-python27"} xmd["mbs"]["buildrequires"]["bash"] = {"koji_tag": "module-bash"} - if ursine_rpms: - # There might already be some ursine RPMs set from another methods. - # We must check they are not overwritten. - xmd["mbs"]["ursine_rpms"] = ursine_rpms mmd.set_xmd(xmd) bm_rpms = { @@ -261,11 +255,11 @@ def test_handle_collisions_with_base_module_rpms( mock_get_session.assert_called_once() xmd_mbs = mmd.get_xmd()["mbs"] - assert set(xmd_mbs["ursine_rpms"]) == set(ursine_rpms).union({ + assert set(xmd_mbs["ursine_rpms"]) == { "bash-0:4.4.19-7.el8.aarch64", "python2-tools-0:2.7.16-11.el8.aarch64", "python2-tools-0:2.7.16-11.el8.x86_64", - }) + } assert mock_grft.call_count == 2 # We can't check the calls directly because the second argument is a set converted to a list, # so the order can't be determined ahead of time.