Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion tests/test_modulemd_depsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]))
Expand Down
42 changes: 39 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -681,25 +682,60 @@ 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(
("name", "stream"),
[("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(
Expand Down
11 changes: 7 additions & 4 deletions ubi_manifest/worker/tasks/depsolver/modulemd_depsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down
11 changes: 11 additions & 0 deletions ubi_manifest/worker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)