diff options
author | Claire Weinan <cweinan@google.com> | 2022-07-16 05:17:19 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-08-04 00:45:33 +0300 |
commit | aefe3786057499a767c5627b0106f0248fa3762d (patch) | |
tree | ff39c461464538d64fa3969fb7a1890aac6d23d3 | |
parent | f610caaeaebc3b6aeaef3cd293ae6e43339af315 (diff) | |
download | bmcweb-aefe3786057499a767c5627b0106f0248fa3762d.tar.xz |
LogService: Refactor dump entry parsing
Refactored common code for parsing dump entry information from D-Bus
response objects (shared by getDumpEntryCollection() and
getDumpEntryById()) into a new function parseDumpEntryFromDbusObject().
The parsing is similar to what is done by parseCrashdumpParameters().
This refactoring is being done in anticipation of adding additional
D-Bus property parsing for dump entries (without this refactoring,
code duplication will increase).
No noticeable client impact.
Tested:
Get dump entries individually and as a collection.
Example commands:
curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries
curl -k -H "X-Auth-Token: $token" -X GET
http://${bmc}/redfish/v1/Managers/bmc/LogServices/FaultLog/Entries/1
curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries
curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries/1
Redfish Service Validator succeeded on the following URI trees:
/redfish/v1/Managers/bmc/LogServices/FaultLog
/redfish/v1/Managers/bmc/LogServices/Dump
/redfish/v1/Systems/system/LogServices/Dump
Signed-off-by: Claire Weinan <cweinan@google.com>
Change-Id: If67fb0c1f35175ae0e2968f8d7a52c13e66b1dc7
-rw-r--r-- | redfish-core/lib/log_services.hpp | 183 |
1 files changed, 67 insertions, 116 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index a10075ac21..6f46a7f5aa 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -326,6 +326,69 @@ static bool return !redfishLogFiles.empty(); } +inline void parseDumpEntryFromDbusObject( + const dbus::utility::ManagedItem& object, std::string& dumpStatus, + uint64_t& size, uint64_t& timestamp, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) +{ + for (const auto& interfaceMap : object.second) + { + if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") + { + for (const auto& propertyMap : interfaceMap.second) + { + if (propertyMap.first == "Status") + { + const auto* status = + std::get_if<std::string>(&propertyMap.second); + if (status == nullptr) + { + messages::internalError(asyncResp->res); + break; + } + dumpStatus = *status; + } + } + } + else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") + { + for (const auto& propertyMap : interfaceMap.second) + { + if (propertyMap.first == "Size") + { + const auto* sizePtr = + std::get_if<uint64_t>(&propertyMap.second); + if (sizePtr == nullptr) + { + messages::internalError(asyncResp->res); + break; + } + size = *sizePtr; + break; + } + } + } + else if (interfaceMap.first == "xyz.openbmc_project.Time.EpochTime") + { + for (const auto& propertyMap : interfaceMap.second) + { + if (propertyMap.first == "Elapsed") + { + const uint64_t* usecsTimeStamp = + std::get_if<uint64_t>(&propertyMap.second); + if (usecsTimeStamp == nullptr) + { + messages::internalError(asyncResp->res); + break; + } + timestamp = *usecsTimeStamp; + break; + } + } + } + } +} + static std::string getDumpEntriesPath(const std::string& dumpType) { std::string entriesPath; @@ -416,65 +479,8 @@ inline void continue; } - for (auto& interfaceMap : object.second) - { - if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") - { - for (const auto& propertyMap : interfaceMap.second) - { - if (propertyMap.first == "Status") - { - const auto* status = - std::get_if<std::string>(&propertyMap.second); - if (status == nullptr) - { - messages::internalError(asyncResp->res); - break; - } - dumpStatus = *status; - } - } - } - else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") - { - - for (auto& propertyMap : interfaceMap.second) - { - if (propertyMap.first == "Size") - { - const auto* sizePtr = - std::get_if<uint64_t>(&propertyMap.second); - if (sizePtr == nullptr) - { - messages::internalError(asyncResp->res); - break; - } - size = *sizePtr; - break; - } - } - } - else if (interfaceMap.first == - "xyz.openbmc_project.Time.EpochTime") - { - - for (const auto& propertyMap : interfaceMap.second) - { - if (propertyMap.first == "Elapsed") - { - const uint64_t* usecsTimeStamp = - std::get_if<uint64_t>(&propertyMap.second); - if (usecsTimeStamp == nullptr) - { - messages::internalError(asyncResp->res); - break; - } - timestamp = (*usecsTimeStamp / 1000 / 1000); - break; - } - } - } - } + parseDumpEntryFromDbusObject(object, dumpStatus, size, timestamp, + asyncResp); if (dumpStatus != "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && @@ -553,63 +559,8 @@ inline void uint64_t size = 0; std::string dumpStatus; - for (const auto& interfaceMap : objectPath.second) - { - if (interfaceMap.first == "xyz.openbmc_project.Common.Progress") - { - for (const auto& propertyMap : interfaceMap.second) - { - if (propertyMap.first == "Status") - { - const std::string* status = - std::get_if<std::string>(&propertyMap.second); - if (status == nullptr) - { - messages::internalError(asyncResp->res); - break; - } - dumpStatus = *status; - } - } - } - else if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") - { - for (const auto& propertyMap : interfaceMap.second) - { - if (propertyMap.first == "Size") - { - const uint64_t* sizePtr = - std::get_if<uint64_t>(&propertyMap.second); - if (sizePtr == nullptr) - { - messages::internalError(asyncResp->res); - break; - } - size = *sizePtr; - break; - } - } - } - else if (interfaceMap.first == - "xyz.openbmc_project.Time.EpochTime") - { - for (const auto& propertyMap : interfaceMap.second) - { - if (propertyMap.first == "Elapsed") - { - const uint64_t* usecsTimeStamp = - std::get_if<uint64_t>(&propertyMap.second); - if (usecsTimeStamp == nullptr) - { - messages::internalError(asyncResp->res); - break; - } - timestamp = *usecsTimeStamp / 1000 / 1000; - break; - } - } - } - } + parseDumpEntryFromDbusObject(objectPath, dumpStatus, size, + timestamp, asyncResp); if (dumpStatus != "xyz.openbmc_project.Common.Progress.OperationStatus.Completed" && |