Skip to content

Commit

Permalink
Fix some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JayZ12138 committed Oct 17, 2019
1 parent c6fcb65 commit e337496
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions tests/test_pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def fixture_mock_repo():
arch="x86_64",
content_set="test_repo-source-rpms",
platform_full_version="7",
ubi_config_version="7",
dist_ids_type_ids=[
("dist_id_1", "dist_type_id_1"),
("dist_id_2", "dist_type_id_2"),
Expand Down
14 changes: 10 additions & 4 deletions tests/test_ubipop.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,15 +727,18 @@ def test_ubi_repo_set(rhel_repo_set, ubi_repo_set, fail, caplog):
@pytest.fixture(name='mocked_ubiconfig_load')
def fixture_mocked_ubiconfig_load():
with patch('ubiconfig.get_loader') as get_loader:
get_loader.return_value.load.return_value = "test"
m = MagicMock()
m.file_name = "test"
m.version = "7.7"
get_loader.return_value.load.return_value = m
yield get_loader


def test_ubipopulate_load_ubiconfig(mocked_ubiconfig_load):
# pylint: disable=unused-argument
ubipop = UbiPopulate("foo.pulp.com", ('foo', 'foo'), False, ['cfg.yaml'])
assert len(ubipop.ubiconfig_list) == 1
assert ubipop.ubiconfig_list[0] == "test"
assert ubipop.ubiconfig_list[0].file_name == "test"


def test_load_ubiconfig_by_content_set_labels():
Expand All @@ -761,15 +764,18 @@ def test_load_ubiconfig_by_repo_ids(mocked_search_repo_by_id):
@pytest.fixture(name='mocked_ubiconfig_load_all')
def fixture_mocked_ubiconfig_load_all():
with patch('ubiconfig.get_loader') as get_loader:
get_loader.return_value.load_all.return_value = ["test"]
m = MagicMock()
m.file_name = "test"
m.version = "7.7"
get_loader.return_value.load_all.return_value = [m]
yield get_loader


def test_ubipopulate_load_all_ubiconfig(mocked_ubiconfig_load_all):
# pylint: disable=unused-argument
ubipop = UbiPopulate("foo.pulp.com", ('foo', 'foo'), False)
assert len(ubipop.ubiconfig_list) == 1
assert ubipop.ubiconfig_list[0] == "test"
assert ubipop.ubiconfig_list[0].file_name == "test"


def test_create_srpms_output_set(mock_ubipop_runner):
Expand Down
12 changes: 6 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

def test_raise_not_implemented_pulp_action():
units = ["unit1", "unit2"]
repo = Repo("test", "1", "test-rpms", "2", None, None)
repo = Repo("test", "1", "test-rpms", "2", "2", None, None)
action = PulpAction(units, repo)
pytest.raises(NotImplementedError, action.get_action, None)


def test_raise_not_implemented_associate_action():
units = ["unit1", "unit2"]
repo = Repo("test", "1", "test-rpms", "2", None, None)
src_repo = Repo("test", "1", "test-rpms", "2", None, None)
repo = Repo("test", "1", "test-rpms", "2", "2", None, None)
src_repo = Repo("test", "1", "test-rpms", "2", "2", None, None)
action = AssociateAction(units, repo, src_repo)
pytest.raises(NotImplementedError, action.get_action, None)

Expand All @@ -36,8 +36,8 @@ def test_raise_not_implemented_associate_action():
])
def test_get_action_associate(klass, method):
units = ["unit1", "unit2"]
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", None, None)
src_repo = Repo("test_src", "1", "test_src-rpms", "2", None, None)
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", "2", None, None)
src_repo = Repo("test_src", "1", "test_src-rpms", "2", "2", None, None)
action = klass(units, dst_repo, src_repo)
associate_action, src_repo_current, dst_repo_current, current_units = \
action.get_action(MagicMock())
Expand All @@ -55,7 +55,7 @@ def test_get_action_associate(klass, method):
])
def test_get_action_unassociate(klass, method):
units = ["unit1", "unit2"]
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", None, None)
dst_repo = Repo("test_dst", "1", "test_dst-rpms", "2", "2", None, None)
action = klass(units, dst_repo)
associate_action, dst_repo_current, current_units = action.get_action(MagicMock())

Expand Down
33 changes: 25 additions & 8 deletions ubipop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class RepoMissing(Exception):
pass


class ConfigMissing(Exception):
pass


RepoSet = namedtuple('RepoSet', ['rpm', 'source', 'debug'])


Expand Down Expand Up @@ -154,7 +158,7 @@ def _create_config_map(self):
config_map = {}
for config in self.ubiconfig_list:
config_map.setdefault(config.version, {})\
.setdefault(config.filename, config)
.setdefault(config.file_name, config)

return config_map

Expand All @@ -175,7 +179,7 @@ def populate_ubi_repos(self):
for cs in to_use:
used_content_sets.add(cs)
else:
_LOG.debug("Skipping %s, since it's been used already", config.filename)
_LOG.debug("Skipping %s, since it's been used already", config.file_name)
continue

try:
Expand All @@ -189,13 +193,26 @@ def populate_ubi_repos(self):
platform_full_version = repo_set.out_repos.rpm.platform_full_version
# get the right config file by ubi_config_version attr, if it's None,
# then it's not a mainline repo, use platform_full_version instead.
# config file could also be missing for specific version, then the
# default config file will be used.
version = ubi_config_version or platform_full_version
right_config = self.ubiconfig_map.get(version, {}).get(config.filename)
# right_config could be None, because the config file for specific version
# might not available, then fall back to use the default config file.
if right_config is None:
right_config = self.ubiconfig_map.get(platform_full_version, {})\
.get(config.filename)
right_config = self.ubiconfig_map\
.get(version, {})\
.get(config.file_name)\
or self.ubiconfig_map\
.get(platform_full_version, {})\
.get(config.file_name)

# if config file is missing from wanted version, as well as default
# branch, raise exception
if not right_config:
_LOG.error(
'Config file %s missing from %s and default %s branches',
config.file_name,
version,
platform_full_version,
)
raise ConfigMissing()

UbiPopulateRunner(self.pulp, repo_set, right_config, self.dry_run,
self._executor).run_ubi_population()
Expand Down

0 comments on commit e337496

Please sign in to comment.