leapp-repository/SOURCES/0058-ipuconfig-Add-source-and-target-distros-to-config.patch
2025-12-01 09:14:24 +00:00

228 lines
9.3 KiB
Diff

From a8ed1d70bde82ad7ff35fcf02648ff246c28dd88 Mon Sep 17 00:00:00 2001
From: Matej Matuska <mmatuska@redhat.com>
Date: Fri, 12 Sep 2025 14:32:06 +0200
Subject: [PATCH 58/69] ipuconfig: Add source and target distros to config
The distros are now stored similarly to how versions are stored.
CurrentActorMocked is modified to take src_distro and dst_distro as
arguments. Although there is already release_id parameter which is kept
for compatibility.
Jira: RHEL-110563
---
.../libraries/ipuworkflowconfig.py | 9 +++-
.../common/libraries/config/__init__.py | 2 +-
.../common/libraries/config/mock_configs.py | 26 ++++++++---
.../common/libraries/testutils.py | 44 +++++++++++++++----
.../system_upgrade/common/models/ipuconfig.py | 13 ++++++
5 files changed, 78 insertions(+), 16 deletions(-)
diff --git a/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py b/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py
index f76677fd..dd84f3a1 100644
--- a/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py
+++ b/repos/system_upgrade/common/actors/ipuworkflowconfig/libraries/ipuworkflowconfig.py
@@ -4,7 +4,7 @@ import platform
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.stdlib import api, CalledProcessError, run
-from leapp.models import EnvVar, IPUConfig, IPUSourceToPossibleTargets, OSRelease, Version
+from leapp.models import Distro, EnvVar, IPUConfig, IPUSourceToPossibleTargets, OSRelease, Version
ENV_IGNORE = ('LEAPP_CURRENT_PHASE', 'LEAPP_CURRENT_ACTOR', 'LEAPP_VERBOSE',
'LEAPP_DEBUG')
@@ -169,6 +169,7 @@ def produce_ipu_config(actor):
os_release.release_id,
source_version,
target_version)
+ target_distro = os.environ.get('LEAPP_TARGET_OS')
actor.produce(IPUConfig(
leapp_env_vars=get_env_vars(),
@@ -182,5 +183,9 @@ def produce_ipu_config(actor):
),
kernel=get_booted_kernel(),
flavour=flavour,
- supported_upgrade_paths=exposed_supported_paths
+ supported_upgrade_paths=exposed_supported_paths,
+ distro=Distro(
+ source=os_release.release_id,
+ target=target_distro,
+ ),
))
diff --git a/repos/system_upgrade/common/libraries/config/__init__.py b/repos/system_upgrade/common/libraries/config/__init__.py
index 0c737f93..11d26c0e 100644
--- a/repos/system_upgrade/common/libraries/config/__init__.py
+++ b/repos/system_upgrade/common/libraries/config/__init__.py
@@ -109,4 +109,4 @@ def get_distro_id():
:return: The ID string from /etc/os_release
:rtype: str
"""
- return api.current_actor().configuration.os_release.release_id
+ return api.current_actor().configuration.distro.source
diff --git a/repos/system_upgrade/common/libraries/config/mock_configs.py b/repos/system_upgrade/common/libraries/config/mock_configs.py
index a7ee0000..a0daac74 100644
--- a/repos/system_upgrade/common/libraries/config/mock_configs.py
+++ b/repos/system_upgrade/common/libraries/config/mock_configs.py
@@ -6,7 +6,7 @@ The library is supposed to be used only for testing purposes. Import of the
library is expected only inside test files.
"""
-from leapp.models import EnvVar, IPUConfig, IPUSourceToPossibleTargets, OSRelease, Version
+from leapp.models import Distro, EnvVar, IPUConfig, IPUSourceToPossibleTargets, OSRelease, Version
CONFIG = IPUConfig(
leapp_env_vars=[EnvVar(name='LEAPP_DEVEL', value='0')],
@@ -27,7 +27,11 @@ CONFIG = IPUConfig(
kernel='3.10.0-957.43.1.el7.x86_64',
supported_upgrade_paths=[
IPUSourceToPossibleTargets(source_version='7.6', target_versions=['8.0'])
- ]
+ ],
+ distro=Distro(
+ source='rhel',
+ target='rhel',
+ ),
)
CONFIG_NO_NETWORK_RENAMING = IPUConfig(
@@ -49,7 +53,11 @@ CONFIG_NO_NETWORK_RENAMING = IPUConfig(
kernel='3.10.0-957.43.1.el7.x86_64',
supported_upgrade_paths=[
IPUSourceToPossibleTargets(source_version='7.6', target_versions=['8.0'])
- ]
+ ],
+ distro=Distro(
+ source='rhel',
+ target='rhel',
+ ),
)
CONFIG_ALL_SIGNED = IPUConfig(
@@ -71,7 +79,11 @@ CONFIG_ALL_SIGNED = IPUConfig(
kernel='3.10.0-957.43.1.el7.x86_64',
supported_upgrade_paths=[
IPUSourceToPossibleTargets(source_version='7.6', target_versions=['8.0'])
- ]
+ ],
+ distro=Distro(
+ source='rhel',
+ target='rhel',
+ ),
)
CONFIG_S390X = IPUConfig(
@@ -92,5 +104,9 @@ CONFIG_S390X = IPUConfig(
kernel='3.10.0-957.43.1.el7.x86_64',
supported_upgrade_paths=[
IPUSourceToPossibleTargets(source_version='7.6', target_versions=['8.0'])
- ]
+ ],
+ distro=Distro(
+ source='rhel',
+ target='rhel',
+ ),
)
diff --git a/repos/system_upgrade/common/libraries/testutils.py b/repos/system_upgrade/common/libraries/testutils.py
index 107ad8a7..0a56d698 100644
--- a/repos/system_upgrade/common/libraries/testutils.py
+++ b/repos/system_upgrade/common/libraries/testutils.py
@@ -78,12 +78,27 @@ def _make_default_config(actor_config_schema):
# pattern would be nice here. Ideally, the builder should actively prevent the developer from setting fields
# that do not affect actor's behavior in __setattr__.
class CurrentActorMocked: # pylint:disable=R0904
- def __init__(self, arch=architecture.ARCH_X86_64, envars=None, # pylint:disable=R0913
- kernel='3.10.0-957.43.1.el7.x86_64',
- release_id='rhel', src_ver='8.10', dst_ver='9.6', msgs=None, flavour='default', config=None,
- virtual_source_version=None, virtual_target_version=None,
- supported_upgrade_paths=None):
+
+ def __init__( # pylint: disable=too-many-arguments
+ self,
+ arch=architecture.ARCH_X86_64,
+ envars=None, # pylint:disable=R0913
+ kernel="3.10.0-957.43.1.el7.x86_64",
+ release_id="rhel",
+ src_ver="8.10",
+ dst_ver="9.6",
+ msgs=None,
+ flavour="default",
+ config=None,
+ virtual_source_version=None,
+ virtual_target_version=None,
+ supported_upgrade_paths=None,
+ src_distro=None,
+ dst_distro=None,
+ ):
"""
+ Note: src_distro and release_id specify the same thing, but src_distro takes priority.
+
:param List[IPUSourceToPossibleTargets] supported_upgrade_paths: List of supported upgrade paths.
"""
envarsList = [EnvVar(name=k, value=v) for k, v in envars.items()] if envars else []
@@ -92,7 +107,11 @@ class CurrentActorMocked: # pylint:disable=R0904
version_values = [src_ver, dst_ver, virtual_source_version or src_ver, virtual_target_version or dst_ver]
version = namedtuple('Version', version_fields)(*version_values)
- release = namedtuple('OS_release', ['release_id', 'version_id'])(release_id, src_ver)
+ release = namedtuple('OS_release', ['release_id', 'version_id'])(src_distro or release_id, src_ver)
+
+ distro = namedtuple("Distro", ["source", "target"])(
+ src_distro or release_id, dst_distro or release_id
+ )
self._common_folder = '../../files'
self._common_tools_folder = '../../tools'
@@ -103,9 +122,18 @@ class CurrentActorMocked: # pylint:disable=R0904
supported_upgrade_paths = [IPUSourceToPossibleTargets(source_version=src_ver, target_versions=[dst_ver])]
ipu_conf_fields = ['architecture', 'kernel', 'leapp_env_vars', 'os_release',
- 'version', 'flavour', 'supported_upgrade_paths']
+ 'version', 'flavour', 'supported_upgrade_paths', 'distro']
config_type = namedtuple('configuration', ipu_conf_fields)
- self.configuration = config_type(arch, kernel, envarsList, release, version, flavour, supported_upgrade_paths)
+ self.configuration = config_type(
+ arch,
+ kernel,
+ envarsList,
+ release,
+ version,
+ flavour,
+ supported_upgrade_paths,
+ distro,
+ )
self._msgs = msgs or []
self.config = {} if config is None else config
diff --git a/repos/system_upgrade/common/models/ipuconfig.py b/repos/system_upgrade/common/models/ipuconfig.py
index 379ac13f..a787e4d5 100644
--- a/repos/system_upgrade/common/models/ipuconfig.py
+++ b/repos/system_upgrade/common/models/ipuconfig.py
@@ -64,6 +64,16 @@ class IPUSourceToPossibleTargets(Model):
"""List of defined target system versions for the `source_version` system."""
+class Distro(Model):
+ topic = SystemInfoTopic
+
+ source = fields.String()
+ """Release id of the source system (e.g. rhel, centos, almalinux)."""
+
+ target = fields.String()
+ """Release id of the target system (e.g. rhel, centos, almalinux)."""
+
+
class IPUConfig(Model):
"""
IPU workflow configuration model
@@ -96,3 +106,6 @@ class IPUConfig(Model):
The list contains only upgrade paths for the `flavour` of the source system.
"""
+
+ distro = fields.Model(Distro)
+ """Release IDs of the source and target system."""
--
2.51.1