From 1d418816d14ec922a0741d1b00d3641302e8d52a Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Mon, 23 Mar 2020 07:46:48 -0700 Subject: [PATCH] Return false for MBR bootloader check on UEFI machines Somewhat common are dual boot images that have both a MBR loader and the contents required for a UEFI boot, as largely the pointer to where to begin reading the rest of the boot loader occurs in the first few hundred bytes on disk which redirects the disk to begin reading from a known address. This goes sideways on UEFI machines where this method of booting is not recognized nor supported. Thus we need to return false when we encounter this state. Change-Id: I8c0b42bb71b9e26ed7fec8894e21ce7fc06b94a1 Story: 2007455 Task: 39133 (cherry picked from commit 81137d40459a7cafb04279acb079b2e004dc97f7) --- ironic_python_agent/extensions/image.py | 8 ++++++++ .../tests/unit/extensions/test_image.py | 12 ++++++++++++ ...ootloader-ignored-uefi-mode-8578a009d5b5be62.yaml | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 releasenotes/notes/bootloader-ignored-uefi-mode-8578a009d5b5be62.yaml diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py index 3fc059998..4ff3b4b97 100644 --- a/ironic_python_agent/extensions/image.py +++ b/ironic_python_agent/extensions/image.py @@ -167,6 +167,14 @@ def _is_bootloader_loaded(dev): return True return False + boot = hardware.dispatch_to_managers('get_boot_info') + + if boot.current_boot_mode != 'bios': + # We're in UEFI mode, this logic is invalid + LOG.debug('Skipping boot sector check as the system is in UEFI ' + 'boot mode.') + return False + try: # Looking for things marked "bootable" in the partition table stdout, stderr = utils.execute('parted', dev, '-s', '-m', diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py index 6ad365abe..16c5784a2 100644 --- a/ironic_python_agent/tests/unit/extensions/test_image.py +++ b/ironic_python_agent/tests/unit/extensions/test_image.py @@ -711,6 +711,8 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n def test__is_bootloader_loaded(self, mock_execute, mock_dispatch): + mock_dispatch.return_value = hardware.BootInfo( + current_boot_mode='bios') parted_output = ('BYT;\n' '/dev/loop1:46.1MB:loopback:512:512:gpt:Loopback ' 'device:;\n' @@ -765,6 +767,16 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n result = image._is_bootloader_loaded(self.fake_dev) self.assertFalse(result) + def test__is_bootloader_loaded_uefi_mode(self, mock_execute, + mock_dispatch): + + mock_dispatch.return_value = hardware.BootInfo( + current_boot_mode='uefi') + result = image._is_bootloader_loaded(self.fake_dev) + self.assertFalse(result) + mock_dispatch.assert_any_call('get_boot_info') + self.assertEqual(0, mock_execute.call_count) + @mock.patch.object(image, '_get_partition', autospec=True) @mock.patch.object(utils, 'get_efi_part_on_device', autospec=True) def test__manage_uefi_no_partition(self, mock_utils_efi_part, diff --git a/releasenotes/notes/bootloader-ignored-uefi-mode-8578a009d5b5be62.yaml b/releasenotes/notes/bootloader-ignored-uefi-mode-8578a009d5b5be62.yaml new file mode 100644 index 000000000..e570f3533 --- /dev/null +++ b/releasenotes/notes/bootloader-ignored-uefi-mode-8578a009d5b5be62.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes an issue with deployment ramdisks running in UEFI boot mode where + dual-boot images may cause the logic to prematurely exit before UEFI + parameters can be updated. Internal checks for a BIOS bootloader will + always return ``False`` now when the machine is in UEFI mode.