Fix internal error caused by unknown PCIe SlotType
Previously, when the SlotType field of a PCIeSlot object in D-Bus was
set to xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.Unknown,
pcie_slots was returning an internal service error. This commit
updates the code to not return the SlotType if it is unknown.
Tested: Validator passed
'''
busctl get-property -j xyz.openbmc_project.Inventory.Manager \
/xyz/openbmc_project/inventory/system/chassis/motherboard/disk_backplane1/nvme5 \
xyz.openbmc_project.Inventory.Item.PCIeSlot SlotType
{
"type" : "s",
"data" : "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.Unknown"
}
curl -k https://$bmc/redfish/v1/Chassis/chassis/PCIeSlots
{
"@odata.id": "/redfish/v1/Chassis/chassis/PCIeSlots",
"@odata.type": "#PCIeSlots.v1_4_1.PCIeSlots",
"Id": "1",
"Name": "PCIe Slot Information",
"Slots": [
{
"HotPluggable": false,
"Lanes": 0
},
.....
}
busctl get-property -j xyz.openbmc_project.Inventory.Manager \
/xyz/openbmc_project/inventory/system/chassis/motherboard/pcieslot9 \
xyz.openbmc_project.Inventory.Item.PCIeSlot SlotType
{
"type" : "s",
"data" : "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.FullLength"
}
curl -k https://$bmc/redfish/v1/Chassis/chassis/PCIeSlots
{
"@odata.id": "/redfish/v1/Chassis/chassis/PCIeSlots",
"@odata.type": "#PCIeSlots.v1_4_1.PCIeSlots",
"Id": "1",
"Name": "PCIe Slot Information",
"Slots": [
{
"HotPluggable": false,
"Lanes": 0
"SlotType": "FullLength"
},
.....
}
'''
Change-Id: Ib7399cebcb8dd4f9f19014d4d2154bc77e9dc999
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
diff --git a/redfish-core/lib/pcie_slots.hpp b/redfish-core/lib/pcie_slots.hpp
index ece84a3..51a5e69 100644
--- a/redfish-core/lib/pcie_slots.hpp
+++ b/redfish-core/lib/pcie_slots.hpp
@@ -21,7 +21,8 @@
namespace redfish
{
-inline pcie_slots::SlotTypes dbusSlotTypeToRf(const std::string& slotType)
+inline std::optional<pcie_slots::SlotTypes>
+ dbusSlotTypeToRf(const std::string& slotType)
{
if (slotType ==
"xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.FullLength")
@@ -65,9 +66,14 @@
{
return pcie_slots::SlotTypes::U2;
}
+ if (slotType ==
+ "xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.Unknown")
+ {
+ return pcie_slots::SlotTypes::Invalid;
+ }
- // Unknown or others
- return pcie_slots::SlotTypes::Invalid;
+ // Unspecified slotType should return an internal error.
+ return std::nullopt;
}
inline void
@@ -133,13 +139,17 @@
if (slotType != nullptr)
{
- pcie_slots::SlotTypes redfishSlotType = dbusSlotTypeToRf(*slotType);
- if (redfishSlotType == pcie_slots::SlotTypes::Invalid)
+ std::optional<pcie_slots::SlotTypes> redfishSlotType =
+ dbusSlotTypeToRf(*slotType);
+ if (!redfishSlotType)
{
messages::internalError(asyncResp->res);
return;
}
- slot["SlotType"] = redfishSlotType;
+ if (*redfishSlotType != pcie_slots::SlotTypes::Invalid)
+ {
+ slot["SlotType"] = *redfishSlotType;
+ }
}
if (hotPluggable != nullptr)