| #include "trompeloeil_doctest.h" |
| #include <iterator> |
| #include <sysrepo-cpp/Enum.hpp> |
| #include <trompeloeil.hpp> |
| #include "ietf-hardware/IETFHardware.h" |
| #include "ietf-hardware/sysrepo/Sysrepo.h" |
| #include "mock/ietf_hardware.h" |
| #include "pretty_printers.h" |
| #include "sysrepo-helpers/alarms.h" |
| #include "sysrepo-helpers/datastore.h" |
| #include "test_log_setup.h" |
| #include "tests/sysrepo-helpers/common.h" |
| |
| using namespace std::literals; |
| |
| #define COMPONENT(RESOURCE) "/ietf-hardware:hardware/component[name='" RESOURCE "']" |
| |
| #define REQUIRE_ALARM_INVENTORY_ADD_ALARM(ALARM_TYPE, DESCRIPTION) \ |
| REQUIRE_NEW_ALARM_INVENTORY_ENTRY(alarmWatcher, ALARM_TYPE, (std::vector<std::string>{}), \ |
| (std::vector<std::string>{}), true, DESCRIPTION) |
| |
| #define REQUIRE_ALARM_INVENTORY_ADD_RESOURCES(ALARM_TYPE, ...) \ |
| REQUIRE_NEW_ALARM_INVENTORY_RESOURCES(alarmWatcher, (std::vector<std::string>{ALARM_TYPE}), (std::vector<std::string>{__VA_ARGS__})) |
| |
| #define REQUIRE_ALARM_RPC(ALARM_TYPE, RESOURCE, SEVERITY, TEXT) \ |
| REQUIRE_NEW_ALARM(alarmWatcher, ALARM_TYPE, COMPONENT(RESOURCE), SEVERITY, TEXT) |
| |
| TEST_CASE("IETF Hardware with sysrepo") |
| { |
| TEST_SYSREPO_INIT_LOGS; |
| TEST_SYSREPO_INIT; |
| TEST_SYSREPO_INIT_CLIENT; |
| |
| srSess.sendRPC(srSess.getContext().newPath("/ietf-factory-default:factory-reset")); |
| |
| auto alarmsClient = sysrepo::Connection{}.sessionStart(sysrepo::Datastore::Operational); |
| |
| static const auto modulePrefix = "/ietf-hardware:hardware"s; |
| |
| client.switchDatastore(sysrepo::Datastore::Operational); |
| |
| trompeloeil::sequence seq1; |
| |
| auto directLeafNodeQuery = [&](const std::string& xpath) { |
| auto val = client.getData(xpath); |
| REQUIRE(val); |
| return std::string{val->findPath(xpath)->asTerm().valueStr()}; |
| }; |
| |
| auto sysfsTempCpu = std::make_shared<FakeHWMon>(); |
| auto sysfsPower = std::make_shared<FakeHWMon>(); |
| |
| using velia::ietf_hardware::OneThreshold; |
| using velia::ietf_hardware::Thresholds; |
| using velia::ietf_hardware::data_reader::SensorType; |
| using velia::ietf_hardware::data_reader::StaticData; |
| using velia::ietf_hardware::data_reader::SysfsValue; |
| |
| std::atomic<bool> psuActive; // this needs to be destroyed after ietfHardware to avoid dangling reference (we are passing it as a ref to PsuDataReader) |
| std::atomic<int64_t> psuSensorValue; |
| std::atomic<int64_t> cpuTempValue; |
| std::atomic<int64_t> powerValue; |
| |
| // register components into hw state |
| auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>(); |
| ietfHardware->registerDataReader(StaticData("ne", std::nullopt, {{"class", "iana-hardware:chassis"}, {"mfg-name", "CESNET"s}})); |
| ietfHardware->registerDataReader(SysfsValue<SensorType::Temperature>("ne:temperature-cpu", "ne", sysfsTempCpu, 1)); |
| ietfHardware->registerDataReader(SysfsValue<SensorType::Power>( |
| "ne:power", |
| "ne", |
| sysfsPower, |
| 1, |
| Thresholds<int64_t>{ |
| .criticalLow = OneThreshold<int64_t>{8'000'000, 500'000}, |
| .warningLow = OneThreshold<int64_t>{10'000'000, 500'000}, |
| .warningHigh = OneThreshold<int64_t>{20'000'000, 500'000}, |
| .criticalHigh = OneThreshold<int64_t>{22'000'000, 500'000}, |
| })); |
| |
| /* 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 |
| * data might not even be pushed (e.g. the child sensors). |
| * Since we push data into sysrepo we have to erase old data (that should no longer be present) from the sysrepo operational DS. |
| * We test such situation via the following data reader which returns data only when psuActive is set to true. |
| */ |
| struct PsuDataReader { |
| const std::atomic<bool>& active; |
| const std::atomic<int64_t>& value; |
| |
| velia::ietf_hardware::SensorPollData operator()() |
| { |
| velia::ietf_hardware::SideLoadedAlarm alarm; |
| velia::ietf_hardware::ThresholdsBySensorPath thr; |
| velia::ietf_hardware::DataTree res = { |
| {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| {COMPONENT("ne:psu") "/parent", "ne"}, |
| {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
| }; |
| |
| if (active) { |
| res[COMPONENT("ne:psu") "/state/oper-state"] = "enabled"; |
| res[COMPONENT("ne:psu:child") "/class"] = "iana-hardware:sensor"; |
| res[COMPONENT("ne:psu:child") "/parent"] = "ne:psu"; |
| res[COMPONENT("ne:psu:child") "/state/oper-state"] = "enabled"; |
| res[COMPONENT("ne:psu:child") "/sensor-data/oper-status"] = "ok"; |
| res[COMPONENT("ne:psu:child") "/sensor-data/value"] = std::to_string(value); |
| res[COMPONENT("ne:psu:child") "/sensor-data/value-precision"] = "0"; |
| res[COMPONENT("ne:psu:child") "/sensor-data/value-scale"] = "milli"; |
| res[COMPONENT("ne:psu:child") "/sensor-data/value-type"] = "volts-DC"; |
| |
| thr[COMPONENT("ne:psu:child") "/sensor-data/value"] = Thresholds<int64_t>{ |
| .criticalLow = std::nullopt, |
| .warningLow = OneThreshold<int64_t>{10000, 2000}, |
| .warningHigh = OneThreshold<int64_t>{15000, 2000}, |
| .criticalHigh = std::nullopt, |
| }; |
| |
| alarm = {"velia-alarms:sensor-missing-alarm", COMPONENT("ne:psu"), "cleared", "PSU missing."}; |
| } else { |
| alarm = {"velia-alarms:sensor-missing-alarm", COMPONENT("ne:psu"), "critical", "PSU missing."}; |
| } |
| |
| return {res, thr, {alarm}}; |
| } |
| }; |
| ietfHardware->registerDataReader(PsuDataReader{psuActive, psuSensorValue}); |
| |
| /* Ensure that there are sane data after each sysrepo change callback (all the component subtrees are expected). */ |
| DatastoreWatcher dsChangeHardware(client, "/ietf-hardware:hardware/component", {"/ietf-hardware:hardware/last-change"}); |
| AlarmWatcher alarmWatcher(client); |
| |
| SECTION("Disappearing sensor plugged from the beginning") |
| { |
| // first batch of values |
| cpuTempValue = 41800; |
| powerValue = 0; |
| psuActive = true; |
| psuSensorValue = 12000; |
| REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).LR_RETURN(cpuTempValue).TIMES(AT_LEAST(1)); |
| REQUIRE_CALL(*sysfsPower, attribute("power1_input")).LR_RETURN(powerValue).TIMES(AT_LEAST(1)); |
| |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-low-value-alarm", "Sensor value is below the low threshold.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-high-value-alarm", "Sensor value is above the high threshold.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-missing-alarm", "Sensor is missing.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-nonoperational", "Sensor is flagged as nonoperational.").IN_SEQUENCE(seq1); |
| |
| 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); |
| 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); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-missing-alarm", COMPONENT("ne:power"), COMPONENT("ne:psu:child"), COMPONENT("ne:temperature-cpu")).IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-nonoperational", COMPONENT("ne:power"), COMPONENT("ne:psu:child"), COMPONENT("ne:temperature-cpu")).IN_SEQUENCE(seq1); |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne") "/class", "iana-hardware:chassis"}, |
| {COMPONENT("ne") "/mfg-name", "CESNET"}, |
| {COMPONENT("ne") "/name", "ne"}, |
| {COMPONENT("ne") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:power") "/class", "iana-hardware:sensor"}, |
| {COMPONENT("ne:power") "/name", "ne:power"}, |
| {COMPONENT("ne:power") "/parent", "ne"}, |
| {COMPONENT("ne:power") "/sensor-data/oper-status", "ok"}, |
| {COMPONENT("ne:power") "/sensor-data/value", "0"}, |
| {COMPONENT("ne:power") "/sensor-data/value-precision", "0"}, |
| {COMPONENT("ne:power") "/sensor-data/value-scale", "micro"}, |
| {COMPONENT("ne:power") "/sensor-data/value-type", "watts"}, |
| {COMPONENT("ne:power") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| {COMPONENT("ne:psu") "/name", "ne:psu"}, |
| {COMPONENT("ne:psu") "/parent", "ne"}, |
| {COMPONENT("ne:psu") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:psu:child") "/class", "iana-hardware:sensor"}, |
| {COMPONENT("ne:psu:child") "/name", "ne:psu:child"}, |
| {COMPONENT("ne:psu:child") "/parent", "ne:psu"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/oper-status", "ok"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value", "12000"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-precision", "0"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-scale", "milli"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-type", "volts-DC"}, |
| {COMPONENT("ne:psu:child") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:temperature-cpu") "/class", "iana-hardware:sensor"}, |
| {COMPONENT("ne:temperature-cpu") "/name", "ne:temperature-cpu"}, |
| {COMPONENT("ne:temperature-cpu") "/parent", "ne"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/oper-status", "ok"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value", "41800"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value-precision", "0"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value-scale", "milli"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value-type", "celsius"}, |
| {COMPONENT("ne:temperature-cpu") "/state/oper-state", "enabled"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-missing-alarm", COMPONENT("ne:psu")).TIMES(AT_LEAST(1)); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold.").IN_SEQUENCE(seq1); |
| |
| auto ietfHardwareSysrepo = std::make_shared<velia::ietf_hardware::sysrepo::Sysrepo>(srSess, ietfHardware, 150ms); |
| 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 |
| |
| std::string lastChange = directLeafNodeQuery(modulePrefix + "/last-change"); |
| |
| // second batch of values, sensor data changed, PSU ejected |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:psu:child") "/class", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/parent", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/oper-status", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-precision", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-scale", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-type", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/state/oper-state", Deleted{}}, |
| {COMPONENT("ne:power") "/sensor-data/value", "11222333"}, |
| {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value", "222"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "critical", "PSU missing.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "cleared", "Sensor value crossed low threshold.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu:child", "warning", |
| "Sensor value not reported. Maybe the sensor was unplugged?").IN_SEQUENCE(seq1); |
| REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).LR_RETURN(cpuTempValue).TIMES(AT_LEAST(1)); |
| REQUIRE_CALL(*sysfsPower, attribute("power1_input")).LR_RETURN(powerValue).TIMES(AT_LEAST(1)); |
| cpuTempValue = 222; |
| powerValue = 11222333; |
| psuActive = false; |
| |
| 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 |
| REQUIRE(directLeafNodeQuery(modulePrefix + "/last-change") > lastChange); // check that last-change leaf has timestamp that is greater than the previous one |
| |
| // third batch of changes, wild PSU appears with a warning |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:psu") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:psu:child") "/class", "iana-hardware:sensor"}, |
| {COMPONENT("ne:psu:child") "/parent", "ne:psu"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/oper-status", "ok"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value", "50000"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-precision", "0"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-scale", "milli"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-type", "volts-DC"}, |
| {COMPONENT("ne:psu:child") "/state/oper-state", "enabled"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "cleared", "PSU missing.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu:child", "cleared", "Sensor value not reported. Maybe the sensor was unplugged?").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:psu:child", "warning", "Sensor value crossed high threshold.").IN_SEQUENCE(seq1); |
| psuSensorValue = 50000; |
| psuActive = true; |
| |
| waitForCompletionAndBitMore(seq1); |
| |
| // fourth round. We unplug with a warning |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:psu:child") "/class", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/parent", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/oper-status", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-precision", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-scale", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-type", Deleted{}}, |
| {COMPONENT("ne:psu:child") "/state/oper-state", Deleted{}}, |
| {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "critical", "PSU missing.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu:child", "warning", "Sensor value not reported. Maybe the sensor was unplugged?").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:psu:child", "cleared", "Sensor value crossed high threshold.").IN_SEQUENCE(seq1); |
| psuActive = false; |
| waitForCompletionAndBitMore(seq1); |
| |
| // 5+th round: test threshold crossings |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:power") "/sensor-data/value", "21000000"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "warning", "Sensor value crossed high threshold.").IN_SEQUENCE(seq1); |
| powerValue = 21'000'000; |
| waitForCompletionAndBitMore(seq1); |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:power") "/sensor-data/value", "24000000"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "critical", "Sensor value crossed high threshold.").IN_SEQUENCE(seq1); |
| powerValue = 24'000'000; |
| waitForCompletionAndBitMore(seq1); |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:power") "/sensor-data/value", "1"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "cleared", "Sensor value crossed high threshold.").IN_SEQUENCE(seq1); |
| powerValue = 1; |
| waitForCompletionAndBitMore(seq1); |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:power") "/sensor-data/value", "14000000"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "cleared", "Sensor value crossed low threshold.").IN_SEQUENCE(seq1); |
| powerValue = 14'000'000; |
| waitForCompletionAndBitMore(seq1); |
| |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:power") "/sensor-data/value", "1000000000"}, |
| {COMPONENT("ne:power") "/sensor-data/oper-status", "nonoperational"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-nonoperational", "ne:power", "warning", |
| "Sensor is nonoperational. The values it reports may not be relevant.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "critical", |
| "Sensor value crossed high threshold.").IN_SEQUENCE(seq1); |
| powerValue = 2'999'999'999; |
| waitForCompletionAndBitMore(seq1); |
| |
| powerValue = 1'999'999'999; |
| waitForCompletionAndBitMore(seq1); |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:power") "/sensor-data/value", "-1000000000"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-high-value-alarm", "ne:power", "cleared", "Sensor value crossed high threshold.").IN_SEQUENCE(seq1); |
| powerValue = -2'999'999'999; |
| waitForCompletionAndBitMore(seq1); |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:power") "/sensor-data/value", "-999999999"}, |
| {COMPONENT("ne:power") "/sensor-data/oper-status", "ok"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-nonoperational", "ne:power", "cleared", |
| "Sensor is nonoperational. The values it reports may not be relevant.").IN_SEQUENCE(seq1); |
| powerValue = -999'999'999; |
| waitForCompletionAndBitMore(seq1); |
| } |
| |
| SECTION("Disappearing sensor unplugged in the beginning") |
| { |
| cpuTempValue = 41800; |
| powerValue = 0; |
| psuActive = false; |
| psuSensorValue = 12000; |
| REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).LR_RETURN(cpuTempValue).TIMES(AT_LEAST(1)); |
| REQUIRE_CALL(*sysfsPower, attribute("power1_input")).LR_RETURN(powerValue).TIMES(AT_LEAST(1)); |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-low-value-alarm", "Sensor value is below the low threshold.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-high-value-alarm", "Sensor value is above the high threshold.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-missing-alarm", "Sensor is missing.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_ALARM("velia-alarms:sensor-nonoperational", "Sensor is flagged as nonoperational.").IN_SEQUENCE(seq1); |
| |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-low-value-alarm", COMPONENT("ne:power"), COMPONENT("ne:temperature-cpu")).IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-high-value-alarm", COMPONENT("ne:power"), COMPONENT("ne:temperature-cpu")).IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-missing-alarm", COMPONENT("ne:power"), COMPONENT("ne:temperature-cpu")).IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-nonoperational", COMPONENT("ne:power"), COMPONENT("ne:temperature-cpu")).IN_SEQUENCE(seq1); |
| |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne") "/class", "iana-hardware:chassis"}, |
| {COMPONENT("ne") "/mfg-name", "CESNET"}, |
| {COMPONENT("ne") "/name", "ne"}, |
| {COMPONENT("ne") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:power") "/class", "iana-hardware:sensor"}, |
| {COMPONENT("ne:power") "/name", "ne:power"}, |
| {COMPONENT("ne:power") "/parent", "ne"}, |
| {COMPONENT("ne:power") "/sensor-data/oper-status", "ok"}, |
| {COMPONENT("ne:power") "/sensor-data/value", "0"}, |
| {COMPONENT("ne:power") "/sensor-data/value-precision", "0"}, |
| {COMPONENT("ne:power") "/sensor-data/value-scale", "micro"}, |
| {COMPONENT("ne:power") "/sensor-data/value-type", "watts"}, |
| {COMPONENT("ne:power") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| {COMPONENT("ne:psu") "/name", "ne:psu"}, |
| {COMPONENT("ne:psu") "/parent", "ne"}, |
| {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
| {COMPONENT("ne:temperature-cpu") "/class", "iana-hardware:sensor"}, |
| {COMPONENT("ne:temperature-cpu") "/name", "ne:temperature-cpu"}, |
| {COMPONENT("ne:temperature-cpu") "/parent", "ne"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/oper-status", "ok"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value", "41800"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value-precision", "0"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value-scale", "milli"}, |
| {COMPONENT("ne:temperature-cpu") "/sensor-data/value-type", "celsius"}, |
| {COMPONENT("ne:temperature-cpu") "/state/oper-state", "enabled"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-missing-alarm", COMPONENT("ne:psu")).TIMES(AT_LEAST(1)); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "critical", "PSU missing.").IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-low-value-alarm", "ne:power", "critical", "Sensor value crossed low threshold.").IN_SEQUENCE(seq1); |
| |
| auto ietfHardwareSysrepo = std::make_shared<velia::ietf_hardware::sysrepo::Sysrepo>(srSess, ietfHardware, 150ms); |
| 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 |
| waitForCompletionAndBitMore(seq1); |
| |
| std::string lastChange = directLeafNodeQuery(modulePrefix + "/last-change"); |
| |
| // PSU inserted |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-low-value-alarm", COMPONENT("ne:psu:child")).IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-high-value-alarm", COMPONENT("ne:psu:child")).IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-missing-alarm", COMPONENT("ne:psu:child")).IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_INVENTORY_ADD_RESOURCES("velia-alarms:sensor-nonoperational", COMPONENT("ne:psu:child")).IN_SEQUENCE(seq1); |
| REQUIRE_DATASTORE_CHANGE(dsChangeHardware, (ValueChanges{ |
| {COMPONENT("ne:psu") "/state/oper-state", "enabled"}, |
| {COMPONENT("ne:psu:child") "/class", "iana-hardware:sensor"}, |
| {COMPONENT("ne:psu:child") "/name", "ne:psu:child"}, |
| {COMPONENT("ne:psu:child") "/parent", "ne:psu"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/oper-status", "ok"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value", "12000"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-precision", "0"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-scale", "milli"}, |
| {COMPONENT("ne:psu:child") "/sensor-data/value-type", "volts-DC"}, |
| {COMPONENT("ne:psu:child") "/state/oper-state", "enabled"}, |
| })) |
| .IN_SEQUENCE(seq1); |
| REQUIRE_ALARM_RPC("velia-alarms:sensor-missing-alarm", "ne:psu", "cleared", "PSU missing.").IN_SEQUENCE(seq1); |
| psuActive = true; |
| waitForCompletionAndBitMore(seq1); |
| |
| std::this_thread::sleep_for(1000ms); // last-change leaf resolution is in seconds, let's wait until the second increments |
| REQUIRE(directLeafNodeQuery(modulePrefix + "/last-change") > lastChange); // check that last-change leaf has timestamp that is greater than the previous one |
| } |
| } |