forked from rpms/leapp-repository
117 lines
5.6 KiB
Diff
117 lines
5.6 KiB
Diff
From f688fbfc7fa500a43dc6cdc33356bc14bfbca964 Mon Sep 17 00:00:00 2001
|
|
From: Matej Matuska <mmatuska@redhat.com>
|
|
Date: Thu, 13 Nov 2025 13:00:05 +0100
|
|
Subject: [PATCH 63/69] Add --target-os CLI option
|
|
|
|
The option specifies the target OS (distribution) to upgrade to. This
|
|
sets the value of LEAPP_TARGET_OS, however LEAPP_DEVEL_TARGET_OS has
|
|
precedence. If none of the envars are defined, default to the source
|
|
distro i.e. only upgrade, no conversion, will be performed.
|
|
|
|
The available options are 'rhel', 'centos' and 'almalinux'.
|
|
Note that the "ID" value from /etc/os-release is used and therefore
|
|
'centos' really refers to Centos Stream.
|
|
|
|
Jira: RHEL-110563
|
|
---
|
|
commands/command_utils.py | 6 +++++-
|
|
commands/preupgrade/__init__.py | 7 +++++++
|
|
commands/tests/test_upgrade_paths.py | 2 +-
|
|
commands/upgrade/__init__.py | 7 +++++++
|
|
commands/upgrade/util.py | 9 ++++++---
|
|
5 files changed, 26 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/commands/command_utils.py b/commands/command_utils.py
|
|
index 31125da5..45a949fc 100644
|
|
--- a/commands/command_utils.py
|
|
+++ b/commands/command_utils.py
|
|
@@ -136,7 +136,7 @@ def get_os_release_version_id(filepath):
|
|
return _retrieve_os_release_contents(_os_release_path=filepath).get('VERSION_ID', '')
|
|
|
|
|
|
-def get_distro_id():
|
|
+def get_source_distro_id():
|
|
"""
|
|
Retrieve the OS release ID from /etc/os-release.
|
|
|
|
@@ -302,3 +302,7 @@ def load_actor_configs_and_store_it_in_db(context, repositories, framework_cfg):
|
|
config_data = audit.ActorConfigData(config=config_text, hash_id=config_text_hash)
|
|
db_config = audit.ActorConfig(config=config_data, context=context)
|
|
db_config.store()
|
|
+
|
|
+
|
|
+def get_available_target_distro_ids():
|
|
+ return [member.value for member in DistroIDs]
|
|
diff --git a/commands/preupgrade/__init__.py b/commands/preupgrade/__init__.py
|
|
index f24e779a..33f11ba2 100644
|
|
--- a/commands/preupgrade/__init__.py
|
|
+++ b/commands/preupgrade/__init__.py
|
|
@@ -38,6 +38,13 @@ from leapp.utils.output import beautify_actor_exception, report_errors, report_i
|
|
@command_opt('iso', help='Use provided target RHEL installation image to perform the in-place upgrade.')
|
|
@command_opt('target', help='Specify RHEL version to upgrade to for {} detected upgrade flavour'.format(
|
|
command_utils.get_upgrade_flavour()))
|
|
+@command_opt(
|
|
+ 'target-os',
|
|
+ help='Specify the OS to upgrade to. If this differs from the OS on the'
|
|
+ ' source system, a conversion is performed during the upgrade.',
|
|
+ choices=command_utils.get_available_target_distro_ids(),
|
|
+ default=command_utils.get_source_distro_id(),
|
|
+)
|
|
@command_opt('report-schema', help='Specify report schema version for leapp-report.json',
|
|
choices=['1.0.0', '1.1.0', '1.2.0'], default=get_config().get('report', 'schema'))
|
|
@command_opt('nogpgcheck', is_flag=True, help='Disable RPM GPG checks. Same as yum/dnf --nogpgcheck option.')
|
|
diff --git a/commands/tests/test_upgrade_paths.py b/commands/tests/test_upgrade_paths.py
|
|
index 95e6519a..59c8ac36 100644
|
|
--- a/commands/tests/test_upgrade_paths.py
|
|
+++ b/commands/tests/test_upgrade_paths.py
|
|
@@ -79,7 +79,7 @@ def test_get_target_release(mock_open, monkeypatch): # do not remove mock_open
|
|
# assumes.
|
|
# Otherwise the test, when ran on Centos, fails because it works
|
|
# with MAJOR.MINOR version format while Centos uses MAJOR format.
|
|
- monkeypatch.setattr(command_utils, 'get_distro_id', lambda: 'rhel')
|
|
+ monkeypatch.setattr(command_utils, 'get_source_distro_id', lambda: 'rhel')
|
|
monkeypatch.setattr(command_utils, 'get_os_release_version_id', lambda x: '8.6')
|
|
|
|
# make sure env var LEAPP_DEVEL_TARGET_RELEASE takes precedence
|
|
diff --git a/commands/upgrade/__init__.py b/commands/upgrade/__init__.py
|
|
index c5900c0d..670a2e7b 100644
|
|
--- a/commands/upgrade/__init__.py
|
|
+++ b/commands/upgrade/__init__.py
|
|
@@ -44,6 +44,13 @@ from leapp.utils.output import beautify_actor_exception, report_errors, report_i
|
|
@command_opt('iso', help='Use provided target RHEL installation image to perform the in-place upgrade.')
|
|
@command_opt('target', help='Specify RHEL version to upgrade to for {} detected upgrade flavour'.format(
|
|
command_utils.get_upgrade_flavour()))
|
|
+@command_opt(
|
|
+ 'target-os',
|
|
+ help='Specify the OS to upgrade to. If this differs from the OS on the'
|
|
+ ' source system, a conversion is performed during the upgrade.',
|
|
+ choices=command_utils.get_available_target_distro_ids(),
|
|
+ default=command_utils.get_source_distro_id(),
|
|
+)
|
|
@command_opt('report-schema', help='Specify report schema version for leapp-report.json',
|
|
choices=['1.0.0', '1.1.0', '1.2.0'], default=get_config().get('report', 'schema'))
|
|
@command_opt('nogpgcheck', is_flag=True, help='Disable RPM GPG checks. Same as yum/dnf --nogpgcheck option.')
|
|
diff --git a/commands/upgrade/util.py b/commands/upgrade/util.py
|
|
index 1c88eab8..da319448 100644
|
|
--- a/commands/upgrade/util.py
|
|
+++ b/commands/upgrade/util.py
|
|
@@ -221,9 +221,12 @@ def prepare_configuration(args):
|
|
if args.enable_experimental_feature:
|
|
os.environ['LEAPP_EXPERIMENTAL'] = '1'
|
|
|
|
- os.environ["LEAPP_TARGET_OS"] = os.getenv(
|
|
- "LEAPP_DEVEL_TARGET_OS", command_utils.get_distro_id()
|
|
- )
|
|
+ if os.getenv('LEAPP_DEVEL_TARGET_OS'):
|
|
+ os.environ['LEAPP_TARGET_OS'] = os.environ['LEAPP_DEVEL_TARGET_OS']
|
|
+ elif args.target_os:
|
|
+ os.environ['LEAPP_TARGET_OS'] = args.target_os
|
|
+ else:
|
|
+ os.environ["LEAPP_TARGET_OS"] = command_utils.get_source_distro_id()
|
|
|
|
os.environ['LEAPP_UNSUPPORTED'] = '0' if os.getenv('LEAPP_UNSUPPORTED', '0') == '0' else '1'
|
|
# force no rhsm on non-rhel systems, regardless of whether the binary is there
|
|
--
|
|
2.51.1
|
|
|