From 2df44df07819d8b1e6aaba06534d38fdcc244335 Mon Sep 17 00:00:00 2001 From: Matej Matuska Date: Fri, 19 Sep 2025 11:37:10 +0200 Subject: [PATCH 64/69] Add --target-version as an alias for the --target option With the introduction of --target-os option, the --target option is a bit ambiguous, therefore --target-version is added as an alias. The leapp-framework dependency version is bumped from 6.1 to 6.2, because 6.2 introduces the ability to add an alias to an option. Jira: RHEL-110563 --- commands/command_utils.py | 6 +++--- commands/preupgrade/__init__.py | 10 ++++++++-- commands/tests/test_upgrade_paths.py | 8 ++++---- commands/upgrade/__init__.py | 10 ++++++++-- packaging/leapp-repository.spec | 2 +- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/commands/command_utils.py b/commands/command_utils.py index 45a949fc..735144f8 100644 --- a/commands/command_utils.py +++ b/commands/command_utils.py @@ -215,8 +215,8 @@ def get_target_release(args): Return the user selected target release or choose one from config. A target release can be specified, ordered by priority, by the - LEAPP_DEVEL_TARGET_RELEASE or args.target (--target cmdline arg) or in the - config file. + LEAPP_DEVEL_TARGET_RELEASE or args.target_version (--target cmdline arg) or + in the config file. NOTE: when specified via the env var or cmdline arg, the version isn't checked against supported versions, this is done later by an actor in the @@ -227,7 +227,7 @@ def get_target_release(args): flavor = get_upgrade_flavour() env_version_override = os.getenv('LEAPP_DEVEL_TARGET_RELEASE') - target_ver = env_version_override or args.target + target_ver = env_version_override or args.target_version target_distro_id = os.getenv('LEAPP_TARGET_OS') if target_ver: expected_version_format = _DISTRO_VERSION_FORMATS.get( diff --git a/commands/preupgrade/__init__.py b/commands/preupgrade/__init__.py index 33f11ba2..29b10c0f 100644 --- a/commands/preupgrade/__init__.py +++ b/commands/preupgrade/__init__.py @@ -36,8 +36,14 @@ from leapp.utils.output import beautify_actor_exception, report_errors, report_i choices=['ga', 'e4s', 'eus', 'aus'], value_type=str.lower) # This allows the choices to be case insensitive @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', + help='Specify RHEL version to upgrade to for {} detected upgrade flavour'.format( + command_utils.get_upgrade_flavour() + ), + aliases=['target-version'], + dest='target_version', +) @command_opt( 'target-os', help='Specify the OS to upgrade to. If this differs from the OS on the' diff --git a/commands/tests/test_upgrade_paths.py b/commands/tests/test_upgrade_paths.py index 59c8ac36..773cdf1c 100644 --- a/commands/tests/test_upgrade_paths.py +++ b/commands/tests/test_upgrade_paths.py @@ -83,7 +83,7 @@ def test_get_target_release(mock_open, monkeypatch): # do not remove mock_open monkeypatch.setattr(command_utils, 'get_os_release_version_id', lambda x: '8.6') # make sure env var LEAPP_DEVEL_TARGET_RELEASE takes precedence - args = mock.Mock(target='9.0') + args = mock.Mock(target_version='9.0') monkeypatch.setenv('LEAPP_DEVEL_TARGET_RELEASE', '9.2') print(os.getenv('LEAPP_DEVEL_TARGET_RELEASE')) assert command_utils.get_target_release(args) == ('9.2', 'default') @@ -100,12 +100,12 @@ def test_get_target_release(mock_open, monkeypatch): # do not remove mock_open assert command_utils.get_target_release(args) == ('1.2', 'default') # no env var set, --target is set to proper version - use it - args = mock.Mock(target='9.0') + args = mock.Mock(target_version='9.0') monkeypatch.delenv('LEAPP_DEVEL_TARGET_RELEASE', raising=False) assert command_utils.get_target_release(args) == ('9.0', 'default') # --target set with incorrectly formatted version, env var not set, fail - args = mock.Mock(target='9.0a') + args = mock.Mock(target_version='9.0a') with pytest.raises(CommandError) as err: command_utils.get_target_release(args) assert 'Unexpected format of target version' in err @@ -113,7 +113,7 @@ def test_get_target_release(mock_open, monkeypatch): # do not remove mock_open # env var is set to proper version, --target set to a bad one: # env var has priority, use it and go on with the upgrade monkeypatch.setenv('LEAPP_DEVEL_TARGET_RELEASE', '9.0') - args = mock.Mock(target='9.0.0') + args = mock.Mock(target_version='9.0.0') assert command_utils.get_target_release(args) == ('9.0', 'default') diff --git a/commands/upgrade/__init__.py b/commands/upgrade/__init__.py index 670a2e7b..31d247df 100644 --- a/commands/upgrade/__init__.py +++ b/commands/upgrade/__init__.py @@ -42,8 +42,14 @@ from leapp.utils.output import beautify_actor_exception, report_errors, report_i choices=['ga', 'e4s', 'eus', 'aus'], value_type=str.lower) # This allows the choices to be case insensitive @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', + help='Specify RHEL version to upgrade to for {} detected upgrade flavour'.format( + command_utils.get_upgrade_flavour() + ), + aliases=['target-version'], + dest='target_version', +) @command_opt( 'target-os', help='Specify the OS to upgrade to. If this differs from the OS on the' diff --git a/packaging/leapp-repository.spec b/packaging/leapp-repository.spec index a2d245c2..ea7f7043 100644 --- a/packaging/leapp-repository.spec +++ b/packaging/leapp-repository.spec @@ -120,7 +120,7 @@ Requires: leapp-repository-dependencies = %{leapp_repo_deps} # IMPORTANT: this is capability provided by the leapp framework rpm. # Check that 'version' instead of the real framework rpm version. -Requires: leapp-framework >= 6.1, leapp-framework < 7 +Requires: leapp-framework >= 6.2, leapp-framework < 7 # Since we provide sub-commands for the leapp utility, we expect the leapp # tool to be installed as well. -- 2.51.1