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
This commit is contained in:
Dmitry Tantsur 2020-10-07 12:06:42 +02:00
parent abd9f91813
commit fc4e0eed6a
3 changed files with 27 additions and 0 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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.