Trigger: make dbus properties writable
This change allows to modify 'Sensors', 'ReportNames' and 'Thresholds'
dbus properties of Trigger interface. They are required by Redfish to
implement PATCH functionality for Trigger schema.
Some backend changes were required to enable this functionality, and as
such few improvements were made for existing code:
- NumericThreshold and DiscreteThreshold now have common implementation
where it was possible.
- Internal sensor info structure for Trigger is now the same as the one
used for Report. This resulted in breaking compatibility with previous
Trigger persistency data.
- Added getInfo / getParams methods for Sensor and Threshold interfaces.
They are used by Trigger dbus getters and persistency mechanism now,
instead of storing this data in Trigger object.
Testing done:
- Unit tests were expanded and are passing
- dbus setters for Sensors and Thresholds are working and modifications
are reflected by calling appropriate getters.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I7a14c15a30d78ce872342b5f938aba43c77be9c0
diff --git a/tests/src/mocks/threshold_mock.hpp b/tests/src/mocks/threshold_mock.hpp
new file mode 100644
index 0000000..2f81b60
--- /dev/null
+++ b/tests/src/mocks/threshold_mock.hpp
@@ -0,0 +1,64 @@
+#pragma once
+
+#include "interfaces/sensor.hpp"
+#include "interfaces/threshold.hpp"
+#include "utils/conv_container.hpp"
+
+#include <vector>
+
+#include <gmock/gmock.h>
+
+class ThresholdMock :
+ public interfaces::Threshold,
+ public std::enable_shared_from_this<ThresholdMock>
+{
+ public:
+ MOCK_METHOD(void, initialize, (), (override));
+
+ MOCK_METHOD(LabeledThresholdParam, getThresholdParam, (),
+ (const, override));
+
+ MOCK_METHOD(void, updateSensors, (Sensors newSensors), (override));
+
+ static std::vector<std::shared_ptr<interfaces::Threshold>>
+ makeThresholds(const LabeledTriggerThresholdParams& params)
+ {
+ using namespace testing;
+ std::vector<std::shared_ptr<NiceMock<ThresholdMock>>> result;
+ if (std::holds_alternative<std::vector<numeric::LabeledThresholdParam>>(
+ params))
+ {
+ auto unpackedParams =
+ std::get<std::vector<numeric::LabeledThresholdParam>>(params);
+ for (const auto& param : unpackedParams)
+ {
+ auto& thresholdMock = result.emplace_back(
+ std::make_shared<NiceMock<ThresholdMock>>());
+ ON_CALL(*thresholdMock, getThresholdParam())
+ .WillByDefault(Return(param));
+ }
+ }
+ else
+ {
+ auto unpackedParams =
+ std::get<std::vector<discrete::LabeledThresholdParam>>(params);
+ for (const auto& param : unpackedParams)
+ {
+ auto& thresholdMock = result.emplace_back(
+ std::make_shared<NiceMock<ThresholdMock>>());
+ ON_CALL(*thresholdMock, getThresholdParam())
+ .WillByDefault(Return(param));
+ }
+ if (unpackedParams.empty())
+ {
+ auto& thresholdMock = result.emplace_back(
+ std::make_shared<NiceMock<ThresholdMock>>());
+ ON_CALL(*thresholdMock, getThresholdParam())
+ .WillByDefault(Return(std::monostate{}));
+ }
+ }
+
+ return utils::convContainer<std::shared_ptr<interfaces::Threshold>>(
+ result);
+ }
+};