bmcweb: Revert to old sensor override logic
See github.com/openbmc/bmcweb/issues/253 for technical details.
This reverts the following commits:
* 3e35c761b7793696267870550bd6f0b0035f4110
* c71d61258bd3cd8573166011b450a1eecce2c572
Tested: Meltan fan diag passes.
```
./blaze-bin/third_party/meltan/diagnostics/servers/fan_speed/fan_speed \
--hwinterface_default_backend=redfish \
--hwinterface_target_address=localhost \
--hwinterface_target_port=1234
...
{
"testRunArtifact": {
"testRunEnd": {
"name": "fan_speed",
"status": "COMPLETE",
"result": "PASS"
}
},
"sequenceNumber": 252,
"timestamp": "2023-05-25T22:14:36.210811Z"
}
```
Google-Bug-Id: 277958097
Google-Bug-Id: 283748401
Change-Id: Ifd7d5bcb11015d73cf75eca1f50d1d9ff75447ac
Signed-off-by: Vlad Sytchenko <vsytch@google.com>
diff --git a/recipes-phosphor/interfaces/bmcweb/0001-Revert-to-old-sensor-override-logic.patch b/recipes-phosphor/interfaces/bmcweb/0001-Revert-to-old-sensor-override-logic.patch
new file mode 100644
index 0000000..362cf53
--- /dev/null
+++ b/recipes-phosphor/interfaces/bmcweb/0001-Revert-to-old-sensor-override-logic.patch
@@ -0,0 +1,157 @@
+From f59adc9c8a920be1cd6d15901afb0d73788336f7 Mon Sep 17 00:00:00 2001
+From: Vlad Sytchenko <vsytch@google.com>
+Date: Fri, 26 May 2023 20:57:26 +0000
+Subject: [PATCH] Revert to old sensor override logic
+
+See github.com/openbmc/bmcweb/issues/253 for technical details.
+
+This reverts the following commits:
+* 3e35c761b7793696267870550bd6f0b0035f4110
+* c71d61258bd3cd8573166011b450a1eecce2c572
+
+Google-Bug-Id: 277958097
+Google-Bug-Id: 283748401
+Signed-off-by: Vlad Sytchenko <vsytch@google.com>
+---
+ redfish-core/lib/sensors.hpp | 51 ++++++++++++++----------------------
+ 1 file changed, 19 insertions(+), 32 deletions(-)
+
+diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
+index 0f673b4f..eb1a5acc 100644
+--- a/redfish-core/lib/sensors.hpp
++++ b/redfish-core/lib/sensors.hpp
+@@ -743,7 +743,7 @@ inline void objectPropertiesToJson(
+ {
+ if (chassisSubNode == sensors::node::sensors)
+ {
+- std::string subNodeEscaped(sensorType);
++ std::string subNodeEscaped(chassisSubNode);
+ subNodeEscaped.erase(
+ std::remove(subNodeEscaped.begin(), subNodeEscaped.end(), '_'),
+ subNodeEscaped.end());
+@@ -763,6 +763,7 @@ inline void objectPropertiesToJson(
+ // Set MemberId and Name for non-power sensors. For PowerSupplies and
+ // PowerControl, those properties have more general values because
+ // multiple sensors can be stored in the same JSON object.
++ sensorJson["MemberId"] = sensorName;
+ std::string sensorNameEs(sensorName);
+ std::replace(sensorNameEs.begin(), sensorNameEs.end(), '_', ' ');
+ sensorJson["Name"] = std::move(sensorNameEs);
+@@ -1112,7 +1113,7 @@ inline void populateFanRedundancy(
+ auto schemaItem =
+ std::find_if(fanRedfish.begin(), fanRedfish.end(),
+ [itemName](const nlohmann::json& fan) {
+- return fan["Name"] == itemName;
++ return fan["MemberId"] == itemName;
+ });
+ if (schemaItem != fanRedfish.end())
+ {
+@@ -1147,6 +1148,7 @@ inline void populateFanRedundancy(
+ redundancy["@odata.id"] = std::move(url);
+ redundancy["@odata.type"] = "#Redundancy.v1_3_2.Redundancy";
+ redundancy["MinNumNeeded"] = minNumNeeded;
++ redundancy["MemberId"] = name;
+ redundancy["Mode"] = "N+m";
+ redundancy["Name"] = name;
+ redundancy["RedundancySet"] = redfishCollection;
+@@ -1192,7 +1194,6 @@ inline void
+ if (value != nullptr)
+ {
+ *value += "/" + std::to_string(count);
+- sensorJson["MemberId"] = std::to_string(count);
+ count++;
+ sensorsAsyncResp->updateUri(sensorJson["Name"], *value);
+ }
+@@ -2223,7 +2224,7 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
+ // Check if matching PowerSupply object already exists in JSON array
+ for (nlohmann::json& powerSupply : powerSupplyArray)
+ {
+- if (powerSupply["Name"] == inventoryItem.name)
++ if (powerSupply["MemberId"] == inventoryItem.name)
+ {
+ return powerSupply;
+ }
+@@ -2236,6 +2237,7 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
+ "redfish", "v1", "Chassis", chassisId, "Power");
+ url.set_fragment(("/PowerSupplies"_json_pointer).to_string());
+ powerSupply["@odata.id"] = std::move(url);
++ powerSupply["MemberId"] = inventoryItem.name;
+ powerSupply["Name"] = boost::replace_all_copy(inventoryItem.name, "_", " ");
+ powerSupply["Manufacturer"] = inventoryItem.manufacturer;
+ powerSupply["Model"] = inventoryItem.model;
+@@ -2602,24 +2604,6 @@ inline bool
+ return false;
+ }
+
+-inline std::pair<std::string, std::string>
+- splitSensorNameAndType(std::string_view sensorId)
+-{
+- size_t index = sensorId.find('_');
+- if (index == std::string::npos)
+- {
+- return std::make_pair<std::string, std::string>("", "");
+- }
+- std::string sensorType{sensorId.substr(0, index)};
+- std::string sensorName{sensorId.substr(index + 1)};
+- // fan_pwm and fan_tach need special handling
+- if (sensorType == "fantach" || sensorType == "fanpwm")
+- {
+- sensorType.insert(3, 1, '_');
+- }
+- return std::make_pair(sensorType, sensorName);
+-}
+-
+ /**
+ * @brief Entry point for overriding sensor values of given sensor
+ *
+@@ -2676,10 +2660,8 @@ inline void setSensorsOverride(
+ for (const auto& item : overrideMap)
+ {
+ const auto& sensor = item.first;
+- std::pair<std::string, std::string> sensorNameType =
+- splitSensorNameAndType(sensor);
+- if (!findSensorNameUsingSensorPath(sensorNameType.second,
+- *sensorsList, *sensorNames))
++ if (!findSensorNameUsingSensorPath(sensor, *sensorsList,
++ *sensorNames))
+ {
+ BMCWEB_LOG_INFO << "Unable to find memberId " << item.first;
+ messages::resourceNotFound(sensorAsyncResp->asyncResp->res,
+@@ -2990,23 +2972,28 @@ inline void handleSensorGet(App& app, const crow::Request& req,
+ {
+ return;
+ }
+- std::pair<std::string, std::string> nameType =
+- splitSensorNameAndType(sensorId);
+- if (nameType.first.empty() || nameType.second.empty())
++ size_t index = sensorId.find('_');
++ if (index == std::string::npos)
+ {
+ messages::resourceNotFound(asyncResp->res, sensorId, "Sensor");
+ return;
+ }
+-
+ asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
+ "redfish", "v1", "Chassis", chassisId, "Sensors", sensorId);
++ std::string sensorType = sensorId.substr(0, index);
++ std::string sensorName = sensorId.substr(index + 1);
++ // fan_pwm and fan_tach need special handling
++ if (sensorType == "fantach" || sensorType == "fanpwm")
++ {
++ sensorType.insert(3, 1, '_');
++ }
+
+ BMCWEB_LOG_DEBUG << "Sensor doGet enter";
+
+ constexpr std::array<std::string_view, 1> interfaces = {
+ "xyz.openbmc_project.Sensor.Value"};
+- std::string sensorPath = "/xyz/openbmc_project/sensors/" + nameType.first +
+- '/' + nameType.second;
++ std::string sensorPath =
++ "/xyz/openbmc_project/sensors/" + sensorType + '/' + sensorName;
+ // Get a list of all of the sensors that implement Sensor.Value
+ // and get the path and service name associated with the sensor
+ ::dbus::utility::getDbusObject(
+--
+2.41.0.rc0.172.g3f132b7071-goog
+
diff --git a/recipes-phosphor/interfaces/bmcweb_%.bbappend b/recipes-phosphor/interfaces/bmcweb_%.bbappend
index fc7f95b..8bb466c 100644
--- a/recipes-phosphor/interfaces/bmcweb_%.bbappend
+++ b/recipes-phosphor/interfaces/bmcweb_%.bbappend
@@ -181,3 +181,8 @@
${@bb.utils.contains('DISTRO_FEATURES', 'bmc-health-monitor', '${bmc_health_monitor_patches}', '', d)} \
"
# gBMC health monitoring support ends
+
+# Bugfix(b/277958097)
+SRC_URI:append:gbmc = " \
+ file://0001-Revert-to-old-sensor-override-logic.patch \
+"