Skip to content

Commit

Permalink
TODO different commit Rework matching modulemd_defaults units [RHELDS…
Browse files Browse the repository at this point in the history
…T-6393]

Matching modulemd_defaults units for ubi repos population is now
reworked and uses Client from pubtools-pulplib in the similar way
as matching other units (modulemd, rpm ...) works.
  • Loading branch information
rbikar committed Sep 15, 2021
1 parent 7878eda commit a8fae6e
Show file tree
Hide file tree
Showing 11 changed files with 738 additions and 808 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Expand Up @@ -3,4 +3,5 @@ more-executors>2.1.0
ubi-config>=2.2.0
rpm-py-installer
pyrsistent<0.17; python_version < '3'
pubtools-pulplib>=2.9.0
pubtools-pulplib>=2.9.0
attrs
32 changes: 32 additions & 0 deletions tests/conftest.py
@@ -0,0 +1,32 @@
import pytest

from pubtools.pulplib import RpmUnit, ModulemdUnit, ModulemdDefaultsUnit, FakeController
from ubipop._matcher import UbiUnit


def _get_test_unit(klass, **kwargs):
repo_id = kwargs.pop("src_repo_id")
return UbiUnit(klass(**kwargs), repo_id)


def get_rpm_unit(**kwargs):
return _get_test_unit(RpmUnit, **kwargs)


def get_srpm_unit(**kwargs):
kwargs["content_type_id"] = "srpm"
kwargs["arch"] = "src"
return _get_test_unit(RpmUnit, **kwargs)


def get_modulemd_unit(**kwargs):
return _get_test_unit(ModulemdUnit, **kwargs)


def get_modulemd_defaults_unit(**kwargs):
return _get_test_unit(ModulemdDefaultsUnit, **kwargs)


@pytest.fixture(name="pulp")
def fake_pulp():
yield FakeController()
76 changes: 66 additions & 10 deletions tests/test_matcher.py
Expand Up @@ -6,8 +6,8 @@
RpmUnit,
Criteria,
YumRepository,
FakeController,
ModulemdUnit,
ModulemdDefaultsUnit,
)
from ubiconfig import UbiConfig

Expand All @@ -22,11 +22,6 @@
from ubipop._utils import vercmp_sort


@pytest.fixture(name="pulp")
def fake_pulp():
yield FakeController()


@pytest.fixture(name="ubi_config")
def fake_ubi_config():
config_dict = {
Expand Down Expand Up @@ -206,7 +201,7 @@ def test_search_rpms(pulp):
matcher = Matcher(None, None)
criteria = matcher._create_or_criteria(["filename"], [("test.x86_64.rpm",)])
# let Future return result
result = matcher._search_rpms(criteria, [repo]).result()
result = matcher.search_rpms(criteria, [repo]).result()
# there should be be only one unit in the result set according to criteria
assert len(result) == 1
assert result.pop().filename == "test.x86_64.rpm"
Expand Down Expand Up @@ -241,7 +236,7 @@ def test_search_srpms(pulp):
matcher = Matcher(None, None)
criteria = matcher._create_or_criteria(["filename"], [("test.src.rpm",)])
# let Future return result
result = matcher._search_srpms(criteria, [repo]).result()
result = matcher.search_srpms(criteria, [repo]).result()
# there should be be only one unit in the result set according to criteria
assert len(result) == 1
assert result.pop().filename == "test.src.rpm"
Expand Down Expand Up @@ -274,12 +269,43 @@ def test_search_moludemds(pulp):
matcher = Matcher(None, None)
criteria = matcher._create_or_criteria(["name", "stream"], [("test", "10")])
# let Future return result
result = matcher._search_moludemds(criteria, [repo]).result()
result = matcher.search_modulemds(criteria, [repo]).result()
# there should be be only one unit in the result set according to criteria
assert len(result) == 1
assert result.pop().nsvca == "test:10:100:abcdef:x86_64"


def test_search_moludemd_defaults(pulp):
"""Test convenient method for searching modulemd_defaults"""
repo = YumRepository(
id="test_repo_1",
)
repo.__dict__["_client"] = pulp.client
unit_1 = ModulemdDefaultsUnit(
name="test",
stream="10",
repo_id="test_repo_1",
)
unit_2 = ModulemdDefaultsUnit(
name="test",
stream="20",
repo_id="test_repo_1",
)

pulp.insert_repository(repo)
pulp.insert_units(repo, [unit_1, unit_2])

matcher = Matcher(None, None)
criteria = matcher._create_or_criteria(["name", "stream"], [("test", "10")])
# let Future return result
result = matcher.search_modulemd_defaults(criteria, [repo]).result()
# there should be be only one unit in the result set according to criteria
assert len(result) == 1
found_unit = result.pop()
assert found_unit.name == "test"
assert found_unit.stream == "10"


def test_modular_rpms_filenames(ubi_config):
"""Test getting filename from module artifacts, srpms are skipped."""
matcher = ModularMatcher(None, ubi_config.modules)
Expand Down Expand Up @@ -490,6 +516,25 @@ def test_get_modulemds_criteria(ubi_config):
# let's not test internal structure of criteria, that's responsibility of pulplib


def test_get_modulemd_defaults_criteria():
"""Test proper creation of criteria for modulemd_defaults query"""
matcher = ModularMatcher(None, None)
unit = UbiUnit(
ModulemdUnit(
name="test", stream="10", version=100, context="abcd", arch="x86_64"
),
None,
)
matcher.modules = [unit]
criteria = matcher._get_modulemd_defaults_criteria()
# there should be 1 criterium created based on modules list of Matcher obj.
assert len(criteria) == 1
# it should be instance of Criteria
for crit in criteria:
assert isinstance(crit, Criteria)
# let's not test internal structure of criteria, that's responsibility of pulplib


def test_get_modular_srpms_criteria(ubi_config):
"""Testing creation of criteria for srpms query"""
matcher = ModularMatcher(None, ubi_config.modules)
Expand Down Expand Up @@ -614,10 +659,16 @@ def test_modular_matcher_run(pulp, ubi_config):
"test-7:1.0-1.x86_64.src",
],
)

modulemd_defaults = ModulemdDefaultsUnit(
name="fake_name",
stream="fake_stream",
repo_id="binary_repo",
)
pulp.insert_repository(repo_1)
pulp.insert_repository(repo_2)
pulp.insert_repository(repo_3)
pulp.insert_units(repo_1, [unit_1, modulemd])
pulp.insert_units(repo_1, [unit_1, modulemd, modulemd_defaults])
pulp.insert_units(repo_2, [unit_2])
pulp.insert_units(repo_3, [unit_3])

Expand All @@ -627,6 +678,7 @@ def test_modular_matcher_run(pulp, ubi_config):

# each public attribute is properly set with one unit
assert len(matcher.modules) == 1
assert len(matcher.modulemd_defaults) == 1
assert len(matcher.binary_rpms) == 1
assert len(matcher.debug_rpms) == 1
assert len(matcher.source_rpms) == 1
Expand All @@ -636,6 +688,10 @@ def test_modular_matcher_run(pulp, ubi_config):
assert output_module.nsvca == "fake_name:fake_stream:100:abcd:x86_64"
assert output_module.associate_source_repo_id == "binary_repo"

output_modulemd_defaults = matcher.modulemd_defaults.pop()
assert output_modulemd_defaults.name == "fake_name"
assert output_modulemd_defaults.stream == "fake_stream"

rpm = matcher.binary_rpms.pop()
assert rpm.filename == "test-1.0-1.x86_64.x86_64.rpm"
assert rpm.associate_source_repo_id == "binary_repo"
Expand Down

0 comments on commit a8fae6e

Please sign in to comment.