blob: a1f932265c673e189a90e24c8bc89b14be86b08a [file] [log] [blame]
Václav Kubernát73109382018-09-14 19:52:03 +02001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
Václav Kubernát26b56082020-02-03 18:28:56 +01009#include "trompeloeil_doctest.hpp"
Jan Kundrát6ee84792020-01-24 01:43:36 +010010#include <sysrepo-cpp/Session.hpp>
Václav Kubernát73109382018-09-14 19:52:03 +020011
Václav Kubernátc31bd602019-03-07 11:44:48 +010012#ifdef sysrepo_BACKEND
Václav Kubernát73109382018-09-14 19:52:03 +020013#include "sysrepo_access.hpp"
Václav Kubernátc31bd602019-03-07 11:44:48 +010014#elif defined(netconf_BACKEND)
15#include "netconf_access.hpp"
16#include "netopeer_vars.hpp"
17#else
18#error "Unknown backend"
19#endif
Jan Kundrátbb525b42020-02-04 11:56:59 +010020#include "pretty_printers.hpp"
Václav Kubernát73109382018-09-14 19:52:03 +020021#include "sysrepo_subscription.hpp"
Václav Kubernát8e121ff2019-10-15 15:47:45 +020022#include "utils.hpp"
Václav Kubernát73109382018-09-14 19:52:03 +020023
Jan Kundrát6ee84792020-01-24 01:43:36 +010024using namespace std::literals::string_literals;
25
Václav Kubernát69aabe92020-01-24 16:53:12 +010026class MockRecorder : public trompeloeil::mock_interface<Recorder> {
Václav Kubernát73109382018-09-14 19:52:03 +020027public:
Václav Kubernát69aabe92020-01-24 16:53:12 +010028 IMPLEMENT_MOCK3(write);
Václav Kubernát73109382018-09-14 19:52:03 +020029};
30
Jan Kundrátbb525b42020-02-04 11:56:59 +010031class MockDataSupplier : public trompeloeil::mock_interface<DataSupplier> {
32public:
33 IMPLEMENT_CONST_MOCK1(get_data);
34};
35
Václav Kubernát8e121ff2019-10-15 15:47:45 +020036TEST_CASE("setting/getting values")
Václav Kubernát73109382018-09-14 19:52:03 +020037{
Václav Kubernát73109382018-09-14 19:52:03 +020038 trompeloeil::sequence seq1;
39 MockRecorder mock;
Václav Kubernátab612e92019-11-26 19:51:31 +010040 SysrepoSubscription subscription("example-schema", &mock);
Václav Kubernátc31bd602019-03-07 11:44:48 +010041
42#ifdef sysrepo_BACKEND
Václav Kubernát73109382018-09-14 19:52:03 +020043 SysrepoAccess datastore("netconf-cli-test");
Václav Kubernátc31bd602019-03-07 11:44:48 +010044#elif defined(netconf_BACKEND)
45 NetconfAccess datastore(NETOPEER_SOCKET_PATH);
46#else
47#error "Unknown backend"
48#endif
Václav Kubernát73109382018-09-14 19:52:03 +020049
Václav Kubernát69aabe92020-01-24 16:53:12 +010050
Václav Kubernát134d78f2019-09-03 16:42:29 +020051 SECTION("set leafInt8 to -128")
Václav Kubernát73109382018-09-14 19:52:03 +020052 {
Václav Kubernát69aabe92020-01-24 16:53:12 +010053 REQUIRE_CALL(mock, write("/example-schema:leafInt8", std::nullopt, "-128"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +020054 datastore.setLeaf("/example-schema:leafInt8", int8_t{-128});
55 datastore.commitChanges();
56 }
57
58 SECTION("set leafInt16 to -32768")
59 {
Václav Kubernát69aabe92020-01-24 16:53:12 +010060 REQUIRE_CALL(mock, write("/example-schema:leafInt16", std::nullopt, "-32768"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +020061 datastore.setLeaf("/example-schema:leafInt16", int16_t{-32768});
62 datastore.commitChanges();
63 }
64
65 SECTION("set leafInt32 to -2147483648")
66 {
Václav Kubernát69aabe92020-01-24 16:53:12 +010067 REQUIRE_CALL(mock, write("/example-schema:leafInt32", std::nullopt, "-2147483648"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +020068 datastore.setLeaf("/example-schema:leafInt32", int32_t{-2147483648});
69 datastore.commitChanges();
70 }
71
72 SECTION("set leafInt64 to -50000000000")
73 {
Václav Kubernát69aabe92020-01-24 16:53:12 +010074 REQUIRE_CALL(mock, write("/example-schema:leafInt64", std::nullopt, "-50000000000"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +020075 datastore.setLeaf("/example-schema:leafInt64", int64_t{-50000000000});
76 datastore.commitChanges();
77 }
78
79 SECTION("set leafUInt8 to 255")
80 {
Václav Kubernát69aabe92020-01-24 16:53:12 +010081 REQUIRE_CALL(mock, write("/example-schema:leafUInt8", std::nullopt, "255"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +020082 datastore.setLeaf("/example-schema:leafUInt8", uint8_t{255});
83 datastore.commitChanges();
84 }
85
86 SECTION("set leafUInt16 to 65535")
87 {
Václav Kubernát69aabe92020-01-24 16:53:12 +010088 REQUIRE_CALL(mock, write("/example-schema:leafUInt16", std::nullopt, "65535"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +020089 datastore.setLeaf("/example-schema:leafUInt16", uint16_t{65535});
90 datastore.commitChanges();
91 }
92
93 SECTION("set leafUInt32 to 4294967295")
94 {
Václav Kubernát69aabe92020-01-24 16:53:12 +010095 REQUIRE_CALL(mock, write("/example-schema:leafUInt32", std::nullopt, "4294967295"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +020096 datastore.setLeaf("/example-schema:leafUInt32", uint32_t{4294967295});
97 datastore.commitChanges();
98 }
99
100 SECTION("set leafUInt64 to 50000000000")
101 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100102 REQUIRE_CALL(mock, write("/example-schema:leafUInt64", std::nullopt, "50000000000"s));
Václav Kubernát134d78f2019-09-03 16:42:29 +0200103 datastore.setLeaf("/example-schema:leafUInt64", uint64_t{50000000000});
Václav Kubernát73109382018-09-14 19:52:03 +0200104 datastore.commitChanges();
105 }
106
107 SECTION("set leafEnum to coze")
108 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100109 REQUIRE_CALL(mock, write("/example-schema:leafEnum", std::nullopt, "coze"s));
Václav Kubernát73109382018-09-14 19:52:03 +0200110 datastore.setLeaf("/example-schema:leafEnum", enum_{"coze"});
111 datastore.commitChanges();
112 }
113
114 SECTION("set leafDecimal to 123.544")
115 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100116 REQUIRE_CALL(mock, write("/example-schema:leafDecimal", std::nullopt, "123.544"s));
Václav Kubernát73109382018-09-14 19:52:03 +0200117 datastore.setLeaf("/example-schema:leafDecimal", 123.544);
118 datastore.commitChanges();
119 }
120
121 SECTION("create presence container")
122 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100123 REQUIRE_CALL(mock, write("/example-schema:pContainer", std::nullopt, ""s));
Václav Kubernát73109382018-09-14 19:52:03 +0200124 datastore.createPresenceContainer("/example-schema:pContainer");
125 datastore.commitChanges();
126 }
127
Václav Kubernátcc7a93f2020-02-04 11:48:15 +0100128 SECTION("create/delete a list instance")
Václav Kubernát45f4a822019-05-29 21:10:50 +0200129 {
Václav Kubernátcc7a93f2020-02-04 11:48:15 +0100130 {
131 REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']", std::nullopt, ""s));
132 REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']/name", std::nullopt, "Nguyen"s));
133 datastore.createListInstance("/example-schema:person[name='Nguyen']");
134 datastore.commitChanges();
135 }
136 {
137 REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']", ""s, std::nullopt));
138 REQUIRE_CALL(mock, write("/example-schema:person[name='Nguyen']/name", "Nguyen"s, std::nullopt));
139 datastore.deleteListInstance("/example-schema:person[name='Nguyen']");
140 datastore.commitChanges();
141 }
Václav Kubernát45f4a822019-05-29 21:10:50 +0200142 }
143
Václav Kubernát3efb5ca2019-10-09 20:07:40 +0200144 SECTION("leafref pointing to a key of a list")
145 {
146 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100147 REQUIRE_CALL(mock, write("/example-schema:person[name='Dan']", std::nullopt, ""s));
148 REQUIRE_CALL(mock, write("/example-schema:person[name='Dan']/name", std::nullopt, "Dan"s));
149 REQUIRE_CALL(mock, write("/example-schema:person[name='Elfi']", std::nullopt, ""s));
150 REQUIRE_CALL(mock, write("/example-schema:person[name='Elfi']/name", std::nullopt, "Elfi"s));
151 REQUIRE_CALL(mock, write("/example-schema:person[name='Kolafa']", std::nullopt, ""s));
152 REQUIRE_CALL(mock, write("/example-schema:person[name='Kolafa']/name", std::nullopt, "Kolafa"s));
Václav Kubernát3efb5ca2019-10-09 20:07:40 +0200153 datastore.createListInstance("/example-schema:person[name='Dan']");
154 datastore.createListInstance("/example-schema:person[name='Elfi']");
155 datastore.createListInstance("/example-schema:person[name='Kolafa']");
156 datastore.commitChanges();
157 }
158
159 // The commitChanges method has to be called in each of the
160 // SECTIONs, because the REQUIRE_CALL only works inside the given
161 // SECTION.
162 SECTION("Dan")
163 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100164 REQUIRE_CALL(mock, write("/example-schema:bossPerson", std::nullopt, "Dan"s));
Václav Kubernát3efb5ca2019-10-09 20:07:40 +0200165 datastore.setLeaf("/example-schema:bossPerson", std::string{"Dan"});
166 datastore.commitChanges();
167 }
168
169 SECTION("Elfi")
170 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100171 REQUIRE_CALL(mock, write("/example-schema:bossPerson", std::nullopt, "Elfi"s));
Václav Kubernát3efb5ca2019-10-09 20:07:40 +0200172 datastore.setLeaf("/example-schema:bossPerson", std::string{"Elfi"});
173 datastore.commitChanges();
174 }
175
176 SECTION("Kolafa")
177 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100178 REQUIRE_CALL(mock, write("/example-schema:bossPerson", std::nullopt, "Kolafa"s));
Václav Kubernát3efb5ca2019-10-09 20:07:40 +0200179 datastore.setLeaf("/example-schema:bossPerson", std::string{"Kolafa"});
180 datastore.commitChanges();
181 }
182 }
Václav Kubernát8e121ff2019-10-15 15:47:45 +0200183 SECTION("bool values get correctly represented as bools")
184 {
185 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100186 REQUIRE_CALL(mock, write("/example-schema:down", std::nullopt, "true"s));
Václav Kubernát8e121ff2019-10-15 15:47:45 +0200187 datastore.setLeaf("/example-schema:down", bool{true});
188 datastore.commitChanges();
189 }
190
Jan Kundrátb331b552020-01-23 15:25:29 +0100191 DatastoreAccess::Tree expected{{"/example-schema:down", bool{true}}};
Václav Kubernát8e121ff2019-10-15 15:47:45 +0200192 REQUIRE(datastore.getItems("/example-schema:down") == expected);
193 }
Václav Kubernát3efb5ca2019-10-09 20:07:40 +0200194
Václav Kubernát9456b5c2019-10-02 21:14:52 +0200195 SECTION("getting items from the whole module")
196 {
197 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100198 REQUIRE_CALL(mock, write("/example-schema:up", std::nullopt, "true"s));
199 REQUIRE_CALL(mock, write("/example-schema:down", std::nullopt, "false"s));
Václav Kubernát9456b5c2019-10-02 21:14:52 +0200200 datastore.setLeaf("/example-schema:up", bool{true});
201 datastore.setLeaf("/example-schema:down", bool{false});
202 datastore.commitChanges();
203 }
204
Jan Kundrátb331b552020-01-23 15:25:29 +0100205 DatastoreAccess::Tree expected{{"/example-schema:down", bool{false}},
Václav Kubernát9456b5c2019-10-02 21:14:52 +0200206 // Sysrepo always returns containers when getting values, but
207 // libnetconf does not. This is fine by the YANG standard:
208 // https://tools.ietf.org/html/rfc7950#section-7.5.7 Furthermore,
209 // NetconfAccess implementation actually only iterates over leafs,
210 // so even if libnetconf did include containers, they wouldn't get
211 // shown here anyway. With sysrepo2, this won't be necessary,
212 // because it'll use the same data structure as libnetconf, so the
213 // results will be consistent.
214#ifdef sysrepo_BACKEND
Václav Kubernát144729d2020-01-08 15:20:35 +0100215 {"/example-schema:lol", special_{SpecialValue::Container}},
Václav Kubernátda8e4b92020-02-04 11:56:30 +0100216 {"/example-schema:inventory", special_{SpecialValue::Container}},
Václav Kubernát9456b5c2019-10-02 21:14:52 +0200217#endif
218 {"/example-schema:up", bool{true}}};
219 REQUIRE(datastore.getItems("/example-schema:*") == expected);
220 }
221
Václav Kubernát152ce222019-12-19 12:23:32 +0100222 SECTION("getItems returns correct datatypes")
223 {
224 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100225 REQUIRE_CALL(mock, write("/example-schema:leafEnum", std::nullopt, "lol"s));
Václav Kubernát152ce222019-12-19 12:23:32 +0100226 datastore.setLeaf("/example-schema:leafEnum", enum_{"lol"});
227 datastore.commitChanges();
228 }
Jan Kundrátb331b552020-01-23 15:25:29 +0100229 DatastoreAccess::Tree expected{{"/example-schema:leafEnum", enum_{"lol"}}};
Václav Kubernát152ce222019-12-19 12:23:32 +0100230
231 REQUIRE(datastore.getItems("/example-schema:leafEnum") == expected);
232 }
233
Václav Kubernátd812cfb2020-01-07 17:30:20 +0100234 SECTION("getItems on a list")
235 {
236 {
Václav Kubernát69aabe92020-01-24 16:53:12 +0100237 REQUIRE_CALL(mock, write("/example-schema:person[name='Jan']", std::nullopt, ""s));
238 REQUIRE_CALL(mock, write("/example-schema:person[name='Jan']/name", std::nullopt, "Jan"s));
239 REQUIRE_CALL(mock, write("/example-schema:person[name='Michal']", std::nullopt, ""s));
240 REQUIRE_CALL(mock, write("/example-schema:person[name='Michal']/name", std::nullopt, "Michal"s));
241 REQUIRE_CALL(mock, write("/example-schema:person[name='Petr']", std::nullopt, ""s));
242 REQUIRE_CALL(mock, write("/example-schema:person[name='Petr']/name", std::nullopt, "Petr"s));
Václav Kubernátd812cfb2020-01-07 17:30:20 +0100243 datastore.createListInstance("/example-schema:person[name='Jan']");
244 datastore.createListInstance("/example-schema:person[name='Michal']");
245 datastore.createListInstance("/example-schema:person[name='Petr']");
246 datastore.commitChanges();
247 }
Jan Kundrátb331b552020-01-23 15:25:29 +0100248 DatastoreAccess::Tree expected{
Václav Kubernát144729d2020-01-08 15:20:35 +0100249 {"/example-schema:person[name='Jan']", special_{SpecialValue::List}},
Václav Kubernátd812cfb2020-01-07 17:30:20 +0100250 {"/example-schema:person[name='Jan']/name", std::string{"Jan"}},
Václav Kubernát144729d2020-01-08 15:20:35 +0100251 {"/example-schema:person[name='Michal']", special_{SpecialValue::List}},
Václav Kubernátd812cfb2020-01-07 17:30:20 +0100252 {"/example-schema:person[name='Michal']/name", std::string{"Michal"}},
Václav Kubernát144729d2020-01-08 15:20:35 +0100253 {"/example-schema:person[name='Petr']", special_{SpecialValue::List}},
Václav Kubernátd812cfb2020-01-07 17:30:20 +0100254 {"/example-schema:person[name='Petr']/name", std::string{"Petr"}}
255 };
256
257 REQUIRE(datastore.getItems("/example-schema:person") == expected);
258 }
259
Václav Kubernát69aabe92020-01-24 16:53:12 +0100260 SECTION("presence containers")
261 {
262 DatastoreAccess::Tree expected;
263 // Make sure it's not there before we create it
264 REQUIRE(datastore.getItems("/example-schema:pContainer") == expected);
265
266 {
267 REQUIRE_CALL(mock, write("/example-schema:pContainer", std::nullopt, ""s));
268 datastore.createPresenceContainer("/example-schema:pContainer");
269 datastore.commitChanges();
270 }
271 expected = {
272 {"/example-schema:pContainer", special_{SpecialValue::PresenceContainer}}
273 };
274 REQUIRE(datastore.getItems("/example-schema:pContainer") == expected);
275
276 // Make sure it's not there after we delete it
277 {
278 REQUIRE_CALL(mock, write("/example-schema:pContainer", ""s, std::nullopt));
279 datastore.deletePresenceContainer("/example-schema:pContainer");
280 datastore.commitChanges();
281 }
282 expected = {};
283 REQUIRE(datastore.getItems("/example-schema:pContainer") == expected);
Václav Kubernátda8e4b92020-02-04 11:56:30 +0100284 }
Václav Kubernát69aabe92020-01-24 16:53:12 +0100285
Václav Kubernátda8e4b92020-02-04 11:56:30 +0100286 SECTION("nested presence container")
287 {
288 DatastoreAccess::Tree expected;
289 // Make sure it's not there before we create it
290 REQUIRE(datastore.getItems("/example-schema:inventory/stuff") == expected);
291 {
292 REQUIRE_CALL(mock, write("/example-schema:inventory", std::nullopt, ""s));
293 REQUIRE_CALL(mock, write("/example-schema:inventory/stuff", std::nullopt, ""s));
294 datastore.createPresenceContainer("/example-schema:inventory/stuff");
295 datastore.commitChanges();
296 }
297 expected = {
298 {"/example-schema:inventory/stuff", special_{SpecialValue::PresenceContainer}}
299 };
300 REQUIRE(datastore.getItems("/example-schema:inventory/stuff") == expected);
301 {
302 REQUIRE_CALL(mock, write("/example-schema:inventory", ""s, std::nullopt));
303 REQUIRE_CALL(mock, write("/example-schema:inventory/stuff", ""s, std::nullopt));
304 datastore.deletePresenceContainer("/example-schema:inventory/stuff");
305 datastore.commitChanges();
306 }
307 expected = {};
308 REQUIRE(datastore.getItems("/example-schema:inventory/stuff") == expected);
Václav Kubernát69aabe92020-01-24 16:53:12 +0100309 }
310
Jan Kundrátbd3169c2020-02-03 19:31:34 +0100311 SECTION("floats")
312 {
313 datastore.setLeaf("/example-schema:leafDecimal", 123.4);
314 REQUIRE_CALL(mock, write("/example-schema:leafDecimal", std::nullopt, "123.4"s));
315 datastore.commitChanges();
316 DatastoreAccess::Tree expected {
317 {"/example-schema:leafDecimal", 123.4},
318 };
319 REQUIRE(datastore.getItems("/example-schema:leafDecimal") == expected);
320 }
321
Jan Kundrátbb525b42020-02-04 11:56:59 +0100322 SECTION("operational data")
323 {
324 MockDataSupplier mockOpsData;
325 OperationalDataSubscription opsDataSub("/example-schema:temperature", mockOpsData);
326 DatastoreAccess::Tree expected;
327 std::string xpath;
328 SECTION("temperature")
329 {
330 expected = {{"/example-schema:temperature", int32_t{22}}};
331 xpath = "/example-schema:temperature";
332 }
333
334 REQUIRE_CALL(mockOpsData, get_data(xpath)).RETURN(expected);
335 REQUIRE(datastore.getItems(xpath) == expected);
336 }
337
338
Václav Kubernát7160a132020-04-03 02:11:01 +0200339 SECTION("copying data from startup refreshes the data")
340 {
341 {
342 REQUIRE(datastore.getItems("/example-schema:leafInt16") == DatastoreAccess::Tree{});
343 REQUIRE_CALL(mock, write("/example-schema:leafInt16", std::nullopt, "123"s));
344 datastore.setLeaf("/example-schema:leafInt16", int16_t{123});
345 datastore.commitChanges();
346 }
347 REQUIRE(datastore.getItems("/example-schema:leafInt16") == DatastoreAccess::Tree{{"/example-schema:leafInt16", int16_t{123}}});
348 REQUIRE_CALL(mock, write("/example-schema:leafInt16", "123"s, std::nullopt));
349 datastore.copyConfig(Datastore::Startup, Datastore::Running);
350 REQUIRE(datastore.getItems("/example-schema:leafInt16") == DatastoreAccess::Tree{});
351 }
352
Václav Kubernát73109382018-09-14 19:52:03 +0200353 waitForCompletionAndBitMore(seq1);
354}
Jan Kundrát6ee84792020-01-24 01:43:36 +0100355
356class RpcCb: public sysrepo::Callback {
357 int rpc(const char *xpath, const ::sysrepo::S_Vals input, ::sysrepo::S_Vals_Holder output, void *) override
358 {
359 const auto nukes = "/example-schema:launch-nukes"s;
360 if (xpath == "/example-schema:noop"s) {
361 return SR_ERR_OK;
362 } else if (xpath == nukes) {
363 uint64_t kilotons = 0;
364 bool hasCities = false;
365 for (size_t i = 0; i < input->val_cnt(); ++i) {
366 const auto& val = input->val(i);
367 if (val->xpath() == nukes + "/payload/kilotons") {
368 kilotons = val->data()->get_uint64();
369 } else if (val->xpath() == nukes + "/payload") {
370 // ignore, container
371 } else if (val->xpath() == nukes + "/description") {
372 // unused
373 } else if (std::string_view{val->xpath()}.find(nukes + "/cities") == 0) {
374 hasCities = true;
375 } else {
376 throw std::runtime_error("RPC launch-nukes: unexpected input "s + val->xpath());
377 }
378 }
379 if (kilotons == 333'666) {
380 // magic, just do not generate any output. This is important because the NETCONF RPC returns just <ok/>.
381 return SR_ERR_OK;
382 }
383 auto buf = output->allocate(2);
384 size_t i = 0;
385 buf->val(i++)->set((nukes + "/blast-radius").c_str(), uint32_t{33'666});
386 buf->val(i++)->set((nukes + "/actual-yield").c_str(), static_cast<uint64_t>(1.33 * kilotons));
387 if (hasCities) {
388 buf = output->reallocate(output->val_cnt() + 2);
389 buf->val(i++)->set((nukes + "/damaged-places/targets[city='London']/city").c_str(), "London");
390 buf->val(i++)->set((nukes + "/damaged-places/targets[city='Berlin']/city").c_str(), "Berlin");
391 }
392 return SR_ERR_OK;
393 }
394 throw std::runtime_error("unrecognized RPC");
395 }
396};
397
398TEST_CASE("rpc") {
399 trompeloeil::sequence seq1;
400 auto srConn = std::make_shared<sysrepo::Connection>("netconf-cli-test-rpc");
401 auto srSession = std::make_shared<sysrepo::Session>(srConn);
402 auto srSubscription = std::make_shared<sysrepo::Subscribe>(srSession);
403 auto cb = std::make_shared<RpcCb>();
404 sysrepo::Logs{}.set_stderr(SR_LL_INF);
405 srSubscription->rpc_subscribe("/example-schema:noop", cb, nullptr, SR_SUBSCR_CTX_REUSE);
406 srSubscription->rpc_subscribe("/example-schema:launch-nukes", cb, nullptr, SR_SUBSCR_CTX_REUSE);
407
408#ifdef sysrepo_BACKEND
409 SysrepoAccess datastore("netconf-cli-test");
410#elif defined(netconf_BACKEND)
411 NetconfAccess datastore(NETOPEER_SOCKET_PATH);
412#else
413#error "Unknown backend"
414#endif
415
416 std::string rpc;
417 DatastoreAccess::Tree input, output;
418
419 SECTION("noop") {
420 rpc = "/example-schema:noop";
421 }
422
423 SECTION("small nuke") {
424 rpc = "/example-schema:launch-nukes";
425 input = {
426 {"description", "dummy"s},
427 {"payload/kilotons", uint64_t{333'666}},
428 };
429 // no data are returned
430 }
431
432 SECTION("small nuke") {
433 rpc = "/example-schema:launch-nukes";
434 input = {
435 {"description", "dummy"s},
436 {"payload/kilotons", uint64_t{4}},
437 };
438 output = {
439 {"blast-radius", uint32_t{33'666}},
440 {"actual-yield", uint64_t{5}},
441 };
442 }
443
444 SECTION("with lists") {
445 rpc = "/example-schema:launch-nukes";
446 input = {
447 {"payload/kilotons", uint64_t{6}},
448 {"cities/targets[city='Prague']/city", "Prague"s},
449 };
450 output = {
451 {"blast-radius", uint32_t{33'666}},
452 {"actual-yield", uint64_t{7}},
453 {"damaged-places", special_{SpecialValue::PresenceContainer}},
454 {"damaged-places/targets[city='London']", special_{SpecialValue::List}},
455 {"damaged-places/targets[city='London']/city", "London"s},
456 {"damaged-places/targets[city='Berlin']", special_{SpecialValue::List}},
457 {"damaged-places/targets[city='Berlin']/city", "Berlin"s},
458 };
459 }
460
461 REQUIRE(datastore.executeRpc(rpc, input) == output);
462
463 waitForCompletionAndBitMore(seq1);
464}