Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 1 | #include "trompeloeil_doctest.h" |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 2 | #include <iterator> |
| 3 | #include <sysrepo-cpp/Enum.hpp> |
| 4 | #include <trompeloeil.hpp> |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 5 | #include "ietf-hardware/IETFHardware.h" |
| 6 | #include "ietf-hardware/sysrepo/Sysrepo.h" |
| 7 | #include "mock/ietf_hardware.h" |
| 8 | #include "pretty_printers.h" |
Tomáš Pecka | baf289c | 2024-01-24 15:12:44 +0100 | [diff] [blame] | 9 | #include "sysrepo-helpers/alarms.h" |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 10 | #include "sysrepo-helpers/datastore.h" |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 11 | #include "test_log_setup.h" |
Tomáš Pecka | c164ca6 | 2024-01-24 13:38:03 +0100 | [diff] [blame] | 12 | #include "tests/sysrepo-helpers/common.h" |
Jan Kundrát | 7935e81 | 2024-09-17 17:02:01 +0200 | [diff] [blame] | 13 | #include "utils/libyang.h" |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 14 | |
| 15 | using namespace std::literals; |
| 16 | |
Tomáš Pecka | 2fdc8ce | 2024-01-18 12:28:37 +0100 | [diff] [blame] | 17 | #define COMPONENT(RESOURCE) "/ietf-hardware:hardware/component[name='" RESOURCE "']" |
Jan Kundrát | c151151 | 2024-01-15 13:47:28 +0100 | [diff] [blame] | 18 | |
Tomáš Pecka | bbfc1c3 | 2024-01-31 13:58:11 +0100 | [diff] [blame] | 19 | #define VEC(...) (std::vector<std::string>{__VA_ARGS__}) |
| 20 | #define ALARMS(...) VEC(__VA_ARGS__) |
| 21 | #define COMPONENTS(...) VEC(__VA_ARGS__) |
| 22 | |
Tomáš Pecka | 9bd6127 | 2024-01-31 15:08:13 +0100 | [diff] [blame] | 23 | #define INTRODUCED_ALARM(ALARM_TYPE, DESCRIPTION) velia::alarms::AlarmInventoryEntry(ALARM_TYPE, DESCRIPTION) |
| 24 | #define REQUIRE_ALARM_INVENTORY_ADD_ALARMS(...) REQUIRE_NEW_ALARM_INVENTORY_ENTRIES(alarmWatcher, (std::vector<velia::alarms::AlarmInventoryEntry>{__VA_ARGS__})) |
Tomáš Pecka | bbfc1c3 | 2024-01-31 13:58:11 +0100 | [diff] [blame] | 25 | #define REQUIRE_ALARM_INVENTORY_ADD_RESOURCES(ALARMS, COMPONENTS) REQUIRE_NEW_ALARM_INVENTORY_RESOURCES(alarmWatcher, ALARMS, COMPONENTS) |
Jan Kundrát | c151151 | 2024-01-15 13:47:28 +0100 | [diff] [blame] | 26 | |
| 27 | #define REQUIRE_ALARM_RPC(ALARM_TYPE, RESOURCE, SEVERITY, TEXT) \ |
Tomáš Pecka | 4163c0c | 2024-01-31 13:21:03 +0100 | [diff] [blame] | 28 | REQUIRE_NEW_ALARM(alarmWatcher, ALARM_TYPE, COMPONENT(RESOURCE), SEVERITY, TEXT) |
Tomáš Pecka | 1b3c173 | 2023-05-12 11:45:01 +0200 | [diff] [blame] | 29 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 30 | TEST_CASE("IETF Hardware with sysrepo") |
| 31 | { |
| 32 | TEST_SYSREPO_INIT_LOGS; |
| 33 | TEST_SYSREPO_INIT; |
| 34 | TEST_SYSREPO_INIT_CLIENT; |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 35 | |
| 36 | srSess.sendRPC(srSess.getContext().newPath("/ietf-factory-default:factory-reset")); |
| 37 | |
Tomáš Pecka | 2117ce5 | 2023-05-12 11:28:34 +0200 | [diff] [blame] | 38 | auto alarmsClient = sysrepo::Connection{}.sessionStart(sysrepo::Datastore::Operational); |
| 39 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 40 | static const auto modulePrefix = "/ietf-hardware:hardware"s; |
| 41 | |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 42 | client.switchDatastore(sysrepo::Datastore::Operational); |
| 43 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 44 | trompeloeil::sequence seq1; |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 45 | |
| 46 | auto directLeafNodeQuery = [&](const std::string& xpath) { |
| 47 | auto val = client.getData(xpath); |
| 48 | REQUIRE(val); |
Jan Kundrát | 8dd54de | 2024-09-17 17:04:00 +0200 | [diff] [blame] | 49 | return velia::utils::asString(*val->findPath(xpath)); |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 50 | }; |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 51 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 52 | auto sysfsTempCpu = std::make_shared<FakeHWMon>(); |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 53 | auto sysfsPower = std::make_shared<FakeHWMon>(); |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 54 | |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 55 | using velia::ietf_hardware::OneThreshold; |
| 56 | using velia::ietf_hardware::Thresholds; |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 57 | using velia::ietf_hardware::data_reader::SensorType; |
| 58 | using velia::ietf_hardware::data_reader::StaticData; |
| 59 | using velia::ietf_hardware::data_reader::SysfsValue; |
Tomáš Pecka | e5366c6 | 2023-04-14 11:03:04 +0200 | [diff] [blame] | 60 | |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 61 | std::atomic<bool> psuActive; // this needs to be destroyed after ietfHardware to avoid dangling reference (we are passing it as a ref to PsuDataReader) |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 62 | std::atomic<int64_t> psuSensorValue; |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 63 | std::atomic<int64_t> cpuTempValue; |
| 64 | std::atomic<int64_t> powerValue; |
| 65 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 66 | // register components into hw state |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 67 | auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>(); |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 68 | ietfHardware->registerDataReader(StaticData("ne", std::nullopt, {{"class", "iana-hardware:chassis"}, {"mfg-name", "CESNET"s}})); |
Tomáš Pecka | e5366c6 | 2023-04-14 11:03:04 +0200 | [diff] [blame] | 69 | ietfHardware->registerDataReader(SysfsValue<SensorType::Temperature>("ne:temperature-cpu", "ne", sysfsTempCpu, 1)); |
Jan Kundrát | c151151 | 2024-01-15 13:47:28 +0100 | [diff] [blame] | 70 | ietfHardware->registerDataReader(SysfsValue<SensorType::Power>( |
| 71 | "ne:power", |
| 72 | "ne", |
| 73 | sysfsPower, |
| 74 | 1, |
| 75 | Thresholds<int64_t>{ |
| 76 | .criticalLow = OneThreshold<int64_t>{8'000'000, 500'000}, |
| 77 | .warningLow = OneThreshold<int64_t>{10'000'000, 500'000}, |
| 78 | .warningHigh = OneThreshold<int64_t>{20'000'000, 500'000}, |
| 79 | .criticalHigh = OneThreshold<int64_t>{22'000'000, 500'000}, |
| 80 | })); |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 81 | |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 82 | /* 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 and Some |
| 83 | * data might not even be pushed (e.g. the child sensors). |
| 84 | * Since we push data into sysrepo we have to erase old data (that should no longer be present) from the sysrepo operational DS. |
| 85 | * We test such situation via the following data reader which returns data only when psuActive is set to true. |
| 86 | */ |
| 87 | struct PsuDataReader { |
| 88 | const std::atomic<bool>& active; |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 89 | const std::atomic<int64_t>& value; |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 90 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 91 | velia::ietf_hardware::SensorPollData operator()() |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 92 | { |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 93 | velia::ietf_hardware::SideLoadedAlarm alarm; |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 94 | velia::ietf_hardware::ThresholdsBySensorPath thr; |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 95 | velia::ietf_hardware::DataTree res = { |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 96 | {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| 97 | {COMPONENT("ne:psu") "/parent", "ne"}, |
| 98 | {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 99 | }; |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 100 | |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 101 | if (active) { |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 102 | res[COMPONENT("ne:psu") "/state/oper-state"] = "enabled"; |
| 103 | res[COMPONENT("ne:psu:child") "/class"] = "iana-hardware:sensor"; |
| 104 | res[COMPONENT("ne:psu:child") "/parent"] = "ne:psu"; |
| 105 | res[COMPONENT("ne:psu:child") "/state/oper-state"] = "enabled"; |
| 106 | res[COMPONENT("ne:psu:child") "/sensor-data/oper-status"] = "ok"; |
| 107 | res[COMPONENT("ne:psu:child") "/sensor-data/value"] = std::to_string(value); |
| 108 | res[COMPONENT("ne:psu:child") "/sensor-data/value-precision"] = "0"; |
| 109 | res[COMPONENT("ne:psu:child") "/sensor-data/value-scale"] = "milli"; |
| 110 | res[COMPONENT("ne:psu:child") "/sensor-data/value-type"] = "volts-DC"; |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 111 | |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 112 | thr[COMPONENT("ne:psu:child") "/sensor-data/value"] = Thresholds<int64_t>{ |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 113 | .criticalLow = std::nullopt, |
| 114 | .warningLow = OneThreshold<int64_t>{10000, 2000}, |
| 115 | .warningHigh = OneThreshold<int64_t>{15000, 2000}, |
| 116 | .criticalHigh = std::nullopt, |
| 117 | }; |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 118 | |
| 119 | alarm = {"velia-alarms:sensor-missing-alarm", COMPONENT("ne:psu"), "cleared", "PSU missing."}; |
| 120 | } else { |
| 121 | alarm = {"velia-alarms:sensor-missing-alarm", COMPONENT("ne:psu"), "critical", "PSU missing."}; |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 122 | } |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 123 | |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 124 | return {res, thr, {alarm}}; |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 125 | } |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 126 | }; |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 127 | ietfHardware->registerDataReader(PsuDataReader{psuActive, psuSensorValue}); |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 128 | |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 129 | /* Ensure that there are sane data after each sysrepo change callback (all the component subtrees are expected). */ |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 130 | DatastoreWatcher dsChangeHardware(client, "/ietf-hardware:hardware/component", {"/ietf-hardware:hardware/last-change"}); |
Tomáš Pecka | baf289c | 2024-01-24 15:12:44 +0100 | [diff] [blame] | 131 | AlarmWatcher alarmWatcher(client); |
Tomáš Pecka | 2117ce5 | 2023-05-12 11:28:34 +0200 | [diff] [blame] | 132 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 133 | SECTION("Disappearing sensor plugged from the beginning") |
| 134 | { |
| 135 | // first batch of values |
| 136 | cpuTempValue = 41800; |
| 137 | powerValue = 0; |
| 138 | psuActive = true; |
| 139 | psuSensorValue = 12000; |
| 140 | REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).LR_RETURN(cpuTempValue).TIMES(AT_LEAST(1)); |
| 141 | REQUIRE_CALL(*sysfsPower, attribute("power1_input")).LR_RETURN(powerValue).TIMES(AT_LEAST(1)); |
Tomáš Pecka | 2848fd0 | 2024-01-30 12:05:59 +0100 | [diff] [blame] | 142 | |
Tomáš Pecka | 9bd6127 | 2024-01-31 15:08:13 +0100 | [diff] [blame] | 143 | REQUIRE_ALARM_INVENTORY_ADD_ALARMS( |
| 144 | INTRODUCED_ALARM("velia-alarms:sensor-low-value-alarm", "Sensor value is below the low threshold."), |
| 145 | INTRODUCED_ALARM("velia-alarms:sensor-high-value-alarm", "Sensor value is above the high threshold."), |
| 146 | INTRODUCED_ALARM("velia-alarms:sensor-missing-alarm", "Sensor is missing."), |
| 147 | INTRODUCED_ALARM("velia-alarms:sensor-nonoperational", "Sensor is flagged as nonoperational.")) |
| 148 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 2848fd0 | 2024-01-30 12:05:59 +0100 | [diff] [blame] | 149 | |
Tomáš Pecka | bbfc1c3 | 2024-01-31 13:58:11 +0100 | [diff] [blame] | 150 | REQUIRE_ALARM_INVENTORY_ADD_RESOURCES( |
| 151 | ALARMS("velia-alarms:sensor-low-value-alarm", |
| 152 | "velia-alarms:sensor-high-value-alarm", |
| 153 | "velia-alarms:sensor-missing-alarm", |
| 154 | "velia-alarms:sensor-nonoperational"), |
| 155 | COMPONENTS( |
| 156 | COMPONENT("ne:power"), |
| 157 | COMPONENT("ne:psu:child"), |
| 158 | COMPONENT("ne:temperature-cpu"))) |
| 159 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 2117ce5 | 2023-05-12 11:28:34 +0200 | [diff] [blame] | 160 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 161 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 162 | {COMPONENT("ne") "/class", "iana-hardware:chassis"}, |
| 163 | {COMPONENT("ne") "/mfg-name", "CESNET"}, |
| 164 | {COMPONENT("ne") "/name", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 165 | {COMPONENT("ne") "/state/oper-state", "enabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 166 | {COMPONENT("ne:power") "/class", "iana-hardware:sensor"}, |
| 167 | {COMPONENT("ne:power") "/name", "ne:power"}, |
| 168 | {COMPONENT("ne:power") "/parent", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 169 | {COMPONENT("ne:power") "/sensor-data/oper-status", "ok"}, |
| 170 | {COMPONENT("ne:power") "/sensor-data/value", "0"}, |
| 171 | {COMPONENT("ne:power") "/sensor-data/value-precision", "0"}, |
| 172 | {COMPONENT("ne:power") "/sensor-data/value-scale", "micro"}, |
| 173 | {COMPONENT("ne:power") "/sensor-data/value-type", "watts"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 174 | {COMPONENT("ne:power") "/state/oper-state", "enabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 175 | {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| 176 | {COMPONENT("ne:psu") "/name", "ne:psu"}, |
| 177 | {COMPONENT("ne:psu") "/parent", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 178 | {COMPONENT("ne:psu") "/state/oper-state", "enabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 179 | {COMPONENT("ne:psu:child") "/class", "iana-hardware:sensor"}, |
| 180 | {COMPONENT("ne:psu:child") "/name", "ne:psu:child"}, |
| 181 | {COMPONENT("ne:psu:child") "/parent", "ne:psu"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 182 | {COMPONENT("ne:psu:child") "/sensor-data/oper-status", "ok"}, |
| 183 | {COMPONENT("ne:psu:child") "/sensor-data/value", "12000"}, |
| 184 | {COMPONENT("ne:psu:child") "/sensor-data/value-precision", "0"}, |
| 185 | {COMPONENT("ne:psu:child") "/sensor-data/value-scale", "milli"}, |
| 186 | {COMPONENT("ne:psu:child") "/sensor-data/value-type", "volts-DC"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 187 | {COMPONENT("ne:psu:child") "/state/oper-state", "enabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 188 | {COMPONENT("ne:temperature-cpu") "/class", "iana-hardware:sensor"}, |
| 189 | {COMPONENT("ne:temperature-cpu") "/name", "ne:temperature-cpu"}, |
| 190 | {COMPONENT("ne:temperature-cpu") "/parent", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 191 | {COMPONENT("ne:temperature-cpu") "/sensor-data/oper-status", "ok"}, |
| 192 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value", "41800"}, |
| 193 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value-precision", "0"}, |
| 194 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value-scale", "milli"}, |
| 195 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value-type", "celsius"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 196 | {COMPONENT("ne:temperature-cpu") "/state/oper-state", "enabled"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 197 | })) |
| 198 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | bbfc1c3 | 2024-01-31 13:58:11 +0100 | [diff] [blame] | 199 | REQUIRE_ALARM_INVENTORY_ADD_RESOURCES(ALARMS("velia-alarms:sensor-missing-alarm"), COMPONENTS(COMPONENT("ne:psu"))).TIMES(AT_LEAST(1)); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 200 | REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold (0 < 8000000).").IN_SEQUENCE(seq1); |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 201 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 202 | auto ietfHardwareSysrepo = std::make_shared<velia::ietf_hardware::sysrepo::Sysrepo>(srSess, ietfHardware, 150ms); |
| 203 | std::this_thread::sleep_for(400ms); // let's wait until the bg polling thread is spawned; 400 ms is probably enough to spawn the thread and poll 2 or 3 times |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 204 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 205 | std::string lastChange = directLeafNodeQuery(modulePrefix + "/last-change"); |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 206 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 207 | // second batch of values, sensor data changed, PSU ejected |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 208 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 209 | {COMPONENT("ne:psu:child") "/class", Deleted{}}, |
| 210 | {COMPONENT("ne:psu:child") "/parent", Deleted{}}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 211 | {COMPONENT("ne:psu:child") "/sensor-data/oper-status", Deleted{}}, |
| 212 | {COMPONENT("ne:psu:child") "/sensor-data/value", Deleted{}}, |
| 213 | {COMPONENT("ne:psu:child") "/sensor-data/value-precision", Deleted{}}, |
| 214 | {COMPONENT("ne:psu:child") "/sensor-data/value-scale", Deleted{}}, |
| 215 | {COMPONENT("ne:psu:child") "/sensor-data/value-type", Deleted{}}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 216 | {COMPONENT("ne:psu:child") "/state/oper-state", Deleted{}}, |
| 217 | {COMPONENT("ne:power") "/sensor-data/value", "11222333"}, |
| 218 | {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
| 219 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value", "222"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 220 | })) |
| 221 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 222 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "critical", "PSU missing.").IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 223 | REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "cleared", "Sensor value is within normal parameters.").IN_SEQUENCE(seq1); |
Jan Kundrát | c151151 | 2024-01-15 13:47:28 +0100 | [diff] [blame] | 224 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu:child", "warning", |
| 225 | "Sensor value not reported. Maybe the sensor was unplugged?").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 226 | REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).LR_RETURN(cpuTempValue).TIMES(AT_LEAST(1)); |
| 227 | REQUIRE_CALL(*sysfsPower, attribute("power1_input")).LR_RETURN(powerValue).TIMES(AT_LEAST(1)); |
| 228 | cpuTempValue = 222; |
| 229 | powerValue = 11222333; |
| 230 | psuActive = false; |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 231 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 232 | std::this_thread::sleep_for(2000ms); // longer sleep here: last-change does not report milliseconds so this should increase last-change timestamp at least by one second |
| 233 | REQUIRE(directLeafNodeQuery(modulePrefix + "/last-change") > lastChange); // check that last-change leaf has timestamp that is greater than the previous one |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 234 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 235 | // third batch of changes, wild PSU appears with a warning |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 236 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 237 | {COMPONENT("ne:psu") "/state/oper-state", "enabled"}, |
| 238 | {COMPONENT("ne:psu:child") "/class", "iana-hardware:sensor"}, |
| 239 | {COMPONENT("ne:psu:child") "/parent", "ne:psu"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 240 | {COMPONENT("ne:psu:child") "/sensor-data/oper-status", "ok"}, |
| 241 | {COMPONENT("ne:psu:child") "/sensor-data/value", "50000"}, |
| 242 | {COMPONENT("ne:psu:child") "/sensor-data/value-precision", "0"}, |
| 243 | {COMPONENT("ne:psu:child") "/sensor-data/value-scale", "milli"}, |
| 244 | {COMPONENT("ne:psu:child") "/sensor-data/value-type", "volts-DC"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 245 | {COMPONENT("ne:psu:child") "/state/oper-state", "enabled"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 246 | })) |
| 247 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 248 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "cleared", "PSU missing.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 249 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu:child", "cleared", "Sensor value not reported. Maybe the sensor was unplugged?").IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 250 | REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:psu:child", "warning", "Sensor value crossed high threshold (50000 > 15000).").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 251 | psuSensorValue = 50000; |
| 252 | psuActive = true; |
Tomáš Pecka | 43ef7ba | 2023-04-13 15:56:48 +0200 | [diff] [blame] | 253 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 254 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 255 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 256 | // fourth round. We unplug with a warning |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 257 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 258 | {COMPONENT("ne:psu:child") "/class", Deleted{}}, |
| 259 | {COMPONENT("ne:psu:child") "/parent", Deleted{}}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 260 | {COMPONENT("ne:psu:child") "/sensor-data/oper-status", Deleted{}}, |
| 261 | {COMPONENT("ne:psu:child") "/sensor-data/value", Deleted{}}, |
| 262 | {COMPONENT("ne:psu:child") "/sensor-data/value-precision", Deleted{}}, |
| 263 | {COMPONENT("ne:psu:child") "/sensor-data/value-scale", Deleted{}}, |
| 264 | {COMPONENT("ne:psu:child") "/sensor-data/value-type", Deleted{}}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 265 | {COMPONENT("ne:psu:child") "/state/oper-state", Deleted{}}, |
| 266 | {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 267 | })) |
| 268 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 269 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "critical", "PSU missing.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 270 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu:child", "warning", "Sensor value not reported. Maybe the sensor was unplugged?").IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 271 | REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:psu:child", "cleared", "Sensor value is within normal parameters.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 272 | psuActive = false; |
| 273 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 274 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 275 | // 5+th round: test threshold crossings |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 276 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 277 | {COMPONENT("ne:power") "/sensor-data/value", "21000000"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 278 | })) |
| 279 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 280 | REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "warning", "Sensor value crossed high threshold (21000000 > 20000000).").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 281 | powerValue = 21'000'000; |
| 282 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 283 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 284 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 285 | {COMPONENT("ne:power") "/sensor-data/value", "24000000"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 286 | })) |
| 287 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 288 | REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "critical", "Sensor value crossed high threshold (24000000 > 22000000).").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 289 | powerValue = 24'000'000; |
| 290 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 291 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 292 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 293 | {COMPONENT("ne:power") "/sensor-data/value", "1"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 294 | })) |
| 295 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 296 | REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold (1 < 8000000).").IN_SEQUENCE(seq1); |
| 297 | REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "cleared", "Sensor value is within normal parameters.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 298 | powerValue = 1; |
| 299 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 300 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 301 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 302 | {COMPONENT("ne:power") "/sensor-data/value", "14000000"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 303 | })) |
| 304 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 305 | REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "cleared", "Sensor value is within normal parameters.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 306 | powerValue = 14'000'000; |
| 307 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 9af4739 | 2023-05-23 14:56:48 +0200 | [diff] [blame] | 308 | |
Tomáš Pecka | 5a4c035 | 2023-12-12 12:29:28 +0100 | [diff] [blame] | 309 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 310 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 311 | {COMPONENT("ne:power") "/sensor-data/value", "1000000000"}, |
| 312 | {COMPONENT("ne:power") "/sensor-data/oper-status", "nonoperational"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 313 | })) |
| 314 | .IN_SEQUENCE(seq1); |
Jan Kundrát | c151151 | 2024-01-15 13:47:28 +0100 | [diff] [blame] | 315 | REQUIRE_ALARM_RPC("velia-alarms:sensor-nonoperational", "ne:power", "warning", |
| 316 | "Sensor is nonoperational. The values it reports may not be relevant.").IN_SEQUENCE(seq1); |
| 317 | REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "critical", |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 318 | "Sensor value crossed high threshold (1000000000 > 22000000).").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 319 | powerValue = 2'999'999'999; |
| 320 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 5a4c035 | 2023-12-12 12:29:28 +0100 | [diff] [blame] | 321 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 322 | powerValue = 1'999'999'999; |
| 323 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 5a4c035 | 2023-12-12 12:29:28 +0100 | [diff] [blame] | 324 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 325 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 326 | {COMPONENT("ne:power") "/sensor-data/value", "-1000000000"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 327 | })) |
| 328 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 329 | REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold (-1000000000 < 8000000).").IN_SEQUENCE(seq1); |
| 330 | REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "cleared", "Sensor value is within normal parameters.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 331 | powerValue = -2'999'999'999; |
| 332 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | 5a4c035 | 2023-12-12 12:29:28 +0100 | [diff] [blame] | 333 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 334 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 335 | {COMPONENT("ne:power") "/sensor-data/value", "-999999999"}, |
| 336 | {COMPONENT("ne:power") "/sensor-data/oper-status", "ok"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 337 | })) |
| 338 | .IN_SEQUENCE(seq1); |
Jan Kundrát | c151151 | 2024-01-15 13:47:28 +0100 | [diff] [blame] | 339 | REQUIRE_ALARM_RPC("velia-alarms:sensor-nonoperational", "ne:power", "cleared", |
| 340 | "Sensor is nonoperational. The values it reports may not be relevant.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 341 | powerValue = -999'999'999; |
| 342 | waitForCompletionAndBitMore(seq1); |
| 343 | } |
| 344 | |
| 345 | SECTION("Disappearing sensor unplugged in the beginning") |
| 346 | { |
| 347 | cpuTempValue = 41800; |
| 348 | powerValue = 0; |
| 349 | psuActive = false; |
| 350 | psuSensorValue = 12000; |
| 351 | REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).LR_RETURN(cpuTempValue).TIMES(AT_LEAST(1)); |
| 352 | REQUIRE_CALL(*sysfsPower, attribute("power1_input")).LR_RETURN(powerValue).TIMES(AT_LEAST(1)); |
Tomáš Pecka | 9bd6127 | 2024-01-31 15:08:13 +0100 | [diff] [blame] | 353 | REQUIRE_ALARM_INVENTORY_ADD_ALARMS( |
| 354 | INTRODUCED_ALARM("velia-alarms:sensor-low-value-alarm", "Sensor value is below the low threshold."), |
| 355 | INTRODUCED_ALARM("velia-alarms:sensor-high-value-alarm", "Sensor value is above the high threshold."), |
| 356 | INTRODUCED_ALARM("velia-alarms:sensor-missing-alarm", "Sensor is missing."), |
| 357 | INTRODUCED_ALARM("velia-alarms:sensor-nonoperational", "Sensor is flagged as nonoperational.")) |
| 358 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 2848fd0 | 2024-01-30 12:05:59 +0100 | [diff] [blame] | 359 | |
Tomáš Pecka | bbfc1c3 | 2024-01-31 13:58:11 +0100 | [diff] [blame] | 360 | REQUIRE_ALARM_INVENTORY_ADD_RESOURCES( |
| 361 | ALARMS("velia-alarms:sensor-low-value-alarm", |
| 362 | "velia-alarms:sensor-high-value-alarm", |
| 363 | "velia-alarms:sensor-missing-alarm", |
| 364 | "velia-alarms:sensor-nonoperational"), |
| 365 | COMPONENTS( |
| 366 | COMPONENT("ne:power"), |
| 367 | COMPONENT("ne:temperature-cpu"))) |
| 368 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 369 | |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 370 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 371 | {COMPONENT("ne") "/class", "iana-hardware:chassis"}, |
| 372 | {COMPONENT("ne") "/mfg-name", "CESNET"}, |
| 373 | {COMPONENT("ne") "/name", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 374 | {COMPONENT("ne") "/state/oper-state", "enabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 375 | {COMPONENT("ne:power") "/class", "iana-hardware:sensor"}, |
| 376 | {COMPONENT("ne:power") "/name", "ne:power"}, |
| 377 | {COMPONENT("ne:power") "/parent", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 378 | {COMPONENT("ne:power") "/sensor-data/oper-status", "ok"}, |
| 379 | {COMPONENT("ne:power") "/sensor-data/value", "0"}, |
| 380 | {COMPONENT("ne:power") "/sensor-data/value-precision", "0"}, |
| 381 | {COMPONENT("ne:power") "/sensor-data/value-scale", "micro"}, |
| 382 | {COMPONENT("ne:power") "/sensor-data/value-type", "watts"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 383 | {COMPONENT("ne:power") "/state/oper-state", "enabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 384 | {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| 385 | {COMPONENT("ne:psu") "/name", "ne:psu"}, |
| 386 | {COMPONENT("ne:psu") "/parent", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 387 | {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 388 | {COMPONENT("ne:temperature-cpu") "/class", "iana-hardware:sensor"}, |
| 389 | {COMPONENT("ne:temperature-cpu") "/name", "ne:temperature-cpu"}, |
| 390 | {COMPONENT("ne:temperature-cpu") "/parent", "ne"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 391 | {COMPONENT("ne:temperature-cpu") "/sensor-data/oper-status", "ok"}, |
| 392 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value", "41800"}, |
| 393 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value-precision", "0"}, |
| 394 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value-scale", "milli"}, |
| 395 | {COMPONENT("ne:temperature-cpu") "/sensor-data/value-type", "celsius"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 396 | {COMPONENT("ne:temperature-cpu") "/state/oper-state", "enabled"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 397 | })) |
| 398 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | bbfc1c3 | 2024-01-31 13:58:11 +0100 | [diff] [blame] | 399 | REQUIRE_ALARM_INVENTORY_ADD_RESOURCES(ALARMS("velia-alarms:sensor-missing-alarm"), COMPONENTS(COMPONENT("ne:psu"))).TIMES(AT_LEAST(1)); |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 400 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "critical", "PSU missing.").IN_SEQUENCE(seq1); |
Tomáš Pecka | 6121285 | 2024-09-30 14:36:50 +0200 | [diff] [blame] | 401 | REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold (0 < 8000000).").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 402 | |
| 403 | auto ietfHardwareSysrepo = std::make_shared<velia::ietf_hardware::sysrepo::Sysrepo>(srSess, ietfHardware, 150ms); |
| 404 | std::this_thread::sleep_for(400ms); // let's wait until the bg polling thread is spawned; 400 ms is probably enough to spawn the thread and poll 2 or 3 times |
| 405 | waitForCompletionAndBitMore(seq1); |
| 406 | |
| 407 | std::string lastChange = directLeafNodeQuery(modulePrefix + "/last-change"); |
| 408 | |
| 409 | // PSU inserted |
Tomáš Pecka | bbfc1c3 | 2024-01-31 13:58:11 +0100 | [diff] [blame] | 410 | REQUIRE_ALARM_INVENTORY_ADD_RESOURCES( |
| 411 | ALARMS("velia-alarms:sensor-low-value-alarm", |
| 412 | "velia-alarms:sensor-high-value-alarm", |
| 413 | "velia-alarms:sensor-missing-alarm", |
| 414 | "velia-alarms:sensor-nonoperational"), |
| 415 | COMPONENTS(COMPONENT("ne:psu:child"))) |
| 416 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 7eb6459 | 2024-01-24 14:10:47 +0100 | [diff] [blame] | 417 | REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 418 | {COMPONENT("ne:psu") "/state/oper-state", "enabled"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 419 | {COMPONENT("ne:psu:child") "/class", "iana-hardware:sensor"}, |
| 420 | {COMPONENT("ne:psu:child") "/name", "ne:psu:child"}, |
| 421 | {COMPONENT("ne:psu:child") "/parent", "ne:psu"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 422 | {COMPONENT("ne:psu:child") "/sensor-data/oper-status", "ok"}, |
| 423 | {COMPONENT("ne:psu:child") "/sensor-data/value", "12000"}, |
| 424 | {COMPONENT("ne:psu:child") "/sensor-data/value-precision", "0"}, |
| 425 | {COMPONENT("ne:psu:child") "/sensor-data/value-scale", "milli"}, |
| 426 | {COMPONENT("ne:psu:child") "/sensor-data/value-type", "volts-DC"}, |
Jan Kundrát | f85b5cb | 2024-01-15 13:11:51 +0100 | [diff] [blame] | 427 | {COMPONENT("ne:psu:child") "/state/oper-state", "enabled"}, |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 428 | })) |
| 429 | .IN_SEQUENCE(seq1); |
Tomáš Pecka | 26b3821 | 2024-01-16 17:23:31 +0100 | [diff] [blame] | 430 | REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "cleared", "PSU missing.").IN_SEQUENCE(seq1); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 431 | psuActive = true; |
| 432 | waitForCompletionAndBitMore(seq1); |
| 433 | |
| 434 | std::this_thread::sleep_for(1000ms); // last-change leaf resolution is in seconds, let's wait until the second increments |
| 435 | REQUIRE(directLeafNodeQuery(modulePrefix + "/last-change") > lastChange); // check that last-change leaf has timestamp that is greater than the previous one |
| 436 | } |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 437 | } |