Refactor redfishPcieGenerationFromDbus and redfishSlotType
This commit refactors the redfishPcieGenerationFromDbus and
redfishSlotType functions by changing their return types. The return
value std::nullopt indicates that there is no output, while the return
value pcie_device::PCIeTypes::Invalid indicates that the input was
invalid and returns an internal error. Additionally, the code that calls
these functions has been updated to accommodate the changes.
Tested: Validator passed
Change-Id: I3f7c1a3c8c6b53fd9a39928e3ad9a5fed9be97ff
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
diff --git a/redfish-core/include/utils/pcie_util.hpp b/redfish-core/include/utils/pcie_util.hpp
index d9e8480..4db6e03 100644
--- a/redfish-core/include/utils/pcie_util.hpp
+++ b/redfish-core/include/utils/pcie_util.hpp
@@ -123,11 +123,10 @@
if (slotType ==
"xyz.openbmc_project.Inventory.Item.PCIeSlot.SlotTypes.Unknown")
{
- return pcie_slots::SlotTypes::Invalid;
+ return std::nullopt;
}
- // Unspecified slotType should return an internal error.
- return std::nullopt;
+ return pcie_slots::SlotTypes::Invalid;
}
inline std::optional<pcie_device::PCIeTypes>
@@ -162,11 +161,10 @@
generationInUse ==
"xyz.openbmc_project.Inventory.Item.PCIeSlot.Generations.Unknown")
{
- return pcie_device::PCIeTypes::Invalid;
+ return std::nullopt;
}
- // The value is not unknown or Gen1-5, need return an internal error.
- return std::nullopt;
+ return pcie_device::PCIeTypes::Invalid;
}
} // namespace pcie_util
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index b63c850..82e1a5f 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -295,11 +295,18 @@
if (!redfishGenerationInUse)
{
- messages::internalError(resp);
- return;
+ BMCWEB_LOG_WARNING << "Unknown PCIe Device Generation: "
+ << *generationInUse;
}
- if (*redfishGenerationInUse != pcie_device::PCIeTypes::Invalid)
+ else
{
+ if (*redfishGenerationInUse == pcie_device::PCIeTypes::Invalid)
+ {
+ BMCWEB_LOG_ERROR << "Invalid PCIe Device Generation: "
+ << *generationInUse;
+ messages::internalError(resp);
+ return;
+ }
resp.jsonValue["PCIeInterface"]["PCIeType"] =
*redfishGenerationInUse;
}
diff --git a/redfish-core/lib/pcie_slots.hpp b/redfish-core/lib/pcie_slots.hpp
index 7246aea..62fef3e 100644
--- a/redfish-core/lib/pcie_slots.hpp
+++ b/redfish-core/lib/pcie_slots.hpp
@@ -69,11 +69,16 @@
pcie_util::redfishPcieGenerationFromDbus(*generation);
if (!pcieType)
{
- messages::internalError(asyncResp->res);
- return;
+ BMCWEB_LOG_WARNING << "Unknown PCIe Slot Generation: "
+ << *generation;
}
- if (*pcieType != pcie_device::PCIeTypes::Invalid)
+ else
{
+ if (*pcieType == pcie_device::PCIeTypes::Invalid)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
slot["PCIeType"] = *pcieType;
}
}
@@ -89,11 +94,16 @@
pcie_util::dbusSlotTypeToRf(*slotType);
if (!redfishSlotType)
{
- messages::internalError(asyncResp->res);
- return;
+ BMCWEB_LOG_WARNING << "Unknown PCIe Slot Type: " << *slotType;
}
- if (*redfishSlotType != pcie_slots::SlotTypes::Invalid)
+ else
{
+ if (*redfishSlotType == pcie_slots::SlotTypes::Invalid)
+ {
+ BMCWEB_LOG_ERROR << "Unknown PCIe Slot Type: " << *slotType;
+ messages::internalError(asyncResp->res);
+ return;
+ }
slot["SlotType"] = *redfishSlotType;
}
}