From 5f9efb34e935e55764d70b1f6f09abc4b6986f56 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 4 Aug 2020 10:13:34 +0200 Subject: [PATCH] Handle default_boot_mode during cleaning/inspection with PXE/iPXE First, use default_boot_mode in get_boot_mode instead of BIOS. Second, call sync_boot_mode for all ramdisk types in the PXE boot, not only during deployment. Change-Id: I3f13bacbdcb319c191eeb8ae93aecf8fba68f9ec --- ironic/drivers/modules/boot_mode_utils.py | 5 +++-- ironic/drivers/modules/pxe_base.py | 3 ++- .../unit/drivers/modules/test_boot_mode_utils.py | 11 +++++++++++ ironic/tests/unit/drivers/modules/test_pxe.py | 3 +-- .../notes/pxe-boot-mode-9084ccf35e54bbc0.yaml | 9 +++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/pxe-boot-mode-9084ccf35e54bbc0.yaml diff --git a/ironic/drivers/modules/boot_mode_utils.py b/ironic/drivers/modules/boot_mode_utils.py index e7ab7017a6..eea09d1c08 100644 --- a/ironic/drivers/modules/boot_mode_utils.py +++ b/ironic/drivers/modules/boot_mode_utils.py @@ -284,7 +284,8 @@ def get_boot_mode(node): return boot_mode # TODO(hshiina): The default boot mode will be changed to UEFI. global warn_about_default_boot_mode - if not warn_about_default_boot_mode: + if (not warn_about_default_boot_mode + and CONF.deploy.default_boot_mode == boot_modes.LEGACY_BIOS): warn_about_default_boot_mode = True LOG.warning('Boot mode is not configured for node %(node_uuid)s ' 'explicitly. The default boot mode is "%(bios)s", but, ' @@ -294,4 +295,4 @@ def get_boot_mode(node): {'node_uuid': node.uuid, 'bios': boot_modes.LEGACY_BIOS, 'uefi': boot_modes.UEFI}) - return boot_modes.LEGACY_BIOS + return CONF.deploy.default_boot_mode diff --git a/ironic/drivers/modules/pxe_base.py b/ironic/drivers/modules/pxe_base.py index 1c4ecb5980..5d9ac49bae 100644 --- a/ironic/drivers/modules/pxe_base.py +++ b/ironic/drivers/modules/pxe_base.py @@ -191,7 +191,8 @@ class PXEBaseMixin(object): pxe_info.update( pxe_utils.get_instance_image_info( task, ipxe_enabled=self.ipxe_enabled)) - boot_mode_utils.sync_boot_mode(task) + + boot_mode_utils.sync_boot_mode(task) pxe_options = pxe_utils.build_pxe_config_options( task, pxe_info, ipxe_enabled=self.ipxe_enabled, diff --git a/ironic/tests/unit/drivers/modules/test_boot_mode_utils.py b/ironic/tests/unit/drivers/modules/test_boot_mode_utils.py index f191eec3e3..0298ff90cd 100644 --- a/ironic/tests/unit/drivers/modules/test_boot_mode_utils.py +++ b/ironic/tests/unit/drivers/modules/test_boot_mode_utils.py @@ -53,3 +53,14 @@ class GetBootModeTestCase(tests_base.TestCase): boot_mode = boot_mode_utils.get_boot_mode(self.node) self.assertEqual(boot_modes.LEGACY_BIOS, boot_mode) self.assertEqual(1, mock_log.warning.call_count) + + @mock.patch.object(boot_mode_utils, 'LOG', autospec=True) + @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', + autospec=True) + def test_get_boot_mode_default_set(self, mock_for_deploy, mock_log): + self.config(default_boot_mode='uefi', group='deploy') + boot_mode_utils.warn_about_default_boot_mode = False + mock_for_deploy.return_value = None + boot_mode = boot_mode_utils.get_boot_mode(self.node) + self.assertEqual(boot_modes.UEFI, boot_mode) + self.assertEqual(0, mock_log.warning.call_count) diff --git a/ironic/tests/unit/drivers/modules/test_pxe.py b/ironic/tests/unit/drivers/modules/test_pxe.py index 79fb2952f5..5c75424026 100644 --- a/ironic/tests/unit/drivers/modules/test_pxe.py +++ b/ironic/tests/unit/drivers/modules/test_pxe.py @@ -276,8 +276,7 @@ class PXEBootTestCase(db_base.DbTestCase): mode=mode, ipxe_enabled=False) provider_mock.update_dhcp.assert_called_once_with(task, dhcp_opts) - if self.node.provision_state == states.DEPLOYING: - get_boot_mode_mock.assert_called_once_with(task) + get_boot_mode_mock.assert_called_once_with(task) set_boot_device_mock.assert_called_once_with(task, boot_devices.PXE, persistent=persistent) diff --git a/releasenotes/notes/pxe-boot-mode-9084ccf35e54bbc0.yaml b/releasenotes/notes/pxe-boot-mode-9084ccf35e54bbc0.yaml new file mode 100644 index 0000000000..360eb4a6cc --- /dev/null +++ b/releasenotes/notes/pxe-boot-mode-9084ccf35e54bbc0.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Fixes cleaning and managed inspection not respecting the + ``default_boot_mode`` configuration option. + - | + Fixes cleaning and managed inspection not following the standard boot + mode handling logic, particularly, not trying to assert the requested + boot mode if the driver allows it.