blob: 62f96f67843f4b26075b6b7e189940948cb68c13 [file] [log] [blame]
Tomáš Peckae1f0abd2022-07-13 19:31:13 +02001#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
15using namespace std::literals;
16
Tomáš Pecka3906c892022-07-26 13:51:17 +020017#define EXPECT_COLOUR(STATE) expectations.emplace_back(NAMED_REQUIRE_CALL(fakeLeds, call(STATE)).IN_SEQUENCE(seq1));
18
Tomáš Peckae1f0abd2022-07-13 19:31:13 +020019struct FakeLedCallback {
20 MAKE_CONST_MOCK1(call, void(velia::health::State));
21};
22
Tomáš Pecka3906c892022-07-26 13:51:17 +020023void setSummary(sysrepo::Session sess, unsigned indeterminate, unsigned warning, unsigned minor, unsigned major, unsigned critical)
24{
25 static const auto cleared = 42;
Tomáš Peckae1f0abd2022-07-13 19:31:13 +020026
Tomáš Pecka3906c892022-07-26 13:51:17 +020027 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áš Peckae1f0abd2022-07-13 19:31:13 +020030
Tomáš Pecka3906c892022-07-26 13:51:17 +020031 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áš Peckae1f0abd2022-07-13 19:31:13 +020034
Tomáš Pecka3906c892022-07-26 13:51:17 +020035 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áš Peckae1f0abd2022-07-13 19:31:13 +020049
50TEST_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áš Pecka3906c892022-07-26 13:51:17 +020062 std::vector<std::unique_ptr<trompeloeil::expectation>> expectations;
Tomáš Peckae1f0abd2022-07-13 19:31:13 +020063
64 SECTION("Start with OK")
65 {
66 EXPECT_COLOUR(velia::health::State::OK);
Tomáš Pecka3906c892022-07-26 13:51:17 +020067 setSummary(srSess, 0, 0, 0, 0, 0);
68 }
Tomáš Peckae1f0abd2022-07-13 19:31:13 +020069
Tomáš Pecka3906c892022-07-26 13:51:17 +020070 SECTION("Start with WARNING")
71 {
72 EXPECT_COLOUR(velia::health::State::WARNING);
73 setSummary(srSess, 0, 1, 0, 0, 0);
Tomáš Peckae1f0abd2022-07-13 19:31:13 +020074 }
75
76 SECTION("Start with ERROR")
77 {
78 EXPECT_COLOUR(velia::health::State::ERROR);
Tomáš Pecka3906c892022-07-26 13:51:17 +020079 setSummary(srSess, 0, 0, 1, 0, 0);
Tomáš Peckae1f0abd2022-07-13 19:31:13 +020080 }
Tomáš Pecka3906c892022-07-26 13:51:17 +020081
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áš Peckae1f0abd2022-07-13 19:31:13 +0200127}