Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 1 | #include "trompeloeil_doctest.h" |
| 2 | #include <sysrepo-cpp/Enum.hpp> |
| 3 | #include <trompeloeil.hpp> |
| 4 | #include "dbus-helpers/dbus_rauc_server.h" |
| 5 | #include "fs-helpers/utils.h" |
| 6 | #include "health/State.h" |
| 7 | #include "health/outputs/AlarmsOutputs.h" |
| 8 | #include "pretty_printers.h" |
| 9 | #include "system/LED.h" |
| 10 | #include "test_log_setup.h" |
| 11 | #include "test_sysrepo_helpers.h" |
| 12 | #include "tests/configure.cmake.h" |
| 13 | #include "utils/io.h" |
| 14 | |
| 15 | using namespace std::literals; |
| 16 | |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 17 | #define EXPECT_COLOUR(STATE) expectations.emplace_back(NAMED_REQUIRE_CALL(fakeLeds, call(STATE)).IN_SEQUENCE(seq1)); |
| 18 | |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 19 | struct FakeLedCallback { |
| 20 | MAKE_CONST_MOCK1(call, void(velia::health::State)); |
| 21 | }; |
| 22 | |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 23 | void setSummary(sysrepo::Session sess, unsigned indeterminate, unsigned warning, unsigned minor, unsigned major, unsigned critical) |
| 24 | { |
| 25 | static const auto cleared = 42; |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 26 | |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 27 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='indeterminate']/total", std::to_string(cleared + indeterminate)); |
| 28 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='indeterminate']/not-cleared", std::to_string(indeterminate)); |
| 29 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='indeterminate']/cleared", std::to_string(cleared)); |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 30 | |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 31 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='warning']/total", std::to_string(cleared + warning)); |
| 32 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='warning']/not-cleared", std::to_string(warning)); |
| 33 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='warning']/cleared", std::to_string(cleared)); |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 34 | |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 35 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='minor']/total", std::to_string(cleared + minor)); |
| 36 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='minor']/not-cleared", std::to_string(minor)); |
| 37 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='minor']/cleared", std::to_string(cleared)); |
| 38 | |
| 39 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='major']/total", std::to_string(cleared + major)); |
| 40 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='major']/not-cleared", std::to_string(major)); |
| 41 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='major']/cleared", std::to_string(cleared)); |
| 42 | |
| 43 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='critical']/total", std::to_string(cleared + critical)); |
| 44 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='critical']/not-cleared", std::to_string(critical)); |
| 45 | sess.setItem("/ietf-alarms:alarms/summary/alarm-summary[severity='critical']/cleared", std::to_string(cleared)); |
| 46 | |
| 47 | sess.applyChanges(); |
| 48 | } |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 49 | |
| 50 | TEST_CASE("Sysrepo reports system LEDs") |
| 51 | { |
| 52 | trompeloeil::sequence seq1; |
| 53 | |
| 54 | TEST_SYSREPO_INIT_LOGS; |
| 55 | TEST_SYSREPO_INIT; |
| 56 | TEST_SYSREPO_INIT_CLIENT; |
| 57 | |
| 58 | client.switchDatastore(sysrepo::Datastore::Operational); |
| 59 | srSess.switchDatastore(sysrepo::Datastore::Operational); |
| 60 | |
| 61 | FakeLedCallback fakeLeds; |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 62 | std::vector<std::unique_ptr<trompeloeil::expectation>> expectations; |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 63 | |
| 64 | SECTION("Start with OK") |
| 65 | { |
| 66 | EXPECT_COLOUR(velia::health::State::OK); |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 67 | setSummary(srSess, 0, 0, 0, 0, 0); |
| 68 | } |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 69 | |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 70 | SECTION("Start with WARNING") |
| 71 | { |
| 72 | EXPECT_COLOUR(velia::health::State::WARNING); |
| 73 | setSummary(srSess, 0, 1, 0, 0, 0); |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | SECTION("Start with ERROR") |
| 77 | { |
| 78 | EXPECT_COLOUR(velia::health::State::ERROR); |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 79 | setSummary(srSess, 0, 0, 1, 0, 0); |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 80 | } |
Tomáš Pecka | 3906c89 | 2022-07-26 13:51:17 +0200 | [diff] [blame] | 81 | |
| 82 | velia::health::AlarmsOutputs alarms(client, {[&](velia::health::State state) { fakeLeds.call(state); }}); |
| 83 | |
| 84 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 85 | setSummary(srSess, 0, 0, 2, 0, 0); |
| 86 | |
| 87 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 88 | setSummary(srSess, 0, 0, 0, 3, 0); |
| 89 | |
| 90 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 91 | setSummary(srSess, 0, 0, 0, 0, 4); |
| 92 | |
| 93 | EXPECT_COLOUR(velia::health::State::WARNING); |
| 94 | setSummary(srSess, 0, 5, 0, 0, 0); |
| 95 | |
| 96 | EXPECT_COLOUR(velia::health::State::WARNING); |
| 97 | setSummary(srSess, 6, 0, 0, 0, 0); |
| 98 | |
| 99 | EXPECT_COLOUR(velia::health::State::OK); |
| 100 | setSummary(srSess, 0, 0, 0, 0, 0); |
| 101 | |
| 102 | EXPECT_COLOUR(velia::health::State::WARNING); |
| 103 | setSummary(srSess, 2, 5, 0, 0, 0); |
| 104 | |
| 105 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 106 | setSummary(srSess, 2, 5, 3, 0, 0); |
| 107 | |
| 108 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 109 | setSummary(srSess, 2, 5, 3, 4, 0); |
| 110 | |
| 111 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 112 | setSummary(srSess, 2, 5, 3, 4, 1); |
| 113 | |
| 114 | EXPECT_COLOUR(velia::health::State::OK); |
| 115 | setSummary(srSess, 0, 0, 0, 0, 0); |
| 116 | |
| 117 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 118 | setSummary(srSess, 0, 1, 1, 0, 0); |
| 119 | |
| 120 | EXPECT_COLOUR(velia::health::State::OK); |
| 121 | setSummary(srSess, 0, 0, 0, 0, 0); |
| 122 | |
| 123 | EXPECT_COLOUR(velia::health::State::ERROR); |
| 124 | setSummary(srSess, 1, 0, 1, 0, 0); |
| 125 | |
| 126 | waitForCompletionAndBitMore(seq1); |
Tomáš Pecka | e1f0abd | 2022-07-13 19:31:13 +0200 | [diff] [blame] | 127 | } |