diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f21c038..f802605f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,8 +49,8 @@ set(LIBYANG_DEP_SOVERSION 3.0.0) set(LIBYANG_DEP_SOVERSION_MAJOR 3) # libnetconf2 required version -set(LIBNETCONF2_DEP_VERSION 3.1.1) -set(LIBNETCONF2_DEP_SOVERSION 4.2.0) +set(LIBNETCONF2_DEP_VERSION 3.3.0) +set(LIBNETCONF2_DEP_SOVERSION 4.3.0) set(LIBNETCONF2_DEP_SOVERSION_MAJOR 4) # sysrepo required version diff --git a/tests/np2_test.c b/tests/np2_test.c index 513967de..58ee82aa 100644 --- a/tests/np2_test.c +++ b/tests/np2_test.c @@ -135,6 +135,78 @@ setup_server_file_exists_wait(const char *path) return 0; } +int +np2_glob_test_setup_sess_ctx(struct nc_session *sess, const char **modules) +{ + struct ly_ctx *ctx; + const char *all_features[] = {"*", NULL}; + const char *sub_ntf_features[] = {"encode-xml", "replay", "subtree", "xpath", NULL}; + uint32_t i; + + ctx = (struct ly_ctx *)nc_session_get_ctx(sess); + + /* base modules */ + ly_ctx_set_searchdir(ctx, LN2_YANG_MODULE_DIR); + if (!ly_ctx_load_module(ctx, "ietf-netconf", "2013-09-29", all_features)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01", NULL)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "ietf-yang-library", "2019-01-04", NULL)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "ietf-datastores", "2018-02-14", NULL)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "notifications", "2008-07-14", NULL)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "nc-notifications", "2008-07-14", NULL)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "ietf-netconf-notifications", "2012-02-06", NULL)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "ietf-netconf-nmda", "2019-01-07", all_features)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "ietf-subscribed-notifications", "2019-09-09", sub_ntf_features)) { + SETUP_FAIL_LOG; + return 1; + } + if (!ly_ctx_load_module(ctx, "ietf-yang-push", "2019-09-09", all_features)) { + SETUP_FAIL_LOG; + return 1; + } + + /* test modules */ + if (modules) { + for (i = 0; modules[i]; ++i) { + if (lys_parse_path(ctx, modules[i], LYS_IN_YANG, NULL)) { + SETUP_FAIL_LOG; + return 1; + } + } + } + + /* schema-mount, uses the final context */ + if (nc_client_set_new_session_context_schema_mount(sess)) { + SETUP_FAIL_LOG; + return 1; + } + + return 0; +} + int np2_glob_test_setup_server(void **state, const char *test_name, const char **modules) { @@ -317,18 +389,29 @@ np2_glob_test_setup_server(void **state, const char *test_name, const char **mod } nc_client_set_schema_searchpath(NP_TEST_MODULE_DIR); + /* disable automatic YANG retrieval */ + nc_client_set_new_session_context_autofill(0); + /* create NETCONF sessions */ st->nc_sess = nc_connect_unix(st->socket_path, NULL); if (!st->nc_sess) { SETUP_FAIL_LOG; return 1; } + if (np2_glob_test_setup_sess_ctx(st->nc_sess, modules)) { + SETUP_FAIL_LOG; + return 1; + } st->nc_sess2 = nc_connect_unix(st->socket_path, NULL); if (!st->nc_sess2) { SETUP_FAIL_LOG; return 1; } + if (np2_glob_test_setup_sess_ctx(st->nc_sess2, modules)) { + SETUP_FAIL_LOG; + return 1; + } return 0; } diff --git a/tests/np2_test.h b/tests/np2_test.h index 798d1716..b306a9c0 100644 --- a/tests/np2_test.h +++ b/tests/np2_test.h @@ -286,6 +286,8 @@ void np2_glob_test_setup_test_name(char *buf); int np2_glob_test_setup_env(const char *test_name); +int np2_glob_test_setup_sess_ctx(struct nc_session *sess, const char **modules); + int np2_glob_test_setup_server(void **state, const char *test_name, const char **modules); int np2_glob_test_teardown_notif(const char *test_name); diff --git a/tests/test_confirmed_commit.c b/tests/test_confirmed_commit.c index c7ffbb75..d3c5cc3d 100644 --- a/tests/test_confirmed_commit.c +++ b/tests/test_confirmed_commit.c @@ -108,12 +108,13 @@ notif_check_cc_timeout(struct np2_test *st, uint32_t expected_timeout) } } +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NULL}; + static int local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NULL}; int rc; /* get test name */ @@ -124,7 +125,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -611,6 +612,7 @@ test_rollback_disconnect(void **state) /* create a new session */ ncs = nc_connect_unix(st->socket_path, NULL); assert_non_null(ncs); + np2_glob_test_setup_sess_ctx(ncs, test_modules); /* send a confirmed-commit rpc with 60s timeout */ st->rpc = nc_rpc_commit(1, 60, NULL, NULL, NC_PARAMTYPE_CONST); @@ -800,6 +802,7 @@ test_cancel_persist(void **state) /* start a new NC session */ nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(nc_sess); + np2_glob_test_setup_sess_ctx(nc_sess, test_modules); /* send a confirmed-commit rpc with persist */ st->rpc = nc_rpc_commit(1, 0, persist, NULL, NC_PARAMTYPE_CONST); diff --git a/tests/test_parallel_sessions.c b/tests/test_parallel_sessions.c index 6333d668..a52eb0d6 100644 --- a/tests/test_parallel_sessions.c +++ b/tests/test_parallel_sessions.c @@ -78,6 +78,8 @@ send_get_thread(void *arg) /* create a NETCONF session */ nc_sess = nc_connect_unix(targ->st->socket_path, NULL); assert_non_null(nc_sess); + np2_glob_test_setup_sess_ctx(nc_sess, NULL); + pthread_barrier_wait(&targ->barrier); /* send get rpc */ diff --git a/tests/test_sub_ntf.c b/tests/test_sub_ntf.c index 726dc43f..d3f1aaf4 100644 --- a/tests/test_sub_ntf.c +++ b/tests/test_sub_ntf.c @@ -32,12 +32,13 @@ #include "np2_test.h" #include "np2_test_config.h" +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; + static int local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; int rc; /* get test name */ @@ -48,7 +49,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -75,6 +76,7 @@ teardown_common(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); return 0; } diff --git a/tests/test_sub_ntf_advanced.c b/tests/test_sub_ntf_advanced.c index 60087a2f..788716b3 100644 --- a/tests/test_sub_ntf_advanced.c +++ b/tests/test_sub_ntf_advanced.c @@ -33,12 +33,13 @@ #include "np2_test.h" #include "np2_test_config.h" +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; + static int local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; int rc; /* get test name */ @@ -49,7 +50,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -80,6 +81,7 @@ teardown_common(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); return 0; } @@ -358,6 +360,7 @@ test_deletesub_fail_diff_sess(void **state) /* Create a new session */ tmp = nc_connect_unix(st->socket_path, NULL); assert_non_null(tmp); + np2_glob_test_setup_sess_ctx(tmp, test_modules); /* Try to delete it */ st->rpc = nc_rpc_deletesub(st->ntf_id); @@ -925,6 +928,7 @@ test_killsub_diff_sess(void **state) /* Create a new session */ tmp = nc_connect_unix(st->socket_path, NULL); assert_non_null(tmp); + np2_glob_test_setup_sess_ctx(tmp, test_modules); /* Kill it */ st->rpc = nc_rpc_killsub(st->ntf_id); diff --git a/tests/test_sub_ntf_filter.c b/tests/test_sub_ntf_filter.c index b1bb8189..92336ee2 100644 --- a/tests/test_sub_ntf_filter.c +++ b/tests/test_sub_ntf_filter.c @@ -32,12 +32,13 @@ #include "np2_test.h" #include "np2_test_config.h" +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; + static int local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; int rc; /* get test name */ @@ -48,7 +49,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -75,6 +76,7 @@ teardown_common(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); return 0; } diff --git a/tests/test_subscribe_filter.c b/tests/test_subscribe_filter.c index 27dd298a..dc98f3ac 100644 --- a/tests/test_subscribe_filter.c +++ b/tests/test_subscribe_filter.c @@ -30,6 +30,8 @@ #include "np2_test.h" #include "np2_test_config.h" +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; + static void setup_data(void **state) { @@ -59,6 +61,7 @@ reestablish_sub(void **state, const char *filter) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(NULL, filter, NULL, NULL, NC_PARAMTYPE_CONST); @@ -76,7 +79,6 @@ local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; int rc; /* get test name */ @@ -87,7 +89,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -173,6 +175,7 @@ test_subtree_filter_no_matching_node(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(NULL, filter, NULL, NULL, NC_PARAMTYPE_CONST); @@ -307,6 +310,7 @@ test_xpath_filter_no_matching_node(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(NULL, "/notif2:devices/device[name='Main']", NULL, NULL, NC_PARAMTYPE_CONST); diff --git a/tests/test_subscribe_param.c b/tests/test_subscribe_param.c index 6dcad1ce..1b9fcfa5 100644 --- a/tests/test_subscribe_param.c +++ b/tests/test_subscribe_param.c @@ -32,6 +32,8 @@ #include "np2_test.h" #include "np2_test_config.h" +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; + static void reestablish_sub(void **state, const char *stream, const char *start_time, const char *stop_time) { @@ -41,6 +43,7 @@ reestablish_sub(void **state, const char *stream, const char *start_time, const nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(stream, NULL, start_time, stop_time, NC_PARAMTYPE_CONST); @@ -69,7 +72,6 @@ local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL}; int rc; /* get test name */ @@ -80,7 +82,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -148,6 +150,7 @@ test_stop_time_invalid(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(NULL, NULL, start_time, stop_time, NC_PARAMTYPE_CONST); @@ -187,6 +190,7 @@ test_start_time_invalid(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(NULL, NULL, start_time, NULL, NC_PARAMTYPE_CONST); @@ -224,6 +228,7 @@ test_stop_time_no_start_time(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(NULL, NULL, NULL, stop_time, NC_PARAMTYPE_CONST); diff --git a/tests/test_yang_push.c b/tests/test_yang_push.c index 647ea40e..74fd05d3 100644 --- a/tests/test_yang_push.c +++ b/tests/test_yang_push.c @@ -32,12 +32,13 @@ #include "np2_test.h" #include "np2_test_config.h" +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NP_TEST_MODULE_DIR "/edit2.yang", NULL}; + static int local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NP_TEST_MODULE_DIR "/edit2.yang", NULL}; int rc; /* get test name */ @@ -48,7 +49,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -84,6 +85,7 @@ teardown_common(void **state) /* create new default NETCONF session */ st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); return 0; } diff --git a/tests/test_yang_push_advanced.c b/tests/test_yang_push_advanced.c index 3eb54800..35f46333 100644 --- a/tests/test_yang_push_advanced.c +++ b/tests/test_yang_push_advanced.c @@ -32,12 +32,13 @@ #include "np2_test.h" #include "np2_test_config.h" +static const char *test_modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NP_TEST_MODULE_DIR "/edit2.yang", NULL}; + static int local_setup(void **state) { struct np2_test *st; char test_name[256]; - const char *modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NP_TEST_MODULE_DIR "/edit2.yang", NULL}; int rc; /* get test name */ @@ -48,7 +49,7 @@ local_setup(void **state) assert_int_equal(rc, 0); /* setup netopeer2 server */ - rc = np2_glob_test_setup_server(state, test_name, modules); + rc = np2_glob_test_setup_server(state, test_name, test_modules); assert_int_equal(rc, 0); st = *state; @@ -73,6 +74,7 @@ teardown_common(void **state) nc_session_free(st->nc_sess, NULL); st->nc_sess = nc_connect_unix(st->socket_path, NULL); assert_non_null(st->nc_sess); + np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules); /* Remove the data */ data = "";