From 4432e62f02af820d040f45d7fc59296cf734bdc5 Mon Sep 17 00:00:00 2001 From: Michal Hecko Date: Sat, 29 Mar 2025 22:00:38 +0100 Subject: [PATCH 17/37] cleanup(ipupaths): remove IPUPaths message Drop the already deprecated IPUPaths message that was used to inform actors about supported upgrade paths. Instead, the functionality has been assumed by IPUConfig. Jira-ref: RHEL-80550 --- .../common/actors/checktargetversion/actor.py | 3 +- .../libraries/checktargetversion.py | 15 +-- .../tests/test_checktargetversion.py | 27 +++--- .../actors/scandefinedipupaths/actor.py | 31 ------ .../libraries/scandefinedipupaths.py | 43 -------- .../tests/files/upgrade_paths.json | 22 ----- .../tests/test_scandefinedipupaths.py | 97 ------------------- .../system_upgrade/common/models/ipupaths.py | 43 -------- 8 files changed, 17 insertions(+), 264 deletions(-) delete mode 100644 repos/system_upgrade/common/actors/scandefinedipupaths/actor.py delete mode 100644 repos/system_upgrade/common/actors/scandefinedipupaths/libraries/scandefinedipupaths.py delete mode 100644 repos/system_upgrade/common/actors/scandefinedipupaths/tests/files/upgrade_paths.json delete mode 100644 repos/system_upgrade/common/actors/scandefinedipupaths/tests/test_scandefinedipupaths.py delete mode 100644 repos/system_upgrade/common/models/ipupaths.py diff --git a/repos/system_upgrade/common/actors/checktargetversion/actor.py b/repos/system_upgrade/common/actors/checktargetversion/actor.py index 291ce3da..31375bfc 100644 --- a/repos/system_upgrade/common/actors/checktargetversion/actor.py +++ b/repos/system_upgrade/common/actors/checktargetversion/actor.py @@ -1,6 +1,5 @@ from leapp.actors import Actor from leapp.libraries.actor import checktargetversion -from leapp.models import IPUPaths from leapp.reporting import Report from leapp.tags import ChecksPhaseTag, IPUWorkflowTag @@ -14,7 +13,7 @@ class CheckTargetVersion(Actor): """ name = 'check_target_version' - consumes = (IPUPaths,) + consumes = () produces = (Report,) tags = (ChecksPhaseTag, IPUWorkflowTag) diff --git a/repos/system_upgrade/common/actors/checktargetversion/libraries/checktargetversion.py b/repos/system_upgrade/common/actors/checktargetversion/libraries/checktargetversion.py index 0df1ece2..2369ae11 100644 --- a/repos/system_upgrade/common/actors/checktargetversion/libraries/checktargetversion.py +++ b/repos/system_upgrade/common/actors/checktargetversion/libraries/checktargetversion.py @@ -1,22 +1,15 @@ from leapp import reporting -from leapp.exceptions import StopActorExecutionError from leapp.libraries.common.config import get_env, version from leapp.libraries.stdlib import api -from leapp.models import IPUPaths -from leapp.utils.deprecation import suppress_deprecation FMT_LIST_SEPARATOR = '\n - ' -@suppress_deprecation(IPUPaths) def get_supported_target_versions(): - ipu_paths = next(api.consume(IPUPaths), None) src_version = version.get_source_version() - if not ipu_paths: - # NOTE: missing unit-tests. Unexpected situation and the solution - # is possibly temporary - raise StopActorExecutionError('Missing the IPUPaths message. Cannot determine defined upgrade paths.') - for ipu_path in ipu_paths.data: + supported_paths = api.current_actor().configuration.supported_upgrade_paths + + for ipu_path in supported_paths: if ipu_path.source_version == src_version: return ipu_path.target_versions @@ -28,7 +21,7 @@ def get_supported_target_versions(): .format(src_version) ) maj_version = version.get_source_major_version() - for ipu_path in ipu_paths.data: + for ipu_path in supported_paths: if ipu_path.source_version == maj_version: return ipu_path.target_versions diff --git a/repos/system_upgrade/common/actors/checktargetversion/tests/test_checktargetversion.py b/repos/system_upgrade/common/actors/checktargetversion/tests/test_checktargetversion.py index 07391e7a..6927af23 100644 --- a/repos/system_upgrade/common/actors/checktargetversion/tests/test_checktargetversion.py +++ b/repos/system_upgrade/common/actors/checktargetversion/tests/test_checktargetversion.py @@ -4,36 +4,33 @@ import pytest from leapp import reporting from leapp.libraries.actor import checktargetversion +from leapp.libraries.common.config import architecture from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, logger_mocked from leapp.libraries.stdlib import api -from leapp.models import IPUPath, IPUPaths +from leapp.models import IPUSourceToPossibleTargets from leapp.utils.deprecation import suppress_deprecation from leapp.utils.report import is_inhibitor -# It must be in a function so we can suppress the deprecation warning in tests. -@suppress_deprecation(IPUPaths) -def _get_upgrade_paths_data(): - return IPUPaths(data=[ - IPUPath(source_version='7.9', target_versions=['8.10']), - IPUPath(source_version='8.10', target_versions=['9.4', '9.5', '9.6']), - IPUPath(source_version='9.6', target_versions=['10.0']), - IPUPath(source_version='7', target_versions=['8.10']), - IPUPath(source_version='8', target_versions=['9.4', '9.5', '9.6']), - IPUPath(source_version='9', target_versions=['10.0']) - ]) - - @pytest.fixture def setup_monkeypatch(monkeypatch): """Fixture to set up common monkeypatches.""" def _setup(source_version, target_version, leapp_unsupported='0'): + suppoted_upgrade_paths = [ + IPUSourceToPossibleTargets(source_version='7.9', target_versions=['8.10']), + IPUSourceToPossibleTargets(source_version='8.10', target_versions=['9.4', '9.5', '9.6']), + IPUSourceToPossibleTargets(source_version='9.6', target_versions=['10.0']), + IPUSourceToPossibleTargets(source_version='7', target_versions=['8.10']), + IPUSourceToPossibleTargets(source_version='8', target_versions=['9.4', '9.5', '9.6']), + IPUSourceToPossibleTargets(source_version='9', target_versions=['10.0']) + ] + curr_actor_mocked = CurrentActorMocked( src_ver=source_version, dst_ver=target_version, envars={'LEAPP_UNSUPPORTED': leapp_unsupported}, - msgs=[_get_upgrade_paths_data()] + supported_upgrade_paths=suppoted_upgrade_paths ) monkeypatch.setattr(api, 'current_actor', curr_actor_mocked) monkeypatch.setattr(api, 'current_logger', logger_mocked()) diff --git a/repos/system_upgrade/common/actors/scandefinedipupaths/actor.py b/repos/system_upgrade/common/actors/scandefinedipupaths/actor.py deleted file mode 100644 index a84c85f2..00000000 --- a/repos/system_upgrade/common/actors/scandefinedipupaths/actor.py +++ /dev/null @@ -1,31 +0,0 @@ -from leapp.actors import Actor -from leapp.libraries.actor import scandefinedipupaths -from leapp.models import IPUPaths -from leapp.tags import FactsPhaseTag, IPUWorkflowTag - - -class ScanDefinedIPUPaths(Actor): - """ - Load defined IPU paths for the current major source system version - and defined upgrade flavour. - - The upgrade paths are defined inside `files/upgrade_paths.json`. - Based on the defined upgrade flavour (default, saphana, ..) loads particular - definitions and filter out all upgrade paths from other system major versions. - I.e. for RHEL 8.10 system with the default upgrade flavour, load all upgrade - paths from any RHEL 8 system defined under the 'default' flavour. - - The code is mostly taken from the CLI command_utils. The duplicate solution - is not so problematic now as it will be unified next time. - - Note the deprecation suppression is expected here as this is considered as - temporary solution now. - """ - - name = 'scan_defined_ipu_paths' - consumes = () - produces = (IPUPaths,) - tags = (IPUWorkflowTag, FactsPhaseTag) - - def process(self): - scandefinedipupaths.process() diff --git a/repos/system_upgrade/common/actors/scandefinedipupaths/libraries/scandefinedipupaths.py b/repos/system_upgrade/common/actors/scandefinedipupaths/libraries/scandefinedipupaths.py deleted file mode 100644 index 1e39f2c8..00000000 --- a/repos/system_upgrade/common/actors/scandefinedipupaths/libraries/scandefinedipupaths.py +++ /dev/null @@ -1,43 +0,0 @@ -import json - -from leapp.libraries.common.config.version import get_source_major_version -from leapp.libraries.stdlib import api -from leapp.models import IPUPath, IPUPaths -from leapp.utils.deprecation import suppress_deprecation - - -def load_ipu_paths_for_flavour(flavour, _filename='upgrade_paths.json'): - """ - Load defined IPU paths from the upgrade_paths.json file for the specified - flavour. - - Note the file is required to be always present, so skipping any test - for the missing file. Crash hard and terribly if the file is missing - or the content is invalid. - - We expect the flavour to be always good as it is under our control - (already sanitized in IPUConfig), but return empty dict and log it if missing. - """ - with open(api.get_common_file_path(_filename)) as fp: - data = json.loads(fp.read()) - if flavour not in data: - api.current_logger().warning( - 'Cannot discover any upgrade paths for flavour: {}' - .format(flavour) - ) - return data.get(flavour, {}) - - -def get_filtered_ipu_paths(ipu_paths, src_major_version): - result = [] - for src_version, tgt_versions in ipu_paths.items(): - if src_version.split('.')[0] == src_major_version: - result.append(IPUPath(source_version=src_version, target_versions=tgt_versions)) - return result - - -@suppress_deprecation(IPUPaths) -def process(): - flavour = api.current_actor().configuration.flavour - ipu_paths = load_ipu_paths_for_flavour(flavour) - api.produce(IPUPaths(data=get_filtered_ipu_paths(ipu_paths, get_source_major_version()))) diff --git a/repos/system_upgrade/common/actors/scandefinedipupaths/tests/files/upgrade_paths.json b/repos/system_upgrade/common/actors/scandefinedipupaths/tests/files/upgrade_paths.json deleted file mode 100644 index b6107376..00000000 --- a/repos/system_upgrade/common/actors/scandefinedipupaths/tests/files/upgrade_paths.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "rhel": { - "default": { - "8.10": ["9.4", "9.5", "9.6"], - "8.4": ["9.2"], - "9.6": ["10.0"], - "8": ["9.4", "9.5", "9.6"], - "9": ["10.0"] - }, - "saphana": { - "8.10": ["9.6", "9.4"], - "8": ["9.6", "9.4"], - "9.6": ["10.0"], - "9": ["10.0"] - } - }, - "centos": { - "default": { - "8": ["9"] - } - } -} diff --git a/repos/system_upgrade/common/actors/scandefinedipupaths/tests/test_scandefinedipupaths.py b/repos/system_upgrade/common/actors/scandefinedipupaths/tests/test_scandefinedipupaths.py deleted file mode 100644 index 9ffc9829..00000000 --- a/repos/system_upgrade/common/actors/scandefinedipupaths/tests/test_scandefinedipupaths.py +++ /dev/null @@ -1,97 +0,0 @@ -import json -import os - -import pytest - -from leapp.libraries.actor import scandefinedipupaths -from leapp.libraries.common.testutils import CurrentActorMocked, produce_mocked -from leapp.models import IPUPath, IPUPaths -from leapp.utils.deprecation import suppress_deprecation - -CUR_DIR = os.path.dirname(os.path.abspath(__file__)) - - -class CurrentActorMockedModified(CurrentActorMocked): - def get_common_file_path(self, fname): - fpath = os.path.join(CUR_DIR, 'files', fname) - assert os.path.exists(fpath) - if os.path.exists(fpath): - return fpath - return None - - -@pytest.mark.parametrize(('flavour', 'expected_result'), ( - ('nonsense', {}), - ( - 'default', - { - '8.10': ['9.4', '9.5', '9.6'], - '8.4': ['9.2'], - '9.6': ['10.0'], - '8': ['9.4', '9.5', '9.6'], - '9': ['10.0'] - } - ), - ( - 'saphana', - { - '8.10': ['9.6', '9.4'], - '8': ['9.6', '9.4'], - '9.6': ['10.0'], - '9': ['10.0'] - } - ), -)) -def test_load_ipu_paths_for_flavour(monkeypatch, flavour, expected_result): - monkeypatch.setattr(scandefinedipupaths.api, 'current_actor', CurrentActorMockedModified()) - - result = scandefinedipupaths.load_ipu_paths_for_flavour(flavour=flavour) - assert result == expected_result - - -_DATA_IPU_PATHS = { - '8.10': ['9.4', '9.5', '9.6'], - '8.4': ['9.2'], - '9.6': ['10.0'], - '8': ['9.4', '9.5', '9.6'], - '80.0': ['81.0'] -} - - -@suppress_deprecation(IPUPaths) -@pytest.mark.parametrize(('maj_version', 'expected_result'), ( - ('7', []), - ( - '8', - [ - IPUPath(source_version='8.10', target_versions=['9.4', '9.5', '9.6']), - IPUPath(source_version='8.4', target_versions=['9.2']), - IPUPath(source_version='8', target_versions=['9.4', '9.5', '9.6']), - ] - ), - ( - '80', - [ - IPUPath(source_version='80.0', target_versions=['81.0']), - ] - ), - - -)) -def test_get_filtered_ipu_paths(monkeypatch, maj_version, expected_result): - result = scandefinedipupaths.get_filtered_ipu_paths(_DATA_IPU_PATHS, maj_version) - result = sorted(result, key=lambda x: x.source_version) - assert result == sorted(expected_result, key=lambda x: x.source_version) - - -def test_scan_defined_ipu_paths(monkeypatch): - # let's try one 'full' happy run - monkeypatch.setattr(scandefinedipupaths.api, 'current_actor', CurrentActorMockedModified(src_ver='9.6')) - monkeypatch.setattr(scandefinedipupaths.api, 'produce', produce_mocked()) - scandefinedipupaths.process() - - assert scandefinedipupaths.api.produce.called == 1 - msg = scandefinedipupaths.api.produce.model_instances[0] - assert isinstance(msg, IPUPaths) - assert len(msg.data) == 2 - assert {i.source_version for i in msg.data} == {'9', '9.6'} diff --git a/repos/system_upgrade/common/models/ipupaths.py b/repos/system_upgrade/common/models/ipupaths.py deleted file mode 100644 index 5469f25e..00000000 --- a/repos/system_upgrade/common/models/ipupaths.py +++ /dev/null @@ -1,43 +0,0 @@ -from leapp.models import fields, Model -from leapp.topics import SystemInfoTopic -from leapp.utils.deprecation import deprecated - - -class IPUPath(Model): - """ - Represent upgrade paths from a source system version. - - This model is not supposed to be produced nor consumed directly by any actor. - See `IPUPaths` instead. - """ - topic = SystemInfoTopic - - source_version = fields.String() - """Version of a particular source system.""" - - target_versions = fields.List(fields.String()) - """List of defined target system versions for the `source_version` system.""" - - -@deprecated( - since="2025-02-01", - message="This model is temporary and not assumed to be used in any actors." -) -class IPUPaths(Model): - """ - Defined Upgrade paths from the source system major version and used upgrade flavour. - - In example for the RHEL 8.10 system with the 'default' upgrade flavour it will - contain information about all defined upgrade paths from any RHEL 8 system - for the 'default' flavour (other flavour can be e.g. 'saphana' for systems - with SAP HANA installed. - - Note this model is marked as deprecated now as it is considered as a temporary - solution. It can be removed in any future release! - """ - topic = SystemInfoTopic - - data = fields.List(fields.Model(IPUPath)) - """ - List of defined (filtered) upgrade paths. - """ -- 2.49.0