diff options
| author | Justin Nguyen <justinnanguyen@gmail.com> | 2026-07-27 18:21:14 +0300 |
|---|---|---|
| committer | Justin Nguyen <justinnanguyen@gmail.com> | 2026-08-19 23:01:11 +0300 |
| commit | 9bbb7982cece8f3cb662153daa99f781248229dc (patch) | |
| tree | dbba457879c4530dc188464934381cfaea90a58d | |
| parent | e7df55ce35e441b4a97d0db9ae280a71968ffee6 (diff) | |
| download | bmcweb-9bbb7982cece8f3cb662153daa99f781248229dc.tar.xz | |
state: Add Available mapping for Fan
- Utilized resource util's getResourceState() and getResourceHealth()
to get Status.State and Status.Health of the fan resource
- Added state mapping for `Available` to Redfish `UnavailableOffline`
Tested:
- Unit tests passed
- Redfish Service Validator passed
- Response as expected:
```
curl -k -v https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0
```
Results in
```
{
"@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0",
"@odata.type": "#Fan.v1_3_0.Fan",
"Id": "fan0",
"Location": {
"PartLocation": {
"ServiceLabel": "U78DA.N00.WZS003H-A0"
}
},
"Manufacturer": "Delta",
"Model": "7B5F",
"Name": "fan0",
"PartNumber": "02YK323",
"SerialNumber": "YL12JP1C1234",
"SparePartNumber": "02YK323",
"Status": {
"Health": "OK",
"State": "UnavailableOffline"
}
```
Where the state can be `Enabled`, `UnavailableOffline`, or `Absent`
Change-Id: I21b257c39735b2f3d519549aa52a8c6a0cc48ac9
Signed-off-by: Justin Nguyen <justinnanguyen@gmail.com>
| -rw-r--r-- | redfish-core/lib/fan.hpp | 62 |
1 files changed, 5 insertions, 57 deletions
diff --git a/redfish-core/lib/fan.hpp b/redfish-core/lib/fan.hpp index 586e214be4..a3158f3925 100644 --- a/redfish-core/lib/fan.hpp +++ b/redfish-core/lib/fan.hpp @@ -17,6 +17,7 @@ #include "utils/chassis_utils.hpp" #include "utils/fan_utils.hpp" #include "utils/json_utils.hpp" +#include "utils/resource_utils.hpp" #include "utils/sensor_utils.hpp" #include <asm-generic/errno.h> @@ -200,61 +201,6 @@ 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"] = resource::State::Enabled; - resp.jsonValue["Status"]["Health"] = resource::Health::OK; -} - -inline void getFanHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& fanPath, const std::string& service) -{ - dbus::utility::getProperty<bool>( - service, fanPath, - "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", - // ast-grep-ignore: long-lambda - [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"] = - resource::Health::Critical; - } - }); -} - -inline void getFanState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& fanPath, const std::string& service) -{ - dbus::utility::getProperty<bool>( - service, fanPath, "xyz.openbmc_project.Inventory.Item", "Present", - // ast-grep-ignore: long-lambda - [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"] = - resource::State::Absent; - } - }); } inline void getFanLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, @@ -392,8 +338,10 @@ inline void afterGetValidFanObject( const std::string& fanPath, const std::string& service) { addFanCommonProperties(asyncResp->res, chassisId, fanId); - getFanState(asyncResp, fanPath, service); - getFanHealth(asyncResp, fanPath, service); + resource_utils::getResourceState(asyncResp, service, fanPath, + ""_json_pointer); + resource_utils::getResourceHealth(asyncResp, service, fanPath, + ""_json_pointer); asset_utils::getAssetInfo(asyncResp, service, fanPath, ""_json_pointer, true); getFanLocation(asyncResp, fanPath, service); |
