Fix PSU threshold mismatch issue
When trying to change thresholds on PSU sensors, PSU service will crash.
Some PSU in entity-manager will have threshold0 to threshodl5 which
contains all labels in one D-Bus path. But in current dbus sensors,
the presist threshold function do not support labels, it only check
severity. So when change a threshold in PSU sensor, it will change some
incorrect threshold in entity-manger. This patch adds label support to
presist threshold function, so that correct theshold in entity-manager
can be changed.
Tested:
After changed PSU1 Temp1 threshold by ipmitool, check the threshold again,
the value should be changed to the value we set. Check entity-manager,
the threshold in entity-manager should also change to the value we set.
Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Change-Id: Ib1c8bb454cd42dff170ae33c4aa768c4b515bb44
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index 0b33829..b5e8685 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -118,14 +118,14 @@
void persistThreshold(const std::string& path, const std::string& baseInterface,
const thresholds::Threshold& threshold,
std::shared_ptr<sdbusplus::asio::connection>& conn,
- size_t thresholdCount)
+ size_t thresholdCount, const std::string& labelMatch)
{
for (size_t ii = 0; ii < thresholdCount; ii++)
{
std::string thresholdInterface =
baseInterface + ".Thresholds" + std::to_string(ii);
conn->async_method_call(
- [&, path, threshold, thresholdInterface](
+ [&, path, threshold, thresholdInterface, labelMatch](
const boost::system::error_code& ec,
const boost::container::flat_map<std::string, BasicVariantType>&
result) {
@@ -134,6 +134,22 @@
return; // threshold not supported
}
+ if (!labelMatch.empty())
+ {
+ auto labelFind = result.find("Label");
+ if (labelFind == result.end())
+ {
+ std::cerr << "No label in threshold configuration\n";
+ return;
+ }
+ std::string label =
+ std::visit(VariantToStringVisitor(), labelFind->second);
+ if (label != labelMatch)
+ {
+ return;
+ }
+ }
+
auto directionFind = result.find("Direction");
auto severityFind = result.find("Severity");
auto valueFind = result.find("Value");