forked from rpms/leapp-repository
124 lines
5.4 KiB
Diff
124 lines
5.4 KiB
Diff
From 09ef3dee08656058d9ac4b9c69d6848b2eae6dfb Mon Sep 17 00:00:00 2001
|
|
From: Michal Hecko <mhecko@redhat.com>
|
|
Date: Mon, 31 Mar 2025 09:56:58 +0200
|
|
Subject: [PATCH 18/37] libs(version): use supported_upgrade_paths
|
|
|
|
Refactor the config.version library to use actor.configuration to obtain
|
|
the list of supported upgrade paths instead of having its own (duplicit)
|
|
definitions.
|
|
|
|
Mark leapp.libraries.common.config.version.SUPPORTED_VERSIONS as
|
|
deprecated and update the documentation.
|
|
|
|
Jira-ref: RHEL-80550
|
|
---
|
|
.../libraries-and-api/deprecations-list.md | 3 +-
|
|
.../libraries/config/tests/test_version.py | 28 +++++++++----------
|
|
.../common/libraries/config/version.py | 23 +++++++++------
|
|
3 files changed, 31 insertions(+), 23 deletions(-)
|
|
|
|
diff --git a/docs/source/libraries-and-api/deprecations-list.md b/docs/source/libraries-and-api/deprecations-list.md
|
|
index 07cbf1d6..c8489af3 100644
|
|
--- a/docs/source/libraries-and-api/deprecations-list.md
|
|
+++ b/docs/source/libraries-and-api/deprecations-list.md
|
|
@@ -14,7 +14,8 @@ Only the versions in which a deprecation has been made are listed.
|
|
|
|
## Next release <span style="font-size:0.5em; font-weight:normal">(till TODO date)</span>
|
|
|
|
-- No new deprecation yet
|
|
+- Shared libraries
|
|
+ - **`leapp.libraries.common.config.version.SUPPORTED_VERSIONS`** - The `SUPPORTED_VERSIONS` dict has been deprecated as it is problematic with the new design. Use `leapp.libraries.common.config.version.is_supported_version()` or `IPUConfig.supported_upgrade_paths` instead.
|
|
|
|
## v0.20.0 <span style="font-size:0.5em; font-weight:normal">(till September 2024)</span>
|
|
- Models
|
|
diff --git a/repos/system_upgrade/common/libraries/config/tests/test_version.py b/repos/system_upgrade/common/libraries/config/tests/test_version.py
|
|
index 303e4de5..37a91c00 100644
|
|
--- a/repos/system_upgrade/common/libraries/config/tests/test_version.py
|
|
+++ b/repos/system_upgrade/common/libraries/config/tests/test_version.py
|
|
@@ -3,6 +3,7 @@ import pytest
|
|
from leapp.libraries.common.config import version
|
|
from leapp.libraries.common.testutils import CurrentActorMocked
|
|
from leapp.libraries.stdlib import api
|
|
+from leapp.models import IPUSourceToPossibleTargets
|
|
from leapp.utils.deprecation import suppress_deprecation
|
|
|
|
|
|
@@ -92,21 +93,20 @@ def test_is_rhel_alt(monkeypatch, result, kernel, release_id, src_ver):
|
|
assert version.is_rhel_alt() == result
|
|
|
|
|
|
-@pytest.mark.parametrize('result,is_alt,src_ver,saphana', [
|
|
- (True, True, '7.6', False),
|
|
- (True, False, '7.8', False),
|
|
- (False, True, '7.8', False),
|
|
- (False, False, '7.6', False),
|
|
- (True, True, '7.6', True),
|
|
- (True, False, '7.7', True),
|
|
- (False, True, '7.7', True),
|
|
- (False, False, '7.6', True),
|
|
+@pytest.mark.parametrize('result,src_ver,is_saphana', [
|
|
+ (True, '7.8', False), # default rhel
|
|
+ (False, '7.6', False),
|
|
+ (True, '7.7', True), # saphana
|
|
+ (False, '7.6', True),
|
|
])
|
|
-def test_is_supported_version(monkeypatch, result, is_alt, src_ver, saphana):
|
|
- monkeypatch.setattr(version, 'is_rhel_alt', lambda: is_alt)
|
|
- monkeypatch.setattr(version, 'is_sap_hana_flavour', lambda: saphana)
|
|
- monkeypatch.setattr(version, 'SUPPORTED_VERSIONS', {'rhel': ['7.8'], 'rhel-alt': ['7.6'], 'rhel-saphana': ['7.7']})
|
|
- monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(src_ver=src_ver))
|
|
+def test_is_supported_version(monkeypatch, result, src_ver, is_saphana):
|
|
+ if is_saphana:
|
|
+ supported_upgrade_paths = [IPUSourceToPossibleTargets(source_version='7.7', target_versions=['8.10'])]
|
|
+ else:
|
|
+ supported_upgrade_paths = [IPUSourceToPossibleTargets(source_version='7.8', target_versions=['8.10'])]
|
|
+
|
|
+ actor_mock = CurrentActorMocked(src_ver=src_ver, supported_upgrade_paths=supported_upgrade_paths)
|
|
+ monkeypatch.setattr(api, 'current_actor', actor_mock)
|
|
assert version.is_supported_version() == result
|
|
|
|
|
|
diff --git a/repos/system_upgrade/common/libraries/config/version.py b/repos/system_upgrade/common/libraries/config/version.py
|
|
index febeed36..b8fc550b 100644
|
|
--- a/repos/system_upgrade/common/libraries/config/version.py
|
|
+++ b/repos/system_upgrade/common/libraries/config/version.py
|
|
@@ -126,6 +126,12 @@ class _SupportedVersionsDict(dict):
|
|
|
|
|
|
SUPPORTED_VERSIONS = _SupportedVersionsDict()
|
|
+"""
|
|
+Deprecated since 2025-03-31.
|
|
+
|
|
+Use is_supported_version(), or IPUConfig.supported_upgrade_paths to check what source
|
|
+versions are supported for the current (release, flavour).
|
|
+"""
|
|
|
|
|
|
def _version_to_tuple(version):
|
|
@@ -319,13 +325,14 @@ def is_supported_version():
|
|
:return: `True` if the current version is supported and `False` otherwise.
|
|
:rtype: bool
|
|
"""
|
|
- release_id, version_id = current_version()
|
|
- if is_rhel_alt():
|
|
- release_id = 'rhel-alt'
|
|
- elif is_sap_hana_flavour():
|
|
- release_id = 'rhel-saphana'
|
|
+ source_version = get_source_version()
|
|
+ supported_upgrade_paths = api.current_actor().configuration.supported_upgrade_paths
|
|
|
|
- if not matches_release(SUPPORTED_VERSIONS, release_id):
|
|
- return False
|
|
+ # Check if there are any paths defined from the current source_version. If not,
|
|
+ # the upgrade version is unsupported
|
|
+ for ipu_source_to_targets in supported_upgrade_paths:
|
|
+ # No need to use matches_version - our version list is always a singleton
|
|
+ if ipu_source_to_targets.source_version == source_version:
|
|
+ return True
|
|
|
|
- return matches_version(SUPPORTED_VERSIONS[release_id], version_id)
|
|
+ return False
|
|
--
|
|
2.49.0
|
|
|