Skip to content

Commit

Permalink
Tell users to use config ini instead of 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). We should be telling users to use the config
file instead of the deprecated env vars.
  • Loading branch information
bocekm committed Nov 22, 2024
1 parent 5be973f commit 913b709
Show file tree
Hide file tree
Showing 35 changed files with 258 additions and 284 deletions.
74 changes: 38 additions & 36 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,16 +49,16 @@ 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":
logger.info("Did not perform host metering configuration. Only supported for RHEL 7.")
self.add_message(
level="INFO",
id="CONFIGURE_HOST_METERING_SKIP",
title="Did not perform host metering configuration.",
description="Host metering is supportted only for RHEL 7.",
id="CONFIGURE_HOST_METERING_SKIP_ONLY_RHEL_7",
title="Did not perform host metering configuration",
description="Host metering is supported only for RHEL 7.",
)
return False

Expand All @@ -72,9 +68,9 @@ def run(self):
logger.info("Did not perform host-metering configuration.")
self.add_message(
level="INFO",
id="CONFIGURE_HOST_METERING_SKIP",
title="Did not perform host metering configuration as not needed.",
description="Host metering is not needed on the system.",
id="CONFIGURE_HOST_METERING_SKIP_NOT_HYPERSCALER",
title="Did not perform host metering configuration",
description="Host metering is not needed on the system as it is not running on a hyperscaler.",
)
return False

Expand All @@ -85,8 +81,8 @@ def run(self):
self.add_message(
level="WARNING",
id="INSTALL_HOST_METERING_FAILURE",
title="Failed to install host metering package.",
description="When installing host metering package an error occurred meaning we can't"
title="Failed to install the host-metering package",
description="When installing the host-metering package an error occurred meaning we can't"
" enable host metering on the system.",
diagnosis="`yum install host-metering` command returned {ret_install} with message {output}".format(
ret_install=ret_install, output=output
Expand All @@ -105,9 +101,9 @@ def run(self):
self.add_message(
level="WARNING",
id="CONFIGURE_HOST_METERING_FAILURE",
title="Failed to enable and start host metering service.",
title="Failed to enable and start the host metering service",
description="The host metering service failed to start"
" successfully and won't be able to keep track.",
" successfully and won't be able to report on the use of the system for the billing purposes.",
diagnosis="Command {command} failed with {error_message}".format(
command=command, error_message=error_message
),
Expand All @@ -125,7 +121,7 @@ def run(self):
self.set_result(
level="ERROR",
id="HOST_METERING_NOT_RUNNING",
title="Host metering service is not running.",
title="Host metering service is not running",
description="host-metering.service is not running.",
remediations="You can try to start the service manually"
" by running following command:\n"
Expand All @@ -134,52 +130,58 @@ 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.",
id="CONFIGURE_HOST_METERING_SKIP_OPTION_NOT_DETECTED",
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.",
)
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
),
remediations="Set the option to `auto` value if you want to 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),
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.",
)
elif tool_opts.configure_host_metering == "auto":
logger.debug("Automatic detection of host hyperscaler and configuration.")
logger.debug("Configuration of host metering set to 'auto' - host-metering will be enabled based on"
" a detected hyperscaler.")

return True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run(self):
self.add_message(
level="INFO",
id="SKIPPED_MODIFIED_RPM_FILES_DIFF",
title="Skipped comparison of 'rpm -Va' output from before and after the conversion.",
title="Skipped comparison of 'rpm -Va' output from before and after the conversion",
description="Comparison of 'rpm -Va' output was not performed due to missing output "
"of the 'rpm -Va' run before the conversion.",
diagnosis="This is caused mainly by using '--no-rpm-va' argument for convert2rhel.",
Expand Down Expand Up @@ -76,7 +76,7 @@ def run(self):
self.add_message(
level="INFO",
id="FOUND_MODIFIED_RPM_FILES",
title="Modified rpm files from before and after the conversion were found.",
title="Modified rpm files from before and after the conversion were found",
description="Comparison of modified rpm files from before and after " "the conversion: \n{}".format(
modified_rpm_files_diff
),
Expand Down
2 changes: 1 addition & 1 deletion convert2rhel/actions/post_conversion/remove_tmp_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def run(self):
self.add_message(
level="WARNING",
id="UNSUCCESSFUL_REMOVE_TMP_DIR",
title="Temporary folder {tmp_dir} wasn't removed.".format(tmp_dir=self.tmp_dir),
title="Temporary folder {tmp_dir} wasn't removed".format(tmp_dir=self.tmp_dir),
description=warning_message,
)
3 changes: 2 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,8 @@ 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 backup of"
" the package files.")
# Return empty list results in no backup of the files
return data
else:
Expand Down
2 changes: 1 addition & 1 deletion convert2rhel/actions/pre_ponr_changes/handle_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def run(self):
self.set_result(
level="ERROR",
id="SPECIAL_PACKAGE_REMOVAL_FAILED",
title="Failed to remove some packages necessary for the conversion.",
title="Failed to remove some packages necessary for the conversion",
description="The cause of this error is unknown, please look at the diagnosis for more information.",
diagnosis=str(e),
)
Expand Down
16 changes: 8 additions & 8 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"
title="Ignoring the check ensuring kernel module availability in RHEL",
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run(self):
self.set_result(
level="ERROR",
id="FIREWALLD_MODULES_CLEANUP_ON_EXIT_CONFIG",
title="Firewalld is set to cleanup modules after exit.",
title="Firewalld is set to cleanup modules after exit",
description="Firewalld running on Oracle Linux 8 can lead to a conversion failure.",
diagnosis=(
"We've detected that firewalld unit is running and that causes iptables and nftables "
Expand Down
5 changes: 3 additions & 2 deletions convert2rhel/actions/system_checks/convert2rhel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ 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
)
)
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
25 changes: 11 additions & 14 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 All @@ -98,15 +95,15 @@ def run(self):
logger.debug("Got the following output: %s", repoquery_output)
logger.warning(
"Couldn't fetch the list of the most recent kernels available in "
"the repositories. Did not perform the loaded kernel check."
"the repositories. Did not perform the loaded kernel currency check."
)
self.add_message(
level="WARNING",
id="UNABLE_TO_FETCH_RECENT_KERNELS",
title="Unable to fetch recent kernels",
description=(
"Couldn't fetch the list of the most recent kernels available in "
"the repositories. Did not perform the loaded kernel check."
"the repositories. Did not perform the loaded kernel currency check."
),
)
return
Expand Down Expand Up @@ -142,8 +139,8 @@ 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."
"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
Loading

0 comments on commit 913b709

Please sign in to comment.