Skip to content

Commit

Permalink
Introduce rpms.get_leapp_packages library function
Browse files Browse the repository at this point in the history
This function can be used as leapp-installation-packages-getter.
Refactoring of other actors using it will be done later.
  • Loading branch information
fernflower committed Dec 14, 2023
1 parent 677e5e6 commit 9de7543
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
34 changes: 34 additions & 0 deletions repos/system_upgrade/common/libraries/rpms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from leapp.libraries import stdlib
from leapp.libraries.common.config.version import get_source_major_version
from leapp.models import InstalledRPM


Expand Down Expand Up @@ -114,3 +115,36 @@ def check_file_modification(config):
"""
output = _read_rpm_modifications(config)
return _parse_config_modification(output, config)


def get_leapp_packages(source_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.
"""
res = set()
# NOTE(ivasilev) mapping has the format component: {source_version: [pkg1, pkg2, ..]}
component_map = {'framework': {'7': ['leapp', 'leapp-deps', 'python2-leapp'],
'8': ['leapp', 'leapp-deps', 'python3-leapp']},
'repository': {'7': ['leapp-upgrade-el7toel8', 'leapp-upgrade-el7toel8-deps'],
'8': ['leapp-upgrade-el8toel9', 'leapp-upgrade-el8toel9-deps']},
'snactor': {'7': ['snactor'],
'8': ['snactor']}}
source_versions = [source_version] if isinstance(source_version, str) else (source_version or
[get_source_major_version()])
components = [component] if isinstance(component, str) else component or list(component_map.keys())
for comp in components:
for src_version in source_versions:
try:
res.update(component_map[comp][src_version])
except KeyError:
continue
if not include_deps:
# filter out deps packages
return sorted([pkg for pkg in res if not pkg.endswith('-deps')])
return sorted(res)
23 changes: 22 additions & 1 deletion repos/system_upgrade/common/libraries/tests/test_rpms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from leapp.libraries.common.rpms import _parse_config_modification
import pytest

from leapp.libraries.common.rpms import _parse_config_modification, get_leapp_packages
from leapp.libraries.common.testutils import CurrentActorMocked
from leapp.libraries.stdlib import api


def test_parse_config_modification():
Expand Down Expand Up @@ -30,3 +34,20 @@ def test_parse_config_modification():
"S.5....T. c /etc/ssh/sshd_config",
]
assert _parse_config_modification(data, "/etc/ssh/sshd_config")


@pytest.mark.parametrize('source_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']),
('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, []),
('8', 'framework', False, ['leapp', 'python3-leapp']),
('8', 'framework', True, ['leapp', 'python3-leapp', 'leapp-deps']),
('8', 'nosuchcomponent', True, []),
])
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)

0 comments on commit 9de7543

Please sign in to comment.