config UPDATE add config replace test
Added test for replacing configuration data. Renamed configuration setup
API calls. Added loading JSON from files.
diff --git a/examples/server.c b/examples/server.c
index c28db62..2ca2215 100644
--- a/examples/server.c
+++ b/examples/server.c
@@ -256,7 +256,7 @@
}
/* apply the created configuration data */
- rc = nc_server_config_setup(config);
+ rc = nc_server_config_setup_diff(config);
if (rc) {
ERR_MSG_CLEANUP("Application of configuration data failed.\n");
}
diff --git a/src/server_config.c b/src/server_config.c
index 41c5a2f..4221741 100644
--- a/src/server_config.c
+++ b/src/server_config.c
@@ -2203,12 +2203,12 @@
NC_CHECK_ARG_RET(NULL, path, 1);
- ret = lyd_parse_data_path(ctx, path, LYD_XML, LYD_PARSE_NO_STATE | LYD_PARSE_STRICT, LYD_VALIDATE_NO_STATE, &tree);
+ ret = lyd_parse_data_path(ctx, path, LYD_UNKNOWN, LYD_PARSE_NO_STATE | LYD_PARSE_STRICT, LYD_VALIDATE_NO_STATE, &tree);
if (ret) {
goto cleanup;
}
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_data(tree);
if (ret) {
goto cleanup;
}
@@ -2240,7 +2240,7 @@
}
API int
-nc_server_config_setup(const struct lyd_node *data)
+nc_server_config_setup_diff(const struct lyd_node *data)
{
int ret = 0;
@@ -2275,7 +2275,7 @@
}
API int
-nc_server_config_setup2(const struct lyd_node *data)
+nc_server_config_setup_data(const struct lyd_node *data)
{
int ret = 0;
struct lyd_node *tree, *iter, *root;
diff --git a/src/server_config.h b/src/server_config.h
index 9d3e161..019db84 100644
--- a/src/server_config.h
+++ b/src/server_config.h
@@ -30,15 +30,15 @@
/**
* @brief Configure server based on the given diff data.
*
- * Expected data is a validated instance of a ietf-netconf-server YANG data.
+ * Expected data are a validated instance of a ietf-netconf-server YANG data.
* The data must be in the diff format and supported operations are: create, replace,
* delete and none. Context must already have implemented the required modules, see
* ::nc_config_load_modules().
*
- * @param[in] data ietf-netconf-server YANG data.
+ * @param[in] diff ietf-netconf-server YANG diff data.
* @return 0 on success, 1 on error.
*/
-int nc_server_config_setup(const struct lyd_node *data);
+int nc_server_config_setup_diff(const struct lyd_node *diff);
/**
* @brief Configure server based on the given data.
@@ -46,17 +46,17 @@
* Expected data is a validated instance of a ietf-netconf-server YANG data.
* Behaves as if all the nodes in data had the replace operation. That means that the current configuration will be deleted
* and just the given data will all be applied.
- * The data must not contain any operation attribute, see ::nc_config_setup() which works with diff.
+ * The data must not contain any operation attribute, see ::nc_config_setup_diff() which works with diff.
* Context must already have implemented the required modules, see * ::nc_config_load_modules().
*
* @param[in] data ietf-netconf-server YANG data.
* @return 0 on success, 1 on error.
*/
-int nc_server_config_setup2(const struct lyd_node *data);
+int nc_server_config_setup_data(const struct lyd_node *data);
/**
* @brief Configure server based on the given ietf-netconf-server YANG data.
- * Wrapper around ::nc_config_setup_server() hiding work with parsing the data.
+ * Wrapper around ::nc_config_setup_server_data() hiding work with parsing the data.
*
* @param[in] ctx libyang context.
* @param[in] path Path to the file with YANG data in XML format.
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2fee776..65ee29e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -9,7 +9,7 @@
# list of all the tests in each directory
#set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_client_thread test_thread_messages)
-set(tests test_two_channels test_keystore test_unix_socket test_config_new test_truststore test_ec test_ed25519)
+set(tests test_two_channels test_keystore test_unix_socket test_config_new test_truststore test_ec test_ed25519 test_replace)
# only enable PAM tests if the version of PAM is greater than 1.4
if(LIBPAM_HAVE_CONFDIR)
diff --git a/tests/test_auth.c b/tests/test_auth.c
index cdd14db..a5a53d5 100644
--- a/tests/test_auth.c
+++ b/tests/test_auth.c
@@ -401,7 +401,7 @@
assert_int_equal(ret, 0);
/* configure the server based on the data */
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
/* initialize client */
diff --git a/tests/test_config_new.c b/tests/test_config_new.c
index f7b7705..b82c6f2 100644
--- a/tests/test_config_new.c
+++ b/tests/test_config_new.c
@@ -168,7 +168,7 @@
assert_int_equal(ret, 0);
/* configure the server based on the data */
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
/* initialize client */
diff --git a/tests/test_ec.c b/tests/test_ec.c
index f3f846c..ad95a4e 100644
--- a/tests/test_ec.c
+++ b/tests/test_ec.c
@@ -231,7 +231,7 @@
assert_int_equal(ret, 0);
/* configure the server based on the data */
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
/* initialize client */
diff --git a/tests/test_ed25519.c b/tests/test_ed25519.c
index 110833a..3a84f22 100644
--- a/tests/test_ed25519.c
+++ b/tests/test_ed25519.c
@@ -162,7 +162,7 @@
assert_int_equal(ret, 0);
/* configure the server based on the data */
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
/* initialize client */
diff --git a/tests/test_keystore.c b/tests/test_keystore.c
index f443b21..9312968 100644
--- a/tests/test_keystore.c
+++ b/tests/test_keystore.c
@@ -218,7 +218,7 @@
assert_int_equal(ret, 0);
/* configure the server based on the data */
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
/* initialize client */
diff --git a/tests/test_replace.c b/tests/test_replace.c
new file mode 100644
index 0000000..28fd032
--- /dev/null
+++ b/tests/test_replace.c
@@ -0,0 +1,298 @@
+/**
+ * @file test_replace.c
+ * @author Roman Janota <xjanot04@fit.vutbr.cz>
+ * @brief libnetconf2 Non-diff YANG data configuration test
+ *
+ * @copyright
+ * Copyright (c) 2023 CESNET, z.s.p.o.
+ *
+ * This source code is licensed under BSD 3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+
+#define _GNU_SOURCE
+
+#include <errno.h>
+#include <pthread.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <cmocka.h>
+
+#include "tests/config.h"
+
+#define NC_ACCEPT_TIMEOUT 2000
+#define NC_PS_POLL_TIMEOUT 2000
+
+struct ly_ctx *ctx;
+
+struct test_state {
+ pthread_barrier_t barrier;
+};
+
+const char *old_data =
+ "<netconf-server xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-server\">\n"
+ " <listen>\n"
+ " <idle-timeout>10</idle-timeout>\n"
+ " <endpoint>\n"
+ " <name>old-ssh</name>\n"
+ " <ssh>\n"
+ " <tcp-server-parameters>\n"
+ " <local-address>127.0.0.1</local-address>\n"
+ " <local-port>10005</local-port>\n"
+ " </tcp-server-parameters>\n"
+ " <ssh-server-parameters>\n"
+ " <server-identity>\n"
+ " <host-key>\n"
+ " <name>old_key</name>\n"
+ " <public-key>\n"
+ " <local-definition>\n"
+ " <public-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:ssh-public-key-format</public-key-format>\n"
+ " <public-key>MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA6ojtjfDmvyQP1ZkIwBpr97eKDuebvpoglRHRdvVuTpf/gU1VArAQmwGh05i6lm8TkVl1noMlIxLJDcWslaeVn6KyvsX0HhsQtXwqPqwka5UCv6alwf/ivAvcNpcX1j0t/uIGCI4dSiKnzQCyf0FTirzQkjrDZUd3meDhNQTruCalGV4gfNWIq3e1oGuwAn1tLlu9oTrE4HzMpgbNEU6wNmsSqpwGxUhYLoSaM7b0dLmqP+ZczSS0Uac0PFNkehGQ2CYIT80f580o4XGtoLCUUGkp6YCTL4Z2CeBEaJABWjDIDH+dKYIUBqUpz4Th12gXAP+h+3qI6+9eppeHrfrzARDsfLjwUNxQJse1QSArjAytf0FKtGHrORc7W0TiCFvR0zaoUNLTKk7enTiRQ9rfWZOAu44fUvPCaXDE6zXXeaVgoKCo4VHlho36erUcjlEBM+jk28IykbZGtBb6igKvYa1tPSgeYm/zJoFVjQcnr14uci/ft1+Na+hOIEoEEiKxcAPk2b2vBKNlRIW7WLJ3u7ZiuQEJTNm6+3cE4+lfwaBCBqBToE+dpzvoUXoMyFFReUFd1O5axu4fXgt00jMaOQxmE0v9OmR/pL/PWIflVF4Zz5yVONYaDVc7l+veY0oEZruEPJ0hlEgxuCzLrcMhjufl2qE2Q7fQIaav/1NqBVkCAwEAAQ==</public-key>\n"
+ " <private-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:rsa-private-key-format</private-key-format>\n"
+ " <cleartext-private-key>MIIJKAIBAAKCAgEA6ojtjfDmvyQP1ZkIwBpr97eKDuebvpoglRHRdvVuTpf/gU1VArAQmwGh05i6lm8TkVl1noMlIxLJDcWslaeVn6KyvsX0HhsQtXwqPqwka5UCv6alwf/ivAvcNpcX1j0t/uIGCI4dSiKnzQCyf0FTirzQkjrDZUd3meDhNQTruCalGV4gfNWIq3e1oGuwAn1tLlu9oTrE4HzMpgbNEU6wNmsSqpwGxUhYLoSaM7b0dLmqP+ZczSS0Uac0PFNkehGQ2CYIT80f580o4XGtoLCUUGkp6YCTL4Z2CeBEaJABWjDIDH+dKYIUBqUpz4Th12gXAP+h+3qI6+9eppeHrfrzARDsfLjwUNxQJse1QSArjAytf0FKtGHrORc7W0TiCFvR0zaoUNLTKk7enTiRQ9rfWZOAu44fUvPCaXDE6zXXeaVgoKCo4VHlho36erUcjlEBM+jk28IykbZGtBb6igKvYa1tPSgeYm/zJoFVjQcnr14uci/ft1+Na+hOIEoEEiKxcAPk2b2vBKNlRIW7WLJ3u7ZiuQEJTNm6+3cE4+lfwaBCBqBToE+dpzvoUXoMyFFReUFd1O5axu4fXgt00jMaOQxmE0v9OmR/pL/PWIflVF4Zz5yVONYaDVc7l+veY0oEZruEPJ0hlEgxuCzLrcMhjufl2qE2Q7fQIaav/1NqBVkCAwEAAQKCAgAeRZw75Oszoqj0jfMmMILdD3Cfad+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ovFb989J7yl++zTrnIrax9XRH1V0cNu+Kj7OMwZ2RRfbNv5JBdOZPvkfqyIKFmbQgYbtD66rHuzNOfJpzqr/WVLO57/zzW8245NKG2B6B0oXkei/KqDY0DAbHR3i3EOj1NPtVI1FC/xX8R9BREaid458bqoHJKuInrGcBjaUI9Cvymv8TbstUgD6NPbJR4Sm6vrLeUqzjWZP3t1+Z6DjXmnpR2vvhMU/FWb//21p/88o=</cleartext-private-key>\n"
+ " </local-definition>\n"
+ " </public-key>\n"
+ " </host-key>\n"
+ " </server-identity>\n"
+ " <client-authentication>\n"
+ " <users>\n"
+ " <user>\n"
+ " <name>old_user</name>\n"
+ " <password>$6$xyz$lomVe5tZ2Gz9uSKKywzXuPcHhqjIByhBbqdUTx/jAwUnw7JRp7QHd4ORiEVqxeZg1NEJkHux.mETo9BFPSh1x.</password>\n"
+ " </user>\n"
+ " </users>\n"
+ " </client-authentication>\n"
+ " </ssh-server-parameters>\n"
+ " </ssh>\n"
+ " </endpoint>\n"
+ " </listen>\n"
+ "</netconf-server>\n";
+
+const char *new_data =
+ "<netconf-server xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-server\">\n"
+ " <listen>\n"
+ " <idle-timeout>10</idle-timeout>\n"
+ " <endpoint>\n"
+ " <name>new-ssh</name>\n"
+ " <ssh>\n"
+ " <tcp-server-parameters>\n"
+ " <local-address>127.0.0.1</local-address>\n"
+ " <local-port>10005</local-port>\n"
+ " </tcp-server-parameters>\n"
+ " <ssh-server-parameters>\n"
+ " <server-identity>\n"
+ " <host-key>\n"
+ " <name>new_key</name>\n"
+ " <public-key>\n"
+ " <local-definition>\n"
+ " <public-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:ssh-public-key-format</public-key-format>\n"
+ " <public-key>AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDRIB2eNSRWU+HNWRUGKr76ghCLg8RaMlUCps9lBjnc6ggaJl2Q+TOLn8se2wAdK3lYBMz3dcqR+SlU7eB8wJAc=</public-key>\n"
+ " <private-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:ec-private-key-format</private-key-format>\n"
+ " <cleartext-private-key>MHcCAQEEICQ2fr9Jt2xluom0YQQ7HseE8YTo5reZRVcQENKUWOrooAoGCCqGSM49AwEHoUQDQgAENEgHZ41JFZT4c1ZFQYqvvqCEIuDxFoyVQKmz2UGOdzqCBomXZD5M4ufyx7bAB0reVgEzPd1ypH5KVTt4HzAkBw==</cleartext-private-key>\n"
+ " </local-definition>\n"
+ " </public-key>\n"
+ " </host-key>\n"
+ " </server-identity>\n"
+ " <client-authentication>\n"
+ " <users>\n"
+ " <user>\n"
+ " <name>new_user</name>\n"
+ " <public-keys>\n"
+ " <local-definition>\n"
+ " <public-key>\n"
+ " <name>test</name>\n"
+ " <public-key-format xmlns:ct=\"urn:ietf:params:xml:ns:yang:ietf-crypto-types\">ct:ssh-public-key-format</public-key-format>\n"
+ " <public-key>AAAAB3NzaC1yc2EAAAADAQABAAABAQDPavVALiM7QwTIUAndO8E9GOkSDQWjuEwkzbJ3kOBPa7kkq71UOZFeecDjFb9eipkljfFys/JYHGQaYVF8/svT0KV5h7HlutRdF6yvqSEbjpbTORb27pdHX3iFEyDCwCIoq9vMeX+wyXnteyn01GpIL0ig0WAnvkqX/SPjuplX5ZItUSr0MhXM7fNSX50BD6G8IO0/djUcdMUcjTjGv73SxB9ZzLvxnhXuUJbzEJJJLj6qajyEIVaJSa73vA33JCD8qzarrsuITojVLPDFmeHwSAoB5dP86yop6e6ypuXzKxxef6yNXcE8oTj8UFYBIXsgIP2nBvWk41EaK0Vk3YFl</public-key>\n"
+ " </public-key>\n"
+ " </local-definition>\n"
+ " </public-keys>\n"
+ " </user>\n"
+ " </users>\n"
+ " </client-authentication>\n"
+ " </ssh-server-parameters>\n"
+ " </ssh>\n"
+ " </endpoint>\n"
+ " </listen>\n"
+ "</netconf-server>\n";
+
+static void *
+server_thread(void *arg)
+{
+ int ret;
+ NC_MSG_TYPE msgtype;
+ struct nc_session *session;
+ struct nc_pollsession *ps;
+ struct test_state *state = arg;
+
+ ps = nc_ps_new();
+ assert_non_null(ps);
+
+ /* accept a session and add it to the poll session structure */
+ pthread_barrier_wait(&state->barrier);
+ msgtype = nc_accept(NC_ACCEPT_TIMEOUT, ctx, &session);
+ assert_int_equal(msgtype, NC_MSG_HELLO);
+
+ ret = nc_ps_add_session(ps, session);
+ assert_int_equal(ret, 0);
+
+ do {
+ ret = nc_ps_poll(ps, NC_PS_POLL_TIMEOUT, NULL);
+ assert_int_equal(ret & NC_PSPOLL_RPC, NC_PSPOLL_RPC);
+ } while (!(ret & NC_PSPOLL_SESSION_TERM));
+
+ nc_ps_clear(ps, 1, NULL);
+ nc_ps_free(ps);
+ nc_thread_destroy();
+ return NULL;
+}
+
+static void *
+client_thread(void *arg)
+{
+ int ret;
+ struct nc_session *session = NULL;
+ struct test_state *state = arg;
+
+ /* skip all hostkey and known_hosts checks */
+ nc_client_ssh_set_knownhosts_mode(NC_SSH_KNOWNHOSTS_SKIP);
+
+ /* set directory where to search for modules */
+ ret = nc_client_set_schema_searchpath(MODULES_DIR);
+ assert_int_equal(ret, 0);
+
+ /* set ssh username */
+ ret = nc_client_ssh_set_username("new_user");
+ assert_int_equal(ret, 0);
+
+ /* add client's key pair */
+ ret = nc_client_ssh_add_keypair(TESTS_DIR "/data/key_rsa.pub", TESTS_DIR "/data/key_rsa");
+ assert_int_equal(ret, 0);
+
+ /* wait for the server to reach polling */
+ pthread_barrier_wait(&state->barrier);
+
+ /* connect */
+ session = nc_connect_ssh("127.0.0.1", 10005, NULL);
+ assert_non_null(session);
+
+ nc_session_free(session, NULL);
+ nc_thread_destroy();
+ return NULL;
+}
+
+static void
+nc_test_replace(void **state)
+{
+ int ret, i;
+ pthread_t tids[2];
+
+ assert_non_null(state);
+
+ ret = pthread_create(&tids[0], NULL, client_thread, *state);
+ assert_int_equal(ret, 0);
+ ret = pthread_create(&tids[1], NULL, server_thread, *state);
+ assert_int_equal(ret, 0);
+
+ for (i = 0; i < 2; i++) {
+ pthread_join(tids[i], NULL);
+ }
+}
+
+static int
+setup_f(void **state)
+{
+ int ret;
+ struct lyd_node *old_tree = NULL, *new_tree = NULL;
+ struct test_state *test_state;
+
+ nc_verbosity(NC_VERB_VERBOSE);
+
+ /* init barrier */
+ test_state = malloc(sizeof *test_state);
+ assert_non_null(test_state);
+
+ ret = pthread_barrier_init(&test_state->barrier, NULL, 2);
+ assert_int_equal(ret, 0);
+
+ *state = test_state;
+
+ /* create new context */
+ ret = ly_ctx_new(MODULES_DIR, 0, &ctx);
+ assert_int_equal(ret, 0);
+
+ /* load default modules into context */
+ ret = nc_server_init_ctx(&ctx);
+ assert_int_equal(ret, 0);
+
+ /* load ietf-netconf-server module and it's imports into context */
+ ret = nc_server_config_load_modules(&ctx);
+ assert_int_equal(ret, 0);
+
+ /* parse yang data */
+ ret = lyd_parse_data_mem(ctx, old_data, LYD_XML, LYD_PARSE_NO_STATE | LYD_PARSE_STRICT, LYD_VALIDATE_NO_STATE, &old_tree);
+ assert_int_equal(ret, 0);
+
+ /* configure the server based on the yang data, treat them as if every node had replace operation */
+ ret = nc_server_config_setup_data(old_tree);
+ assert_int_equal(ret, 0);
+
+ /* parse the new yang data */
+ ret = lyd_parse_data_mem(ctx, new_data, LYD_XML, LYD_PARSE_NO_STATE | LYD_PARSE_STRICT, LYD_VALIDATE_NO_STATE, &new_tree);
+ assert_int_equal(ret, 0);
+
+ /* configure the server based on the yang data, meaning
+ * everything configured will be deleted and only the new data applied
+ */
+ ret = nc_server_config_setup_data(new_tree);
+ assert_int_equal(ret, 0);
+
+ /* initialize the client */
+ nc_client_init();
+
+ /* initialize the server */
+ ret = nc_server_init();
+ assert_int_equal(ret, 0);
+
+ lyd_free_all(old_tree);
+ lyd_free_all(new_tree);
+
+ return 0;
+}
+
+static int
+teardown_f(void **state)
+{
+ int ret = 0;
+ struct test_state *test_state;
+
+ assert_non_null(state);
+ test_state = *state;
+
+ ret = pthread_barrier_destroy(&test_state->barrier);
+ assert_int_equal(ret, 0);
+
+ free(*state);
+ nc_client_destroy();
+ nc_server_destroy();
+ ly_ctx_destroy(ctx);
+
+ return 0;
+}
+
+int
+main(void)
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(nc_test_replace, setup_f, teardown_f),
+ };
+
+ setenv("CMOCKA_TEST_ABORT", "1", 1);
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/tests/test_truststore.c b/tests/test_truststore.c
index aa5af9f..5b38658 100644
--- a/tests/test_truststore.c
+++ b/tests/test_truststore.c
@@ -222,7 +222,7 @@
assert_int_equal(ret, 0);
/* configure the server based on the data */
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
/* initialize client */
diff --git a/tests/test_two_channels.c b/tests/test_two_channels.c
index 85ee438..d56becc 100644
--- a/tests/test_two_channels.c
+++ b/tests/test_two_channels.c
@@ -234,7 +234,7 @@
ret = lyd_parse_data_mem(ctx, data, LYD_XML, LYD_PARSE_NO_STATE | LYD_PARSE_STRICT, LYD_VALIDATE_NO_STATE, &tree);
assert_int_equal(ret, 0);
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
ret = nc_server_init();
diff --git a/tests/test_unix_socket.c b/tests/test_unix_socket.c
index e106982..deed6f9 100644
--- a/tests/test_unix_socket.c
+++ b/tests/test_unix_socket.c
@@ -147,7 +147,7 @@
assert_int_equal(ret, 0);
/* configure the server based on the data */
- ret = nc_server_config_setup(tree);
+ ret = nc_server_config_setup_diff(tree);
assert_int_equal(ret, 0);
/* initialize client */