diff --git a/repos/system_upgrade/common/libraries/rpms.py b/repos/system_upgrade/common/libraries/rpms.py index eebd000220..0676799e8e 100644 --- a/repos/system_upgrade/common/libraries/rpms.py +++ b/repos/system_upgrade/common/libraries/rpms.py @@ -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 @@ -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) diff --git a/repos/system_upgrade/common/libraries/tests/test_rpms.py b/repos/system_upgrade/common/libraries/tests/test_rpms.py index 744f8ba2c6..11b658cc16 100644 --- a/repos/system_upgrade/common/libraries/tests/test_rpms.py +++ b/repos/system_upgrade/common/libraries/tests/test_rpms.py @@ -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)