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