Deprecated field in Redfish Driver

Replaces depracated field ``storage.storage_controllers`` with the
new ``storage.controllers`` in the Redfish driver.

Closes-Bug: #2070485
Change-Id: Ibe66c73c8d2e402fabaa7a3a2fbc2f3c44e47dbd
This commit is contained in:
cid 2024-06-27 15:06:09 +01:00
parent 6ed746cf5e
commit 944ee5eee1
6 changed files with 30 additions and 13 deletions

View File

@ -1362,8 +1362,7 @@ class DracRedfishRAID(redfish_raid.RedfishRAID):
"""
for storage in system.storage.get_members():
if storage.identity == identity:
controller = (storage.storage_controllers[0]
if storage.storage_controllers else None)
controller = redfish_utils.get_first_controller(storage)
if controller:
return storage, controller

View File

@ -125,8 +125,7 @@ def get_physical_disks(node):
try:
collection = system.storage
for storage in collection.get_members():
controller = (storage.storage_controllers[0]
if storage.storage_controllers else None)
controller = redfish_utils.get_first_controller(storage)
if controller and controller.raid_types == []:
continue
disks.extend(storage.drives)
@ -590,8 +589,7 @@ def _get_storage_controller(node, system, physical_disks):
collection = system.storage
for storage in collection.get_members():
# Using first controller as expecting only one
controller = (storage.storage_controllers[0]
if storage.storage_controllers else None)
controller = redfish_utils.get_first_controller(storage)
if controller and controller.raid_types == []:
continue
for drive in storage.drives:
@ -1130,8 +1128,7 @@ class RedfishRAID(base.RAIDInterface):
any_left = False
try:
for storage in system.storage.get_members():
controller = (storage.storage_controllers[0]
if storage.storage_controllers else None)
controller = redfish_utils.get_first_controller(storage)
controller_id = None
if controller:
controller_id = storage.identity

View File

@ -322,6 +322,19 @@ def get_event_service(node):
raise exception.RedfishError(error=e)
def get_first_controller(storage):
"""Get the first storage controller from a storage object.
:param storage: a storage object
:returns: the first storage controller or None
"""
if hasattr(storage, 'controllers'):
return storage.controllers[0]
elif hasattr(storage, 'storage_controllers'):
return storage.storage_controllers[0]
return None
def get_system(node):
"""Get a Redfish System that represents a node.

View File

@ -2388,11 +2388,11 @@ class DracRedfishRAIDTestCase(test_utils.BaseDracTest):
identity='Disk.Direct.0-0:AHCI.Slot.2-1')
mock_controller1 = mock.Mock()
mock_storage1 = mock.Mock(storage_controllers=[mock_controller1],
mock_storage1 = mock.Mock(controllers=[mock_controller1],
drives=[mock_drive1, mock_drive2],
identity='RAID.Integrated.1-1')
mock_controller2 = mock.Mock()
mock_storage2 = mock.Mock(storage_controllers=[mock_controller2],
mock_storage2 = mock.Mock(controllers=[mock_controller2],
drives=[mock_drive3],
identity='AHCI.Slot.2-1')

View File

@ -102,7 +102,7 @@ class RedfishRAIDTestCase(db_base.DbTestCase):
self.mock_storage.drives = mock_drives
mock_controller = mock.Mock()
mock_controller.raid_types = ['RAID1', 'RAID5', 'RAID10']
self.mock_storage.storage_controllers = [mock_controller]
self.mock_storage.controllers = [mock_controller]
mock_volumes = mock.MagicMock()
self.mock_storage.volumes = mock_volumes
self.free_space_bytes = {d: d.capacity_bytes for d in
@ -1137,7 +1137,7 @@ class RedfishRAIDTestCase(db_base.DbTestCase):
nonraid_controller = mock.Mock()
nonraid_controller.raid_types = []
nonraid_storage = mock.MagicMock()
nonraid_storage.storage_controllers = [nonraid_controller]
nonraid_storage.controllers = [nonraid_controller]
nonraid_storage.drives = [_mock_drive(
identity='Drive1', block_size_bytes=512,
capacity_bytes=899527000000,
@ -1162,7 +1162,7 @@ class RedfishRAIDTestCase(db_base.DbTestCase):
nonraid_controller = mock.Mock()
nonraid_controller.raid_types = []
nonraid_storage = mock.MagicMock()
nonraid_storage.storage_controllers = [nonraid_controller]
nonraid_storage.controllers = [nonraid_controller]
nonraid_storage.drives = mock.Mock()
mock_get_system.return_value.storage.get_members.return_value = [

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Replaces deprecated ``Storage.StorageControllers`` in Redfish RAID
with ``Storage.Controllers``, which provides an array of links to
controller objects instead of embedding the full controller objects.
The old field is now used as a fallback.