Fixes error handling if efibootmgr is not present in ramdisk
Python2.7 problem: FileNotFoundError is not defined, and it
will raise OSError exception instead. The code was adapted
to handle this case.
Change-Id: I8edff252e72cb91282f8984cd6935f39cd744cfe
Story: 2007324
Task: 38842
(cherry picked from commit 823a7cd9db
)
This commit is contained in:
parent
4c69b3c0c0
commit
f30dcb671f
@ -516,9 +516,15 @@ class ImageExtension(base.BaseAgentExtension):
|
||||
boot = hardware.dispatch_to_managers('get_boot_info')
|
||||
if boot.current_boot_mode == 'uefi':
|
||||
has_efibootmgr = True
|
||||
# NOTE(iurygregory): adaptation for py27 since we don't have
|
||||
# FileNotFoundError defined.
|
||||
try:
|
||||
FileNotFoundError
|
||||
except NameError:
|
||||
FileNotFoundError = OSError
|
||||
try:
|
||||
utils.execute('efibootmgr', '--version')
|
||||
except errors.CommandExecutionError:
|
||||
except FileNotFoundError:
|
||||
LOG.warning("efibootmgr is not available in the ramdisk")
|
||||
has_efibootmgr = False
|
||||
|
||||
|
@ -293,6 +293,28 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
prep_boot_part_uuid=self.fake_prep_boot_part_uuid)
|
||||
mock_iscsi_clean.assert_called_once_with(self.fake_dev)
|
||||
|
||||
@mock.patch.object(os.path, 'exists', lambda *_: False)
|
||||
@mock.patch.object(iscsi, 'clean_up', autospec=True)
|
||||
def test_install_bootloader_failure(self, mock_iscsi_clean, mock_execute,
|
||||
mock_dispatch):
|
||||
# NOTE(iurygregory): adaptation for py27 since we don't have
|
||||
# FileNotFoundError defined.
|
||||
try:
|
||||
FileNotFoundError
|
||||
except NameError:
|
||||
FileNotFoundError = OSError
|
||||
|
||||
mock_dispatch.side_effect = [
|
||||
self.fake_dev, hardware.BootInfo(current_boot_mode='uefi')
|
||||
]
|
||||
mock_execute.side_effect = FileNotFoundError
|
||||
self.assertRaises(FileNotFoundError,
|
||||
self.agent_extension.install_bootloader,
|
||||
root_uuid=self.fake_root_uuid,
|
||||
efi_system_part_uuid=None)
|
||||
expected = [mock.call('efibootmgr', '--version')]
|
||||
mock_execute.assert_has_calls(expected)
|
||||
|
||||
@mock.patch.object(image, '_is_bootloader_loaded', lambda *_: False)
|
||||
@mock.patch.object(hardware, 'is_md_device', autospec=True)
|
||||
@mock.patch.object(hardware, 'md_get_raid_devices', autospec=True)
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes error handling if efibootmgr is not present in ramdisk.
|
||||
See `story <https://storyboard.openstack.org/#!/story/2007324>`_
|
||||
for more details.
|
Loading…
Reference in New Issue
Block a user