From 6d1a08cbbd464bcf874601d3b0a182dbc82288f0 Mon Sep 17 00:00:00 2001 From: Inessa Vasilevskaya Date: Fri, 22 Dec 2023 12:54:40 +0100 Subject: [PATCH] Resolve comments after abdger's review Addressed: - components_map made global - dependencies are specified separately for each component - ternary expressions refactored Not addressed: - if no such component/version then this is logged as warning with empty list retured (originally an exception was requested, but imho that's an overkill, let's discuss though) - no separate function for dependencies, it's still a parameter (also let's discuss) --- repos/system_upgrade/common/libraries/rpms.py | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/repos/system_upgrade/common/libraries/rpms.py b/repos/system_upgrade/common/libraries/rpms.py index faa97b3eed..8c6aa4c179 100644 --- a/repos/system_upgrade/common/libraries/rpms.py +++ b/repos/system_upgrade/common/libraries/rpms.py @@ -2,6 +2,26 @@ from leapp.libraries.common.config.version import get_source_major_version from leapp.models import InstalledRPM +LEAPP_PACKAGES_MAP = { + 'framework': {'7': {'pkgs': ['leapp', 'python2-leapp'], + 'deps': ['leapp-deps']}, + '8': {'pkgs': ['leapp', 'python3-leapp'], + 'deps': ['leapp-deps']} + }, + 'repository': {'7': {'pkgs': ['leapp-upgrade-el7toel8'], + 'deps': ['leapp-upgrade-el7toel8-deps']}, + '8': {'pkgs': ['leapp-upgrade-el8toel9'], + 'deps': ['leapp-upgrade-el8toel9-deps']} + }, + 'cockpit': {'7': {'pkgs': ['cockpit-leapp']}, + '8': {'pkgs': ['cockpit-leapp']} + }, + 'tools': {'7': {'pkgs': ['snactor']}, + '8': {'pkgs': ['snactor']} + } + } +LEAPP_DEFAULT_COMPONENTS = ['framework', 'repository', 'tools'] + def get_installed_rpms(): rpm_cmd = [ @@ -128,23 +148,24 @@ def get_leapp_packages(source_version=None, component=None, include_deps=False): :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()) + 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 + # requested + source_versions = [get_source_major_version()] + components = [component] if isinstance(component, str) else component + if not component: + # No component of interest specified -> treat as if packages for all components are requested + components = LEAPP_DEFAULT_COMPONENTS for comp in components: for src_version in source_versions: try: - res.update(component_map[comp][src_version]) + 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 not include_deps: - # filter out deps packages - return sorted([pkg for pkg in res if not pkg.endswith('-deps')]) return sorted(res)