diff options
author | Lakshmi Yadlapati <lakshmiy@us.ibm.com> | 2023-06-27 10:36:53 +0300 |
---|---|---|
committer | Lakshmi Yadlapati <lakshmiy@us.ibm.com> | 2023-06-30 23:01:05 +0300 |
commit | cf3b484e14fe9754c1812d9871d77b5b1ac9f620 (patch) | |
tree | ca10a8862e24439ef3cb65374dce29f12b37a684 | |
parent | c05bba459941ae17aa9508529ccd0284e5300213 (diff) | |
download | bmcweb-cf3b484e14fe9754c1812d9871d77b5b1ac9f620.tar.xz |
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>
-rw-r--r-- | redfish-core/include/utils/pcie_util.hpp | 10 | ||||
-rw-r--r-- | redfish-core/lib/pcie.hpp | 13 | ||||
-rw-r--r-- | redfish-core/lib/pcie_slots.hpp | 22 |
3 files changed, 30 insertions, 15 deletions
diff --git a/redfish-core/include/utils/pcie_util.hpp b/redfish-core/include/utils/pcie_util.hpp index d9e8480cc9..4db6e03249 100644 --- a/redfish-core/include/utils/pcie_util.hpp +++ b/redfish-core/include/utils/pcie_util.hpp @@ -123,11 +123,10 @@ inline std::optional<pcie_slots::SlotTypes> 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 @@ inline std::optional<pcie_device::PCIeTypes> 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 b63c850479..82e1a5f1a6 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -295,11 +295,18 @@ inline void addPCIeDeviceProperties( 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 7246aea9e2..62fef3ea95 100644 --- a/redfish-core/lib/pcie_slots.hpp +++ b/redfish-core/lib/pcie_slots.hpp @@ -69,11 +69,16 @@ inline void 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 @@ inline void 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; } } |