From c779be9f7d18779d9befed9c6d92253d50448a12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aija=20Jaunt=C4=93va?= <aija.jaunteva@dell.com>
Date: Mon, 14 Jun 2021 10:59:00 -0400
Subject: [PATCH] Redfish: Skip non-RAID controllers for RAID

Avoid processing non-RAID controllers as they cannot be
used for RAID operations to save some time and requests
and avoid possible errors later if non-RAID disks
are picked up for configuration.

Related to: I369bdbb17064baf34f90e864d0ece600529de509

Change-Id: I728f03dc829fb76cad9804c8f8df20810307ce2c
---
 ironic/drivers/modules/redfish/raid.py         |  5 +++++
 .../unit/drivers/modules/redfish/test_raid.py  | 18 ++++++++++++++++++
 ...p-nonraid-controllers-f4a79e2c9e8080ce.yaml |  7 +++++++
 3 files changed, 30 insertions(+)
 create mode 100644 releasenotes/notes/skip-nonraid-controllers-f4a79e2c9e8080ce.yaml

diff --git a/ironic/drivers/modules/redfish/raid.py b/ironic/drivers/modules/redfish/raid.py
index d856eabe45..4c29771372 100644
--- a/ironic/drivers/modules/redfish/raid.py
+++ b/ironic/drivers/modules/redfish/raid.py
@@ -591,6 +591,11 @@ def _filter_logical_disks(logical_disks, include_root_volume,
 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)
+        if controller and controller.raid_types == []:
+            continue
         for drive in storage.drives:
             if drive.identity in physical_disks:
                 return storage
diff --git a/ironic/tests/unit/drivers/modules/redfish/test_raid.py b/ironic/tests/unit/drivers/modules/redfish/test_raid.py
index 87a0575887..7c6ab4ba10 100644
--- a/ironic/tests/unit/drivers/modules/redfish/test_raid.py
+++ b/ironic/tests/unit/drivers/modules/redfish/test_raid.py
@@ -886,3 +886,21 @@ class RedfishRAIDTestCase(db_base.DbTestCase):
 
             self.assertNotIn(nonraid_storage.drives[0], disks)
             self.assertNotIn(nonraid_storage.drives[0], disk_to_controller)
+
+    def test__get_storage_controller(self, mock_get_system):
+        nonraid_controller = mock.Mock()
+        nonraid_controller.raid_types = []
+        nonraid_storage = mock.MagicMock()
+        nonraid_storage.storage_controllers = [nonraid_controller]
+        nonraid_storage.drives = mock.Mock()
+
+        mock_get_system.return_value.storage.get_members.return_value = [
+            nonraid_storage, self.mock_storage]
+
+        with task_manager.acquire(self.context, self.node.uuid,
+                                  shared=True) as task:
+            storage = redfish_raid._get_storage_controller(
+                task.node, mock_get_system.return_value, ['32ADF365C6C1B7BD'])
+
+            self.assertEqual(storage, self.mock_storage)
+            nonraid_storage.drives.assert_not_called()
diff --git a/releasenotes/notes/skip-nonraid-controllers-f4a79e2c9e8080ce.yaml b/releasenotes/notes/skip-nonraid-controllers-f4a79e2c9e8080ce.yaml
new file mode 100644
index 0000000000..2b3ed415d6
--- /dev/null
+++ b/releasenotes/notes/skip-nonraid-controllers-f4a79e2c9e8080ce.yaml
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    In Redfish RAID clean and deploy steps skip non-RAID storage controllers
+    for RAID operations. In Redfish systems that do not implement
+    ``SupportedRAIDTypes`` they are still processed and could result in
+    unexpected errors.