monitor: Read fan state from dbus inventory upon starting
tach sensors previously defaulted to functional. Now they default to the
inventory state. For counter-based sensors, nonfunctional state forces
the count to exceed the threshold.
Fan's functional state now depends on the number of functional sensors.
test plan:
1) power-off chassis, stop phosphor-fan-monitor service
2) use busctl to make a fan's tach sensor nonfunctional
3) start fan-monitor
4) verify the fan's state == nonfunctional
5) poweron chassis, verify that fan-monitor updates _sensor_ to
functional
6) fan should remain nonfunctional
7) set Fan to non-present, then to present again (simulate
replacement)
8) observe the fans functional state is now true in inventory
Signed-off-by: Mike Capps <mikepcapps@gmail.com>
Change-Id: I0a109a1d85390c0201f8a54942efcd2fb21a2b65
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 342b07b..b3cc2a0 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -64,10 +64,6 @@
_fanMissingErrorDelay(std::get<fanMissingErrDelayField>(def)),
_setFuncOnPresent(std::get<funcOnPresentField>(def))
{
- // Start from a known state of functional (even if
- // _numSensorFailsForNonFunc is 0)
- updateInventory(true);
-
// Setup tach sensors for monitoring
auto& sensors = std::get<sensorListField>(def);
for (auto& s : sensors)
@@ -84,6 +80,12 @@
_trustManager->registerSensor(_sensors.back());
}
+ bool functionalState =
+ (_numSensorFailsForNonFunc == 0) ||
+ (countNonFunctionalSensors() < _numSensorFailsForNonFunc);
+
+ updateInventory(functionalState);
+
#ifndef MONITOR_USE_JSON
// Check current tach state when entering monitor mode
if (mode != Mode::init)
@@ -337,7 +339,7 @@
return target;
}
-size_t Fan::countNonFunctionalSensors()
+size_t Fan::countNonFunctionalSensors() const
{
return std::count_if(_sensors.begin(), _sensors.end(),
[](const auto& s) { return !s->functional(); });