| #include "trompeloeil_doctest.h" |
| #include <sysrepo-cpp/Enum.hpp> |
| #include <trompeloeil.hpp> |
| #include "dbus-helpers/dbus_rauc_server.h" |
| #include "fs-helpers/utils.h" |
| #include "health/State.h" |
| #include "health/outputs/AlarmsOutputs.h" |
| #include "pretty_printers.h" |
| #include "system/LED.h" |
| #include "test_log_setup.h" |
| #include "test_sysrepo_helpers.h" |
| #include "tests/configure.cmake.h" |
| #include "utils/io.h" |
| |
| using namespace std::literals; |
| |
| #define EXPECT_COLOUR(STATE) expectations.emplace_back(NAMED_REQUIRE_CALL(fakeLeds, call(STATE)).IN_SEQUENCE(seq1)); |
| |
| struct FakeLedCallback { |
| MAKE_CONST_MOCK1(call, void(velia::health::State)); |
| }; |
| |
| void setSummary(sysrepo::Session sess, unsigned indeterminate, unsigned warning, unsigned minor, unsigned major, unsigned critical) |
| { |
| static const auto cleared = 42; |
| |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='indeterminate']/total", std::to_string(cleared + indeterminate)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='indeterminate']/not-cleared", std::to_string(indeterminate)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='indeterminate']/cleared", std::to_string(cleared)); |
| |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='warning']/total", std::to_string(cleared + warning)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='warning']/not-cleared", std::to_string(warning)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='warning']/cleared", std::to_string(cleared)); |
| |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='minor']/total", std::to_string(cleared + minor)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='minor']/not-cleared", std::to_string(minor)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='minor']/cleared", std::to_string(cleared)); |
| |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='major']/total", std::to_string(cleared + major)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='major']/not-cleared", std::to_string(major)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='major']/cleared", std::to_string(cleared)); |
| |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='critical']/total", std::to_string(cleared + critical)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='critical']/not-cleared", std::to_string(critical)); |
| sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='critical']/cleared", std::to_string(cleared)); |
| |
| sess.applyChanges(); |
| } |
| |
| TEST_CASE("Sysrepo reports system LEDs") |
| { |
| trompeloeil::sequence seq1; |
| |
| TEST_SYSREPO_INIT_LOGS; |
| TEST_SYSREPO_INIT; |
| TEST_SYSREPO_INIT_CLIENT; |
| |
| client.switchDatastore(sysrepo::Datastore::Operational); |
| srSess.switchDatastore(sysrepo::Datastore::Operational); |
| |
| FakeLedCallback fakeLeds; |
| std::vector<std::unique_ptr<trompeloeil::expectation>> expectations; |
| |
| SECTION("Start with OK") |
| { |
| EXPECT_COLOUR(velia::health::State::OK); |
| setSummary(srSess, 0, 0, 0, 0, 0); |
| } |
| |
| SECTION("Start with WARNING") |
| { |
| EXPECT_COLOUR(velia::health::State::WARNING); |
| setSummary(srSess, 0, 1, 0, 0, 0); |
| } |
| |
| SECTION("Start with ERROR") |
| { |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 0, 0, 1, 0, 0); |
| } |
| |
| velia::health::AlarmsOutputs alarms(client, {[&](velia::health::State state) { fakeLeds.call(state); }}); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 0, 0, 2, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 0, 0, 0, 3, 0); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 0, 0, 0, 0, 4); |
| |
| EXPECT_COLOUR(velia::health::State::WARNING); |
| setSummary(srSess, 0, 5, 0, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::WARNING); |
| setSummary(srSess, 6, 0, 0, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::OK); |
| setSummary(srSess, 0, 0, 0, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::WARNING); |
| setSummary(srSess, 2, 5, 0, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 2, 5, 3, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 2, 5, 3, 4, 0); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 2, 5, 3, 4, 1); |
| |
| EXPECT_COLOUR(velia::health::State::OK); |
| setSummary(srSess, 0, 0, 0, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 0, 1, 1, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::OK); |
| setSummary(srSess, 0, 0, 0, 0, 0); |
| |
| EXPECT_COLOUR(velia::health::State::ERROR); |
| setSummary(srSess, 1, 0, 1, 0, 0); |
| |
| waitForCompletionAndBitMore(seq1); |
| } |