blob: 07dc575e42a5a5a72af5aae22718c54be203c574 [file] [log] [blame]
Tomáš Peckacb7a5f82021-01-20 15:12:00 +01001#include "trompeloeil_doctest.h"
2#include "dbus-helpers/dbus_rauc_server.h"
3#include "pretty_printers.h"
4#include "system/CzechlightSystem.h"
5#include "test_log_setup.h"
6#include "test_sysrepo_helpers.h"
7#include "tests/configure.cmake.h"
8
9using namespace std::literals;
10
11TEST_CASE("czechlight-system")
12{
13 trompeloeil::sequence seq1;
14
15 TEST_SYSREPO_INIT_LOGS;
16 TEST_SYSREPO_INIT;
17 TEST_SYSREPO_INIT_CLIENT;
18
19 auto dbusServerConnection = sdbus::createSessionBusConnection("de.pengutronix.rauc");
20 auto dbusClientConnection = sdbus::createSessionBusConnection();
21 dbusClientConnection->enterEventLoopAsync();
22 dbusServerConnection->enterEventLoopAsync();
23
24 std::map<std::string, velia::system::RAUC::SlotProperties> dbusRaucStatus = {
25 {"rootfs.1", {
26 {"activated.count", uint32_t {39}},
27 {"activated.timestamp", "2021-01-13T17:20:18Z"},
28 {"bootname", "B"},
29 {"boot-status", "good"},
30 {"bundle.compatible", "czechlight-clearfog"},
31 {"bundle.version", "v4-103-g34d2f48"},
32 {"class", "rootfs"},
33 {"device", "/dev/mmcblk0p3"},
34 {"installed.count", uint32_t {39}},
35 {"installed.timestamp", "2021-01-13T17:20:15Z"},
36 {"mountpoint", "/"},
37 {"sha256", "07b30d065c7aad64d2006ce99fd339c929d3ca97b666fca4584b9ef726469fc4"},
38 {"size", uint64_t {45601892}},
39 {"state", "booted"},
40 {"status", "ok"},
41 {"type", "ext4"},
42 }},
43 {"rootfs.0", {
44 {"activated.count", uint32_t {41}},
45 {"activated.timestamp", "2021-01-13T17:15:54Z"},
46 {"bootname", "A"},
47 {"boot-status", "bad"},
48 {"bundle.compatible", "czechlight-clearfog"},
49 {"bundle.version", "v4-104-ge80fcd4"},
50 {"class", "rootfs"},
51 {"device", "/dev/mmcblk0p1"},
52 {"installed.count", uint32_t {41}},
53 {"installed.timestamp", "2021-01-13T17:15:50Z"},
54 {"sha256", "6d81e8f341edd17c127811f7347c7e23d18c2fc25c0bdc29ac56999cc9c25629"},
55 {"size", uint64_t {45647664}},
56 {"state", "inactive"},
57 {"status", "ok"},
58 {"type", "ext4"},
59 }},
60 {"cfg.1", {
61 {"bundle.compatible", "czechlight-clearfog"},
62 {"bundle.version", "v4-103-g34d2f48"},
63 {"class", "cfg"},
64 {"device", "/dev/mmcblk0p4"},
65 {"installed.count", uint32_t {39}},
66 {"installed.timestamp", "2021-01-13T17:20:18Z"},
67 {"mountpoint", "/cfg"},
68 {"parent", "rootfs.1"},
69 {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"},
70 {"size", uint64_t {108}},
71 {"state", "active"},
72 {"status", "ok"},
73 {"type", "ext4"},
74 }},
75 {"cfg.0", {
76 {"bundle.compatible", "czechlight-clearfog"},
77 {"bundle.version", "v4-104-ge80fcd4"},
78 {"class", "cfg"},
79 {"device", "/dev/mmcblk0p2"},
80 {"installed.count", uint32_t {41}},
81 {"installed.timestamp", "2021-01-13T17:15:54Z"},
82 {"parent", "rootfs.0"},
83 {"sha256", "5ca1b6c461fc194055d52b181f57c63dc1d34c19d041f6395e6f6abc039692bb"},
84 {"size", uint64_t {108}},
85 {"state", "inactive"},
86 {"status", "ok"},
87 {"type", "ext4"},
88 }},
89 };
90 auto raucServer = DBusRAUCServer(*dbusServerConnection, "rootfs.1", dbusRaucStatus);
91 auto sysrepo = std::make_shared<velia::system::CzechlightSystem>(srConn, *dbusClientConnection);
92
93 REQUIRE(dataFromSysrepo(client, "/czechlight-system:firmware", SR_DS_OPERATIONAL) == std::map<std::string, std::string>{
94 {"/installation", ""},
95 {"/installation/message", ""},
96 {"/installation/status", "none"},
97 });
98
99 SECTION("Firmware install RPC")
100 {
101 auto rpcInput = std::make_shared<sysrepo::Vals>(1);
102 rpcInput->val(0)->set("/czechlight-system:firmware/installation/install/url", "/path/to/bundle/update.raucb");
103
104 SECTION("Installation runs")
105 {
106 DBusRAUCServer::InstallBehaviour installType;
107 std::map<std::string, std::string> expectedFinished, expectedInProgress = {
108 {"/installation", ""},
109 {"/installation/message", ""},
110 {"/installation/status", "in-progress"},
111 };
112
113 SECTION("Successfull install")
114 {
115 installType = DBusRAUCServer::InstallBehaviour::OK;
116 expectedFinished = {
117 {"/installation", ""},
118 {"/installation/message", ""},
119 {"/installation/status", "succeeded"},
120 };
121 }
122
123 SECTION("Unsuccessfull install")
124 {
125 installType = DBusRAUCServer::InstallBehaviour::FAILURE;
126 expectedFinished = {
127 {"/installation", ""},
128 {"/installation/message", "Failed to download bundle https://10.88.3.11:8000/update.raucb: Transfer failed: error:1408F10B:SSL routines:ssl3_get_record:wrong version number"},
129 {"/installation/status", "failed"},
130 };
131 }
132
133 raucServer.installBundleBehaviour(installType);
134 auto res = client->rpc_send("/czechlight-system:firmware/installation/install", rpcInput);
135 REQUIRE(res->val_cnt() == 0);
136
137 std::this_thread::sleep_for(10ms); // lets wait a while, so the RAUC's callback for operation changed takes place
138 REQUIRE(dataFromSysrepo(client, "/czechlight-system:firmware", SR_DS_OPERATIONAL) == expectedInProgress);
139
140 std::this_thread::sleep_for(2s); // lets wait a while, so the installation can finish
141 REQUIRE(dataFromSysrepo(client, "/czechlight-system:firmware", SR_DS_OPERATIONAL) == expectedFinished);
142 }
143
144 SECTION("Invoke another installation before the first finishes")
145 {
146 client->rpc_send("/czechlight-system:firmware/installation/install", rpcInput);
147 std::this_thread::sleep_for(10ms);
148 REQUIRE_THROWS_WITH_AS(client->rpc_send("/czechlight-system:firmware/installation/install", rpcInput), "User callback failed", sysrepo::sysrepo_exception);
149 }
150 }
151}