diff --git a/tests/test_modulemd_depsolver.py b/tests/test_modulemd_depsolver.py index fe2179be..551941a0 100644 --- a/tests/test_modulemd_depsolver.py +++ b/tests/test_modulemd_depsolver.py @@ -140,7 +140,10 @@ def test_run(pulp): assert output_modules == expected_out["modulemds"] # Check that the modulemdDefaults have been resolved - assert len(depsolver.default_modulemds) == 4 + # due to design, there is one duplicate modulemd_default unit "dependency_2:2.22" + # because it got queried again as two modules share the same dependency + # later it's deduplicated by export() call + assert len(depsolver.default_modulemds) == 5 output_def_modules = list( (x.name, x.stream, x.repo_id) for x in depsolver.default_modulemds @@ -151,6 +154,19 @@ def test_run(pulp): # check the modular rpms: assert depsolver.rpm_dependencies == expected_out["modular_rpms"] + # re-check with export() call, does extra de-duplication for modulemd_defaults + data = depsolver.export() + assert data["rpm_dependencies"] == expected_out["modular_rpms"] + + modules_repo1 = [x for x in expected_out["modulemds"] if x[2] == "test_repo_1"] + assert ( + len(data["modules_out"]["test_repo_1"]) + == len(modules_repo1) + len(expected_out["modulemd_defaults"]) - 1 + ) # deduplication of 1 modulemd_default unit + modules_repo2 = [x for x in expected_out["modulemds"] if x[2] == "test_repo_2"] + # no modulemd_defaults in repo_2 + assert len(data["modules_out"]["test_repo_2"]) == len(modules_repo2) + def _prepare_pulp(pulp): # Define mock repos @@ -365,6 +381,8 @@ def _prepare_pulp(pulp): for module in repo_1_units if isinstance(module, ModulemdDefaultsUnit) and not module.name == "ignored" ] + # extra added due to change in modulemd_default search which ignores stream + + [(module_dep_def2.name, module_dep_def2.stream, module_dep_def2.repo_id)] ) expected_modulemd_defaults.sort(key=lambda x: (x[0], x[1])) expected_modulemds.sort(key=lambda x: (x[0], x[1])) diff --git a/tests/test_utils.py b/tests/test_utils.py index d1223bd6..00a0ad12 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -17,6 +17,7 @@ from ubi_manifest.worker.utils import ( create_or_criteria, flatten_list_of_sets, + get_criteria_for_modulemd_defaults, get_criteria_for_modules, get_modulemd_output_set, get_n_latest_from_content, @@ -681,18 +682,28 @@ def test_get_modulemd_output_set(): def test_get_criteria_for_modules(): # define units to search - unit1 = ModulemdDependency( + unit1 = ModulemdUnit( name="perl", stream="5.30", + version=8, + context="abc", + arch="x86_64", ) - unit2 = ModulemdDependency( + unit2 = ModulemdUnit( name="perl", stream="6.30", + version=8, + context="abc", + arch="x86_64", ) - unit3 = ModulemdDependency( + unit3 = ModulemdUnit( name="perl-YAML", + stream=None, + version=8, + context="abc", + arch="x86_64", ) expected_criteria = create_or_criteria( @@ -700,6 +711,31 @@ def test_get_criteria_for_modules(): [("perl", "5.30"), ("perl", "6.30"), ("perl-YAML", Matcher.exists())], ) criteria = get_criteria_for_modules([unit1, unit2, unit3]) + assert criteria == expected_criteria + + +def test_get_criteria_for_modulemd_defaults(): + # define units to search + unit1 = ModulemdUnit( + name="perl", + stream="5.30", + version=8, + context="abc", + arch="x86_64", + ) + unit2 = ModulemdUnit( + name="perl-YAML", + stream="1.24", + version=8, + context="abc", + arch="x86_64", + ) + expected_criteria = create_or_criteria( + ["name"], + [("perl",), ("perl-YAML",)], + ) + criteria = get_criteria_for_modulemd_defaults([unit1, unit2]) + assert criteria == expected_criteria @pytest.mark.parametrize( diff --git a/ubi_manifest/worker/tasks/depsolver/modulemd_depsolver.py b/ubi_manifest/worker/tasks/depsolver/modulemd_depsolver.py index 24d31a3c..f9d0c1b0 100644 --- a/ubi_manifest/worker/tasks/depsolver/modulemd_depsolver.py +++ b/ubi_manifest/worker/tasks/depsolver/modulemd_depsolver.py @@ -15,6 +15,7 @@ from ubi_manifest.worker.models import ModularDepsolverItem, UbiUnit from ubi_manifest.worker.pulp_queries import search_modulemd_defaults, search_modulemds from ubi_manifest.worker.utils import ( + get_criteria_for_modulemd_defaults, get_criteria_for_modules, get_modulemd_output_set, split_filename, @@ -91,7 +92,9 @@ def _depsolve_modules(self, modules: set[UbiUnit]) -> None: self.modules.extend(filtered_modules) modules_to_search = [] - modulemd_defaults_criteria = get_criteria_for_modules(filtered_modules) + modulemd_defaults_criteria = get_criteria_for_modulemd_defaults( + filtered_modules + ) self.default_modulemds.extend( f_proxy( # type: ignore [arg-type] self._executor.submit( @@ -175,11 +178,11 @@ def export(self) -> dict[str, Any]: ) # append ModulemdDefaultsUnits to output set - def_mod_ids = set() + def_mod_name_stream_set = set() for def_mod in self.default_modulemds: # filter duplicates - if def_mod.unit_id not in def_mod_ids: - def_mod_ids.add(f"{def_mod.name}:{def_mod.stream}") + if f"{def_mod.name}:{def_mod.stream}" not in def_mod_name_stream_set: + def_mod_name_stream_set.add(f"{def_mod.name}:{def_mod.stream}") modules_out.setdefault(def_mod.associate_source_repo_id, []).append( def_mod ) diff --git a/ubi_manifest/worker/utils.py b/ubi_manifest/worker/utils.py index 4f2937f9..a4ee23a9 100644 --- a/ubi_manifest/worker/utils.py +++ b/ubi_manifest/worker/utils.py @@ -419,3 +419,14 @@ def get_criteria_for_modules(modules: list[UbiUnit]) -> list[Criteria]: fields = ["name", "stream"] or_criteria = create_or_criteria(fields, criteria_values) return or_criteria + + +def get_criteria_for_modulemd_defaults(modules: list[UbiUnit]) -> list[Criteria]: + """ + Creates OR criteria that search for all modulemd_defaults by name. + """ + criteria_values = [] + for module in modules: + criteria_values.append((module.name,)) + fields = ["name"] + return create_or_criteria(fields, criteria_values)