Skip to content

Commit 8077a63

Browse files
committed
port to libyang v4
- the prefix of the "ietf-netconf-with-defaults" module has changed, - RPC parsing needs a flag to reject unknown input data nodes, - due to the "printed context" mess, we now need an extra flag to ensure that we can still access the YANG schema source. The last item is interesting. We could also read directly from the on-disk location, but that looks a bit meh. It's also a bit annoying that one has to change this thing over a lot of places, but I think that this is much nicer than trying to force a change over an existing connection (e.g., via a connection-specific call in the Server::Server ctor which might hit some internal locks depending on how the sysrepo state look like). I was considering adding a wrapper for `ly_ctx_get_options()` and a check in Server::Server, but then I decided that I won't bother. Oh, and this "disable printed context" is also needed for the RESTCONF *client* which is used in the unit test. The `lyd_parse_op` cannot parse notifications *iff* the `notifications` module from RFC 5277 is missing *and* when the libyang context does not have the "parsed" info from the `ietf-yang-types` available. The printed context, as provided by sysrepo, does not have that data available. This is all papered over as long as the context flag setting works, which is the case with post-4.2.4 version of sysrepo (still untagged). Yay. We still set these flags to a single value in all of the unit tests and in the main() as well to maintain the remaining bits of our sanity, of course. Change-Id: I142f650affb53411b5c1dd81311400a2aa6dec20 Depends-on: https://gerrit.cesnet.cz/c/CzechLight/dependencies/+/8990 Bug: CESNET/libyang#2448 Depends-on: sysrepo/sysrepo@6dc5641
1 parent 4493316 commit 8077a63

14 files changed

+33
-9
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ find_package(PkgConfig)
7474
pkg_check_modules(nghttp2 REQUIRED IMPORTED_TARGET libnghttp2_asio>=0.0.90 libnghttp2) # To compile under boost 1.87 you have to patch nghttp2-asio using https://github.com/nghttp2/nghttp2-asio/issues/23
7575
find_package(Boost 1.66 REQUIRED CONFIG COMPONENTS system thread)
7676

77-
pkg_check_modules(SYSREPO REQUIRED sysrepo>=3.6.5 IMPORTED_TARGET)
78-
pkg_check_modules(SYSREPO-CPP REQUIRED IMPORTED_TARGET sysrepo-cpp>=6)
79-
pkg_check_modules(LIBYANG-CPP REQUIRED IMPORTED_TARGET libyang-cpp>=4)
77+
pkg_check_modules(SYSREPO REQUIRED sysrepo IMPORTED_TARGET)
78+
pkg_check_modules(SYSREPO-CPP REQUIRED IMPORTED_TARGET sysrepo-cpp>=7)
79+
pkg_check_modules(LIBYANG-CPP REQUIRED IMPORTED_TARGET libyang-cpp>=5)
8080
pkg_check_modules(SYSTEMD IMPORTED_TARGET libsystemd)
8181
pkg_check_modules(PAM REQUIRED IMPORTED_TARGET pam)
8282
pkg_check_modules(DOCOPT REQUIRED IMPORTED_TARGET docopt)

src/restconf/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void processActionOrRPC(std::shared_ptr<RequestContext> requestCtx, const std::c
487487
auto [parent, rpcNode] = ctx.newPath2(requestCtx->restconfRequest.path);
488488

489489
if (!requestCtx->payload.empty()) {
490-
rpcNode->parseOp(requestCtx->payload, *requestCtx->dataFormat.request, libyang::OperationType::RpcRestconf);
490+
rpcNode->parseOp(requestCtx->payload, *requestCtx->dataFormat.request, libyang::OperationType::RpcRestconf, libyang::ParseOptions::Strict);
491491
}
492492

493493
std::optional<libyang::DataNode> rpcReply;

src/restconf/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <docopt.h>
2323
#include <spdlog/spdlog.h>
2424
#include <sysrepo-cpp/Session.hpp>
25+
#include <sysrepo-cpp/utils/utils.hpp>
2526
#include "restconf/Server.h"
2627
static const char usage[] =
2728
R"(Rousette - RESTCONF server
@@ -103,6 +104,9 @@ int main(int argc, char* argv [])
103104
throw std::runtime_error("Could not set locale C.UTF-8");
104105
}
105106

107+
// schema access is required
108+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
109+
106110
auto conn = sysrepo::Connection{};
107111
auto server = rousette::restconf::Server{conn, "::1", "10080", timeout};
108112

tests/restconf-defaults.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
static const auto SERVER_PORT = "10087";
1010
#include <nghttp2/asio_http2.h>
1111
#include <spdlog/spdlog.h>
12+
#include <sysrepo-cpp/utils/utils.hpp>
1213
#include "restconf/Server.h"
1314
#include "tests/aux-utils.h"
1415
#include "tests/event_watchers.h"
@@ -18,6 +19,7 @@ TEST_CASE("default handling")
1819
trompeloeil::sequence seq1;
1920

2021
spdlog::set_level(spdlog::level::trace);
22+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
2123
auto srConn = sysrepo::Connection{};
2224
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
2325
auto nacmGuard = manageNacm(srSess);

tests/restconf-delete.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
static const auto SERVER_PORT = "10086";
99
#include <nghttp2/asio_http2.h>
1010
#include <spdlog/spdlog.h>
11+
#include <sysrepo-cpp/utils/utils.hpp>
1112
#include "restconf/Server.h"
1213
#include "tests/aux-utils.h"
1314
#include "tests/event_watchers.h"
@@ -16,6 +17,7 @@ static const auto SERVER_PORT = "10086";
1617
TEST_CASE("deleting data")
1718
{
1819
spdlog::set_level(spdlog::level::trace);
20+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
1921
auto srConn = sysrepo::Connection{};
2022
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
2123
auto nacmGuard = manageNacm(srSess);

tests/restconf-eventstream.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TEST_CASE("Event stream tests")
2929

3030
std::vector<std::unique_ptr<trompeloeil::expectation>> expectations;
3131

32+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
3233
auto srConn = sysrepo::Connection{};
3334
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
3435
srSess.sendRPC(srSess.getContext().newPath("/ietf-factory-default:factory-reset"));

tests/restconf-nacm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ static const auto SERVER_PORT = "10082";
1010
#include "tests/aux-utils.h"
1111
#include <nghttp2/asio_http2.h>
1212
#include <spdlog/spdlog.h>
13+
#include <sysrepo-cpp/utils/utils.hpp>
1314
#include "restconf/Server.h"
1415

1516
TEST_CASE("NACM")
1617
{
1718
spdlog::set_level(spdlog::level::trace);
19+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
1820
auto srConn = sysrepo::Connection{};
1921
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
2022
auto nacmGuard = manageNacm(srSess);

tests/restconf-notifications.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TEST_CASE("NETCONF notification streams")
2929

3030
std::vector<std::unique_ptr<trompeloeil::expectation>> expectations;
3131

32+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
3233
auto srConn = sysrepo::Connection{};
3334
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
3435
srSess.sendRPC(srSess.getContext().newPath("/ietf-factory-default:factory-reset"));

tests/restconf-plain-patch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
static const auto SERVER_PORT = "10089";
99
#include <nghttp2/asio_http2.h>
1010
#include <spdlog/spdlog.h>
11+
#include <sysrepo-cpp/utils/utils.hpp>
1112
#include "restconf/Server.h"
1213
#include "tests/aux-utils.h"
1314
#include "tests/event_watchers.h"
@@ -16,6 +17,7 @@ static const auto SERVER_PORT = "10089";
1617
TEST_CASE("Plain patch")
1718
{
1819
spdlog::set_level(spdlog::level::trace);
20+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
1921
auto srConn = sysrepo::Connection{};
2022
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
2123
auto nacmGuard = manageNacm(srSess);

tests/restconf-reading.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ static const auto SERVER_PORT = "10081";
1010
#include "tests/aux-utils.h"
1111
#include <nghttp2/asio_http2.h>
1212
#include <spdlog/spdlog.h>
13+
#include <sysrepo-cpp/utils/utils.hpp>
1314
#include "restconf/Server.h"
1415
#include "tests/event_watchers.h"
1516

1617
TEST_CASE("reading data")
1718
{
1819
spdlog::set_level(spdlog::level::trace);
20+
sysrepo::setGlobalContextOptions(sysrepo::ContextFlags::LibYangPrivParsed | sysrepo::ContextFlags::NoPrinted, sysrepo::GlobalContextEffect::Immediate);
1921
auto srConn = sysrepo::Connection{};
2022
auto srSess = srConn.sessionStart(sysrepo::Datastore::Running);
2123
srSess.sendRPC(srSess.getContext().newPath("/ietf-factory-default:factory-reset"));
@@ -794,7 +796,7 @@ TEST_CASE("reading data")
794796
"c": {
795797
"enabled": true,
796798
"@enabled": {
797-
"ietf-netconf-with-defaults:default": true
799+
"default:default": true
798800
}
799801
}
800802
},
@@ -803,7 +805,7 @@ TEST_CASE("reading data")
803805
"c": {
804806
"enabled": true,
805807
"@enabled": {
806-
"ietf-netconf-with-defaults:default": true
808+
"default:default": true
807809
}
808810
}
809811
}
@@ -868,7 +870,7 @@ TEST_CASE("reading data")
868870
"c": {
869871
"enabled": true,
870872
"@enabled": {
871-
"ietf-netconf-with-defaults:default": true
873+
"default:default": true
872874
}
873875
}
874876
},
@@ -877,7 +879,7 @@ TEST_CASE("reading data")
877879
"c": {
878880
"enabled": true,
879881
"@enabled": {
880-
"ietf-netconf-with-defaults:default": true
882+
"default:default": true
881883
}
882884
}
883885
}
@@ -932,7 +934,7 @@ TEST_CASE("reading data")
932934
"c": {
933935
"enabled": true,
934936
"@enabled": {
935-
"ietf-netconf-with-defaults:default": true
937+
"default:default": true
936938
}
937939
}
938940
}

0 commit comments

Comments
 (0)