summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0021-Define-PSU-redundancy-property.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0021-Define-PSU-redundancy-property.patch')
-rw-r--r--meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0021-Define-PSU-redundancy-property.patch206
1 files changed, 206 insertions, 0 deletions
diff --git a/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0021-Define-PSU-redundancy-property.patch b/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0021-Define-PSU-redundancy-property.patch
new file mode 100644
index 000000000..1a3a45d58
--- /dev/null
+++ b/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0021-Define-PSU-redundancy-property.patch
@@ -0,0 +1,206 @@
+From fe04a2f507a5813f586acd1bf30d3a8694109144 Mon Sep 17 00:00:00 2001
+From: Kuiying Wang <kuiying.wang@intel.com>
+Date: Wed, 26 Aug 2020 17:10:20 +0800
+Subject: [PATCH] Define PSU redundancy property.
+
+Currently PSU redundancy property is not implemented.
+
+Tested:
+1. Passed redfish validator.
+2. Redundancy property is shown in the redfish interace
+ redfish/v1/Chassis/WC_Baseboard/Power/
+"Redundancy": [
+{
+"@odata.id": "/redfish/v1/Chassis/WC_Baseboard/Power#/Redundancy/0" ,
+"@odata.type": "#Redundancy.v1_3_2.Redundancy" ,
+"MemberId": "PSURedundancy" ,
+"MinNumNeeded": 2 ,
+"Mode": "Failover" ,
+"Name": "PSURedundancy" ,
+"RedundancySet": [
+{
+"@odata.id": "/redfish/v1/Chassis/WC_Baseboard/Power#/PowerSupplies/0"
+} ,
+{
+"@odata.id": "/redfish/v1/Chassis/WC_Baseboard/Power#/PowerSupplies/1"
+}
+] ,
+"Status": {
+"Health": "OK" ,
+"State": "Enabled"
+}
+}
+]
+
+Change-Id: I58e44db8ea767d4c66f07638c43edec3bf6d2e53
+Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
+
+%% original patch: 0021-Define-PSU-redundancy-property.patch
+
+Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
+---
+ redfish-core/lib/sensors.hpp | 141 ++++++++++++++++++++++++++++++++++-
+ 1 file changed, 140 insertions(+), 1 deletion(-)
+
+diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
+index f12bbe0..48aa439 100644
+--- a/redfish-core/lib/sensors.hpp
++++ b/redfish-core/lib/sensors.hpp
+@@ -1043,7 +1043,141 @@ void objectInterfacesToJson(
+ BMCWEB_LOG_DEBUG << "Added sensor " << sensorName;
+ }
+
+-static void
++inline void
++ populatePSURedundancy(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp)
++{
++ crow::connections::systemBus->async_method_call(
++ [sensorsAsyncResp](const boost::system::error_code ec,
++ const GetSubTreeType& resp) {
++ if (ec)
++ {
++ return; // don't have to have this interface
++ }
++ for (const std::pair<std::string,
++ std::vector<std::pair<
++ std::string, std::vector<std::string>>>>&
++ pathPair : resp)
++ {
++ const std::string& path = pathPair.first;
++ const std::vector<
++ std::pair<std::string, std::vector<std::string>>>& objDict =
++ pathPair.second;
++ if (objDict.empty())
++ {
++ continue; // this should be impossible
++ }
++ const std::string& owner = objDict.begin()->first;
++
++ crow::connections::systemBus->async_method_call(
++ [path, owner, sensorsAsyncResp](
++ const boost::system::error_code err,
++ const boost::container::flat_map<
++ std::string, std::variant<uint8_t, uint32_t, bool,
++ std::vector<uint8_t>,
++ std::string>>& ret) {
++ if (err)
++ {
++ BMCWEB_LOG_ERROR
++ << "Failed to call PSU redundancy interface";
++ messages::internalError(sensorsAsyncResp->res);
++ return;
++ }
++
++ auto findPSUNumber = ret.find("PSUNumber");
++ auto findRedundantCount = ret.find("RedundantCount");
++ auto findEnabled =
++ ret.find("PowerSupplyRedundancyEnabled");
++ if (findPSUNumber == ret.end() ||
++ findRedundantCount == ret.end() ||
++ findEnabled == ret.end())
++ {
++ BMCWEB_LOG_ERROR << "Failed to find PSUNumber | "
++ "PowerSupplyRedundancyEnabled";
++ messages::internalError(sensorsAsyncResp->res);
++ return;
++ }
++
++ auto psuNumber =
++ std::get_if<uint8_t>(&(findPSUNumber->second));
++ auto enabled =
++ std::get_if<bool>(&(findEnabled->second));
++ auto redundantCount =
++ std::get_if<uint8_t>(&(findRedundantCount->second));
++
++ if (psuNumber == nullptr || enabled == nullptr ||
++ redundantCount == nullptr)
++ {
++ BMCWEB_LOG_ERROR
++ << "Invalid PSU redundancy property "
++ "types";
++ messages::internalError(sensorsAsyncResp->res);
++ return;
++ }
++
++ std::string health;
++ std::string state;
++ size_t minNumNeeded = *redundantCount;
++ if (*enabled)
++ {
++ state = "Enabled";
++ }
++ else
++ {
++ state = "Disabled";
++ }
++ if (*psuNumber >= minNumNeeded)
++ {
++ health = "OK";
++ }
++ else
++ {
++ health = "Warning";
++ }
++
++ nlohmann::json& jResp =
++ sensorsAsyncResp->res.jsonValue["Redundancy"];
++ jResp.push_back(
++ {{"@odata.id",
++ "/redfish/v1/Chassis/" +
++ sensorsAsyncResp->chassisId + "/" +
++ sensorsAsyncResp->chassisSubNode +
++ "#/Redundancy/" +
++ std::to_string(jResp.size())},
++ {"@odata.type", "#Redundancy.v1_3_2.Redundancy"},
++ {"MemberId", "PSURedundancy"},
++ {"MinNumNeeded", minNumNeeded},
++ {"Mode", "Failover"},
++ {"Name", "PSURedundancy"},
++ {"RedundancySet", nlohmann::json::array()},
++ {"Status",
++ {{"Health", health}, {"State", state}}}});
++ nlohmann::json& redundancySet =
++ jResp[0]["RedundancySet"];
++ const nlohmann::json& psuRedfish =
++ sensorsAsyncResp->res.jsonValue["PowerSupplies"];
++ for (auto& schemaItem : psuRedfish)
++ {
++ auto inputPower = schemaItem["PowerInputWatts"];
++ if (inputPower > 0)
++ {
++ redundancySet.push_back(
++ {{"@odata.id", schemaItem["@odata.id"]}});
++ }
++ }
++ },
++ owner, path, "org.freedesktop.DBus.Properties", "GetAll",
++ "xyz.openbmc_project.Control.PowerSupplyRedundancy");
++ }
++ },
++ "xyz.openbmc_project.ObjectMapper",
++ "/xyz/openbmc_project/object_mapper",
++ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
++ "/xyz/openbmc_project/control", 2,
++ std::array<const char*, 1>{
++ "xyz.openbmc_project.Control.PowerSupplyRedundancy"});
++}
++
++inline void
+ populateFanRedundancy(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp)
+ {
+ crow::connections::systemBus->async_method_call(
+@@ -2581,6 +2715,11 @@ void getSensorData(
+ {
+ populateFanRedundancy(SensorsAsyncResp);
+ }
++ else if (SensorsAsyncResp->chassisSubNode ==
++ sensors::node::power)
++ {
++ populatePSURedundancy(SensorsAsyncResp);
++ }
+ }
+ BMCWEB_LOG_DEBUG << "getManagedObjectsCb exit";
+ };
+--
+2.17.1
+