Skip to content

Commit

Permalink
Tell users to use config file, not env vars
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bocekm committed Nov 26, 2024
1 parent 5be973f commit 539280d
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 135 deletions.
47 changes: 26 additions & 21 deletions convert2rhel/actions/post_conversion/hostmetering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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":
Expand Down Expand Up @@ -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.",
Expand Down
5 changes: 4 additions & 1 deletion convert2rhel/actions/pre_ponr_changes/backup_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions convert2rhel/actions/pre_ponr_changes/kernel_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions convert2rhel/actions/system_checks/convert2rhel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
23 changes: 10 additions & 13 deletions convert2rhel/actions/system_checks/is_loaded_kernel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions convert2rhel/actions/system_checks/tainted_kmods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
),
)
Expand Down
6 changes: 2 additions & 4 deletions convert2rhel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions convert2rhel/toolopts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 539280d

Please sign in to comment.