commit 840e165385d1bf82d57085625ee4a0930db99920 Author: Dmitry Tantsur Date: Wed Oct 7 12:06:42 2020 +0200 Don't try to call GRUB when root UUID is not provided We don't have a really working way to detect root UUID for whole disk images at the moment, which results in an ignored traceback every time install_bootloader is called with whole disk images in UEFI mode. Avoid it by skipping GRUB2 if root UUID is unknown. Change-Id: I84245538f59c664b72d1cafbca8d61be0978f489 (cherry picked from commit fc4e0eed6aabbc88ab7ee9e037b3cf8ab64fcd26) diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py index aa40009..2395a70 100644 --- a/ironic_python_agent/extensions/image.py +++ b/ironic_python_agent/extensions/image.py @@ -744,6 +744,13 @@ class ImageExtension(base.BaseAgentExtension): efi_system_part_uuid=efi_system_part_uuid): return + # We don't have a working root UUID detection for whole disk images. + # Until we can do it, avoid a confusing traceback. + if root_uuid == '0x00000000' or root_uuid is None: + LOG.info('Not using grub2-install since root UUID is not provided.' + ' Assuming a whole disk image') + return + # In case we can't use efibootmgr for uefi we will continue using grub2 LOG.debug('Using grub2-install to set up boot files') _install_grub2(device, diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py index 02d6fc6..0200df5 100644 --- a/ironic_python_agent/tests/unit/extensions/test_image.py +++ b/ironic_python_agent/tests/unit/extensions/test_image.py @@ -95,6 +95,21 @@ class TestImageExtension(base.IronicAgentTest): ) mock_iscsi_clean.assert_called_once_with(self.fake_dev) + @mock.patch.object(iscsi, 'clean_up', autospec=True) + @mock.patch.object(image, '_install_grub2', autospec=True) + def test__install_bootloader_no_root(self, mock_grub2, mock_iscsi_clean, + mock_execute, mock_dispatch): + mock_dispatch.side_effect = [ + self.fake_dev, hardware.BootInfo(current_boot_mode='bios') + ] + self.agent_extension.install_bootloader( + root_uuid='0x00000000').join() + mock_dispatch.assert_any_call('get_os_install_device') + mock_dispatch.assert_any_call('get_boot_info') + self.assertEqual(2, mock_dispatch.call_count) + self.assertFalse(mock_grub2.called) + mock_iscsi_clean.assert_called_once_with(self.fake_dev) + @mock.patch.object(hardware, 'is_md_device', lambda *_: False) @mock.patch.object(os.path, 'exists', lambda *_: False) @mock.patch.object(iscsi, 'clean_up', autospec=True) diff --git a/releasenotes/notes/whole-disk-grub-0b1b8b9c44e31d28.yaml b/releasenotes/notes/whole-disk-grub-0b1b8b9c44e31d28.yaml new file mode 100644 index 0000000..2f218c6 --- /dev/null +++ b/releasenotes/notes/whole-disk-grub-0b1b8b9c44e31d28.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Avoids a traceback when using ``install_bootloader`` with whole disk + images. If the root UUID cannot be detected, don't try to call grub.