diff options
author | Ali Ahmed <ama213000@gmail.com> | 2021-08-31 22:59:58 +0300 |
---|---|---|
committer | Ali Ahmed <ama213000@gmail.com> | 2021-09-03 10:46:31 +0300 |
commit | a1978347588642a9677eca4d96d2a89e93d225a0 (patch) | |
tree | 8468b1f65609852551437bf76247517c1a990d4a /redfish-core/lib/systems.hpp | |
parent | 877044644f53d4dd93499d3a99d8c227694fd3a5 (diff) | |
download | bmcweb-a1978347588642a9677eca4d96d2a89e93d225a0.tar.xz |
Have ProcessorSummary correctly set Status
Remove unnecessary condition, and correctly get Status
from Present and Functional properties.
Removal of if, else code:
1. If condition never evaluates to false ('else' branch is never taken)
Properties size will always be 7 as that's how it's defined here [1]
Context:
The 'if' code branch was originally there for a company that was NOT
following the d-bus interfaces. See commit 57e8c9b [2] & gerrit [3].
Later, properties were added to the Inventory.Item.Cpu interface,
so now everyone is hitting this 'if' branch. See commit 259f49e [4].
The code in the 'else' condition uses Inventory.Item Present and
State.Decorator.OperationalStatus Function to determine Redfish "Count",
"Status""State", "Status""Health", since this is the correct way to
determine Redfish Status.
Summary:
1) Removes the if/else condition, and
2) Retains the code that was in the else condition
[1] https://github.com/openbmc/phosphor-dbus-interfaces/blob/master
/yaml/xyz/openbmc_project/Inventory/Item/Cpu.interface.yaml
[2] https://github.com/openbmc/bmcweb/commit/57e8c9b
[3] https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/20572/4
[4] https://github.com/openbmc/phosphor-dbus-interfaces/commit/259f49e
Tested:
curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system
Before:
...
"ProcessorSummary": {
"Count": 0,
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Disabled"
}
},
...
After:
...
"ProcessorSummary": {
"Count": 2,
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
}
},
...
Signed-off-by: Ali Ahmed <ama213000@gmail.com>
Change-Id: I1a38086b87f4f1e2ebbfa3b5058d95158d29002a
Diffstat (limited to 'redfish-core/lib/systems.hpp')
-rw-r--r-- | redfish-core/lib/systems.hpp | 182 |
1 files changed, 57 insertions, 125 deletions
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 320f4e4f26..680a0ee7db 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -326,135 +326,67 @@ inline void << properties.size() << " Cpu properties."; - if (properties.size() > 0) - { - const uint64_t* processorId = nullptr; - const std::string* procFamily = nullptr; - nlohmann::json& procSummary = - aResp->res.jsonValue["ProcessorSumm" - "ary"]; - nlohmann::json& procCount = - procSummary["Count"]; - - auto procCountPtr = procCount.get_ptr< - nlohmann::json:: - number_integer_t*>(); - if (procCountPtr == nullptr) - { - messages::internalError(aResp->res); - return; - } - for (const auto& property : properties) - { - - if (property.first == "Id") + auto getCpuPresenceState = + [aResp]( + const boost::system::error_code ec3, + const std::variant<bool>& + cpuPresenceCheck) { + if (ec3) { - processorId = - std::get_if<uint64_t>( - &property.second); - if (nullptr != procFamily) - { - break; - } - continue; + BMCWEB_LOG_ERROR + << "DBUS response error " + << ec3; + return; } - - if (property.first == "Family") - { - procFamily = - std::get_if<std::string>( - &property.second); - if (nullptr != processorId) - { - break; - } - continue; - } - } - - if (procFamily != nullptr && - processorId != nullptr) - { - if (procCountPtr != nullptr && - *processorId != 0) + modifyCpuPresenceState( + aResp, cpuPresenceCheck); + }; + + auto getCpuFunctionalState = + [aResp]( + const boost::system::error_code ec3, + const std::variant<bool>& + cpuFunctionalCheck) { + if (ec3) { - *procCountPtr += 1; - procSummary["Status"]["State"] = - "Enabled"; - - procSummary["Model"] = - *procFamily; + BMCWEB_LOG_ERROR + << "DBUS response error " + << ec3; + return; } - } - } - else - { - auto getCpuPresenceState = - [aResp]( - const boost::system::error_code - ec3, - const std::variant<bool>& - cpuPresenceCheck) { - if (ec3) - { - BMCWEB_LOG_ERROR - << "DBUS response " - "error " - << ec3; - return; - } - modifyCpuPresenceState( - aResp, cpuPresenceCheck); - }; - - auto getCpuFunctionalState = - [aResp]( - const boost::system::error_code - ec3, - const std::variant<bool>& - cpuFunctionalCheck) { - if (ec3) - { - BMCWEB_LOG_ERROR - << "DBUS response " - "error " - << ec3; - return; - } - modifyCpuFunctionalState( - aResp, cpuFunctionalCheck); - }; - // Get the Presence of CPU - crow::connections::systemBus - ->async_method_call( - std::move(getCpuPresenceState), - service, path, - "org.freedesktop.DBus." - "Properties", - "Get", - "xyz.openbmc_project.Inventory." - "Item", - "Present"); - - // Get the Functional State - crow::connections::systemBus - ->async_method_call( - std::move( - getCpuFunctionalState), - service, path, - "org.freedesktop.DBus." - "Properties", - "Get", - "xyz.openbmc_project.State." - "Decorator." - "OperationalStatus", - "Functional"); - - // Get the MODEL from - // xyz.openbmc_project.Inventory.Decorator.Asset - // support it later as Model is Empty - // currently. - } + modifyCpuFunctionalState( + aResp, cpuFunctionalCheck); + }; + + // Get the Presence of CPU + crow::connections::systemBus + ->async_method_call( + std::move(getCpuPresenceState), + service, path, + "org.freedesktop.DBus." + "Properties", + "Get", + "xyz.openbmc_project.Inventory." + "Item", + "Present"); + + // Get the Functional State + crow::connections::systemBus + ->async_method_call( + std::move(getCpuFunctionalState), + service, path, + "org.freedesktop.DBus." + "Properties", + "Get", + "xyz.openbmc_project.State." + "Decorator." + "OperationalStatus", + "Functional"); + + // Get the MODEL from + // xyz.openbmc_project.Inventory.Decorator.Asset + // support it later as Model is Empty + // currently. }, connection.first, path, "org.freedesktop.DBus.Properties", "GetAll", |