blob: abdb5ee9b1dba280ead929632f0d6ade71dcdcf8 [file] [log] [blame]
Tomáš Pecka7acf3922021-08-10 11:16:57 +02001#include "trompeloeil_doctest.h"
2#include <sysrepo-cpp/Connection.hpp>
Václav Kubernát7efd6d52021-11-09 01:31:11 +01003#include "pretty_printers.h"
Tomáš Pecka7acf3922021-08-10 11:16:57 +02004#include "system/LLDP.h"
5#include "system/LLDPCallback.h"
6#include "test_log_setup.h"
7#include "test_sysrepo_helpers.h"
8#include "tests/configure.cmake.h"
9
10TEST_CASE("Sysrepo opsdata callback")
11{
12 TEST_SYSREPO_INIT_LOGS;
13 TEST_SYSREPO_INIT;
14 TEST_SYSREPO_INIT_CLIENT;
15
Tomáš Pecka7acf3922021-08-10 11:16:57 +020016 std::map<std::string, std::string> expected;
Tomáš Pecka070f60d2021-10-13 21:48:14 +020017 std::string json;
Tomáš Pecka7acf3922021-08-10 11:16:57 +020018
19 SECTION("Single link, single neighbor")
20 {
Tomáš Pecka070f60d2021-10-13 21:48:14 +020021 json = R"({"ve-image": [{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "7062a9e41c924ac6942da39c56e6b820", "enabledCapabilities": "a"}}]})";
Tomáš Pecka7acf3922021-08-10 11:16:57 +020022 expected = {
23 {"/neighbors[1]", ""},
24 {"/neighbors[1]/ifName", "ve-image"},
25 {"/neighbors[1]/remotePortId", "host0"},
26 {"/neighbors[1]/remoteSysName", "image"},
27 {"/neighbors[1]/remoteChassisId", "7062a9e41c924ac6942da39c56e6b820"},
Tomáš Pecka7acf3922021-08-10 11:16:57 +020028 {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"},
29 };
30 }
31
32 SECTION("Two links per one neighbor")
33 {
Tomáš Pecka070f60d2021-10-13 21:48:14 +020034 json = R"({
35"enp0s31f6": [{"neighbor": {"systemName": "sw-a1128-01.fit.cvut.cz", "portId": "Gi3/0/7", "chassisId": "00:b8:b3:e6:17:80", "enabledCapabilities": "b"}}],
36"ve-image": [{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "8b90f96f448140fb9b5d9d68e86d052e", "enabledCapabilities": "a"}}]
37 })";
Tomáš Pecka7acf3922021-08-10 11:16:57 +020038 expected = {
39 {"/neighbors[1]", ""},
40 {"/neighbors[1]/ifName", "enp0s31f6"},
41 {"/neighbors[1]/remoteSysName", "sw-a1128-01.fit.cvut.cz"},
42 {"/neighbors[1]/remotePortId", "Gi3/0/7"},
43 {"/neighbors[1]/remoteChassisId", "00:b8:b3:e6:17:80"},
Tomáš Pecka7acf3922021-08-10 11:16:57 +020044 {"/neighbors[1]/systemCapabilitiesEnabled", "bridge"},
45 {"/neighbors[2]", ""},
46 {"/neighbors[2]/ifName", "ve-image"},
47 {"/neighbors[2]/remoteSysName", "image"},
48 {"/neighbors[2]/remotePortId", "host0"},
49 {"/neighbors[2]/remoteChassisId", "8b90f96f448140fb9b5d9d68e86d052e"},
Tomáš Pecka7acf3922021-08-10 11:16:57 +020050 {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"},
51 };
52 }
53
54 SECTION("Multiple neighbors")
55 {
Tomáš Pecka070f60d2021-10-13 21:48:14 +020056 json = R"({"host0": [
57{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "1631331c24bb499bb644fcdf7c9fd467", "enabledCapabilities": "a"}},
58{"neighbor": {"systemName": "enterprise", "portId": "vb-image2", "chassisId": "1efe5cecbfc248a09065ad6177a98b41", "enabledCapabilities": "a"}}
59 ]})";
60
Tomáš Pecka7acf3922021-08-10 11:16:57 +020061 expected = {
62 {"/neighbors[1]", ""},
63 {"/neighbors[1]/ifName", "host0"},
64 {"/neighbors[1]/remoteChassisId", "1631331c24bb499bb644fcdf7c9fd467"},
65 {"/neighbors[1]/remotePortId", "host0"},
66 {"/neighbors[1]/remoteSysName", "image"},
67 {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"},
Tomáš Pecka7acf3922021-08-10 11:16:57 +020068 {"/neighbors[2]", ""},
69 {"/neighbors[2]/ifName", "host0"},
70 {"/neighbors[2]/remoteChassisId", "1efe5cecbfc248a09065ad6177a98b41"},
71 {"/neighbors[2]/remotePortId", "vb-image2"},
72 {"/neighbors[2]/remoteSysName", "enterprise"},
73 {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"},
Tomáš Pecka7acf3922021-08-10 11:16:57 +020074 };
75 }
76
Tomáš Pecka070f60d2021-10-13 21:48:14 +020077 auto lldp = std::make_shared<velia::system::LLDPDataProvider>([&]() { return json; });
Václav Kubernát7efd6d52021-11-09 01:31:11 +010078 auto sub = srSess.onOperGet("czechlight-lldp", velia::system::LLDPCallback(lldp), "/czechlight-lldp:nbr-list");
Tomáš Pecka7acf3922021-08-10 11:16:57 +020079
Václav Kubernát7efd6d52021-11-09 01:31:11 +010080 client.switchDatastore(sysrepo::Datastore::Operational);
Tomáš Pecka7acf3922021-08-10 11:16:57 +020081 REQUIRE(dataFromSysrepo(client, "/czechlight-lldp:nbr-list") == expected);
82}