summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/interfaces/bmcweb/0021-Define-PSU-redundancy-property.patch
blob: 1a3a45d58a3142051e1b1f7cdc9eb6e7cbb89722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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