Skip to content

Commit

Permalink
Address pstodulk and abadger's comments
Browse files Browse the repository at this point in the history
Raise exception if requested source_version or component
is not found with possible choices listed.
  • Loading branch information
fernflower committed Jan 3, 2024
1 parent 1b368da commit af3eada
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
22 changes: 13 additions & 9 deletions repos/system_upgrade/common/libraries/rpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def get_leapp_packages(source_version=None, component=None, include_deps=False):
:param component: a list or string specifying leapp components. If defined then only packages related
to the specific component will be returned.
:param include_deps: a flag to control whether deps meta packages are to be filtered out.
:raises ValueError: if a requested component or source_version doesn't exist.
"""
res = set()
source_versions = [source_version] if isinstance(source_version, str) else source_version
Expand All @@ -169,13 +170,16 @@ def get_leapp_packages(source_version=None, component=None, include_deps=False):
components = _LEAPP_DEFAULT_COMPONENTS
for comp in components:
for src_version in source_versions:
try:
res.update(_LEAPP_PACKAGES_MAP[comp][src_version].get('pkgs', []))
if include_deps:
res.update(_LEAPP_PACKAGES_MAP[comp][src_version].get('deps', []))
except KeyError:
stdlib.api.current_logger().warning(
"The requested component {comp} or source_version {ver} is unknown".format(
comp=component, ver=src_version))
continue
if comp not in _LEAPP_PACKAGES_MAP:
error_msg = "The requested component {comp} is unknown, available choices are {choices}".format(
comp=component, choices=sorted(_LEAPP_PACKAGES_MAP.keys()))
raise ValueError(error_msg)
if src_version not in _LEAPP_PACKAGES_MAP[comp]:
error_msg = "The requested source_version {ver} is unknown, available choices are {choices}".format(
ver=src_version, choices=sorted(_LEAPP_PACKAGES_MAP[comp].keys()))
raise ValueError(error_msg)
# All went well otherwise, get the data
res.update(_LEAPP_PACKAGES_MAP[comp][src_version].get('pkgs', []))
if include_deps:
res.update(_LEAPP_PACKAGES_MAP[comp][src_version].get('deps', []))
return sorted(res)
16 changes: 13 additions & 3 deletions repos/system_upgrade/common/libraries/tests/test_rpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ def test_parse_config_modification():
('7', None, False, ['leapp', 'python2-leapp', 'leapp-upgrade-el7toel8', 'snactor']),
(['7', '8'], None, False, ['leapp', 'python2-leapp', 'leapp-upgrade-el7toel8',
'python3-leapp', 'leapp-upgrade-el8toel9', 'snactor']),
('nosuchversion', None, False, []),
('nosuchversion', None, False,
(ValueError, r"source_version nosuchversion is unknown, available choices are \['7', '8']")),
('8', 'framework', False, ['leapp', 'python3-leapp']),
('8', 'framework', True, ['leapp', 'python3-leapp', 'leapp-deps']),
('8', 'nosuchcomponent', True, []),
('8', 'nosuchcomponent', True,
(ValueError,
r"component nosuchcomponent is unknown, available choices are \['cockpit', 'framework', 'repository', 'tools']")),
])
def test_get_leapp_packages(source_version, component, include_deps, result, monkeypatch):
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='8.9', dst_ver='9.3'))
assert set(get_leapp_packages(source_version, component, include_deps)) == set(result)
if isinstance(result, list):
assert set(get_leapp_packages(source_version, component, include_deps)) == set(result)
else:
# expect an exception tuple
exc_type, exc_msg = result
with pytest.raises(exc_type) as err:
get_leapp_packages(source_version, component, include_deps)
assert err.match(exc_msg)

0 comments on commit af3eada

Please sign in to comment.