diff options
author | Zuul <zuul@review.opendev.org> | 2020-05-13 22:39:31 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-05-13 22:39:31 +0000 |
commit | 552ff8cd4b1d1c23d4cf5a451637b90550c1fff6 (patch) | |
tree | efa9e11926c9a13ed6103672b40495402015b4cd /ironic/tests | |
parent | 3ed8bf5757d3ccfae4cecea5f8a45eb879a03813 (diff) | |
parent | 18a8e2f6e9d80a827acba39a6ace366c13d40e31 (diff) | |
download | ironic-552ff8cd4b1d1c23d4cf5a451637b90550c1fff6.tar.gz |
Merge "redfish: handle hardware that is unable to set persistent boot"
Diffstat (limited to 'ironic/tests')
-rw-r--r-- | ironic/tests/unit/drivers/modules/redfish/test_management.py | 80 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/redfish/test_power.py | 36 |
2 files changed, 107 insertions, 9 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): diff --git a/ironic/tests/unit/drivers/modules/redfish/test_power.py b/ironic/tests/unit/drivers/modules/redfish/test_power.py index 22470a727..d976e15a6 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_power.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_power.py @@ -20,6 +20,7 @@ from oslo_utils import importutils from ironic.common import exception from ironic.common import states from ironic.conductor import task_manager +from ironic.drivers.modules.redfish import management as redfish_mgmt from ironic.drivers.modules.redfish import power as redfish_power from ironic.drivers.modules.redfish import utils as redfish_utils from ironic.tests.unit.db import base as db_base @@ -84,19 +85,21 @@ class RedfishPowerTestCase(db_base.DbTestCase): mock_get_system.assert_called_once_with(task.node) mock_get_system.reset_mock() + @mock.patch.object(redfish_mgmt.RedfishManagement, 'restore_boot_device', + autospec=True) @mock.patch.object(redfish_utils, 'get_system', autospec=True) - def test_set_power_state(self, mock_get_system): + def test_set_power_state(self, mock_get_system, mock_restore_bootdev): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: expected_values = [ - (states.POWER_ON, sushy.RESET_ON), - (states.POWER_OFF, sushy.RESET_FORCE_OFF), - (states.REBOOT, sushy.RESET_FORCE_RESTART), - (states.SOFT_REBOOT, sushy.RESET_GRACEFUL_RESTART), - (states.SOFT_POWER_OFF, sushy.RESET_GRACEFUL_SHUTDOWN) + (states.POWER_ON, sushy.RESET_ON, True), + (states.POWER_OFF, sushy.RESET_FORCE_OFF, False), + (states.REBOOT, sushy.RESET_FORCE_RESTART, True), + (states.SOFT_REBOOT, sushy.RESET_GRACEFUL_RESTART, True), + (states.SOFT_POWER_OFF, sushy.RESET_GRACEFUL_SHUTDOWN, False) ] - for target, expected in expected_values: + for target, expected, restore_bootdev in expected_values: if target in (states.POWER_OFF, states.SOFT_POWER_OFF): final = sushy.SYSTEM_POWER_STATE_OFF transient = sushy.SYSTEM_POWER_STATE_ON @@ -115,9 +118,15 @@ class RedfishPowerTestCase(db_base.DbTestCase): system_result[0].reset_system.assert_called_once_with(expected) mock_get_system.assert_called_with(task.node) self.assertEqual(4, mock_get_system.call_count) + if restore_bootdev: + mock_restore_bootdev.assert_called_once_with( + task.driver.management, task, system_result[0]) + else: + self.assertFalse(mock_restore_bootdev.called) # Reset mocks mock_get_system.reset_mock() + mock_restore_bootdev.reset_mock() @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_set_power_state_not_reached(self, mock_get_system): @@ -166,8 +175,11 @@ class RedfishPowerTestCase(db_base.DbTestCase): sushy.RESET_ON) mock_get_system.assert_called_once_with(task.node) + @mock.patch.object(redfish_mgmt.RedfishManagement, 'restore_boot_device', + autospec=True) @mock.patch.object(redfish_utils, 'get_system', autospec=True) - def test_reboot_from_power_off(self, mock_get_system): + def test_reboot_from_power_off(self, mock_get_system, + mock_restore_bootdev): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: system_result = [ @@ -187,9 +199,13 @@ class RedfishPowerTestCase(db_base.DbTestCase): sushy.RESET_ON) mock_get_system.assert_called_with(task.node) self.assertEqual(3, mock_get_system.call_count) + mock_restore_bootdev.assert_called_once_with( + task.driver.management, task, system_result[0]) + @mock.patch.object(redfish_mgmt.RedfishManagement, 'restore_boot_device', + autospec=True) @mock.patch.object(redfish_utils, 'get_system', autospec=True) - def test_reboot_from_power_on(self, mock_get_system): + def test_reboot_from_power_on(self, mock_get_system, mock_restore_bootdev): with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: system_result = [ @@ -211,6 +227,8 @@ class RedfishPowerTestCase(db_base.DbTestCase): ]) mock_get_system.assert_called_with(task.node) self.assertEqual(3, mock_get_system.call_count) + mock_restore_bootdev.assert_called_once_with( + task.driver.management, task, system_result[0]) @mock.patch.object(redfish_utils, 'get_system', autospec=True) def test_reboot_not_reached(self, mock_get_system): |