diff options
author | Nan Zhou <nanzhoumails@gmail.com> | 2022-05-21 00:22:32 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-05-26 01:08:59 +0300 |
commit | ef00d7d42cc8f7d90957ab7ca1f678cd531c2cb4 (patch) | |
tree | 7483dce76aa35de5a333252830e9e55473b1248d | |
parent | b1e8a8e38db7cf36f8d93071d9aff1989d447d43 (diff) | |
download | bmcweb-ef00d7d42cc8f7d90957ab7ca1f678cd531c2cb4.tar.xz |
memory: move Partition codes from callbacks into separate functions
Another change to move codes from callbacks to functions in the memory
resource.
It is a bit cleaner to have separate functions rather than keep codes in
the callback, as callback normally have deeper indent.
The main reason is that this helps code review of later changes that
make Expand at MemoryCollection efficient.
Tested:
1. on my mockup environment; added partition data into the fake dimm;
URL /redfish/v1/Systems/system/Memory/dimm0
```
{
"@odata.id": "/redfish/v1/Systems/system/Memory/dimm0",
"@odata.type": "#Memory.v1_11_0.Memory",
"AllowedSpeedsMHz": [],
"BaseModuleType": "RDIMM",
"BusWidthBits": 0,
"CapacityMiB": 1024,
"DataWidthBits": 0,
"ErrorCorrection": "NoECC",
"FirmwareRevision": "0",
"Id": "dimm0",
"Name": "DIMM Slot",
"OperatingSpeedMhz": 0,
"RankCount": 0,
"Regions": [
{
"MemoryClassification": "",
"OffsetMiB": 0,
"PassphraseEnabled": false,
"RegionId": "",
"SizeMiB": 1024
}
],
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
}
}
```
2. No new Redfish Validator failures on MemoryCollection on real
hardware.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I27b251ff32bab026d6fa919abf7b6dcf2905e4a3
-rw-r--r-- | redfish-core/lib/memory.hpp | 126 |
1 files changed, 65 insertions, 61 deletions
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp index f84a17a709..4e9b4b7e86 100644 --- a/redfish-core/lib/memory.hpp +++ b/redfish-core/lib/memory.hpp @@ -709,6 +709,70 @@ inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); } +inline void assembleDimmPartitionData( + const std::shared_ptr<bmcweb::AsyncResp>& aResp, + const dbus::utility::DBusPropertiesMap& properties) +{ + nlohmann::json& partition = + aResp->res.jsonValue["Regions"].emplace_back(nlohmann::json::object()); + for (const auto& [key, val] : properties) + { + if (key == "MemoryClassification") + { + const std::string* value = std::get_if<std::string>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + return; + } + partition[key] = *value; + } + else if (key == "OffsetInKiB") + { + const uint64_t* value = std::get_if<uint64_t>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + return; + } + + partition["OffsetMiB"] = (*value >> 10); + } + else if (key == "PartitionId") + { + const std::string* value = std::get_if<std::string>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + return; + } + partition["RegionId"] = *value; + } + + else if (key == "PassphraseState") + { + const bool* value = std::get_if<bool>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + return; + } + partition["PassphraseEnabled"] = *value; + } + else if (key == "SizeInKiB") + { + const uint64_t* value = std::get_if<uint64_t>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + BMCWEB_LOG_DEBUG << "Invalid property type for SizeInKiB"; + return; + } + partition["SizeMiB"] = (*value >> 10); + } + } +} + inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp, const std::string& service, const std::string& path) @@ -724,67 +788,7 @@ inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp, return; } - - nlohmann::json& partition = - aResp->res.jsonValue["Regions"].emplace_back( - nlohmann::json::object()); - for (const auto& [key, val] : properties) - { - if (key == "MemoryClassification") - { - const std::string* value = std::get_if<std::string>(&val); - if (value == nullptr) - { - messages::internalError(aResp->res); - return; - } - partition[key] = *value; - } - else if (key == "OffsetInKiB") - { - const uint64_t* value = std::get_if<uint64_t>(&val); - if (value == nullptr) - { - messages::internalError(aResp->res); - return; - } - - partition["OffsetMiB"] = (*value >> 10); - } - else if (key == "PartitionId") - { - const std::string* value = std::get_if<std::string>(&val); - if (value == nullptr) - { - messages::internalError(aResp->res); - return; - } - partition["RegionId"] = *value; - } - - else if (key == "PassphraseState") - { - const bool* value = std::get_if<bool>(&val); - if (value == nullptr) - { - messages::internalError(aResp->res); - return; - } - partition["PassphraseEnabled"] = *value; - } - else if (key == "SizeInKiB") - { - const uint64_t* value = std::get_if<uint64_t>(&val); - if (value == nullptr) - { - messages::internalError(aResp->res); - BMCWEB_LOG_DEBUG - << "Invalid property type for SizeInKiB"; - return; - } - partition["SizeMiB"] = (*value >> 10); - } - } + assembleDimmPartitionData(aResp, properties); }, service, path, "org.freedesktop.DBus.Properties", "GetAll", |