blob: e9ac33d32a8b669f032570b9325f36a7e7f767a4 [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
17struct FakeLedCallback {
18 MAKE_CONST_MOCK1(call, void(velia::health::State));
19};
20
21const std::string alarmNode = "/ietf-alarms:alarms/alarm-list/alarm";
22
23#define EXPECT_COLOUR(STATE) REQUIRE_CALL(fakeLeds, call(STATE)).IN_SEQUENCE(seq1)
24
25#define SET_ALARM(RESOURCE, SEVERITY, IS_CLEARED) \
26 srSess.setItem(alarmNode + "[alarm-type-id='velia-alarms:systemd-unit-failure'][alarm-type-qualifier=''][resource='" RESOURCE "']/perceived-severity", SEVERITY); \
27 srSess.setItem(alarmNode + "[alarm-type-id='velia-alarms:systemd-unit-failure'][alarm-type-qualifier=''][resource='" RESOURCE "']/is-cleared", IS_CLEARED);
28
29
30TEST_CASE("Sysrepo reports system LEDs")
31{
32 trompeloeil::sequence seq1;
33
34 TEST_SYSREPO_INIT_LOGS;
35 TEST_SYSREPO_INIT;
36 TEST_SYSREPO_INIT_CLIENT;
37
38 client.switchDatastore(sysrepo::Datastore::Operational);
39 srSess.switchDatastore(sysrepo::Datastore::Operational);
40
41 FakeLedCallback fakeLeds;
42
43 SECTION("Start with OK")
44 {
45 EXPECT_COLOUR(velia::health::State::OK);
46 SET_ALARM("unit1", "major", "true");
47 SET_ALARM("unit2", "critical", "true");
48 srSess.applyChanges();
49
50 velia::health::AlarmsOutputs alarms(client, {[&](velia::health::State state) { fakeLeds.call(state); }});
51
52 EXPECT_COLOUR(velia::health::State::ERROR);
53 SET_ALARM("unit1", "major", "false");
54 srSess.applyChanges();
55
56 EXPECT_COLOUR(velia::health::State::ERROR);
57 SET_ALARM("unit2", "major", "false");
58 srSess.applyChanges();
59
60 EXPECT_COLOUR(velia::health::State::ERROR);
61 SET_ALARM("unit3", "major", "true");
62 srSess.applyChanges();
63
64 EXPECT_COLOUR(velia::health::State::OK);
65 SET_ALARM("unit1", "major", "true");
66 SET_ALARM("unit2", "major", "true");
67 srSess.applyChanges();
68
69 waitForCompletionAndBitMore(seq1);
70 }
71
72 SECTION("Start with ERROR")
73 {
74 EXPECT_COLOUR(velia::health::State::ERROR);
75 SET_ALARM("unit1", "major", "false");
76 srSess.applyChanges();
77
78 velia::health::AlarmsOutputs alarms(client, {[&](velia::health::State state) { fakeLeds.call(state); }});
79
80 EXPECT_COLOUR(velia::health::State::ERROR);
81 SET_ALARM("unit1", "critical", "false");
82 srSess.applyChanges();
83
84 EXPECT_COLOUR(velia::health::State::OK);
85 SET_ALARM("unit1", "major", "true");
86 srSess.applyChanges();
87
88 waitForCompletionAndBitMore(seq1);
89 }
90}