Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHELC-1780] Fix bad grub2-mkconfig call on UEFI EL9+ #1444

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions convert2rhel/actions/post_conversion/update_grub.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ def run(self):
level="WARNING",
id="GRUB2_CONFIG_CREATION_FAILED",
title="The grub2-mkconfig call failed to complete",
description=(
"The grub2-mkconfig call failed with output: '{0}'. The conversion will continue but there"
" may be issues with the current grub2 config and image formats.".format(output)
),
remediations="If there are issues with the current grub2 config and image we recommend manually "
"re-generating them with 'grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg' and"
"'grub2-install [block device, e.g. /dev/sda]'.",
description="There may be issues with the bootloader configuration."
" Follow the recommended remediation before rebooting the system.",
diagnosis="The grub2-mkconfig call failed with output:\n'{0}'".format(output.rstrip("\n")),
remediations="Resolve the problem reported in the diagnosis and then run 'grub2-mkconfig -o {0}' and"
" 'grub2-install [block device, e.g. /dev/sda]'.".format(grub2_config_file),
)
return

Expand Down
4 changes: 3 additions & 1 deletion convert2rhel/grub.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ def get_grub_config_file():
"""
grub_config_path = GRUB2_BIOS_CONFIG_FILE

if is_efi():
# On RHEL 9 the path to the grub config file on UEFI has been unified with the one on BIOS. See:
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html-single/9.0_release_notes/index#enhancement_boot-loader
if is_efi() and systeminfo.system_info.version.major < 9:
grub_config_path = os.path.join(RHEL_EFIDIR_CANONICAL_PATH, "grub.cfg")

return grub_config_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,83 @@ def test_update_grub(


@pytest.mark.parametrize(
("config_path", "grub2_mkconfig_exit_code", "grub2_install_exit_code", "expected"),
("config_path", "is_efi", "grub2_mkconfig_exit_code", "grub2_install_exit_code", "releasever_major", "expected"),
(
(
"/boot/grub2/grub.cfg",
True,
1,
0,
9,
set(
(
actions.ActionMessage(
level="WARNING",
id="GRUB2_CONFIG_CREATION_FAILED",
title="The grub2-mkconfig call failed to complete",
description=(
"The grub2-mkconfig call failed with output: 'output'. The conversion will continue but there"
" may be issues with the current grub2 config and image formats."
"There may be issues with the bootloader configuration."
" Follow the recommended remediation before rebooting the system."
),
diagnosis=None,
remediations="If there are issues with the current grub2 config and image we recommend manually "
"re-generating them with 'grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg' and"
"'grub2-install [block device, e.g. /dev/sda]'.",
diagnosis="The grub2-mkconfig call failed with output:\n'output'",
remediations="Resolve the problem reported in the diagnosis and then run 'grub2-mkconfig -o"
" /boot/grub2/grub.cfg' and 'grub2-install [block device, e.g. /dev/sda]'.",
),
)
),
),
(
"/boot/efi/EFI/redhat/grub.cfg",
True,
1,
0,
7,
set(
(
actions.ActionMessage(
level="WARNING",
id="GRUB2_CONFIG_CREATION_FAILED",
title="The grub2-mkconfig call failed to complete",
description=(
"There may be issues with the bootloader configuration."
" Follow the recommended remediation before rebooting the system."
),
diagnosis="The grub2-mkconfig call failed with output:\n'output'",
remediations="Resolve the problem reported in the diagnosis and then run 'grub2-mkconfig -o"
" /boot/efi/EFI/redhat/grub.cfg' and 'grub2-install [block device, e.g. /dev/sda]'.",
),
)
),
),
(
"/boot/grub2/grub.cfg",
False,
1,
0,
7,
set(
(
actions.ActionMessage(
level="WARNING",
id="GRUB2_CONFIG_CREATION_FAILED",
title="The grub2-mkconfig call failed to complete",
description=(
"There may be issues with the bootloader configuration."
" Follow the recommended remediation before rebooting the system."
),
diagnosis="The grub2-mkconfig call failed with output:\n'output'",
remediations="Resolve the problem reported in the diagnosis and then run 'grub2-mkconfig -o"
" /boot/grub2/grub.cfg' and 'grub2-install [block device, e.g. /dev/sda]'.",
),
)
),
),
(
"/boot/grub2/grub.cfg",
False,
0,
1,
7,
set(
(
actions.ActionMessage(
Expand All @@ -131,11 +180,21 @@ def test_update_grub(
),
)
def test_update_grub_action_messages(
update_grub_instance, monkeypatch, config_path, grub2_mkconfig_exit_code, grub2_install_exit_code, expected
update_grub_instance,
monkeypatch,
config_path,
is_efi,
grub2_mkconfig_exit_code,
grub2_install_exit_code,
releasever_major,
expected,
):
monkeypatch.setattr("convert2rhel.grub.get_grub_device", mock.Mock(return_value="/dev/sda"))
monkeypatch.setattr(grub, "is_efi", mock.Mock(return_value=False))
monkeypatch.setattr("convert2rhel.systeminfo.system_info.version", namedtuple("Version", ["major"])(7))
monkeypatch.setattr("convert2rhel.grub.get_grub_config_file", mock.Mock(return_value=config_path))
monkeypatch.setattr(grub, "is_efi", mock.Mock(return_value=is_efi))
monkeypatch.setattr(
"convert2rhel.systeminfo.system_info.version", namedtuple("Version", ["major"])(releasever_major)
)
run_subprocess_mocked = RunSubprocessMocked(
side_effect=run_subprocess_side_effect(
(
Expand Down
11 changes: 7 additions & 4 deletions convert2rhel/unit_tests/grub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,16 @@ def test__remove_orig_boot_entry(


@pytest.mark.parametrize(
("is_efi", "config_path"),
("is_efi", "config_path", "releasever_major"),
(
(False, "/boot/grub2/grub.cfg"),
(True, "/boot/efi/EFI/redhat/grub.cfg"),
(False, "/boot/grub2/grub.cfg", 8),
(True, "/boot/efi/EFI/redhat/grub.cfg", 8),
(True, "/boot/grub2/grub.cfg", 9),
(False, "/boot/grub2/grub.cfg", 9),
),
)
def test_get_grub_config_file(is_efi, config_path, monkeypatch):
def test_get_grub_config_file(is_efi, config_path, releasever_major, monkeypatch):
monkeypatch.setattr("convert2rhel.systeminfo.system_info.version", mock.Mock(major=releasever_major))
monkeypatch.setattr("convert2rhel.grub.is_efi", mock.Mock(return_value=is_efi))
config_file = grub.get_grub_config_file()

Expand Down
Loading