Don't push non finite numbers to Redfish
Redfish Sensor schema is based around Edm.Number, which doesn't have an
allowance for things like infinity, -infinity, or NAN. Because these
are theoretically possible in the dbus interfaces, we need to omit the
properties if they are set to anything that Redfish doesn't support.
Because the DBus sensor Value interface relies on NAN to represent
unavailable, this is explicitly set to null in the json response. This
behavior was discussed with DMTF in a forum meeting, and is the
protocol-correct behavior for handling unavailable numbers. All other
number-assigning dbus properties are omitted from the response, to show
that they are "not supported" if they produce out-of-range values.
Tested: Unclear if there are any implementations that do this to test
against. Code inspection only.
Redfish-service-validator passes (on previous patchset).
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia3dde24cd604b0bb5dc596e7b8a6461a4b339b71
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 59c954b..930eb52 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -39,6 +39,7 @@
#include <array>
#include <cmath>
#include <iterator>
+#include <limits>
#include <map>
#include <set>
#include <string_view>
@@ -930,6 +931,19 @@
BMCWEB_LOG_ERROR << "Got value interface that wasn't double";
continue;
}
+ if (!std::isfinite(*doubleValue))
+ {
+ if (valueName == "Value")
+ {
+ // Readings are allowed to be NAN for unavailable; coerce
+ // them to null in the json response.
+ sensorJson[key] = nullptr;
+ continue;
+ }
+ BMCWEB_LOG_WARNING << "Sensor value for " << valueName
+ << " was unexpectedly " << *doubleValue;
+ continue;
+ }
if (forceToInt)
{
sensorJson[key] = static_cast<int64_t>(*doubleValue);