diff --git a/repos/system_upgrade/common/libraries/rpms.py b/repos/system_upgrade/common/libraries/rpms.py index 0676799e8e..e1f3eae755 100644 --- a/repos/system_upgrade/common/libraries/rpms.py +++ b/repos/system_upgrade/common/libraries/rpms.py @@ -4,6 +4,13 @@ class LeappComponents(object): + """ + Supported component values to be used with get_packages_function: + * FRAMEWORK - the leapp project + * REPOSITORY - the leapp-repository project + * COCKPIT - the cockpit-leapp project + * TOOLS - miscelaneous tooling like snactor + """ FRAMEWORK = 'framework' REPOSITORY = 'repository' COCKPIT = 'cockpit' @@ -147,39 +154,40 @@ def check_file_modification(config): return _parse_config_modification(output, config) -def get_leapp_packages(source_version=None, component=None, include_deps=False): +def get_leapp_packages(major_version=None, component=None, include_deps=False): """ Get list of leapp packages. - :param source_version: a list or string specifying source_versions. If not defined then all packages - for current source_target_version will be returned. - :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. + :param major_version: a list or string specifying major_versions. If not defined then current + system_version will be used. + :param component: a list of or a single enum value specifying leapp components + (use enum :class: LeappComponents) If defined then only packages related to the specific + component(s) will be returned. + :param include_deps: a flag to control whether deps meta packages are to be included. + :raises ValueError: if a requested component or major_version doesn't exist. """ res = set() - source_versions = [source_version] if isinstance(source_version, str) else source_version - if not source_versions: - # No source_version of interest specified -> treat as if only current source system version + major_versions = [major_version] if isinstance(major_version, str) else major_version + if not major_versions: + # No major_version of interest specified -> treat as if only current source system version # requested - source_versions = [get_source_major_version()] + major_versions = [get_source_major_version()] components = [component] if isinstance(component, str) else component if not component: # No component of interest specified -> return default leapp components components = _LEAPP_DEFAULT_COMPONENTS for comp in components: - for src_version in source_versions: + for major_version in major_versions: 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())) + if major_version not in _LEAPP_PACKAGES_MAP[comp]: + error_msg = "The requested major_version {ver} is unknown, available choices are {choices}".format( + ver=major_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', [])) + res.update(_LEAPP_PACKAGES_MAP[comp][major_version].get('pkgs', [])) if include_deps: - res.update(_LEAPP_PACKAGES_MAP[comp][src_version].get('deps', [])) + res.update(_LEAPP_PACKAGES_MAP[comp][major_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 d09e40bdd1..bb67d84ef6 100644 --- a/repos/system_upgrade/common/libraries/tests/test_rpms.py +++ b/repos/system_upgrade/common/libraries/tests/test_rpms.py @@ -36,7 +36,7 @@ def test_parse_config_modification(): assert _parse_config_modification(data, "/etc/ssh/sshd_config") -@pytest.mark.parametrize('source_version,component,include_deps,result', [ +@pytest.mark.parametrize('major_version,component,include_deps,result', [ (None, None, False, ['leapp', 'python3-leapp', 'leapp-upgrade-el8toel9', 'snactor']), (None, None, True, ['leapp', 'leapp-deps', 'python3-leapp', 'leapp-upgrade-el8toel9', 'leapp-upgrade-el8toel9-deps', 'snactor']), @@ -44,20 +44,20 @@ def test_parse_config_modification(): (['7', '8'], None, False, ['leapp', 'python2-leapp', 'leapp-upgrade-el7toel8', 'python3-leapp', 'leapp-upgrade-el8toel9', 'snactor']), ('nosuchversion', None, False, - (ValueError, r"source_version nosuchversion is unknown, available choices are \['7', '8']")), + (ValueError, r"major_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, (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): +def test_get_leapp_packages(major_version, component, include_deps, result, monkeypatch): monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='8.9', dst_ver='9.3')) if isinstance(result, list): - assert set(get_leapp_packages(source_version, component, include_deps)) == set(result) + assert set(get_leapp_packages(major_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) + get_leapp_packages(major_version, component, include_deps) assert err.match(exc_msg)