From 823a7cd9dbf93dc343021410dbab889ea1711ffb Mon Sep 17 00:00:00 2001 From: mvpnitesh Date: Fri, 21 Feb 2020 05:24:05 -0600 Subject: [PATCH] Fixes error handling if efibootmgr is not present in ramdisk Change-Id: I8edff252e72cb91282f8984cd6935f39cd744cfe Story: 2007324 Task: 38842 --- ironic_python_agent/extensions/image.py | 2 +- .../tests/unit/extensions/test_image.py | 15 +++++++++++++++ ...r-not-present-in-ramdisk-f11b4241edcf0e81.yaml | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fixes-error-handling-of-efibootmgr-not-present-in-ramdisk-f11b4241edcf0e81.yaml diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py index 5353e976e..6808f6766 100644 --- a/ironic_python_agent/extensions/image.py +++ b/ironic_python_agent/extensions/image.py @@ -520,7 +520,7 @@ class ImageExtension(base.BaseAgentExtension): has_efibootmgr = True try: utils.execute('efibootmgr', '--version') - except errors.CommandExecutionError: + except FileNotFoundError: LOG.warning("efibootmgr is not available in the ramdisk") has_efibootmgr = False diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py index 44dce7b7a..a7c24b3a4 100644 --- a/ironic_python_agent/tests/unit/extensions/test_image.py +++ b/ironic_python_agent/tests/unit/extensions/test_image.py @@ -293,6 +293,21 @@ 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): + 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) diff --git a/releasenotes/notes/fixes-error-handling-of-efibootmgr-not-present-in-ramdisk-f11b4241edcf0e81.yaml b/releasenotes/notes/fixes-error-handling-of-efibootmgr-not-present-in-ramdisk-f11b4241edcf0e81.yaml new file mode 100644 index 000000000..5e6f6d0c7 --- /dev/null +++ b/releasenotes/notes/fixes-error-handling-of-efibootmgr-not-present-in-ramdisk-f11b4241edcf0e81.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes error handling if efibootmgr is not present in ramdisk. + See `story `_ + for more details.