Migrate to new NETCONF stack

Changes from old sysrepo:

- sysrepod and sysrepo-plugind are no longer required, so references to
those were removed.

- New Netopeer now uses NACM - the tests neeeded to be changed, so that
they disable NACM.

- Some TSan suppressions needed to be added, because of
https://github.com/sysrepo/sysrepo/issues/2123

- sysrepo now provides easy access to a libyang context with all
modules, which means we no longer have manually fetch them to fill out
YangSchema

- sysrepo now uses a different datastore model
(https://tools.ietf.org/html/rfc8342). This changes the way sysrepo
behaves in the datastore tests, especially that running config is no
longer reset, when closing subscriptions. Because of that, the running
config is always reset at the start of a test. Also, getItems had to be
changed to use the "operational" datastore so that state data is still
fetched.

- sysrepo is now more parallelized and uses non-blocking mechanisms to
defer some actions. The most notable example is committing changes (the
new function is called `apply_changes()`). It is still possible to mimic
the old behavior, because all the "defer-able" functions have a `wait`
argument.

- As sysrepo now uses libyang internally, data can be fetched as libyang
nodes. I replaced the `sr_val_t` (and friends) to this mechanism. This
also unifies some stuff in datastore_access test (mainly the containers,
that had to be #ifdef'd).

- Inside RPC callbacks, libyang context is available. Use this context
to do libyang stuff, instead of injecting a YangSchema.

Depends-on: https://cesnet-gerrit-czechlight/c/CzechLight/dependencies/+/2884
Depends-on: https://cesnet-gerrit-public/c/CzechLight/dependencies/+/2884
Depends-on: https://gerrit.cesnet.cz/c/CzechLight/dependencies/+/2884
Change-Id: Iaf4281bc3bd6cda64ab7d8727c28b9b9d132050a
diff --git a/tests/mock/sysrepo_subscription.cpp b/tests/mock/sysrepo_subscription.cpp
index ba276a7..5527c41 100644
--- a/tests/mock/sysrepo_subscription.cpp
+++ b/tests/mock/sysrepo_subscription.cpp
@@ -10,9 +10,10 @@
 #include <sstream>
 #include <sysrepo-cpp/Session.hpp>
 #include "sysrepo_subscription.hpp"
+#include "utils.hpp"
 
 
-class MyCallback : public sysrepo::Callback {
+class MyCallback {
 public:
     MyCallback(const std::string& moduleName, Recorder* rec)
         : m_moduleName(moduleName)
@@ -20,16 +21,20 @@
     {
     }
 
-    int module_change(sysrepo::S_Session sess, const char* module_name, sr_notif_event_t event, void*) override
+    int operator()(
+            sysrepo::S_Session sess,
+            const char *module_name,
+            [[maybe_unused]] const char *xpath,
+            [[maybe_unused]] sr_event_t event,
+            [[maybe_unused]] uint32_t request_id)
     {
         using namespace std::string_literals;
-        auto xpath = "/"s + module_name + ":*";
-        auto it = sess->get_changes_iter(xpath.c_str());
-
-        if (event == SR_EV_APPLY) {
+        if (event == SR_EV_CHANGE) {
             return SR_ERR_OK;
         }
 
+        auto it = sess->get_changes_iter(("/"s + module_name + ":*//.").c_str());
+
         while (auto change = sess->get_change_next(it)) {
             auto xpath = (change->new_val() ? change->new_val() : change->old_val())->xpath();
 
@@ -51,19 +56,21 @@
 DataSupplier::~DataSupplier() = default;
 
 SysrepoSubscription::SysrepoSubscription(const std::string& moduleName, Recorder* rec)
-    : m_connection(new sysrepo::Connection("netconf-cli-test-subscription"))
+    : m_connection(std::make_shared<sysrepo::Connection>())
 {
     m_session = std::make_shared<sysrepo::Session>(m_connection);
     m_subscription = std::make_shared<sysrepo::Subscribe>(m_session);
+    sysrepo::ModuleChangeCb cb;
     if (rec) {
-        m_callback = std::make_shared<MyCallback>(moduleName, rec);
+        cb = MyCallback{moduleName, rec};
     } else {
-        m_callback = std::make_shared<sysrepo::Callback>();
+        cb = [] (auto, auto, auto, auto, auto) { return SR_ERR_OK; };
     }
 
-    m_subscription->module_change_subscribe(moduleName.c_str(), m_callback);
+    m_subscription->module_change_subscribe(moduleName.c_str(), cb);
 }
 
+
 struct leafDataToSysrepoVal {
     leafDataToSysrepoVal (sysrepo::S_Val v, const std::string& xpath)
         : v(v)
@@ -119,32 +126,50 @@
     std::string xpath;
 };
 
-class OperationalDataCallback : public sysrepo::Callback {
+class OperationalDataCallback {
 public:
     OperationalDataCallback(const DataSupplier& dataSupplier)
         : m_dataSupplier(dataSupplier)
     {
     }
-    int dp_get_items(const char *xpath, sysrepo::S_Vals_Holder vals, [[maybe_unused]] uint64_t request_id, [[maybe_unused]] const char *original_xpath, [[maybe_unused]] void *private_ctx) override
+    int operator()(
+            [[maybe_unused]] sysrepo::S_Session sess,
+            [[maybe_unused]] const char *module_name,
+            const char* path,
+            [[maybe_unused]] const char* request_xpath,
+            [[maybe_unused]] uint32_t request_id,
+            libyang::S_Data_Node& parent)
     {
-        auto data = m_dataSupplier.get_data(xpath);
-        auto out = vals->allocate(data.size());
-        size_t i = 0;
-        for (auto it = data.cbegin(); it != data.cend(); ++it, ++i) {
-            std::string valuePath = it->first;
-            boost::apply_visitor(leafDataToSysrepoVal(out->val(i), valuePath), it->second);
+        auto data = m_dataSupplier.get_data(path);
+        libyang::S_Data_Node res;
+        for (const auto& [p, v] : data) {
+            if (!res) {
+                res = std::make_shared<libyang::Data_Node>(
+                        sess->get_context(),
+                        p.c_str(),
+                        v.type() == typeid(empty_) ? nullptr : leafDataToString(v).c_str(),
+                        LYD_ANYDATA_CONSTSTRING,
+                        0);
+            } else {
+                res->new_path(
+                        sess->get_context(),
+                        p.c_str(),
+                        v.type() == typeid(empty_) ? nullptr : leafDataToString(v).c_str(),
+                        LYD_ANYDATA_CONSTSTRING,
+                        0);
+            }
         }
+        parent = res;
         return SR_ERR_OK;
     }
 private:
     const DataSupplier& m_dataSupplier;
 };
 
-OperationalDataSubscription::OperationalDataSubscription(const std::string& moduleName, const DataSupplier& dataSupplier)
-    : m_connection(new sysrepo::Connection("netconf-cli-test-subscription"))
+OperationalDataSubscription::OperationalDataSubscription(const std::string& moduleName, const std::string& path, const DataSupplier& dataSupplier)
+    : m_connection(std::make_shared<sysrepo::Connection>())
     , m_session(std::make_shared<sysrepo::Session>(m_connection))
     , m_subscription(std::make_shared<sysrepo::Subscribe>(m_session))
-    , m_callback(std::make_shared<OperationalDataCallback>(dataSupplier))
 {
-    m_subscription->dp_get_items_subscribe(moduleName.c_str(), m_callback);
+    m_subscription->oper_get_items_subscribe(moduleName.c_str(), OperationalDataCallback{dataSupplier}, path.c_str());
 }