From a2d89f4a6821586616dbb266b4aaf3637ab4bbee Mon Sep 17 00:00:00 2001 From: Daniel Diblik Date: Mon, 2 Dec 2024 14:20:57 +0100 Subject: [PATCH 1/2] [RHELC-1780] Fix bad grub2-mkconfig call on EL9+ The output of the `grub2-mkconfig` call suggests to not use /boot/efi/EFI/redhat/grub.cfg as an output file, but use the /boot/grub2/grub.cfg instead. Check what major version of OS is running and assign the grub config variable based on that. Additionally make the grub config into a variable inside the remediation - do not always advise to use /boot/efi/EFI/redhat/grub.cfg Reformat the action message. Signed-off-by: Daniel Diblik --- .../actions/post_conversion/update_grub.py | 8 +-- convert2rhel/grub.py | 2 +- .../post_conversion/update_grub_test.py | 72 +++++++++++++++++-- convert2rhel/unit_tests/grub_test.py | 11 +-- 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/convert2rhel/actions/post_conversion/update_grub.py b/convert2rhel/actions/post_conversion/update_grub.py index 9f4470a1dd..3dca47536a 100644 --- a/convert2rhel/actions/post_conversion/update_grub.py +++ b/convert2rhel/actions/post_conversion/update_grub.py @@ -54,12 +54,12 @@ def run(self): 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) + "The grub2-mkconfig call failed with output:\n'{0}'.\nThe conversion will continue but there" + " may be issues with the current grub2 config and image formats.".format(output.rstrip("\n")) ), 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]'.", + "re-generating them with 'grub2-mkconfig -o {0}' and" + "'grub2-install [block device, e.g. /dev/sda]'.".format(grub2_config_file), ) return diff --git a/convert2rhel/grub.py b/convert2rhel/grub.py index 11c3ed037c..67d2ef2a11 100644 --- a/convert2rhel/grub.py +++ b/convert2rhel/grub.py @@ -502,7 +502,7 @@ def get_grub_config_file(): """ grub_config_path = GRUB2_BIOS_CONFIG_FILE - if is_efi(): + 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 diff --git a/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py b/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py index 930ebf4bfa..0fd147e255 100644 --- a/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py +++ b/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py @@ -87,12 +87,14 @@ 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( @@ -100,7 +102,31 @@ def test_update_grub( 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" + "The grub2-mkconfig call failed with output:\n'output'.\nThe conversion will continue but there" + " may be issues with the current grub2 config and image formats." + ), + 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/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=( + "The grub2-mkconfig call failed with output:\n'output'.\nThe conversion will continue but there" " may be issues with the current grub2 config and image formats." ), diagnosis=None, @@ -113,8 +139,34 @@ def test_update_grub( ), ( "/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=( + "The grub2-mkconfig call failed with output:\n'output'.\nThe conversion will continue but there" + " may be issues with the current grub2 config and image formats." + ), + 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/grub2/grub.cfg' and" + "'grub2-install [block device, e.g. /dev/sda]'.", + ), + ) + ), + ), + ( + "/boot/grub2/grub.cfg", + False, 0, 1, + 7, set( ( actions.ActionMessage( @@ -131,11 +183,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( ( diff --git a/convert2rhel/unit_tests/grub_test.py b/convert2rhel/unit_tests/grub_test.py index 03c2064dfd..76cf297446 100644 --- a/convert2rhel/unit_tests/grub_test.py +++ b/convert2rhel/unit_tests/grub_test.py @@ -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() From 6a69cd2fde89fd23219489ffc07d277fcd23ce7c Mon Sep 17 00:00:00 2001 From: Michal Bocek Date: Mon, 2 Dec 2024 17:25:48 +0100 Subject: [PATCH 2/2] Additional grub2 config failure msg tweaks --- .../actions/post_conversion/update_grub.py | 12 +++---- convert2rhel/grub.py | 2 ++ .../post_conversion/update_grub_test.py | 33 +++++++++---------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/convert2rhel/actions/post_conversion/update_grub.py b/convert2rhel/actions/post_conversion/update_grub.py index 3dca47536a..76c24e452c 100644 --- a/convert2rhel/actions/post_conversion/update_grub.py +++ b/convert2rhel/actions/post_conversion/update_grub.py @@ -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:\n'{0}'.\nThe conversion will continue but there" - " may be issues with the current grub2 config and image formats.".format(output.rstrip("\n")) - ), - remediations="If there are issues with the current grub2 config and image we recommend manually " - "re-generating them with 'grub2-mkconfig -o {0}' and" - "'grub2-install [block device, e.g. /dev/sda]'.".format(grub2_config_file), + 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 diff --git a/convert2rhel/grub.py b/convert2rhel/grub.py index 67d2ef2a11..ce8f59bbc0 100644 --- a/convert2rhel/grub.py +++ b/convert2rhel/grub.py @@ -502,6 +502,8 @@ def get_grub_config_file(): """ grub_config_path = GRUB2_BIOS_CONFIG_FILE + # 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") diff --git a/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py b/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py index 0fd147e255..4d94eaedfe 100644 --- a/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py +++ b/convert2rhel/unit_tests/actions/post_conversion/update_grub_test.py @@ -102,13 +102,12 @@ def test_update_grub( id="GRUB2_CONFIG_CREATION_FAILED", title="The grub2-mkconfig call failed to complete", description=( - "The grub2-mkconfig call failed with output:\n'output'.\nThe 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/grub2/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]'.", ), ) ), @@ -126,13 +125,12 @@ def test_update_grub( id="GRUB2_CONFIG_CREATION_FAILED", title="The grub2-mkconfig call failed to complete", description=( - "The grub2-mkconfig call failed with output:\n'output'.\nThe 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/efi/EFI/redhat/grub.cfg' and 'grub2-install [block device, e.g. /dev/sda]'.", ), ) ), @@ -150,13 +148,12 @@ def test_update_grub( id="GRUB2_CONFIG_CREATION_FAILED", title="The grub2-mkconfig call failed to complete", description=( - "The grub2-mkconfig call failed with output:\n'output'.\nThe 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/grub2/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]'.", ), ) ),