Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 22, 2024
1 parent 913b709 commit 2f57d51
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 127 deletions.
22 changes: 14 additions & 8 deletions convert2rhel/actions/post_conversion/hostmetering.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,25 @@ def _check_host_metering_configuration(self):
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.",
" the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.",
)
return False

if tool_opts.configure_host_metering not in ("force", "auto"):
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))
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="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),
" 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.",
)
Expand All @@ -180,8 +184,10 @@ def _check_host_metering_configuration(self):
" For generic usage please use the 'auto' option.",
)
elif tool_opts.configure_host_metering == "auto":
logger.debug("Configuration of host metering set to 'auto' - host-metering will be enabled based on"
" a detected hyperscaler.")
logger.debug(
"Configuration of host metering set to 'auto' - host-metering will be enabled based on"
" a detected hyperscaler."
)

return True

Expand Down
5 changes: 3 additions & 2 deletions convert2rhel/actions/pre_ponr_changes/backup_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ def _get_changed_package_files(self):
except IOError as err:
warn_deprecated_env("CONVERT2RHEL_INCOMPLETE_ROLLBACK")
if tool_opts.incomplete_rollback:
logger.debug("You have set the incomplete rollback inhibitor override - skipping backup of"
" the package files.")
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/system_checks/convert2rhel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def run(self):
)
),
remediations="If you want to disregard this check, set the allow_older_version inhibitor"
" override in the /etc/convert2rhel.ini config file to true.",
" override in the /etc/convert2rhel.ini config file to true.",
)
return

Expand Down
4 changes: 2 additions & 2 deletions convert2rhel/actions/system_checks/is_loaded_kernel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def run(self):
id="UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK_DETECTED",
title="Did not perform the kernel currency 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."
"\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
5 changes: 3 additions & 2 deletions convert2rhel/actions/system_checks/tainted_kmods.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def run(self):
" 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)
" 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
)
),
)
return
Expand Down
4 changes: 1 addition & 3 deletions convert2rhel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ def _register_options(self):
" to show you what rpm files have been affected by the conversion."
" Cannot be used with analyze subcommand."
" 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
),
" 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/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def register_system():
id_="FAILED_TO_SUBSCRIBE_SYSTEM",
title="Failed to subscribe the system",
description="After several attempts, convert2rhel was unable to subscribe the system using"
" subscription-manager. This issue might occur because of but not limited to DBus,"
" file permission-related issues, bad credentials, or network issues.",
" subscription-manager. This issue might occur because of but not limited to DBus,"
" file permission-related issues, bad credentials, or network issues.",
diagnosis="System registration failed with error {}.".format(str(troublesome_exception)),
)

Expand Down
138 changes: 76 additions & 62 deletions convert2rhel/unit_tests/actions/post_conversion/hostmetering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,14 @@ def test_configure_host_metering(
(None, 0),
("", ""),
False,
{actions.ActionMessage(
level="INFO",
id="CONFIGURE_HOST_METERING_SKIP_ONLY_RHEL_7",
title="Did not perform host metering configuration",
description="Host metering is supported only for RHEL 7.",
)},
{
actions.ActionMessage(
level="INFO",
id="CONFIGURE_HOST_METERING_SKIP_ONLY_RHEL_7",
title="Did not perform host metering configuration",
description="Host metering is supported only for RHEL 7.",
)
},
actions.ActionResult(level="SUCCESS", id="SUCCESS"),
),
(
Expand All @@ -209,14 +211,16 @@ def test_configure_host_metering(
(None, 0),
("", ""),
True,
{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.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"),
),
(
Expand All @@ -226,15 +230,17 @@ def test_configure_host_metering(
(None, 0),
("", ""),
None,
{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.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"),
),
(
Expand All @@ -244,12 +250,14 @@ def test_configure_host_metering(
(None, 0),
("", ""),
None,
{actions.ActionMessage(
level="INFO",
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.",
)},
{
actions.ActionMessage(
level="INFO",
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.",
)
},
actions.ActionResult(level="SUCCESS", id="SUCCESS"),
),
(
Expand All @@ -259,19 +267,21 @@ def test_configure_host_metering(
("yum install fail", 1),
("", ""),
None,
{actions.ActionMessage(
level="WARNING",
id="INSTALL_HOST_METERING_FAILURE",
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 1 with message yum install fail",
remediations="You can try install and set up the host metering"
" manually using following commands:\n"
" - `yum install host-metering`\n"
" - `systemctl enable host-metering.service`\n"
" - `systemctl start host-metering.service`",
)},
{
actions.ActionMessage(
level="WARNING",
id="INSTALL_HOST_METERING_FAILURE",
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 1 with message yum install fail",
remediations="You can try install and set up the host metering"
" manually using following commands:\n"
" - `yum install host-metering`\n"
" - `systemctl enable host-metering.service`\n"
" - `systemctl start host-metering.service`",
)
},
actions.ActionResult(level="SUCCESS", id="SUCCESS"),
),
(
Expand All @@ -281,18 +291,20 @@ def test_configure_host_metering(
("", 0),
("systemctl enable host-metering.service", "Failed to enable"),
None,
{actions.ActionMessage(
level="WARNING",
id="CONFIGURE_HOST_METERING_FAILURE",
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 report on the use of the system for the billing purposes.",
diagnosis="Command systemctl enable host-metering.service failed with Failed to enable",
remediations="You can try set up the host metering"
" service manually using following commands:\n"
" - `systemctl enable host-metering.service`\n"
" - `systemctl start host-metering.service`",
)},
{
actions.ActionMessage(
level="WARNING",
id="CONFIGURE_HOST_METERING_FAILURE",
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 report on the use of the system for the billing purposes.",
diagnosis="Command systemctl enable host-metering.service failed with Failed to enable",
remediations="You can try set up the host metering"
" service manually using following commands:\n"
" - `systemctl enable host-metering.service`\n"
" - `systemctl start host-metering.service`",
)
},
actions.ActionResult(level="SUCCESS", id="SUCCESS"),
),
(
Expand Down Expand Up @@ -361,14 +373,16 @@ def test_configure_host_metering_messages_and_results(


def test_configure_host_metering_no_env_var(monkeypatch, hostmetering_instance, global_tool_opts):
expected = {actions.ActionMessage(
level="INFO",
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.",
)}
expected = {
actions.ActionMessage(
level="INFO",
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.",
)
}
monkeypatch.setattr(hostmetering, "tool_opts", global_tool_opts)

hostmetering_instance.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ def test_ensure_compatibility_of_kmods_check_env_and_message(
assert STATUS_CODE["WARNING"] == message.level
assert "ALLOW_UNAVAILABLE_KERNEL_MODULES" == message.id
assert "Ignoring the check ensuring kernel module availability in RHEL" == message.title
assert "We will continue the conversion with the following kernel modules unavailable in RHEL:" in message.description
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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_convert2rhel_latest_outdated_version_inhibitor(
"Only the latest version is supported for conversion.".format(running_version, latest_version)
),
remediations="If you want to disregard this check, set the allow_older_version inhibitor"
" override in the /etc/convert2rhel.ini config file to true.",
" override in the /etc/convert2rhel.ini config file to true.",
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -771,7 +771,7 @@ def test_convert2rhel_latest_bad_nevra_to_parse_pkg_string(
"Only the latest version is supported for conversion.".format(running_version, latest_version)
),
remediations="If you want to disregard this check, set the allow_older_version inhibitor"
" override in the /etc/convert2rhel.ini config file to true."
" override in the /etc/convert2rhel.ini config file to true.",
)

def test_convert2rhel_latest_unable_to_get_c2r_repofile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def test_is_loaded_kernel_latest_eus_system(
"WARNING",
"UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK_DETECTED",
"Did not perform the kernel currency check",
"We will not be checking if the loaded kernel is of the latest version available." \
"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,
Expand Down Expand Up @@ -426,14 +426,16 @@ def test_is_loaded_kernel_latest_skip_warnings(
{"CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK": skip_check},
)

expected_set = {actions.ActionMessage(
level=level,
id=id,
title=title,
description=description,
diagnosis=diagnosis,
remediations=remediations,
)}
expected_set = {
actions.ActionMessage(
level=level,
id=id,
title=title,
description=description,
diagnosis=diagnosis,
remediations=remediations,
)
}
is_loaded_kernel_latest_action.run()
assert description in caplog.records[-1].message
assert expected_set.issuperset(is_loaded_kernel_latest_action.messages)
Expand Down
Loading

0 comments on commit 2f57d51

Please sign in to comment.