Skip to content

Commit

Permalink
config UPDATE add config replace test
Browse files Browse the repository at this point in the history
Added test for replacing configuration data. Renamed configuration setup
API calls. Added loading JSON from files.
  • Loading branch information
roman committed May 25, 2023
1 parent 61dc9d5 commit 4ca1620
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ init(struct ly_ctx **context, struct nc_pollsession **ps, const char *path, NC_T
}

/* 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");
}
Expand Down
8 changes: 4 additions & 4 deletions src/server_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2203,12 +2203,12 @@ nc_server_config_setup_path(const struct ly_ctx *ctx, const char *path)

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;
}
Expand Down Expand Up @@ -2240,7 +2240,7 @@ nc_server_config_fill_nectonf_server(const struct lyd_node *data, NC_OPERATION o
}

API int
nc_server_config_setup(const struct lyd_node *data)
nc_server_config_setup_diff(const struct lyd_node *data)
{
int ret = 0;

Expand Down Expand Up @@ -2275,7 +2275,7 @@ nc_server_config_setup(const struct lyd_node *data)
}

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;
Expand Down
12 changes: 6 additions & 6 deletions src/server_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@ extern "C" {
/**
* @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.
*
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ endif()

# 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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ setup_f(void **state)
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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ setup_f(void **state)
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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ setup_f(void **state)
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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ed25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ setup_f(void **state)
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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/test_keystore.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ setup_f(void **state)
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 */
Expand Down
Loading

0 comments on commit 4ca1620

Please sign in to comment.