Merge "Improve redfish set-boot-device behaviour"

This commit is contained in:
Zuul 2020-04-14 16:21:20 +00:00 committed by Gerrit Code Review
commit 123cb22c73
3 changed files with 41 additions and 2 deletions
ironic
drivers/modules/redfish
tests/unit/drivers/modules/redfish
releasenotes/notes

@ -126,10 +126,17 @@ class RedfishManagement(base.ManagementInterface):
"""
system = redfish_utils.get_system(task.node)
desired_persistence = BOOT_DEVICE_PERSISTENT_MAP_REV[persistent]
current_persistence = system.boot.get('enabled')
# NOTE(etingof): this can be racy, esp if BMC is not RESTful
enabled = (desired_persistence
if desired_persistence != current_persistence else None)
try:
system.set_system_boot_options(
BOOT_DEVICE_MAP_REV[device],
enabled=BOOT_DEVICE_PERSISTENT_MAP_REV[persistent])
BOOT_DEVICE_MAP_REV[device], enabled=enabled)
except sushy.exceptions.SushyError as e:
error_msg = (_('Redfish set boot device failed for node '
'%(node)s. Error: %(error)s') %

@ -127,6 +127,31 @@ class RedfishManagementTestCase(db_base.DbTestCase):
fake_system.set_system_boot_options.reset_mock()
mock_get_system.reset_mock()
@mock.patch.object(redfish_utils, 'get_system', autospec=True)
def test_set_boot_device_persistency_no_change(self, mock_get_system):
fake_system = mock.Mock()
mock_get_system.return_value = fake_system
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
expected_values = [
(True, sushy.BOOT_SOURCE_ENABLED_CONTINUOUS),
(False, sushy.BOOT_SOURCE_ENABLED_ONCE)
]
for target, expected in expected_values:
fake_system.boot.get.return_value = expected
task.driver.management.set_boot_device(
task, boot_devices.PXE, persistent=target)
fake_system.set_system_boot_options.assert_called_once_with(
sushy.BOOT_SOURCE_TARGET_PXE, enabled=None)
mock_get_system.assert_called_once_with(task.node)
# Reset mocks
fake_system.set_system_boot_options.reset_mock()
mock_get_system.reset_mock()
@mock.patch.object(sushy, 'Sushy', autospec=True)
@mock.patch.object(redfish_utils, 'get_system', autospec=True)
def test_set_boot_device_fail(self, mock_get_system, mock_sushy):

@ -0,0 +1,7 @@
---
features:
- |
Makes management interface of ``redfish`` hardware type not changing
current boot frequency if currently set is the same as the desired one.
The goal is to avoid touching potentially faulty BMC option whenever
possible.