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/CMakeLists.txt b/CMakeLists.txt
index 555e2ee..d6b26ff 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,9 +57,9 @@
 endif()
 
 find_package(PkgConfig)
-pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.130 IMPORTED_TARGET libyang)
-pkg_check_modules(SYSREPO REQUIRED libSysrepo-cpp>=0.7.9 IMPORTED_TARGET libsysrepo)
-pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=0.12.64 IMPORTED_TARGET libnetconf2)
+pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.190 IMPORTED_TARGET libyang)
+pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.79 IMPORTED_TARGET sysrepo)
+pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=1.1.32 IMPORTED_TARGET libnetconf2)
 
 # we don't need filename tracking, and we prefer to use header-only Boost
 add_definitions(-DBOOST_SPIRIT_X3_NO_FILESYSTEM)
@@ -200,20 +200,6 @@
         message(FATAL_ERROR "Unable to find sysrepocfg, set SYSREPOCFG_EXECUTABLE manually.")
     endif()
 
-    if (NOT SYSREPOD_EXECUTABLE)
-        find_program(SYSREPOD_EXECUTABLE sysrepod)
-    endif()
-    if (NOT SYSREPOD_EXECUTABLE)
-        message(FATAL_ERROR "Unable to find sysrepod, set SYSREPOD_EXECUTABLE manually.")
-    endif()
-
-    if (NOT SYSREPO_PLUGIND_EXECUTABLE)
-        find_program(SYSREPO_PLUGIND_EXECUTABLE sysrepo-plugind)
-    endif()
-    if (NOT SYSREPO_PLUGIND_EXECUTABLE)
-        message(FATAL_ERROR "Unable to find sysrepo-plugind, set SYSREPO_EXECUTABLE manually.")
-    endif()
-
     if (NOT NETOPEER2_EXECUTABLE)
         find_program(NETOPEER2_EXECUTABLE netopeer2-server)
     endif()
@@ -221,32 +207,32 @@
         message(FATAL_ERROR "Unable to find netopeer2-server, set NETOPEER2_EXECUTABLE manually.")
     endif()
 
-    if (NOT FAKEROOT_EXECUTABLE)
-        find_program(FAKEROOT_EXECUTABLE fakeroot)
-    endif()
-    if (NOT FAKEROOT_EXECUTABLE)
-        message(FATAL_ERROR "Unable to find fakeroot, set FAKEROOT_EXECUTABLE manually.")
-    endif()
-
     set(NETOPEER_SOCKET_PATH "${CMAKE_CURRENT_BINARY_DIR}/netopeer2-server.sock")
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/start_daemons.sh.in ${CMAKE_CURRENT_BINARY_DIR}/start_daemons.sh @ONLY)
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/netopeer_vars.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/netopeer_vars.hpp @ONLY)
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/yang_access_test_vars.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/yang_access_test_vars.hpp @ONLY)
+    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/manage_nacm.sh.in ${CMAKE_CURRENT_BINARY_DIR}/manage_nacm.sh @ONLY)
 
     function(setup_datastore_tests)
-        add_test(NAME setup_netopeer COMMAND ${SYSREPOCFG_EXECUTABLE} ietf-netconf-server -i ${CMAKE_CURRENT_SOURCE_DIR}/tests/netopeer-test-config.xml --datastore=startup --format=xml)
-        add_test(NAME start_daemons COMMAND ${FAKEROOT_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/start_daemons.sh)
         add_test(NAME example-schema_init
-            COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL_EXECUTABLE} ${SYSREPOCFG_EXECUTABLE} install ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang )
+            COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL_EXECUTABLE} ${SYSREPOCFG_EXECUTABLE} install ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang)
         add_test(NAME example-schema_cleanup
-            COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL_EXECUTABLE} ${SYSREPOCFG_EXECUTABLE} uninstall ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang )
+            COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL_EXECUTABLE} ${SYSREPOCFG_EXECUTABLE} uninstall ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang)
+        add_test(NAME disable_nacm COMMAND ${CMAKE_CURRENT_BINARY_DIR}/manage_nacm.sh disable)
+        add_test(NAME enable_nacm COMMAND ${CMAKE_CURRENT_BINARY_DIR}/manage_nacm.sh enable)
+        add_test(NAME setup_netopeer COMMAND ${SYSREPOCFG_EXECUTABLE} --import=${CMAKE_CURRENT_SOURCE_DIR}/tests/netopeer-test-config.xml --datastore=startup --format=xml --module=ietf-netconf-server)
+        add_test(NAME start_daemons COMMAND ${CMAKE_CURRENT_BINARY_DIR}/start_daemons.sh)
         add_test(NAME kill_daemons COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/kill_daemons.sh)
-        set_tests_properties(example-schema_init PROPERTIES FIXTURES_REQUIRED netopeer_running FIXTURES_SETUP example-schema_setup)
-        set_tests_properties(example-schema_cleanup PROPERTIES FIXTURES_CLEANUP example-schema_setup)
-        set_tests_properties(setup_netopeer start_daemons kill_daemons example-schema_init example-schema_cleanup PROPERTIES RESOURCE_LOCK sysrepo)
+        set_tests_properties(disable_nacm PROPERTIES FIXTURES_SETUP nacm_disabled)
+        set_tests_properties(enable_nacm PROPERTIES FIXTURES_CLEANUP nacm_disabled)
+        set_tests_properties(example-schema_init PROPERTIES FIXTURES_SETUP example-schema_setup)
         set_tests_properties(setup_netopeer PROPERTIES FIXTURES_SETUP netopeer_configured)
+        set_tests_properties(example-schema_cleanup PROPERTIES FIXTURES_CLEANUP example-schema_setup)
+        set_tests_properties(setup_netopeer start_daemons kill_daemons example-schema_init example-schema_cleanup disable_nacm enable_nacm PROPERTIES RESOURCE_LOCK sysrepo)
+        set_property(TEST setup_netopeer APPEND PROPERTY FIXTURES_REQUIRED nacm_disabled)
+        set_property(TEST setup_netopeer APPEND PROPERTY FIXTURES_REQUIRED example-schema_setup)
         set_tests_properties(start_daemons PROPERTIES FIXTURES_REQUIRED netopeer_configured FIXTURES_SETUP netopeer_running)
-        set_property(TEST kill_daemons APPEND PROPERTY DEPENDS example-schema_cleanup)
+        set_property(TEST example-schema_cleanup APPEND PROPERTY DEPENDS kill_daemons)
         set_property(TEST kill_daemons APPEND PROPERTY FIXTURES_CLEANUP netopeer_running)
     endfunction()
 
@@ -325,6 +311,9 @@
     target_link_libraries(netconf_cli_py PUBLIC netconfaccess)
 
     if(BUILD_TESTING)
+        pybind11_add_module(sysrepo_subscription_py tests/mock/sysrepo_subscription_python.cpp)
+        target_link_libraries(sysrepo_subscription_py PUBLIC sysreposubscription utils)
+
         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/python_netconfaccess.py
             ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py @ONLY)
         add_test(NAME test_netconf_cli_py COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py)