bmcweb: Redfish make MemorySizeInKB optional
This commit makes Memory Size an optional parameter.
On X86 platforms, MemorySizeInKB is coming from the MDR daemon.
For other platforms it is undefined. Still some work to do here,
but this commit fixes the internal error in
/redfish/v1/Systems/{ComputerSystemId}/Memory/{MemoryId} on non-X86
systems.
Resolves: openbmc/bmcweb#19
curl -k -H "X-Auth-Token: $bmc_token" -X GET \
https://${bmc}/redfish/v1/Systems/motherboard/Memory/dimm9
{
"@odata.context": "/redfish/v1/$metadata#Memory.Memory",
"@odata.id": "/redfish/v1/Systems/motherboard/Memory/dimm9",
"@odata.type": "#Memory.v1_2_0.Memory",
"Id": "dimm9",
"Name": "DIMM Slot",
"Status": {
"Health": "OK",
"State": "Enabled"
}
}
Change-Id: Ib2b558ba2299674edab0132a21dc6109e4b81732
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/redfish-core/lib/cpudimm.hpp b/redfish-core/lib/cpudimm.hpp
index ca2f164..ada4332 100644
--- a/redfish-core/lib/cpudimm.hpp
+++ b/redfish-core/lib/cpudimm.hpp
@@ -216,32 +216,28 @@
aResp->res.jsonValue["Name"] = "DIMM Slot";
const auto memorySizeProperty = properties.find("MemorySizeInKB");
- if (memorySizeProperty == properties.end())
+ if (memorySizeProperty != properties.end())
{
- // Important property not in result
- messages::internalError(aResp->res);
+ const uint32_t *memorySize =
+ sdbusplus::message::variant_ns::get_if<uint32_t>(
+ &memorySizeProperty->second);
+ if (memorySize == nullptr)
+ {
+ // Important property not in desired type
+ messages::internalError(aResp->res);
- return;
+ return;
+ }
+ if (*memorySize == 0)
+ {
+ // Slot is not populated, set status end return
+ aResp->res.jsonValue["Status"]["State"] = "Absent";
+ aResp->res.jsonValue["Status"]["Health"] = "OK";
+ // HTTP Code will be set up automatically, just return
+ return;
+ }
+ aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10);
}
- const uint32_t *memorySize =
- sdbusplus::message::variant_ns::get_if<uint32_t>(
- &memorySizeProperty->second);
- if (memorySize == nullptr)
- {
- // Important property not in desired type
- messages::internalError(aResp->res);
-
- return;
- }
- if (*memorySize == 0)
- {
- // Slot is not populated, set status end return
- aResp->res.jsonValue["Status"]["State"] = "Absent";
- aResp->res.jsonValue["Status"]["Health"] = "OK";
- // HTTP Code will be set up automatically, just return
- return;
- }
- aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10);
aResp->res.jsonValue["Status"]["State"] = "Enabled";
aResp->res.jsonValue["Status"]["Health"] = "OK";