summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/modules/redfish/test_management.py
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@protonmail.com>2020-05-04 13:34:05 +0200
committerDmitry Tantsur <dtantsur@protonmail.com>2020-05-08 13:31:13 +0200
commit18a8e2f6e9d80a827acba39a6ace366c13d40e31 (patch)
tree427f2e89ed6ad87c118b481824aecd2e885d144f /ironic/tests/unit/drivers/modules/redfish/test_management.py
parent8562df092f4286afc1e592951c7006eb56a4bf09 (diff)
downloadironic-18a8e2f6e9d80a827acba39a6ace366c13d40e31.tar.gz
redfish: handle hardware that is unable to set persistent boot
Some hardware has dropped support for continuous boot, see this thread: http://lists.openstack.org/pipermail/openstack-discuss/2020-April/014543.html Work around by falling back to one-time boot device, restoring it on every reboot or power on. Story: #2007527 Task: #39320 Change-Id: I762056dea4f7b8ccdb8f95b2f21e26b45763905d
Diffstat (limited to 'ironic/tests/unit/drivers/modules/redfish/test_management.py')
-rw-r--r--ironic/tests/unit/drivers/modules/redfish/test_management.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/ironic/tests/unit/drivers/modules/redfish/test_management.py b/ironic/tests/unit/drivers/modules/redfish/test_management.py
index 2336a64e3..7ee818cef 100644
--- a/ironic/tests/unit/drivers/modules/redfish/test_management.py
+++ b/ironic/tests/unit/drivers/modules/redfish/test_management.py
@@ -100,6 +100,8 @@ class RedfishManagementTestCase(db_base.DbTestCase):
fake_system.set_system_boot_options.assert_called_once_with(
expected, enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
mock_get_system.assert_called_once_with(task.node)
+ self.assertNotIn('redfish_boot_device',
+ task.node.driver_internal_info)
# Reset mocks
fake_system.set_system_boot_options.reset_mock()
@@ -123,6 +125,8 @@ class RedfishManagementTestCase(db_base.DbTestCase):
fake_system.set_system_boot_options.assert_called_once_with(
sushy.BOOT_SOURCE_TARGET_PXE, enabled=expected)
mock_get_system.assert_called_once_with(task.node)
+ self.assertNotIn('redfish_boot_device',
+ task.node.driver_internal_info)
# Reset mocks
fake_system.set_system_boot_options.reset_mock()
@@ -170,6 +174,82 @@ class RedfishManagementTestCase(db_base.DbTestCase):
sushy.BOOT_SOURCE_TARGET_PXE,
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
mock_get_system.assert_called_once_with(task.node)
+ self.assertNotIn('redfish_boot_device',
+ task.node.driver_internal_info)
+
+ @mock.patch.object(sushy, 'Sushy', autospec=True)
+ @mock.patch.object(redfish_utils, 'get_system', autospec=True)
+ def test_set_boot_device_persistence_fallback(self, mock_get_system,
+ mock_sushy):
+ fake_system = mock.Mock()
+ fake_system.set_system_boot_options.side_effect = [
+ sushy.exceptions.SushyError(),
+ None,
+ ]
+ mock_get_system.return_value = fake_system
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
+ task.driver.management.set_boot_device(
+ task, boot_devices.PXE, persistent=True)
+ fake_system.set_system_boot_options.assert_has_calls([
+ mock.call(sushy.BOOT_SOURCE_TARGET_PXE,
+ enabled=sushy.BOOT_SOURCE_ENABLED_CONTINUOUS),
+ mock.call(sushy.BOOT_SOURCE_TARGET_PXE,
+ enabled=sushy.BOOT_SOURCE_ENABLED_ONCE),
+ ])
+ mock_get_system.assert_called_once_with(task.node)
+
+ task.node.refresh()
+ self.assertEqual(
+ sushy.BOOT_SOURCE_TARGET_PXE,
+ task.node.driver_internal_info['redfish_boot_device'])
+
+ def test_restore_boot_device(self):
+ fake_system = mock.Mock()
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
+ task.node.driver_internal_info['redfish_boot_device'] = (
+ sushy.BOOT_SOURCE_TARGET_HDD
+ )
+
+ task.driver.management.restore_boot_device(task, fake_system)
+
+ fake_system.set_system_boot_options.assert_called_once_with(
+ sushy.BOOT_SOURCE_TARGET_HDD, enabled=None)
+ # The stored boot device is kept intact
+ self.assertEqual(
+ sushy.BOOT_SOURCE_TARGET_HDD,
+ task.node.driver_internal_info['redfish_boot_device'])
+
+ def test_restore_boot_device_noop(self):
+ fake_system = mock.Mock()
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
+ task.driver.management.restore_boot_device(task, fake_system)
+
+ self.assertFalse(fake_system.set_system_boot_options.called)
+
+ @mock.patch.object(redfish_mgmt.LOG, 'warning', autospec=True)
+ def test_restore_boot_device_failure(self, mock_log):
+ fake_system = mock.Mock()
+ fake_system.set_system_boot_options.side_effect = (
+ sushy.exceptions.SushyError()
+ )
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
+ task.node.driver_internal_info['redfish_boot_device'] = (
+ sushy.BOOT_SOURCE_TARGET_HDD
+ )
+
+ task.driver.management.restore_boot_device(task, fake_system)
+
+ fake_system.set_system_boot_options.assert_called_once_with(
+ sushy.BOOT_SOURCE_TARGET_HDD, enabled=None)
+ self.assertTrue(mock_log.called)
+ # The stored boot device is kept intact
+ self.assertEqual(
+ sushy.BOOT_SOURCE_TARGET_HDD,
+ task.node.driver_internal_info['redfish_boot_device'])
@mock.patch.object(redfish_utils, 'get_system', autospec=True)
def test_get_boot_device(self, mock_get_system):