leapp-repository/SOURCES/0003-cli-upgrade-allow-users-to-enable-entire-experimenta.patch
eabdullin b1bd6e77a6 Import from CS git
(cherry picked from commit 5bdc5cf293)
2025-05-15 11:55:21 +03:00

135 lines
6.3 KiB
Diff

From 9ea195e84dbc70e4539efe86b6d8f8ca597e2661 Mon Sep 17 00:00:00 2001
From: Michal Hecko <mhecko@redhat.com>
Date: Thu, 27 Feb 2025 09:36:45 +0100
Subject: [PATCH 03/37] cli(upgrade): allow users to enable entire experimental
features
Introduce a new CLI option --enable-experimental-feature that allows
users to enable entire features that might be facilitated by a large
number of experimental actors. Previously, the used had to
remember/figure out the names of all of these actors and list them
manually using `--whitelist-experimental`. Using
`--enable-experimental-feature` therefore lifts this burden from the
user, and the user simply needs to know what experimental feature to
enable. The help for the new options includes a list of all supported
experimental feature - at the moment, the list contains only 'livemode'.
Jira-ref: RHELMISC-10648
---
commands/preupgrade/__init__.py | 4 ++++
commands/rerun/__init__.py | 1 +
commands/upgrade/__init__.py | 4 ++++
commands/upgrade/util.py | 35 ++++++++++++++++++++++++++++++++-
4 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/commands/preupgrade/__init__.py b/commands/preupgrade/__init__.py
index c1fabbbd..e52b6561 100644
--- a/commands/preupgrade/__init__.py
+++ b/commands/preupgrade/__init__.py
@@ -14,6 +14,10 @@ from leapp.utils.output import beautify_actor_exception, report_errors, report_i
@command('preupgrade', help='Generate preupgrade report')
@command_opt('whitelist-experimental', action='append', metavar='ActorName', help='Enables experimental actors')
+@command_opt('enable-experimental-feature', action='append', metavar='Feature',
+ help=('Enable experimental feature. '
+ 'Available experimental features: {}').format(util.get_help_str_with_avail_experimental_features()),
+ choices=list(util.EXPERIMENTAL_FEATURES), default=[])
@command_opt('debug', is_flag=True, help='Enable debug mode', inherit=False)
@command_opt('verbose', is_flag=True, help='Enable verbose logging', inherit=False)
@command_opt('no-rhsm', is_flag=True, help='Use only custom repositories and skip actions'
diff --git a/commands/rerun/__init__.py b/commands/rerun/__init__.py
index a06dd266..842178af 100644
--- a/commands/rerun/__init__.py
+++ b/commands/rerun/__init__.py
@@ -71,6 +71,7 @@ def rerun(args):
nogpgcheck=False,
channel=None,
report_schema='1.1.0',
+ enable_experimental_feature=[],
whitelist_experimental=[],
enablerepo=[]))
diff --git a/commands/upgrade/__init__.py b/commands/upgrade/__init__.py
index 608099ac..6f7504bf 100644
--- a/commands/upgrade/__init__.py
+++ b/commands/upgrade/__init__.py
@@ -20,6 +20,10 @@ from leapp.utils.output import beautify_actor_exception, report_errors, report_i
@command_opt('resume', is_flag=True, help='Continue the last execution after it was stopped (e.g. after reboot)')
@command_opt('reboot', is_flag=True, help='Automatically performs reboot when requested.')
@command_opt('whitelist-experimental', action='append', metavar='ActorName', help='Enable experimental actors')
+@command_opt('enable-experimental-feature', action='append', metavar='Feature',
+ help=('Enable experimental feature. '
+ 'Available experimental features: {}').format(util.get_help_str_with_avail_experimental_features()),
+ choices=list(util.EXPERIMENTAL_FEATURES), default=[])
@command_opt('debug', is_flag=True, help='Enable debug mode', inherit=False)
@command_opt('verbose', is_flag=True, help='Enable verbose logging', inherit=False)
@command_opt('no-rhsm', is_flag=True, help='Use only custom repositories and skip actions'
diff --git a/commands/upgrade/util.py b/commands/upgrade/util.py
index b20c316d..bfdbc4fa 100644
--- a/commands/upgrade/util.py
+++ b/commands/upgrade/util.py
@@ -17,6 +17,25 @@ from leapp.utils.output import report_unsupported
from leapp.utils.report import fetch_upgrade_report_messages, generate_report_file
+EXPERIMENTAL_FEATURES = {
+ 'livemode': [
+ 'live_image_generator',
+ 'live_mode_config_scanner',
+ 'live_mode_reporter',
+ 'prepare_live_image',
+ 'emit_livemode_requirements',
+ 'remove_live_image',
+ ]
+}
+""" Maps experimental features to a set of experimental actors that need to be enabled. """
+
+
+def get_help_str_with_avail_experimental_features():
+ if EXPERIMENTAL_FEATURES:
+ return ', '.join(EXPERIMENTAL_FEATURES)
+ return 'There are no experimental features available'
+
+
def disable_database_sync():
def disable_db_sync_decorator(f):
@functools.wraps(f)
@@ -184,11 +203,25 @@ def handle_output_level(args):
# the latest supported release because of target_version discovery attempt.
def prepare_configuration(args):
"""Returns a configuration dict object while setting a few env vars as a side-effect"""
+
if args.whitelist_experimental:
args.whitelist_experimental = list(itertools.chain(*[i.split(',') for i in args.whitelist_experimental]))
os.environ['LEAPP_EXPERIMENTAL'] = '1'
else:
os.environ['LEAPP_EXPERIMENTAL'] = '0'
+ args.whitelist_experimental = []
+
+ for experimental_feature in set(args.enable_experimental_feature):
+ # It might happen that there are no experimental features, which would allow user
+ # to pass us any string as an experimental feature.
+ if experimental_feature not in EXPERIMENTAL_FEATURES:
+ continue
+
+ actors_needed_for_feature = EXPERIMENTAL_FEATURES[experimental_feature]
+ args.whitelist_experimental.extend(actors_needed_for_feature)
+ if args.enable_experimental_feature:
+ os.environ['LEAPP_EXPERIMENTAL'] = '1'
+
os.environ['LEAPP_UNSUPPORTED'] = '0' if os.getenv('LEAPP_UNSUPPORTED', '0') == '0' else '1'
if args.no_rhsm:
os.environ['LEAPP_NO_RHSM'] = '1'
@@ -235,7 +268,7 @@ def prepare_configuration(args):
configuration = {
'debug': os.getenv('LEAPP_DEBUG', '0'),
'verbose': os.getenv('LEAPP_VERBOSE', '0'),
- 'whitelist_experimental': args.whitelist_experimental or (),
+ 'whitelist_experimental': args.whitelist_experimental or (), # Modified to also contain exp. features
'environment': {env: os.getenv(env) for env in os.environ if env.startswith('LEAPP_')},
'cmd': sys.argv,
}
--
2.49.0