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
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index f84a17a..4e9b4b7 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -709,6 +709,70 @@
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 @@
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",