blob: 7a6e46c75d767b97ed5e2a3b08f2628f91533add [file] [log] [blame]
Tomáš Pecka339bc672020-11-11 15:59:03 +01001#include "trompeloeil_doctest.h"
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +02002#include <cstdint>
Tomáš Pecka339bc672020-11-11 15:59:03 +01003#include "ietf-hardware/IETFHardware.h"
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +02004#include "ietf-hardware/thresholds.h"
Tomáš Pecka339bc672020-11-11 15:59:03 +01005#include "mock/ietf_hardware.h"
6#include "pretty_printers.h"
7#include "test_log_setup.h"
Tomáš Pecka339bc672020-11-11 15:59:03 +01008
9using namespace std::literals;
10
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020011#define NUKE_LAST_CHANGE(DATA) DATA.erase("/ietf-hardware:hardware/last-change")
12
13#define THRESHOLD_STATE(RESOURCE, STATE) {"/ietf-hardware:hardware/component[name='" RESOURCE "']/sensor-data/value", STATE}
14
15using velia::ietf_hardware::State;
16
Tomáš Pecka339bc672020-11-11 15:59:03 +010017TEST_CASE("HardwareState")
18{
19 TEST_INIT_LOGS;
Tomáš Pecka339bc672020-11-11 15:59:03 +010020
21 trompeloeil::sequence seq1;
Tomáš Pecka83b62e12020-12-16 14:50:49 +010022 auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>();
Tomáš Pecka339bc672020-11-11 15:59:03 +010023
24 auto fans = std::make_shared<FakeHWMon>();
25 auto sysfsTempCpu = std::make_shared<FakeHWMon>();
Václav Kubernát97e5ea12021-03-24 00:36:57 +010026 auto sysfsVoltageAc = std::make_shared<FakeHWMon>();
27 auto sysfsVoltageDc = std::make_shared<FakeHWMon>();
28 auto sysfsPower = std::make_shared<FakeHWMon>();
29 auto sysfsCurrent = std::make_shared<FakeHWMon>();
Tomáš Pecka339bc672020-11-11 15:59:03 +010030 auto emmc = std::make_shared<FakeEMMC>();
31
32 std::map<std::string, std::string> attributesEMMC;
33 std::map<std::string, int64_t> attributesHWMon;
34
35 // initialize all mocks
36 attributesEMMC = {
37 // FIXME passing initializer_list to macro is hell
38 {"date"s, "02/2017"s},
39 {"serial"s, "0x00a8808d"s},
40 {"name"s, "8GME4R"s},
41 };
42 FAKE_EMMC(emmc, attributesEMMC);
43
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020044 std::array<int64_t, 4> fanValues = {777, 0, 1280, 666};
45 REQUIRE_CALL(*fans, attribute("fan1_input"s)).LR_RETURN(fanValues[0]).TIMES(4);
46 REQUIRE_CALL(*fans, attribute("fan2_input"s)).LR_RETURN(fanValues[1]).TIMES(4);
47 REQUIRE_CALL(*fans, attribute("fan3_input"s)).LR_RETURN(fanValues[2]).TIMES(4);
48 REQUIRE_CALL(*fans, attribute("fan4_input"s)).LR_RETURN(fanValues[3]).TIMES(4);
Tomáš Pecka339bc672020-11-11 15:59:03 +010049
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020050 REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).RETURN(41800).TIMES(4);
Tomáš Pecka339bc672020-11-11 15:59:03 +010051
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020052 REQUIRE_CALL(*sysfsVoltageAc, attribute("in1_input")).RETURN(220000).TIMES(4);
53 REQUIRE_CALL(*sysfsVoltageDc, attribute("in1_input")).RETURN(12000).TIMES(4);
54 REQUIRE_CALL(*sysfsPower, attribute("power1_input")).RETURN(14000000).TIMES(4);
55 REQUIRE_CALL(*sysfsCurrent, attribute("curr1_input")).RETURN(200).TIMES(4);
Václav Kubernát97e5ea12021-03-24 00:36:57 +010056
Tomáš Pecka339bc672020-11-11 15:59:03 +010057 attributesEMMC = {{"life_time"s, "40"s}};
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020058 FAKE_EMMC(emmc, attributesEMMC).TIMES(4);
Tomáš Pecka339bc672020-11-11 15:59:03 +010059
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020060 using velia::ietf_hardware::OneThreshold;
61 using velia::ietf_hardware::Thresholds;
Tomáš Pecka63c3c3c2023-04-13 18:20:22 +020062 using velia::ietf_hardware::data_reader::EMMC;
63 using velia::ietf_hardware::data_reader::Fans;
Václav Kubernát6c17d0a2021-03-29 04:55:31 +020064 using velia::ietf_hardware::data_reader::SensorType;
65 using velia::ietf_hardware::data_reader::StaticData;
Václav Kubernát6c17d0a2021-03-29 04:55:31 +020066 using velia::ietf_hardware::data_reader::SysfsValue;
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020067
Tomáš Pecka339bc672020-11-11 15:59:03 +010068 // register components into hw state
Václav Kubernát6c17d0a2021-03-29 04:55:31 +020069 ietfHardware->registerDataReader(StaticData("ne", std::nullopt, {{"class", "iana-hardware:chassis"}, {"mfg-name", "CESNET"s}}));
70 ietfHardware->registerDataReader(StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}}));
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020071 ietfHardware->registerDataReader(Fans("ne:fans", "ne", fans, 4, Thresholds<int64_t>{
72 .criticalLow = OneThreshold<int64_t>{300, 200},
73 .warningLow = OneThreshold<int64_t>{600, 200},
74 .warningHigh = std::nullopt,
75 .criticalHigh =std::nullopt,
76 }));
Václav Kubernát6c17d0a2021-03-29 04:55:31 +020077 ietfHardware->registerDataReader(SysfsValue<SensorType::Temperature>("ne:ctrl:temperature-cpu", "ne:ctrl", sysfsTempCpu, 1));
Václav Kubernát97e5ea12021-03-24 00:36:57 +010078 ietfHardware->registerDataReader(SysfsValue<SensorType::VoltageAC>("ne:ctrl:voltage-in", "ne:ctrl", sysfsVoltageAc, 1));
79 ietfHardware->registerDataReader(SysfsValue<SensorType::VoltageDC>("ne:ctrl:voltage-out", "ne:ctrl", sysfsVoltageDc, 1));
80 ietfHardware->registerDataReader(SysfsValue<SensorType::Power>("ne:ctrl:power", "ne:ctrl", sysfsPower, 1));
81 ietfHardware->registerDataReader(SysfsValue<SensorType::Current>("ne:ctrl:current", "ne:ctrl", sysfsCurrent, 1));
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +020082 ietfHardware->registerDataReader(EMMC("ne:ctrl:emmc", "ne:ctrl", emmc, Thresholds<int64_t>{
83 .criticalLow = OneThreshold<int64_t>{20, 0},
84 .warningLow = OneThreshold<int64_t>{50, 0},
85 .warningHigh = std::nullopt,
86 .criticalHigh = std::nullopt,
87 }));
88
89 /* Some data readers (like our PSU reader, see the FspYhPsu test) may set oper-state to enabled/disabled depending on whether the device is present.
90 * If the device is not present we also don't want to report some elements of the data tree that contain a sensor (ne:psu:child in this case).
91 * This should also trigger the alarm reporting that the sensor is missing so we should test that the State::NoValue is reported when the sensor disappears.
92 */
93 struct PsuDataReader {
94 const bool& active;
95
96 velia::ietf_hardware::DataTree operator()()
97 {
98 velia::ietf_hardware::DataTree res = {
99 {"/ietf-hardware:hardware/component[name='ne:psu']/class", "iana-hardware:power-supply"},
100 {"/ietf-hardware:hardware/component[name='ne:psu']/parent", "ne"},
101 {"/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state", "disabled"},
102 };
103
104 if (active) {
105 res["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "enabled";
106 res["/ietf-hardware:hardware/component[name='ne:psu:child']/class"] = "iana-hardware:sensor";
107 res["/ietf-hardware:hardware/component[name='ne:psu:child']/parent"] = "ne:psu";
108 res["/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state"] = "enabled";
109 res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status"] = "ok";
110 res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value"] = "20000";
111 res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision"] = "0";
112 res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale"] = "milli";
113 res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type"] = "volts-DC";
114 }
115
116 return res;
117 }
118
119 velia::ietf_hardware::ThresholdsBySensorPath thresholds() const
120 {
121 return {{"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value", Thresholds<int64_t>{
122 .criticalLow = std::nullopt,
123 .warningLow = OneThreshold<int64_t>{10000, 2000},
124 .warningHigh = OneThreshold<int64_t>{15000, 2000},
125 .criticalHigh = std::nullopt,
126 }}};
127 }
128 };
129 bool psuActive = true;
130 ietfHardware->registerDataReader(PsuDataReader{psuActive});
Tomáš Pecka339bc672020-11-11 15:59:03 +0100131
Tomáš Pecka3f811962023-04-14 10:54:32 +0200132 std::map<std::string, std::string> expected = {
133 {"/ietf-hardware:hardware/component[name='ne']/class", "iana-hardware:chassis"},
134 {"/ietf-hardware:hardware/component[name='ne']/mfg-name", "CESNET"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200135 {"/ietf-hardware:hardware/component[name='ne']/state/oper-state", "enabled"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100136
Tomáš Pecka3f811962023-04-14 10:54:32 +0200137 {"/ietf-hardware:hardware/component[name='ne:fans']/class", "iana-hardware:module"},
138 {"/ietf-hardware:hardware/component[name='ne:fans']/parent", "ne"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200139 {"/ietf-hardware:hardware/component[name='ne:fans']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200140 {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/class", "iana-hardware:fan"},
141 {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/parent", "ne:fans"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200142 {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200143 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/class", "iana-hardware:sensor"},
144 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/parent", "ne:fans:fan1"},
145 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/oper-status", "ok"},
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +0200146 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value", "777"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200147 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-precision", "0"},
148 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-scale", "units"},
149 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-type", "rpm"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200150 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200151 {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/class", "iana-hardware:fan"},
152 {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/parent", "ne:fans"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200153 {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200154 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/class", "iana-hardware:sensor"},
155 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/parent", "ne:fans:fan2"},
156 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/oper-status", "ok"},
157 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value", "0"},
158 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-precision", "0"},
159 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-scale", "units"},
160 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-type", "rpm"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200161 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200162 {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/class", "iana-hardware:fan"},
163 {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/parent", "ne:fans"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200164 {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200165 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/class", "iana-hardware:sensor"},
166 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/parent", "ne:fans:fan3"},
167 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/oper-status", "ok"},
168 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value", "1280"},
169 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-precision", "0"},
170 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-scale", "units"},
171 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-type", "rpm"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200172 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200173 {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/class", "iana-hardware:fan"},
174 {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/parent", "ne:fans"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200175 {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200176 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/class", "iana-hardware:sensor"},
177 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/parent", "ne:fans:fan4"},
178 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/oper-status", "ok"},
179 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value", "666"},
180 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-precision", "0"},
181 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-scale", "units"},
182 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-type", "rpm"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200183 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/state/oper-state", "enabled"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100184
Tomáš Pecka3f811962023-04-14 10:54:32 +0200185 {"/ietf-hardware:hardware/component[name='ne:ctrl']/parent", "ne"},
186 {"/ietf-hardware:hardware/component[name='ne:ctrl']/class", "iana-hardware:module"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200187 {"/ietf-hardware:hardware/component[name='ne:ctrl']/state/oper-state", "enabled"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100188
Tomáš Pecka3f811962023-04-14 10:54:32 +0200189 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/class", "iana-hardware:sensor"},
190 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/parent", "ne:ctrl"},
191 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/oper-status", "ok"},
192 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value", "41800"},
193 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-precision", "0"},
194 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-scale", "milli"},
195 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-type", "celsius"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200196 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/state/oper-state", "enabled"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100197
Tomáš Pecka3f811962023-04-14 10:54:32 +0200198 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/class", "iana-hardware:sensor"},
199 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/parent", "ne:ctrl"},
200 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/oper-status", "ok"},
201 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value", "14000000"},
202 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value-precision", "0"},
203 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value-scale", "micro"},
204 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value-type", "watts"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200205 {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/state/oper-state", "enabled"},
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100206
Tomáš Pecka3f811962023-04-14 10:54:32 +0200207 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/class", "iana-hardware:sensor"},
208 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/parent", "ne:ctrl"},
209 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/oper-status", "ok"},
210 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value", "220000"},
211 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value-precision", "0"},
212 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value-scale", "milli"},
213 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value-type", "volts-AC"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200214 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200215 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/class", "iana-hardware:sensor"},
216 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/parent", "ne:ctrl"},
217 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/oper-status", "ok"},
218 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value", "12000"},
219 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value-precision", "0"},
220 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value-scale", "milli"},
221 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value-type", "volts-DC"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200222 {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/state/oper-state", "enabled"},
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100223
Tomáš Pecka3f811962023-04-14 10:54:32 +0200224 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/class", "iana-hardware:sensor"},
225 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/parent", "ne:ctrl"},
226 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/oper-status", "ok"},
227 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value", "200"},
228 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value-precision", "0"},
229 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value-scale", "milli"},
230 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value-type", "amperes"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200231 {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/state/oper-state", "enabled"},
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100232
Tomáš Pecka3f811962023-04-14 10:54:32 +0200233 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/parent", "ne:ctrl"},
234 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/class", "iana-hardware:module"},
235 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/serial-num", "0x00a8808d"},
236 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/mfg-date", "2017-02-01T00:00:00-00:00"},
237 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/model-name", "8GME4R"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200238 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/state/oper-state", "enabled"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200239 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/class", "iana-hardware:sensor"},
240 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/parent", "ne:ctrl:emmc"},
241 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/oper-status", "ok"},
242 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value", "40"},
243 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-precision", "0"},
244 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-scale", "units"},
245 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-type", "other"},
246 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/units-display", "percent"},
Tomáš Pecka7eb0c422023-04-21 15:36:33 +0200247 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/state/oper-state", "enabled"},
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +0200248
249 {"/ietf-hardware:hardware/component[name='ne:psu']/class", "iana-hardware:power-supply"},
250 {"/ietf-hardware:hardware/component[name='ne:psu']/parent", "ne"},
251 {"/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state", "enabled"},
252 {"/ietf-hardware:hardware/component[name='ne:psu:child']/class", "iana-hardware:sensor"},
253 {"/ietf-hardware:hardware/component[name='ne:psu:child']/parent", "ne:psu"},
254 {"/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state", "enabled"},
255 {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status", "ok"},
256 {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value", "20000"},
257 {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision", "0"},
258 {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale", "milli"},
259 {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type", "volts-DC"},
Tomáš Pecka3f811962023-04-14 10:54:32 +0200260 };
Tomáš Pecka339bc672020-11-11 15:59:03 +0100261
Tomáš Pecka0d8d8ee2023-05-10 12:22:58 +0200262 {
263 auto [data, alarms] = ietfHardware->process();
264 NUKE_LAST_CHANGE(data);
265 REQUIRE(data == expected);
266 REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{
267 THRESHOLD_STATE("ne:ctrl:current", State::Disabled),
268 THRESHOLD_STATE("ne:ctrl:power", State::Disabled),
269 THRESHOLD_STATE("ne:ctrl:temperature-cpu", State::Disabled),
270 THRESHOLD_STATE("ne:ctrl:voltage-in", State::Disabled),
271 THRESHOLD_STATE("ne:ctrl:voltage-out", State::Disabled),
272 THRESHOLD_STATE("ne:ctrl:emmc:lifetime", State::WarningLow),
273 THRESHOLD_STATE("ne:fans:fan1:rpm", State::Normal),
274 THRESHOLD_STATE("ne:fans:fan2:rpm", State::CriticalLow),
275 THRESHOLD_STATE("ne:fans:fan3:rpm", State::Normal),
276 THRESHOLD_STATE("ne:fans:fan4:rpm", State::Normal),
277 THRESHOLD_STATE("ne:psu:child", State::WarningHigh),
278 });
279 }
280
281 fanValues[1] = 500;
282 expected["/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value"] = "500";
283 {
284 auto [data, alarms] = ietfHardware->process();
285 NUKE_LAST_CHANGE(data);
286 REQUIRE(data == expected);
287 REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{
288 THRESHOLD_STATE("ne:fans:fan2:rpm", State::WarningLow),
289 });
290 }
291
292 psuActive = false;
293 fanValues[1] = 1;
294 fanValues[2] = 5000;
295
296 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/class");
297 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/parent");
298 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state");
299 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status");
300 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value");
301 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision");
302 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale");
303 expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type");
304 expected["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "disabled";
305 expected["/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value"] = "1";
306 expected["/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value"] = "5000";
307
308 {
309 auto [data, alarms] = ietfHardware->process();
310 NUKE_LAST_CHANGE(data);
311
312 REQUIRE(data == expected);
313 REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{
314 THRESHOLD_STATE("ne:fans:fan2:rpm", State::CriticalLow),
315 THRESHOLD_STATE("ne:psu:child", State::NoValue),
316 });
317 }
318
319 psuActive = true;
320 expected["/ietf-hardware:hardware/component[name='ne:psu']/class"] = "iana-hardware:power-supply";
321 expected["/ietf-hardware:hardware/component[name='ne:psu']/parent"] = "ne";
322 expected["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "enabled";
323 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/class"] = "iana-hardware:sensor";
324 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/parent"] = "ne:psu";
325 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state"] = "enabled";
326 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status"] = "ok";
327 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value"] = "20000";
328 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision"] = "0";
329 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale"] = "milli";
330 expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type"] = "volts-DC";
331
332 {
333 auto [data, alarms] = ietfHardware->process();
334 NUKE_LAST_CHANGE(data);
335
336 REQUIRE(data == expected);
337 REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{
338 THRESHOLD_STATE("ne:psu:child", State::WarningHigh),
339 });
340 }
Tomáš Pecka339bc672020-11-11 15:59:03 +0100341}