diff --git a/convert2rhel/actions/post_conversion/update_grub.py b/convert2rhel/actions/post_conversion/update_grub.py index 9f4470a1dd..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: '{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 diff --git a/convert2rhel/grub.py b/convert2rhel/grub.py index 11c3ed037c..ce8f59bbc0 100644 --- a/convert2rhel/grub.py +++ b/convert2rhel/grub.py @@ -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 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..4d94eaedfe 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,21 +102,68 @@ 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" - " 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( @@ -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( ( 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()