diff --git a/ironic/drivers/modules/redfish/management.py b/ironic/drivers/modules/redfish/management.py index 289c4755d7..e4715d95bc 100644 --- a/ironic/drivers/modules/redfish/management.py +++ b/ironic/drivers/modules/redfish/management.py @@ -66,6 +66,14 @@ BOOT_DEVICE_MAP_REV_COMPAT = dict( **{'bios setup': sushy.BOOT_SOURCE_TARGET_BIOS_SETUP} ) +VMEDIA_DEVICES_MAP = { + sushy.VIRTUAL_MEDIA_CD: boot_devices.CDROM, + sushy.VIRTUAL_MEDIA_FLOPPY: boot_devices.FLOPPY, + sushy.VIRTUAL_MEDIA_USBSTICK: boot_devices.DISK +} + +VMEDIA_DEVICES_MAP_REV = {v: k for k, v in VMEDIA_DEVICES_MAP.items()} + BOOT_MODE_MAP = { sushy.BOOT_SOURCE_MODE_UEFI: boot_modes.UEFI, sushy.BOOT_SOURCE_MODE_BIOS: boot_modes.LEGACY_BIOS @@ -1347,7 +1355,7 @@ class RedfishManagement(base.ManagementInterface): """ redfish_boot.insert_vmedia(task, image_url, - BOOT_DEVICE_MAP_REV[device_type]) + VMEDIA_DEVICES_MAP_REV[device_type]) @task_manager.require_exclusive_lock def detach_virtual_media(self, task, device_types=None): @@ -1364,4 +1372,4 @@ class RedfishManagement(base.ManagementInterface): else: for device_type in device_types: redfish_boot.eject_vmedia(task, - BOOT_DEVICE_MAP_REV[device_type]) + VMEDIA_DEVICES_MAP_REV[device_type]) diff --git a/ironic/tests/unit/drivers/modules/redfish/test_management.py b/ironic/tests/unit/drivers/modules/redfish/test_management.py index bf782520f0..669a0146a9 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_management.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_management.py @@ -1879,3 +1879,24 @@ class RedfishManagementTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: self.assertIsNone(task.driver.management.get_mac_addresses(task)) + + @mock.patch.object(redfish_boot, 'insert_vmedia', autospec=True) + def test_attach_virtual_media(self, mock_insert_vmedia): + with task_manager.acquire(self.context, self.node.uuid) as task: + task.driver.management.attach_virtual_media(task, 'cdrom', + 'http://test.iso') + mock_insert_vmedia.assert_called_once_with(task, 'http://test.iso', + sushy.VIRTUAL_MEDIA_CD) + + @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + def test_detach_virtual_media(self, mock_eject_vmedia): + with task_manager.acquire(self.context, self.node.uuid) as task: + task.driver.management.detach_virtual_media(task, ['cdrom']) + mock_eject_vmedia.assert_called_once_with(task, + sushy.VIRTUAL_MEDIA_CD) + + @mock.patch.object(redfish_boot, 'eject_vmedia', autospec=True) + def test_detach_virtual_media_all(self, mock_eject_vmedia): + with task_manager.acquire(self.context, self.node.uuid) as task: + task.driver.management.detach_virtual_media(task) + mock_eject_vmedia.assert_called_once_with(task) diff --git a/releasenotes/notes/fix-redfish-advmedia-part02-67ac1b22153ff1cf.yaml b/releasenotes/notes/fix-redfish-advmedia-part02-67ac1b22153ff1cf.yaml new file mode 100644 index 0000000000..5d85dc553c --- /dev/null +++ b/releasenotes/notes/fix-redfish-advmedia-part02-67ac1b22153ff1cf.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes an issue in redfish attach/detach generic virtual media where the + attached devices are not correctly recognized causing the attach operation + to fail.