summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/modules/redfish/test_management.py
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@protonmail.com>2021-11-04 18:24:18 +0100
committerDmitry Tantsur <dtantsur@protonmail.com>2021-11-10 12:25:43 +0100
commit93fd147b6f99701e1f5a75c2659f5ec4945eb895 (patch)
treeab4e79747505791c7cf49adc2886b728205eb961 /ironic/tests/unit/drivers/modules/redfish/test_management.py
parent815705bc7deb877c2efaee750bbfaabcd3e635ff (diff)
downloadironic-93fd147b6f99701e1f5a75c2659f5ec4945eb895.tar.gz
Stop relying on explicit values of Redfish constants
There are a few places in unit tests where we rely on Redfish constants having well-known values. Use constants themselves instead. An even more problematic place is _set_boot_device: it relies on storing Redfish constants in driver_internal_info. With the future switch to enums, it will no longer be possible. Use Ironic constants and provide a compatibility layer. Change-Id: I8e075f808e013afd778dd7cdc0927fe339309b70
Diffstat (limited to 'ironic/tests/unit/drivers/modules/redfish/test_management.py')
-rw-r--r--ironic/tests/unit/drivers/modules/redfish/test_management.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/ironic/tests/unit/drivers/modules/redfish/test_management.py b/ironic/tests/unit/drivers/modules/redfish/test_management.py
index f67efa9f0..738bd8802 100644
--- a/ironic/tests/unit/drivers/modules/redfish/test_management.py
+++ b/ironic/tests/unit/drivers/modules/redfish/test_management.py
@@ -263,7 +263,7 @@ class RedfishManagementTestCase(db_base.DbTestCase):
task.node.refresh()
self.assertEqual(
- sushy.BOOT_SOURCE_TARGET_PXE,
+ boot_devices.PXE,
task.node.driver_internal_info['redfish_boot_device'])
@mock.patch.object(redfish_utils, 'get_system', autospec=True)
@@ -305,7 +305,7 @@ class RedfishManagementTestCase(db_base.DbTestCase):
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
+ boot_devices.DISK
)
task.driver.management.restore_boot_device(task, fake_system)
@@ -315,7 +315,24 @@ class RedfishManagementTestCase(db_base.DbTestCase):
enabled=sushy.BOOT_SOURCE_ENABLED_ONCE)
# The stored boot device is kept intact
self.assertEqual(
+ boot_devices.DISK,
+ task.node.driver_internal_info['redfish_boot_device'])
+
+ def test_restore_boot_device_compat(self):
+ fake_system = mock.Mock()
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
+ # Previously we used sushy constants
+ task.node.driver_internal_info['redfish_boot_device'] = "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=sushy.BOOT_SOURCE_ENABLED_ONCE)
+ # The stored boot device is kept intact
+ self.assertEqual(
+ "hdd",
task.node.driver_internal_info['redfish_boot_device'])
def test_restore_boot_device_noop(self):
@@ -335,7 +352,7 @@ class RedfishManagementTestCase(db_base.DbTestCase):
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
+ boot_devices.DISK
)
task.driver.management.restore_boot_device(task, fake_system)
@@ -346,7 +363,7 @@ class RedfishManagementTestCase(db_base.DbTestCase):
self.assertTrue(mock_log.called)
# The stored boot device is kept intact
self.assertEqual(
- sushy.BOOT_SOURCE_TARGET_HDD,
+ boot_devices.DISK,
task.node.driver_internal_info['redfish_boot_device'])
@mock.patch.object(redfish_utils, 'get_system', autospec=True)
@@ -394,7 +411,7 @@ class RedfishManagementTestCase(db_base.DbTestCase):
# Asserts
fake_system.set_system_boot_options.assert_called_once_with(
- mode=mode)
+ mode=expected)
mock_get_system.assert_called_once_with(task.node)
# Reset mocks
@@ -419,7 +436,7 @@ class RedfishManagementTestCase(db_base.DbTestCase):
exception.RedfishError, 'Setting boot mode',
task.driver.management.set_boot_mode, task, boot_modes.UEFI)
fake_system.set_system_boot_options.assert_called_once_with(
- mode=boot_modes.UEFI)
+ mode=sushy.BOOT_SOURCE_MODE_UEFI)
mock_get_system.assert_called_once_with(task.node)
@mock.patch.object(sushy, 'Sushy', autospec=True)
@@ -440,7 +457,7 @@ class RedfishManagementTestCase(db_base.DbTestCase):
'does not support set_boot_mode',
task.driver.management.set_boot_mode, task, boot_modes.UEFI)
fake_system.set_system_boot_options.assert_called_once_with(
- mode=boot_modes.UEFI)
+ mode=sushy.BOOT_SOURCE_MODE_UEFI)
mock_get_system.assert_called_once_with(task.node)
@mock.patch.object(redfish_utils, 'get_system', autospec=True)