storage: Call function only if interfaces exist
Avoid making the dbus call if the interface does not exist and is
expected to error out to reduce the number of dbus calls.
Tested:
Redfish Validator passed for Drives
```
$ wget -qO- \
http://localhost:80/redfish/v1/Systems/system/Storage/1/Drives/drive
{
"@odata.id": "/redfish/v1/Systems/system/Storage/1/Drives/drive",
"@odata.type": "#Drive.v1_7_0.Drive",
"Id": "warthog",
"Links": {
"Chassis": {
"@odata.id": "/redfish/v1/Chassis/chassis"
}
},
"Manufacturer": "XXX",
"MediaType": "SSD",
"Model": "XXX",
"Name": "drive",
"PartNumber": "xxxxxxxxxxxxx",
"Protocol": "SATA",
"SerialNumber": "123456",
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
}
}
```
Change-Id: Ic83c8ee5a49f75b71d443781faf8b65d8fab31b6
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index 7f1e0de..0f5b0f9 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -564,10 +564,30 @@
const std::string& connectionName =
connectionNames[0].first;
- getDriveAsset(asyncResp, connectionName, path);
- getDrivePresent(asyncResp, connectionName, path);
- getDriveState(asyncResp, connectionName, path);
- getDriveItemProperties(asyncResp, connectionName, path);
+ for (const std::string& interface :
+ connectionNames[0].second)
+ {
+ if (interface ==
+ "xyz.openbmc_project.Inventory.Decorator.Asset")
+ {
+ getDriveAsset(asyncResp, connectionName, path);
+ }
+ else if (interface ==
+ "xyz.openbmc_project.Inventory.Item")
+ {
+ getDrivePresent(asyncResp, connectionName, path);
+ }
+ else if (interface == "xyz.openbmc_project.State.Drive")
+ {
+ getDriveState(asyncResp, connectionName, path);
+ }
+ else if (interface ==
+ "xyz.openbmc_project.Inventory.Item.Drive")
+ {
+ getDriveItemProperties(asyncResp, connectionName,
+ path);
+ }
+ }
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",