diff --git a/ironic/drivers/modules/drac/raid.py b/ironic/drivers/modules/drac/raid.py index 6a3a06baf6..1f1b6eb0db 100644 --- a/ironic/drivers/modules/drac/raid.py +++ b/ironic/drivers/modules/drac/raid.py @@ -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 diff --git a/ironic/drivers/modules/redfish/raid.py b/ironic/drivers/modules/redfish/raid.py index be22f41d16..76b4cb245e 100644 --- a/ironic/drivers/modules/redfish/raid.py +++ b/ironic/drivers/modules/redfish/raid.py @@ -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 diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py index b1f8552cf9..797fa20878 100644 --- a/ironic/drivers/modules/redfish/utils.py +++ b/ironic/drivers/modules/redfish/utils.py @@ -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. diff --git a/ironic/tests/unit/drivers/modules/drac/test_raid.py b/ironic/tests/unit/drivers/modules/drac/test_raid.py index 091906704b..29d6b7d6e7 100644 --- a/ironic/tests/unit/drivers/modules/drac/test_raid.py +++ b/ironic/tests/unit/drivers/modules/drac/test_raid.py @@ -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') diff --git a/ironic/tests/unit/drivers/modules/redfish/test_raid.py b/ironic/tests/unit/drivers/modules/redfish/test_raid.py index 17c90e79a6..cf14b44ee5 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_raid.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_raid.py @@ -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 = [ diff --git a/releasenotes/notes/replace_deprecated_field_in_redfish_driver-eb75e6bf67913963.yaml b/releasenotes/notes/replace_deprecated_field_in_redfish_driver-eb75e6bf67913963.yaml new file mode 100644 index 0000000000..eb49c99ccd --- /dev/null +++ b/releasenotes/notes/replace_deprecated_field_in_redfish_driver-eb75e6bf67913963.yaml @@ -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. +