diff options
author | Albert Zhang <zhanghaodi@inspur.com> | 2021-06-10 09:41:48 +0300 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2023-07-13 06:01:59 +0300 |
commit | 9f1ae5ae73212293cc2fe92dff1fa2449039fa81 (patch) | |
tree | 40230a2129b6946d8bdb1ecb4cdeb32a7431c9bd /redfish-core/lib | |
parent | e4e54232c271f3c4b92531b1de78329d08a05fff (diff) | |
download | bmcweb-9f1ae5ae73212293cc2fe92dff1fa2449039fa81.tar.xz |
Add Status information for Fan
This commit is to add Fan State/Health status according to the
Redfish Fan schema.
If the `xyz.openbmc_project.Inventory.Item`
interface does not exist, the state status property is set to
default "Present".
If the `xyz.openbmc_project.State.Decorator.OperationalStatus`
interface does not exist, the health status property is set to
default "OK".
ref: https://redfish.dmtf.org/schemas/v1/Fan.v1_3_0.json
Code that updates the OperationalStatus for all the inventory
https://github.com/openbmc/openpower-vpd-parser/blob/3fb026386546cfd288ab4f86156c9aa0ffa145d6/ibm_vpd_app.cpp#L620
Tested: Validator passes
'''
1.doGet method to get Fan
curl -k https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0
{
"@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0",
"@odata.type": "#Fan.v1_3_0.Fan",
"Id": "fan0",
"Name": "Fan",
"Status": {
"Health": "OK",
"State": "Enabled"
}
}
2.Enter the wrong fanId with the doGet method to get fan
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type Fan named 'fanx' was not found.",
"MessageArgs": [
"Fan",
"fanx"
],
"MessageId": "Base.1.13.0.ResourceNotFound",
"MessageSeverity": "Critical",
"Resolution": "Provide a valid resource identifier and resubmit the request."
}
],
"code": "Base.1.13.0.ResourceNotFound",
"message": "The requested resource of type Fan named 'fanx' was not found."
}
}
'''
Signed-off-by: Albert Zhang <zhanghaodi@inspur.com>
Change-Id: I52c465f745587233e43a2947c392d1435b2d980b
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
Diffstat (limited to 'redfish-core/lib')
-rw-r--r-- | redfish-core/lib/fan.hpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/redfish-core/lib/fan.hpp b/redfish-core/lib/fan.hpp index 47d65ee23b..fb2ba20cc1 100644 --- a/redfish-core/lib/fan.hpp +++ b/redfish-core/lib/fan.hpp @@ -7,7 +7,9 @@ #include "registries/privilege_registry.hpp" #include "utils/chassis_utils.hpp" +#include <boost/system/error_code.hpp> #include <boost/url/format.hpp> +#include <sdbusplus/asio/property.hpp> #include <sdbusplus/message/types.hpp> #include <functional> @@ -222,6 +224,58 @@ inline void addFanCommonProperties(crow::Response& resp, resp.jsonValue["Id"] = fanId; resp.jsonValue["@odata.id"] = boost::urls::format( "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans/{}", chassisId, fanId); + resp.jsonValue["Status"]["State"] = "Enabled"; + resp.jsonValue["Status"]["Health"] = "OK"; +} + +inline void getFanHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& fanPath, const std::string& service) +{ + sdbusplus::asio::getProperty<bool>( + *crow::connections::systemBus, service, fanPath, + "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", + [asyncResp](const boost::system::error_code& ec, const bool value) { + if (ec) + { + if (ec.value() != EBADR) + { + BMCWEB_LOG_ERROR << "DBUS response error for Health " + << ec.value(); + messages::internalError(asyncResp->res); + } + return; + } + + if (!value) + { + asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; + } + }); +} + +inline void getFanState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& fanPath, const std::string& service) +{ + sdbusplus::asio::getProperty<bool>( + *crow::connections::systemBus, service, fanPath, + "xyz.openbmc_project.Inventory.Item", "Present", + [asyncResp](const boost::system::error_code& ec, const bool value) { + if (ec) + { + if (ec.value() != EBADR) + { + BMCWEB_LOG_ERROR << "DBUS response error for State " + << ec.value(); + messages::internalError(asyncResp->res); + } + return; + } + + if (!value) + { + asyncResp->res.jsonValue["Status"]["State"] = "Absent"; + } + }); } inline void @@ -229,8 +283,9 @@ inline void const std::string& chassisId, const std::string& fanId, const std::string& fanPath, const std::string& service) { - BMCWEB_LOG_DEBUG << "fanPath = " << fanPath << " service = " << service; addFanCommonProperties(asyncResp->res, chassisId, fanId); + getFanState(asyncResp, fanPath, service); + getFanHealth(asyncResp, fanPath, service); } inline void doFanGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |