system: get LLDP neighbors from JSON output of networkctl

Old way of getting the LLDP neighbours list was through patched systemd.
We patched the systemd in a way that the functions working with LLDP
files in /run/systemd/netif/lldp were made public and thus we could use
them to parse the data [1]. That required to use patched systemd (for
br2-external and for CI test runs). This was not easily maintainable
with new systemd versions.

New attempt is parsing the output of `networkctl lldp --json=pretty`
which is available with the new patch [2].
This also asks for a redesign of tests as we currently have no way of
'injecting' LLDP neighbours into systemd-networkd unless we implement
our own varlink server providing the LLDP data (see the patch).

As we are parsing only the output of `networkctl lldp`, and we do not
rely on any systemd function (even for tests), there is no need to
compile patched systemd. That will also speedup the CI runs, yay.

[1] https://github.com/systemd/systemd/pull/16744
[2] https://github.com/systemd/systemd/pull/20333

Change-Id: Ib880fef50e8d44ca257b582e7d15027ffc5194c9
diff --git a/tests/sysrepo_system-lldp.cpp b/tests/sysrepo_system-lldp.cpp
index 450b248..a49b282 100644
--- a/tests/sysrepo_system-lldp.cpp
+++ b/tests/sysrepo_system-lldp.cpp
@@ -1,7 +1,5 @@
 #include "trompeloeil_doctest.h"
 #include <sysrepo-cpp/Connection.hpp>
-#include <unistd.h>
-#include "dbus-helpers/dbus_network1_server.h"
 #include "system/LLDP.h"
 #include "system/LLDPCallback.h"
 #include "test_log_setup.h"
@@ -14,55 +12,51 @@
     TEST_SYSREPO_INIT;
     TEST_SYSREPO_INIT_CLIENT;
 
-    const auto serverBus = "local.pid" + std::to_string(getpid()) + ".org.freedesktop.network1";
-    auto dbusServerConnection = sdbus::createSessionBusConnection(serverBus);
-    dbusServerConnection->enterEventLoopAsync();
-
-    std::filesystem::path lldpDirectory;
-    std::vector<std::pair<int, std::string>> links;
     std::map<std::string, std::string> expected;
+    std::string json;
 
     SECTION("Single link, single neighbor")
     {
-        lldpDirectory = CMAKE_CURRENT_SOURCE_DIR "/tests/lldp/single-link";
-        links = {{8, "ve-image"}};
+        json = R"({"ve-image": [{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "7062a9e41c924ac6942da39c56e6b820", "enabledCapabilities": "a"}}]})";
         expected = {
             {"/neighbors[1]", ""},
             {"/neighbors[1]/ifName", "ve-image"},
             {"/neighbors[1]/remotePortId", "host0"},
             {"/neighbors[1]/remoteSysName", "image"},
             {"/neighbors[1]/remoteChassisId", "7062a9e41c924ac6942da39c56e6b820"},
-            {"/neighbors[1]/systemCapabilitiesSupported", "bridge router station-only"},
             {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"},
         };
     }
 
     SECTION("Two links per one neighbor")
     {
-        lldpDirectory = CMAKE_CURRENT_SOURCE_DIR "/tests/lldp/two-links";
-        links = {{3, "enp0s31f6"}, {4, "ve-image"}};
+        json = R"({
+"enp0s31f6": [{"neighbor": {"systemName": "sw-a1128-01.fit.cvut.cz", "portId": "Gi3/0/7", "chassisId": "00:b8:b3:e6:17:80", "enabledCapabilities": "b"}}],
+"ve-image":  [{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "8b90f96f448140fb9b5d9d68e86d052e", "enabledCapabilities": "a"}}]
+        })";
         expected = {
             {"/neighbors[1]", ""},
             {"/neighbors[1]/ifName", "enp0s31f6"},
             {"/neighbors[1]/remoteSysName", "sw-a1128-01.fit.cvut.cz"},
             {"/neighbors[1]/remotePortId", "Gi3/0/7"},
             {"/neighbors[1]/remoteChassisId", "00:b8:b3:e6:17:80"},
-            {"/neighbors[1]/systemCapabilitiesSupported", "bridge router"},
             {"/neighbors[1]/systemCapabilitiesEnabled", "bridge"},
             {"/neighbors[2]", ""},
             {"/neighbors[2]/ifName", "ve-image"},
             {"/neighbors[2]/remoteSysName", "image"},
             {"/neighbors[2]/remotePortId", "host0"},
             {"/neighbors[2]/remoteChassisId", "8b90f96f448140fb9b5d9d68e86d052e"},
-            {"/neighbors[2]/systemCapabilitiesSupported", "bridge router station-only"},
             {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"},
         };
     }
 
     SECTION("Multiple neighbors")
     {
-        lldpDirectory = CMAKE_CURRENT_SOURCE_DIR "/tests/lldp/multiple-neighbors";
-        links = {{1, "host0"}};
+        json = R"({"host0": [
+{"neighbor": {"systemName": "image", "portId": "host0", "chassisId": "1631331c24bb499bb644fcdf7c9fd467", "enabledCapabilities": "a"}},
+{"neighbor": {"systemName": "enterprise", "portId": "vb-image2", "chassisId": "1efe5cecbfc248a09065ad6177a98b41", "enabledCapabilities": "a"}}
+        ]})";
+
         expected = {
             {"/neighbors[1]", ""},
             {"/neighbors[1]/ifName", "host0"},
@@ -70,23 +64,18 @@
             {"/neighbors[1]/remotePortId", "host0"},
             {"/neighbors[1]/remoteSysName", "image"},
             {"/neighbors[1]/systemCapabilitiesEnabled", "station-only"},
-            {"/neighbors[1]/systemCapabilitiesSupported", "bridge router station-only"},
             {"/neighbors[2]", ""},
             {"/neighbors[2]/ifName", "host0"},
             {"/neighbors[2]/remoteChassisId", "1efe5cecbfc248a09065ad6177a98b41"},
             {"/neighbors[2]/remotePortId", "vb-image2"},
             {"/neighbors[2]/remoteSysName", "enterprise"},
             {"/neighbors[2]/systemCapabilitiesEnabled", "station-only"},
-            {"/neighbors[2]/systemCapabilitiesSupported", "bridge router station-only"},
         };
     }
 
-    auto dbusClient = sdbus::createSessionBusConnection();
-    auto lldp = std::make_shared<velia::system::LLDPDataProvider>(lldpDirectory, *dbusClient, serverBus);
+    auto lldp = std::make_shared<velia::system::LLDPDataProvider>([&]() { return json; });
     srSubs->oper_get_items_subscribe("czechlight-lldp", velia::system::LLDPCallback(lldp), "/czechlight-lldp:nbr-list");
 
-    auto dbusServer = DbusServer(*dbusServerConnection);
-    dbusServer.setLinks(links);
     client->session_switch_ds(SR_DS_OPERATIONAL);
     REQUIRE(dataFromSysrepo(client, "/czechlight-lldp:nbr-list") == expected);
 }