Fix attach/detach vmedia redfish implementation

We need to map with virtual media devices and not boot
devices only.

Change-Id: I88b56ae26d9f1d8642ed6ffc5c055f8d56f6939a
(cherry picked from commit c1f3daf7b0)
This commit is contained in:
Riccardo Pittau 2024-04-22 15:25:46 +02:00
parent d31ea3d051
commit 5026e30797
3 changed files with 39 additions and 2 deletions

View File

@ -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
@ -1346,7 +1354,8 @@ class RedfishManagement(base.ManagementInterface):
:param image_url: URL of the image to attach, HTTP or HTTPS.
"""
redfish_boot.insert_vmedia(task, image_url, device_type)
redfish_boot.insert_vmedia(task, image_url,
VMEDIA_DEVICES_MAP_REV[device_type])
@task_manager.require_exclusive_lock
def detach_virtual_media(self, task, device_types=None):
@ -1362,4 +1371,5 @@ class RedfishManagement(base.ManagementInterface):
redfish_boot.eject_vmedia(task)
else:
for device_type in device_types:
redfish_boot.eject_vmedia(task, device_type)
redfish_boot.eject_vmedia(task,
VMEDIA_DEVICES_MAP_REV[device_type])

View File

@ -1893,3 +1893,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)

View File

@ -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.