From 539280d27ca47f70664d9644094ca7505ddbdee5 Mon Sep 17 00:00:00 2001 From: Michal Bocek Date: Mon, 25 Nov 2024 22:26:57 +0100 Subject: [PATCH] Tell users to use config file, not env vars Env vars have been deprecated in favor of the ini config file (e.g. /etc/convert2rhel.ini). for that reason We should be telling users to use the config file instead of the deprecated env vars. --- .../actions/post_conversion/hostmetering.py | 47 ++++++++------ .../actions/pre_ponr_changes/backup_system.py | 5 +- .../pre_ponr_changes/kernel_modules.py | 14 ++-- .../system_checks/convert2rhel_latest.py | 7 +- .../system_checks/is_loaded_kernel_latest.py | 23 +++---- .../actions/system_checks/tainted_kmods.py | 9 +-- convert2rhel/cli.py | 6 +- convert2rhel/toolopts/__init__.py | 4 +- .../post_conversion/hostmetering_test.py | 64 +++++++++---------- .../pre_ponr_changes/backup_system_test.py | 2 +- .../pre_ponr_changes/kernel_modules_test.py | 10 +-- .../system_checks/convert2rhel_latest_test.py | 9 +-- .../is_loaded_kernel_latest_test.py | 14 ++-- .../system_checks/tainted_kmods_test.py | 9 +-- convert2rhel/unit_tests/cli_test.py | 5 +- .../unit_tests/toolopts/toolopts_test.py | 4 +- convert2rhel/unit_tests/utils/utils_test.py | 25 ++++++-- convert2rhel/utils/__init__.py | 15 ++--- .../test_basic_sanity_checks.py | 7 +- .../kernel-modules/test_unsupported_kmod.py | 7 +- .../test_system_release_backup.py | 4 +- 21 files changed, 155 insertions(+), 135 deletions(-) diff --git a/convert2rhel/actions/post_conversion/hostmetering.py b/convert2rhel/actions/post_conversion/hostmetering.py index 4602b6a17..f83e69fcd 100644 --- a/convert2rhel/actions/post_conversion/hostmetering.py +++ b/convert2rhel/actions/post_conversion/hostmetering.py @@ -28,20 +28,16 @@ class ConfigureHostMetering(actions.Action): - """Configure host metering on a machine if it's needed. - - env_var: str - Content of CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable. - """ + """Configure host metering on a machine if it's needed.""" id = "CONFIGURE_HOST_METERING_IF_NEEDED" def run(self): """ - Decide whether to install, enable and start host-metering on the system based on the - CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable. + Decide whether to install, enable and start host-metering on the system based on the setting of + 'configure_host_metering' in /etc/convert2rhel.ini. - Behavior can be controlled CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable: + The behavior can be controlled via the 'configure_host_metering' as follows: - "auto": host-metering will be configured based on the above conditions - "force": forces configuration of host-metering (e.g., even if not running on a hyperscaler) - any other value: Will be ignored and host metering will not be configured. @@ -53,7 +49,7 @@ def run(self): super(ConfigureHostMetering, self).run() warn_deprecated_env("CONVERT2RHEL_CONFIGURE_HOST_METERING") - if not self._check_env_var(): + if not self._check_host_metering_configuration(): return False if system_info.version.major != 7 and tool_opts.configure_host_metering == "auto": @@ -134,46 +130,55 @@ def run(self): return service_running - def _check_env_var(self): - """Check if the env var is set and if it has the right content. If the - content is auto|force, the hostmetering should be configued on the system. + def _check_host_metering_configuration(self): + """Check if host metering has been configured by the user and if the configuration option has the right value. + If the value is auto|force, the host metering should be configured on the system. :return: Return True if the value is equal to auto|force, otherwise False :rtype: bool """ if tool_opts.configure_host_metering is None: - logger.debug("CONVERT2RHEL_CONFIGURE_HOST_METERING was not set. Skipping it.") + logger.debug("Configuration of host metering has not been enabled. Skipping it.") self.add_message( level="INFO", id="CONFIGURE_HOST_METERING_SKIP", title="Did not perform host metering configuration.", - description="CONVERT2RHEL_CONFIGURE_HOST_METERING was not set.", + description="Configuration of host metering has been skipped.", + diagnosis="We haven't detected 'configure_host_metering' in the convert2rhel.ini config file nor" + " the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.", ) return False if tool_opts.configure_host_metering not in ("force", "auto"): - logger.debug("Value for environment variable not recognized: {}".format(tool_opts.configure_host_metering)) + logger.debug( + "Unexpected value of 'configure_host_metering' in convert2rhel.ini or the" + " CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable: {}".format( + tool_opts.configure_host_metering + ) + ) self.add_message( level="WARNING", id="UNRECOGNIZED_OPTION_CONFIGURE_HOST_METERING", - title="Unrecognized option in CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.", - description="Environment variable {env_var} not recognized.".format( - env_var=tool_opts.configure_host_metering + title="Unexpected value of the host metering setting", + diagnosis="Unexpected value of 'configure_host_metering' in convert2rhel.ini or the" + " CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable: {}".format( + tool_opts.configure_host_metering ), - remediations="Set the option to `auto` value if you want to configure host metering.", + description="Host metering will not be configured.", + remediations="Set the option to 'auto' or 'force' if you want to configure host metering.", ) return False if tool_opts.configure_host_metering == "force": logger.warning( - "The `force' option has been used for the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable." + "You've set the host metering setting to 'force'." " Please note that this option is mainly used for testing and will configure host-metering unconditionally. " " For generic usage please use the 'auto' option." ) self.add_message( level="WARNING", id="FORCED_CONFIGURE_HOST_METERING", - title="The `force' option has been used for the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.", + title="Configuration of host metering set to 'force'", description="Please note that this option is mainly used for testing and" " will configure host-metering unconditionally." " For generic usage please use the 'auto' option.", diff --git a/convert2rhel/actions/pre_ponr_changes/backup_system.py b/convert2rhel/actions/pre_ponr_changes/backup_system.py index 97a63f873..a33bd62c3 100644 --- a/convert2rhel/actions/pre_ponr_changes/backup_system.py +++ b/convert2rhel/actions/pre_ponr_changes/backup_system.py @@ -192,7 +192,10 @@ def _get_changed_package_files(self): except IOError as err: warn_deprecated_env("CONVERT2RHEL_INCOMPLETE_ROLLBACK") if tool_opts.incomplete_rollback: - logger.debug("Skipping backup of the package files. CONVERT2RHEL_INCOMPLETE_ROLLBACK detected.") + logger.debug( + "You have set the incomplete rollback inhibitor override - skipping backing up of the package" + " files." + ) # Return empty list results in no backup of the files return data else: diff --git a/convert2rhel/actions/pre_ponr_changes/kernel_modules.py b/convert2rhel/actions/pre_ponr_changes/kernel_modules.py index d99f884ce..06f5f2abd 100644 --- a/convert2rhel/actions/pre_ponr_changes/kernel_modules.py +++ b/convert2rhel/actions/pre_ponr_changes/kernel_modules.py @@ -247,21 +247,21 @@ def run(self): rhel_supported_kmods = self._get_rhel_supported_kmods() unsupported_kmods = self._get_unsupported_kmods(host_kmods, rhel_supported_kmods) - # Check if we have the environment variable set, if we do, send a + # Check if the user has specified that they allow unavailable kmods and if so, print a # warning and return. warn_deprecated_env("CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS") if tool_opts.allow_unavailable_kmods: logger.warning( - "Detected 'CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS' environment variable." - " We will continue the conversion with the following kernel modules unavailable in RHEL:\n" + "You have set the option to allow unavailable kernel modules." + " The conversion will continue with the following kernel modules unavailable in RHEL:\n" "{kmods}\n".format(kmods="\n".join(unsupported_kmods)) ) self.add_message( level="WARNING", id="ALLOW_UNAVAILABLE_KERNEL_MODULES", title="Did not perform the ensure kernel modules compatibility check", - description="Detected 'CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS' environment variable.", - diagnosis="We will continue the conversion with the following kernel modules unavailable in RHEL:\n" + diagnosis="You have set the option to allow unavailable kernel modules.", + description="We will continue the conversion with the following kernel modules unavailable in RHEL:\n" "{kmods}\n".format(kmods="\n".join(unsupported_kmods)), ) return @@ -280,8 +280,8 @@ def run(self): "message persists, you can prevent the modules from loading by following {0} and rerun convert2rhel.\n" "Keeping them loaded could cause the system to malfunction after the conversion as they might not work " "properly with the RHEL kernel.\n" - "To circumvent this check and accept the risk you can set environment variable " - "'CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS=1'.".format(LINK_PREVENT_KMODS_FROM_LOADING), + "To circumvent this check and accept the risk, set the allow_unavailable_kmods inhibitor override in the" + "/etc/convert2rhel.ini config file to true.".format(LINK_PREVENT_KMODS_FROM_LOADING), ) return diff --git a/convert2rhel/actions/system_checks/convert2rhel_latest.py b/convert2rhel/actions/system_checks/convert2rhel_latest.py index e6b4c210a..5fea4275a 100644 --- a/convert2rhel/actions/system_checks/convert2rhel_latest.py +++ b/convert2rhel/actions/system_checks/convert2rhel_latest.py @@ -179,14 +179,14 @@ def run(self): if tool_opts.allow_older_version: diagnosis = ( "You are currently running {} and the latest version of convert2rhel is {}.\n" - "'CONVERT2RHEL_ALLOW_OLDER_VERSION' environment variable detected, continuing conversion".format( + "You have set the option to allow older convert2rhel version, continuing conversion".format( formatted_convert2rhel_version, formatted_available_version ) ) logger.warning(diagnosis) self.add_message( level="WARNING", - id="ALLOW_OLDER_VERSION_ENVIRONMENT_VARIABLE", + id="ALLOW_OLDER_VERSION_OPTION", title="Outdated convert2rhel version detected", description="An outdated convert2rhel version has been detected", diagnosis=diagnosis, @@ -224,7 +224,8 @@ def run(self): formatted_convert2rhel_version, formatted_available_version ) ), - remediations="If you want to disregard this check, then set the environment variable 'CONVERT2RHEL_ALLOW_OLDER_VERSION=1' to continue.", + remediations="If you want to disregard this check, set the allow_older_version inhibitor" + " override in the /etc/convert2rhel.ini config file to true.", ) return diff --git a/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py b/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py index 106902984..5398d8bce 100644 --- a/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py +++ b/convert2rhel/actions/system_checks/is_loaded_kernel_latest.py @@ -69,20 +69,17 @@ def run(self): warn_deprecated_env("CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK") if tool_opts.skip_kernel_currency_check: logger.warning( - "Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable, we will skip " - "the {} comparison.\n" - "Beware, this could leave your system in a broken state.".format(package_to_check) + "You have set the option to skip the kernel currency check. We will not be checking if the loaded" + " kernel is of the latest version available.\nBeware, this could leave your system in a broken state." ) self.add_message( level="WARNING", id="UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK_DETECTED", title="Did not perform the kernel currency check", - description=( - "Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable, we will skip " - "the {} comparison.\n" - "Beware, this could leave your system in a broken state.".format(package_to_check) - ), + description="We will not be checking if the loaded kernel is of the latest version available." + "\nBeware, this could leave your system in a broken state.", + diagnosis="You have set the option to skip the kernel currency check.", ) return @@ -141,9 +138,9 @@ def run(self): ) ), remediations=( - "Please, check if you have any vendor repositories enabled to proceed with the conversion.\n" - "If you wish to disregard this message, set the environment variable " - "'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' to 1." + "Please check if you have any vendor repositories enabled to proceed with the conversion.\n" + "If you wish to disregard this message, set the skip_kernel_currency_check inhibitor override in" + " the /etc/convert2rhel.ini config file to true." ), ) return @@ -184,8 +181,8 @@ def run(self): "To proceed with the conversion, update the kernel version by executing the following step:\n\n" "1. yum install {}-{} -y\n" "2. reboot\n" - "If you wish to ignore this message, set the environment variable " - "'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' to 1.".format(package_to_check, latest_kernel) + "If you wish to ignore this message, set the skip_kernel_currency_check inhibitor override in" + " the /etc/convert2rhel.ini config file to true.".format(package_to_check, latest_kernel) ), ) return diff --git a/convert2rhel/actions/system_checks/tainted_kmods.py b/convert2rhel/actions/system_checks/tainted_kmods.py index a289bdf82..5f56293f5 100644 --- a/convert2rhel/actions/system_checks/tainted_kmods.py +++ b/convert2rhel/actions/system_checks/tainted_kmods.py @@ -62,8 +62,9 @@ def run(self): remediations=( "Prevent the modules from loading by following {0}" " and run convert2rhel again to continue with the conversion." - " Although it is not recommended, you can disregard this message by setting the environment variable" - " 'CONVERT2RHEL_TAINTED_KERNEL_MODULE_CHECK_SKIP' to 1. Overriding this check can be dangerous" + " Although it is not recommended, you can disregard this message by setting the" + " tainted_kernel_module_check_skip inhibitor override in the /etc/convert2rhel.ini" + " config file to true. Overriding this check can be dangerous" " so it is recommended that you do a system backup beforehand." " For information on what a tainted kernel module is, please refer to this documentation {1}".format( LINK_PREVENT_KMODS_FROM_LOADING, LINK_TAINTED_KMOD_DOCS @@ -76,9 +77,9 @@ def run(self): level="WARNING", id="SKIP_TAINTED_KERNEL_MODULE_CHECK", title="Skip tainted kernel module check", + diagnosis="You have set the option to skip the tainted kernel module check.", description=( - "Detected 'CONVERT2RHEL_TAINTED_KERNEL_MODULE_CHECK_SKIP' environment variable, we will skip " - "the tainted kernel module check.\n" + "We will ignore results of the check that makes sure no tainted kernel modules are loaded.\n" "Beware, this could leave your system in a broken state." ), ) diff --git a/convert2rhel/cli.py b/convert2rhel/cli.py index a4e83439a..3ae5251b8 100644 --- a/convert2rhel/cli.py +++ b/convert2rhel/cli.py @@ -133,10 +133,8 @@ def _register_options(self): " stored in log files {} and {}. At the end of the conversion, these logs are compared" " to show you what rpm files have been affected by the conversion." " Cannot be used with analyze subcommand." - " The environment variable CONVERT2RHEL_INCOMPLETE_ROLLBACK" - " needs to be set to 1 to use this argument.".format( - utils.rpm.PRE_RPM_VA_LOG_FILENAME, utils.rpm.POST_RPM_VA_LOG_FILENAME - ), + " The incomplete_rollback option needs to be set to true in the /etc/convert2rhel.ini config file to" + " use this argument.".format(utils.rpm.PRE_RPM_VA_LOG_FILENAME, utils.rpm.POST_RPM_VA_LOG_FILENAME), ) self._shared_options_parser.add_argument( "--eus", diff --git a/convert2rhel/toolopts/__init__.py b/convert2rhel/toolopts/__init__.py index 14c685467..6094dd761 100644 --- a/convert2rhel/toolopts/__init__.py +++ b/convert2rhel/toolopts/__init__.py @@ -99,8 +99,8 @@ def _handle_config_conflict(self, config_sources): message = ( "We need to run the 'rpm -Va' command to be able to perform a complete rollback of changes" " done to the system during the pre-conversion analysis. If you accept the risk of an" - " incomplete rollback, set the CONVERT2RHEL_INCOMPLETE_ROLLBACK=1 environment" - " variable. Otherwise, remove the --no-rpm-va option." + " incomplete rollback, set the incomplete_rollback option in the /etc/convert2rhel.ini" + " config file to true. Otherwise, remove the --no-rpm-va option." ) loggerinst.critical(message) diff --git a/convert2rhel/unit_tests/actions/post_conversion/hostmetering_test.py b/convert2rhel/unit_tests/actions/post_conversion/hostmetering_test.py index 6befe3ff2..4d72410f0 100644 --- a/convert2rhel/unit_tests/actions/post_conversion/hostmetering_test.py +++ b/convert2rhel/unit_tests/actions/post_conversion/hostmetering_test.py @@ -213,18 +213,16 @@ def test_configure_host_metering( (None, 0), ("", ""), True, - set( - ( - actions.ActionMessage( - level="WARNING", - id="FORCED_CONFIGURE_HOST_METERING", - title="The `force' option has been used for the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.", - description="Please note that this option is mainly used for testing and" - " will configure host-metering unconditionally." - " For generic usage please use the 'auto' option.", - ), - ), - ), + { + actions.ActionMessage( + level="WARNING", + id="FORCED_CONFIGURE_HOST_METERING", + title="Configuration of host metering set to 'force'", + description="Please note that this option is mainly used for testing and" + " will configure host-metering unconditionally." + " For generic usage please use the 'auto' option.", + ) + }, actions.ActionResult(level="SUCCESS", id="SUCCESS"), ), ( @@ -234,17 +232,17 @@ def test_configure_host_metering( (None, 0), ("", ""), None, - set( - ( - actions.ActionMessage( - level="WARNING", - id="UNRECOGNIZED_OPTION_CONFIGURE_HOST_METERING", - title="Unrecognized option in CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.", - description="Environment variable wrong_env not recognized.", - remediations="Set the option to `auto` value if you want to configure host metering.", - ), - ), - ), + { + actions.ActionMessage( + level="WARNING", + id="UNRECOGNIZED_OPTION_CONFIGURE_HOST_METERING", + title="Unexpected value of the host metering setting", + diagnosis="Unexpected value of 'configure_host_metering' in convert2rhel.ini or the" + " CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable: wrong_env", + description="Host metering will not be configured.", + remediations="Set the option to 'auto' or 'force' if you want to configure host metering.", + ) + }, actions.ActionResult(level="SUCCESS", id="SUCCESS"), ), ( @@ -383,16 +381,16 @@ def test_configure_host_metering_messages_and_results( def test_configure_host_metering_no_env_var(monkeypatch, hostmetering_instance, global_tool_opts): - expected = set( - ( - actions.ActionMessage( - level="INFO", - id="CONFIGURE_HOST_METERING_SKIP", - title="Did not perform host metering configuration.", - description="CONVERT2RHEL_CONFIGURE_HOST_METERING was not set.", - ), - ), - ) + expected = { + actions.ActionMessage( + level="INFO", + id="CONFIGURE_HOST_METERING_SKIP", + title="Did not perform host metering configuration.", + description="Configuration of host metering has been skipped.", + diagnosis="We haven't detected 'configure_host_metering' in the convert2rhel.ini config file nor" + " the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.", + ) + } monkeypatch.setattr(hostmetering, "tool_opts", global_tool_opts) hostmetering_instance.run() diff --git a/convert2rhel/unit_tests/actions/pre_ponr_changes/backup_system_test.py b/convert2rhel/unit_tests/actions/pre_ponr_changes/backup_system_test.py index adadd7ee6..5ad69a351 100644 --- a/convert2rhel/unit_tests/actions/pre_ponr_changes/backup_system_test.py +++ b/convert2rhel/unit_tests/actions/pre_ponr_changes/backup_system_test.py @@ -223,7 +223,7 @@ def test_get_changed_package_files(self, rpm_va_output, expected, message, caplo def test_get_changed_package_files_missing( self, caplog, tmpdir, monkeypatch, backup_package_files_action, global_tool_opts ): - message = "Skipping backup of the package files. CONVERT2RHEL_INCOMPLETE_ROLLBACK detected." + message = "You have set the incomplete rollback inhibitor override - skipping backing up of the package files." monkeypatch.setattr(backup_system, "LOG_DIR", str(tmpdir)) monkeypatch.setenv("CONVERT2RHEL_INCOMPLETE_ROLLBACK", "1") monkeypatch.setattr(toolopts, "tool_opts", global_tool_opts) diff --git a/convert2rhel/unit_tests/actions/pre_ponr_changes/kernel_modules_test.py b/convert2rhel/unit_tests/actions/pre_ponr_changes/kernel_modules_test.py index fe5a7289a..9e3ee44e7 100644 --- a/convert2rhel/unit_tests/actions/pre_ponr_changes/kernel_modules_test.py +++ b/convert2rhel/unit_tests/actions/pre_ponr_changes/kernel_modules_test.py @@ -230,8 +230,8 @@ def test_ensure_compatibility_of_kmods_check_env_and_message( ensure_kernel_modules_compatibility_instance.run() should_be_in_logs = ( - ".*Detected 'CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS' environment variable." - " We will continue the conversion with the following kernel modules unavailable in RHEL:.*" + ".*You have set the option to allow unavailable kernel modules." + " The conversion will continue with the following kernel modules unavailable in RHEL:.*" ) assert re.match(pattern=should_be_in_logs, string=caplog.records[-1].message, flags=re.MULTILINE | re.DOTALL) # cannot assert exact action message contents as the kmods arrangement in the message is not static @@ -239,8 +239,10 @@ def test_ensure_compatibility_of_kmods_check_env_and_message( assert STATUS_CODE["WARNING"] == message.level assert "ALLOW_UNAVAILABLE_KERNEL_MODULES" == message.id assert "Did not perform the ensure kernel modules compatibility check" == message.title - assert "Detected 'CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS' environment variable." in message.description - assert "We will continue the conversion with the following kernel modules unavailable in RHEL:" in message.diagnosis + assert ( + "We will continue the conversion with the following kernel modules unavailable in RHEL:" in message.description + ) + assert "You have set the option to allow unavailable kernel modules." in message.diagnosis @pytest.mark.parametrize( diff --git a/convert2rhel/unit_tests/actions/system_checks/convert2rhel_latest_test.py b/convert2rhel/unit_tests/actions/system_checks/convert2rhel_latest_test.py index 8686df352..af6939898 100644 --- a/convert2rhel/unit_tests/actions/system_checks/convert2rhel_latest_test.py +++ b/convert2rhel/unit_tests/actions/system_checks/convert2rhel_latest_test.py @@ -157,12 +157,12 @@ def test_convert2rhel_latest_outdated_version_inhibitor( level="OVERRIDABLE", id="OUT_OF_DATE", title="Outdated convert2rhel version detected", - description="An outdated convert2rhel version has been detected", diagnosis=( "You are currently running {} and the latest version of convert2rhel is {}.\n" "Only the latest version is supported for conversion.".format(running_version, latest_version) ), - remediations="If you want to disregard this check, then set the environment variable 'CONVERT2RHEL_ALLOW_OLDER_VERSION=1' to continue.", + remediations="If you want to disregard this check, set the allow_older_version inhibitor" + " override in the /etc/convert2rhel.ini config file to true.", ) @pytest.mark.parametrize( @@ -337,7 +337,7 @@ def test_convert2rhel_latest_log_check_env( log_msg = ( "You are currently running {} and the latest version of convert2rhel is {}.\n" - "'CONVERT2RHEL_ALLOW_OLDER_VERSION' environment variable detected, continuing conversion".format( + "You have set the option to allow older convert2rhel version, continuing conversion".format( running_version, latest_version ) ) @@ -769,7 +769,8 @@ def test_convert2rhel_latest_bad_nevra_to_parse_pkg_string( "You are currently running {} and the latest version of convert2rhel is {}.\n" "Only the latest version is supported for conversion.".format(running_version, latest_version) ), - remediations="If you want to disregard this check, then set the environment variable 'CONVERT2RHEL_ALLOW_OLDER_VERSION=1' to continue.", + remediations="If you want to disregard this check, set the allow_older_version inhibitor" + " override in the /etc/convert2rhel.ini config file to true.", ) def test_convert2rhel_latest_unable_to_get_c2r_repofile( diff --git a/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py b/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py index 10da0b684..b6f8d2f62 100644 --- a/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py +++ b/convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py @@ -372,12 +372,10 @@ def test_is_loaded_kernel_latest_eus_system( "WARNING", "UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK_DETECTED", "Did not perform the kernel currency check", - ( - "Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable, we will skip the kernel-core comparison.\nBeware, this could leave your system in a broken state." - ), - None, + "We will not be checking if the loaded kernel is of the latest version available." + "\nBeware, this could leave your system in a broken state.", + "You have set the option to skip the kernel currency check.", None, - id="Unsupported skip with environment var set to 1", ), ), ) @@ -554,9 +552,9 @@ def test_is_loaded_kernel_latest_unable_to_fetch_kernels( "Please refer to the diagnosis for further information", "Could not find any {0} from repositories to compare against the loaded kernel.", ( - "Please, check if you have any vendor repositories enabled to proceed with the conversion.\n" - "If you wish to disregard this message, set the environment variable " - "'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' to 1." + "Please check if you have any vendor repositories enabled to proceed with the conversion.\n" + "If you wish to disregard this message, set the skip_kernel_currency_check inhibitor override in" + " the /etc/convert2rhel.ini config file to true." ), id="Repoquery failure without environment var", ), diff --git a/convert2rhel/unit_tests/actions/system_checks/tainted_kmods_test.py b/convert2rhel/unit_tests/actions/system_checks/tainted_kmods_test.py index adacfddc6..3bc26a10c 100644 --- a/convert2rhel/unit_tests/actions/system_checks/tainted_kmods_test.py +++ b/convert2rhel/unit_tests/actions/system_checks/tainted_kmods_test.py @@ -80,8 +80,9 @@ def test_check_tainted_kmods(monkeypatch, command_return, is_error, tainted_kmod remediations=( "Prevent the modules from loading by following {0}" " and run convert2rhel again to continue with the conversion." - " Although it is not recommended, you can disregard this message by setting the environment variable" - " 'CONVERT2RHEL_TAINTED_KERNEL_MODULE_CHECK_SKIP' to 1. Overriding this check can be dangerous" + " Although it is not recommended, you can disregard this message by setting the" + " tainted_kernel_module_check_skip inhibitor override in the /etc/convert2rhel.ini" + " config file to true. Overriding this check can be dangerous" " so it is recommended that you do a system backup beforehand." " For information on what a tainted kernel module is, please refer to this documentation {1}".format( LINK_PREVENT_KMODS_FROM_LOADING, LINK_TAINTED_KMOD_DOCS @@ -145,9 +146,9 @@ def test_check_tainted_kmods_skip(monkeypatch, command_return, is_error, tainted level="WARNING", id="SKIP_TAINTED_KERNEL_MODULE_CHECK", title="Skip tainted kernel module check", + diagnosis="You have set the option to skip the tainted kernel module check.", description=( - "Detected 'CONVERT2RHEL_TAINTED_KERNEL_MODULE_CHECK_SKIP' environment variable, we will skip " - "the tainted kernel module check.\n" + "We will ignore results of the check that makes sure no tainted kernel modules are loaded.\n" "Beware, this could leave your system in a broken state." ), ), diff --git a/convert2rhel/unit_tests/cli_test.py b/convert2rhel/unit_tests/cli_test.py index e290ba041..8f15676ca 100644 --- a/convert2rhel/unit_tests/cli_test.py +++ b/convert2rhel/unit_tests/cli_test.py @@ -543,7 +543,10 @@ def test_critical_exit_no_rpm_va_setting(monkeypatch, global_tool_opts, tmpdir): monkeypatch.setattr(sys, "argv", mock_cli_arguments(["--no-rpm-va"])) with pytest.raises( SystemExit, - match="We need to run the 'rpm -Va' command to be able to perform a complete rollback of changes done to the system during the pre-conversion analysis. If you accept the risk of an incomplete rollback, set the CONVERT2RHEL_INCOMPLETE_ROLLBACK=1 environment variable. Otherwise, remove the --no-rpm-va option.", + match="We need to run the 'rpm -Va' command to be able to perform a complete rollback of changes" + " done to the system during the pre-conversion analysis. If you accept the risk of an" + " incomplete rollback, set the incomplete_rollback option in the /etc/convert2rhel.ini" + " config file to true. Otherwise, remove the --no-rpm-va option.", ): cli.CLI() diff --git a/convert2rhel/unit_tests/toolopts/toolopts_test.py b/convert2rhel/unit_tests/toolopts/toolopts_test.py index be73cba02..95414eb61 100644 --- a/convert2rhel/unit_tests/toolopts/toolopts_test.py +++ b/convert2rhel/unit_tests/toolopts/toolopts_test.py @@ -333,8 +333,8 @@ def test_handle_config_conflicts_system_exit(config_sources): match=( "We need to run the 'rpm -Va' command to be able to perform a complete rollback of changes" " done to the system during the pre-conversion analysis. If you accept the risk of an" - " incomplete rollback, set the CONVERT2RHEL_INCOMPLETE_ROLLBACK=1 environment" - " variable. Otherwise, remove the --no-rpm-va option." + " incomplete rollback, set the incomplete_rollback option in the /etc/convert2rhel.ini" + " config file to true. Otherwise, remove the --no-rpm-va option." ), ): tool_opts.initialize(config_sources) diff --git a/convert2rhel/unit_tests/utils/utils_test.py b/convert2rhel/unit_tests/utils/utils_test.py index cff9c219d..5addda105 100644 --- a/convert2rhel/unit_tests/utils/utils_test.py +++ b/convert2rhel/unit_tests/utils/utils_test.py @@ -530,31 +530,34 @@ def test_download_pkg_assertion_error(self, monkeypatch): custom_releasever=None, ) - def test_download_pkg_failed_download_exit(self, monkeypatch): + def test_download_pkg_failed_download_exit(self, monkeypatch, global_tool_opts): monkeypatch.setattr(system_info, "releasever", "7Server") monkeypatch.setattr(system_info, "version", systeminfo.Version(7, 0)) monkeypatch.setattr(utils, "run_cmd_in_pty", RunCmdInPtyMocked(return_code=1)) monkeypatch.setattr(os, "environ", {}) + monkeypatch.setattr(utils, "tool_opts", global_tool_opts) with pytest.raises(SystemExit): utils.download_pkg("kernel") - def test_download_pkg_failed_during_analysis_download_exit(self, monkeypatch): + def test_download_pkg_failed_during_analysis_download_exit(self, monkeypatch, global_tool_opts): monkeypatch.setattr(system_info, "releasever", "7Server") monkeypatch.setattr(system_info, "version", systeminfo.Version(7, 0)) monkeypatch.setattr(utils, "run_cmd_in_pty", RunCmdInPtyMocked(return_code=1)) monkeypatch.setattr(os, "environ", {"CONVERT2RHEL_INCOMPLETE_ROLLBACK": "1"}) - monkeypatch.setattr(toolopts.tool_opts, "activity", "analysis") + monkeypatch.setattr(utils, "tool_opts", global_tool_opts) + monkeypatch.setattr(global_tool_opts, "activity", "analysis") with pytest.raises(SystemExit): utils.download_pkg("kernel") - def test_download_pkg_failed_download_overridden(self, monkeypatch): + def test_download_pkg_failed_download_overridden(self, monkeypatch, global_tool_opts): monkeypatch.setattr(system_info, "releasever", "7Server") monkeypatch.setattr(system_info, "version", systeminfo.Version(7, 0)) monkeypatch.setattr(utils, "run_cmd_in_pty", RunCmdInPtyMocked(return_code=1)) monkeypatch.setattr(os, "environ", {"CONVERT2RHEL_INCOMPLETE_ROLLBACK": "1"}) - monkeypatch.setattr(toolopts.tool_opts, "activity", "conversion") + monkeypatch.setattr(utils, "tool_opts", global_tool_opts) + monkeypatch.setattr(global_tool_opts, "activity", "conversion") path = utils.download_pkg("kernel") @@ -571,6 +574,7 @@ def test_download_pkg_incorrect_output(self, output, monkeypatch, global_tool_op monkeypatch.setattr(system_info, "releasever", "7Server") monkeypatch.setattr(system_info, "version", systeminfo.Version(7, 0)) monkeypatch.setattr(utils, "run_cmd_in_pty", RunCmdInPtyMocked(return_string=output)) + monkeypatch.setattr(utils, "tool_opts", global_tool_opts) with pytest.raises(SystemExit): utils.download_pkg("kernel") @@ -587,14 +591,21 @@ def test_get_rpm_path_from_yumdownloader_output(output): ("envvar", "activity", "should_raise", "message"), ( (None, "conversion", True, "If you would rather disregard this check"), - ("CONVERT2RHEL_INCOMPLETE_ROLLBACK", "conversion", False, "environment variable detected"), + ( + "CONVERT2RHEL_INCOMPLETE_ROLLBACK", + "conversion", + False, + "You have set the incomplete rollback inhibitor override", + ), (None, "analysis", True, "you can choose to disregard this check"), ("CONVERT2RHEL_INCOMPLETE_ROLLBACK", "analysis", True, "you can choose to disregard this check"), ), ) def test_report_on_a_download_error(envvar, activity, should_raise, message, monkeypatch, caplog, global_tool_opts): + monkeypatch.setattr(utils, "tool_opts", global_tool_opts) global_tool_opts.activity = activity - monkeypatch.setattr(os, "environ", {envvar: "1"}) + if envvar: + monkeypatch.setattr(os, "environ", {envvar: "1"}) if should_raise: with pytest.raises(SystemExit): diff --git a/convert2rhel/utils/__init__.py b/convert2rhel/utils/__init__.py index b0542bfb4..6d23a3fef 100644 --- a/convert2rhel/utils/__init__.py +++ b/convert2rhel/utils/__init__.py @@ -783,25 +783,24 @@ def report_on_a_download_error(output, pkg): # (4) Making the choices here mean that when used inside of the Action # framework, we are limited to returning a FAILURE for the Action # plugin whereas returning SKIP would be more accurate. - from convert2rhel import toolopts from convert2rhel.systeminfo import system_info - if toolopts.tool_opts.activity == "conversion": - if "CONVERT2RHEL_INCOMPLETE_ROLLBACK" not in os.environ: + if tool_opts.activity == "conversion": + warn_deprecated_env("CONVERT2RHEL_INCOMPLETE_ROLLBACK") + if not tool_opts.incomplete_rollback: logger.critical( "Couldn't download the {} package. This means we will not be able to do a" " complete rollback and may put the system in a broken state.\n" "Check to make sure that the {} repositories are enabled" " and the package is updated to its latest version.\n" - "If you would rather disregard this check set the environment variable" - " 'CONVERT2RHEL_INCOMPLETE_ROLLBACK=1'.".format(pkg, system_info.name) + "If you would rather disregard this check set the incomplete_rollback option in the" + " /etc/convert2rhel.ini config file to true.".format(pkg, system_info.name) ) else: - warn_deprecated_env("CONVERT2RHEL_INCOMPLETE_ROLLBACK") logger.warning( "Couldn't download the {} package. This means we will not be able to do a" " complete rollback and may put the system in a broken state.\n" - "'CONVERT2RHEL_INCOMPLETE_ROLLBACK' environment variable detected, continuing" + "You have set the incomplete rollback inhibitor override, continuing" " conversion.".format(pkg) ) else: @@ -810,7 +809,7 @@ def report_on_a_download_error(output, pkg): " Check to make sure that the {} repositories are enabled and the package is" " updated to its latest version.\n" "Note that you can choose to disregard this check when running a conversion by" - " setting the environment variable 'CONVERT2RHEL_INCOMPLETE_ROLLBACK=1'" + " setting the incomplete_rollback option in the /etc/convert2rhel.ini config file to true," " but not during a pre-conversion analysis.".format(pkg, system_info.name) ) diff --git a/tests/integration/tier0/non-destructive/basic-sanity-checks/test_basic_sanity_checks.py b/tests/integration/tier0/non-destructive/basic-sanity-checks/test_basic_sanity_checks.py index aa3c05187..6cd3568b2 100644 --- a/tests/integration/tier0/non-destructive/basic-sanity-checks/test_basic_sanity_checks.py +++ b/tests/integration/tier0/non-destructive/basic-sanity-checks/test_basic_sanity_checks.py @@ -165,7 +165,7 @@ def test_c2r_version_latest_override_inhibitor(convert2rhel, c2r_version, versio assert c2r.expect("You are currently running 0.01.0", timeout=300) == 0 assert ( c2r.expect( - "'CONVERT2RHEL_ALLOW_OLDER_VERSION' environment variable detected, continuing conversion", + "You have set the option to allow older convert2rhel version, continuing conversion", timeout=300, ) == 0 @@ -279,7 +279,8 @@ def test_analyze_incomplete_rollback(remove_repositories, convert2rhel): # Verify the user is informed to not use the envar during the analysis assert ( c2r.expect( - "setting the environment variable 'CONVERT2RHEL_INCOMPLETE_ROLLBACK=1' but not during a pre-conversion analysis", + "setting the incomplete_rollback option in the /etc/convert2rhel.ini config file to true," + " but not during a pre-conversion analysis", timeout=300, ) == 0 @@ -295,7 +296,7 @@ def test_analyze_incomplete_rollback(remove_repositories, convert2rhel): c2r.sendline("y") assert ( c2r.expect( - "'CONVERT2RHEL_INCOMPLETE_ROLLBACK' environment variable detected, continuing conversion.", + "You have set the incomplete rollback inhibitor override, continuing conversion.", timeout=300, ) == 0 diff --git a/tests/integration/tier0/non-destructive/kernel-modules/test_unsupported_kmod.py b/tests/integration/tier0/non-destructive/kernel-modules/test_unsupported_kmod.py index b923d0819..e4d843a50 100644 --- a/tests/integration/tier0/non-destructive/kernel-modules/test_unsupported_kmod.py +++ b/tests/integration/tier0/non-destructive/kernel-modules/test_unsupported_kmod.py @@ -70,8 +70,8 @@ def test_override_inhibitor_with_unavailable_kmod_loaded( c2r.expect("Continue with the system conversion?") c2r.sendline("y") - c2r.expect("Detected 'CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS' environment variable") - c2r.expect("We will continue the conversion with the following kernel modules") + c2r.expect("You have set the option to allow unavailable kernel modules.") + c2r.expect("The conversion will continue with the following kernel modules unavailable in RHEL") c2r.sendcontrol("c") @@ -191,7 +191,8 @@ def test_inhibitor_with_custom_built_tainted_kmod(custom_kmod, convert2rhel): ) as c2r: c2r.expect("Tainted kernel modules detected") c2r.expect( - "disregard this message by setting the environment variable 'CONVERT2RHEL_TAINTED_KERNEL_MODULE_CHECK_SKIP'" + "disregard this message by setting the tainted_kernel_module_check_skip inhibitor override in the" + " /etc/convert2rhel.ini config file" ) c2r.sendcontrol("c") diff --git a/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py b/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py index 856b98fdc..31702f766 100644 --- a/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py +++ b/tests/integration/tier0/non-destructive/system-release-backup/test_system_release_backup.py @@ -60,7 +60,7 @@ def test_inhibitor_os_release_restored(shell, convert2rhel, fixture_satellite, r c2r.expect("Continue with the system conversion?") c2r.sendline("y") - c2r.expect_exact("set the environment variable 'CONVERT2RHEL_INCOMPLETE_ROLLBACK", timeout=600) + c2r.expect_exact("set the incomplete_rollback option in the /etc/convert2rhel.ini config file", timeout=600) # We expect the return code to be 2, given an error is raised assert c2r.exitstatus == 2 @@ -96,7 +96,7 @@ def test_override_inhibitor_os_release_restored( c2r.expect("Continue with the system conversion?") c2r.sendline("y") - c2r.expect("'CONVERT2RHEL_INCOMPLETE_ROLLBACK' environment variable detected, continuing conversion.") + c2r.expect("You have set the incomplete rollback inhibitor override, continuing conversion.") c2r.expect("Continue with the system conversion") c2r.sendline("n")