Change discrete threshold value to string
For compliance with redfish schema, trigger with discrete
thresholds should use string as a value - instead of double.
This will impact dbus method "AddTrigger" for Trigger interface.
As there are currently no known sensors with discrete values,
telemetry service will still treat the value as a double internally.
Tested:
- UT passed.
- Trigger with discrete threshold value was successfully created
using dbus call.
- local redfish-tests for trigger persistency are passing after
type modification.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I8201ce5e2a45647206c5ccd85fc45ea8f32961af
diff --git a/src/interfaces/trigger_types.hpp b/src/interfaces/trigger_types.hpp
index 568756f..6721e68 100644
--- a/src/interfaces/trigger_types.hpp
+++ b/src/interfaces/trigger_types.hpp
@@ -39,13 +39,13 @@
return std::string(utils::enumToString(details::convDataSeverity, v));
}
-using ThresholdParam = std::tuple<std::string, std::string, uint64_t, double>;
+using ThresholdParam =
+ std::tuple<std::string, std::string, uint64_t, std::string>;
-using LabeledThresholdParam =
- utils::LabeledTuple<std::tuple<std::string, Severity, uint64_t, double>,
- utils::tstring::UserId, utils::tstring::Severity,
- utils::tstring::DwellTime,
- utils::tstring::ThresholdValue>;
+using LabeledThresholdParam = utils::LabeledTuple<
+ std::tuple<std::string, Severity, uint64_t, std::string>,
+ utils::tstring::UserId, utils::tstring::Severity, utils::tstring::DwellTime,
+ utils::tstring::ThresholdValue>;
} // namespace discrete
namespace numeric
diff --git a/src/trigger_factory.cpp b/src/trigger_factory.cpp
index b491274..6e2ad21 100644
--- a/src/trigger_factory.cpp
+++ b/src/trigger_factory.cpp
@@ -47,7 +47,7 @@
labeledThresholdParam.at_label<ts::Severity>();
std::chrono::milliseconds dwellTime = std::chrono::milliseconds(
labeledThresholdParam.at_label<ts::DwellTime>());
- double thresholdValue =
+ std::string thresholdValue =
labeledThresholdParam.at_label<ts::ThresholdValue>();
if (logToJournal)
@@ -68,7 +68,7 @@
thresholds.emplace_back(std::make_shared<DiscreteThreshold>(
bus->get_io_context(), sensors, sensorNames, std::move(actions),
- std::chrono::milliseconds(dwellTime), thresholdValue,
+ std::chrono::milliseconds(dwellTime), std::stod(thresholdValue),
thresholdName));
}
if (labeledDiscreteThresholdParams.empty())
diff --git a/tests/src/test_trigger.cpp b/tests/src/test_trigger.cpp
index cf7d96c..2336267 100644
--- a/tests/src/test_trigger.cpp
+++ b/tests/src/test_trigger.cpp
@@ -27,10 +27,10 @@
.thresholdParams(std::vector<discrete::LabeledThresholdParam>{
discrete::LabeledThresholdParam{
"userId", discrete::Severity::warning,
- std::chrono::milliseconds(10).count(), 15.2},
+ std::chrono::milliseconds(10).count(), "15.2"},
discrete::LabeledThresholdParam{
"userId_2", discrete::Severity::critical,
- std::chrono::milliseconds(5).count(), 32.7},
+ std::chrono::milliseconds(5).count(), "32.7"},
});
std::unique_ptr<TriggerManagerMock> triggerManagerMockPtr =
@@ -341,13 +341,13 @@
expectedItem0["userId"] = "userId";
expectedItem0["severity"] = discrete::Severity::warning;
expectedItem0["dwellTime"] = 10;
- expectedItem0["thresholdValue"] = 15.2;
+ expectedItem0["thresholdValue"] = "15.2";
nlohmann::json expectedItem1;
expectedItem1["userId"] = "userId_2";
expectedItem1["severity"] = discrete::Severity::critical;
expectedItem1["dwellTime"] = 5;
- expectedItem1["thresholdValue"] = 32.7;
+ expectedItem1["thresholdValue"] = "32.7";
ASSERT_THAT(storedDiscreteConfiguration.at("ThresholdParamsDiscriminator"),
Eq(1));
diff --git a/tests/src/test_trigger_manager.cpp b/tests/src/test_trigger_manager.cpp
index 773b809..704c497 100644
--- a/tests/src/test_trigger_manager.cpp
+++ b/tests/src/test_trigger_manager.cpp
@@ -76,9 +76,9 @@
{
TriggerParams triggerParamsDiscrete;
auto thresholds = std::vector<discrete::LabeledThresholdParam>{
- {"discrete_threshold1", discrete::Severity::ok, 10, 11.0},
- {"discrete_threshold2", discrete::Severity::warning, 10, 12.0},
- {"discrete_threshold3", discrete::Severity::critical, 10, 13.0}};
+ {"discrete_threshold1", discrete::Severity::ok, 10, "11.0"},
+ {"discrete_threshold2", discrete::Severity::warning, 10, "12.0"},
+ {"discrete_threshold3", discrete::Severity::critical, 10, "13.0"}};
triggerParamsDiscrete.thresholdParams(thresholds).isDiscrete(true);
@@ -230,8 +230,8 @@
{
LabeledTriggerThresholdParams thresholdParams =
std::vector<discrete::LabeledThresholdParam>{
- {"userId1", discrete::Severity::warning, 15, 10.0},
- {"userId2", discrete::Severity::critical, 5, 20.0}};
+ {"userId1", discrete::Severity::warning, 15, "10.0"},
+ {"userId2", discrete::Severity::critical, 5, "20.0"}};
data1["ThresholdParamsDiscriminator"] = thresholdParams.index();