* Clixon transaction mechanism has changed which may affect your backend plugin callbacks:
* Validate-only transactions are terminated by an `end` or `abort` callback. * If a commit user callback fails, a new `revert` callback will be made to plugins that have made a succesful commit.
This commit is contained in:
parent
99b7a1fe5b
commit
b103599a1a
9 changed files with 422 additions and 87 deletions
|
|
@ -53,6 +53,11 @@
|
||||||
|
|
||||||
### API changes on existing features (you may need to change your code)
|
### API changes on existing features (you may need to change your code)
|
||||||
|
|
||||||
|
* Clixon transaction mechanism has changed which may affect your backend plugin callbacks:
|
||||||
|
* Validate-only transactions are terminated by an `end` or `abort` callback. Now all started transactions are terminated either by an `end` or `abort` without exceptions
|
||||||
|
* Validate-only transactions used to be terminated by `complete`
|
||||||
|
* If a commit user callback fails, a new `revert` callback will be made to plugins that have made a succesful commit.
|
||||||
|
* Clixon used to play the (already made) commit callbacks in reverse order
|
||||||
* Clixon config option `CLICON_XMLDB_CACHE` renamed to `CLICON_DATASTORE_CACHE` and changed type from `boolean` to `datastore_cache`
|
* Clixon config option `CLICON_XMLDB_CACHE` renamed to `CLICON_DATASTORE_CACHE` and changed type from `boolean` to `datastore_cache`
|
||||||
* Change code from: `clicon_option_bool(h, "CLICON_XMLDB_CACHE")` to `clicon_datastore_cache(h) == DATASTORE_CACHE`
|
* Change code from: `clicon_option_bool(h, "CLICON_XMLDB_CACHE")` to `clicon_datastore_cache(h) == DATASTORE_CACHE`
|
||||||
* Type `datastore_cache` have values: nocache, cache, or cache-zerocopy
|
* Type `datastore_cache` have values: nocache, cache, or cache-zerocopy
|
||||||
|
|
|
||||||
|
|
@ -271,10 +271,15 @@ startup_validate(clicon_handle h,
|
||||||
/* Handcraft a transition with only target and add trees */
|
/* Handcraft a transition with only target and add trees */
|
||||||
if ((td = transaction_new()) == NULL)
|
if ((td = transaction_new()) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
if ((ret = startup_common(h, db, td, cbret)) < 0)
|
if ((ret = startup_common(h, db, td, cbret)) < 0){
|
||||||
|
plugin_transaction_abort(h, td);
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0)
|
}
|
||||||
|
if (ret == 0){
|
||||||
|
plugin_transaction_abort(h, td);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
plugin_transaction_end(h, td);
|
||||||
/* Clear cached trees from default values and marking */
|
/* Clear cached trees from default values and marking */
|
||||||
if (xmldb_get_clear(h, td->td_target) < 0)
|
if (xmldb_get_clear(h, td->td_target) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -348,10 +353,11 @@ startup_commit(clicon_handle h,
|
||||||
goto fail;
|
goto fail;
|
||||||
/* 10. Call plugin transaction end callbacks */
|
/* 10. Call plugin transaction end callbacks */
|
||||||
plugin_transaction_end(h, td);
|
plugin_transaction_end(h, td);
|
||||||
|
|
||||||
retval = 1;
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
if (td){
|
if (td){
|
||||||
|
if (retval < 1)
|
||||||
|
plugin_transaction_abort(h, td);
|
||||||
xmldb_get_free(h, &td->td_target);
|
xmldb_get_free(h, &td->td_target);
|
||||||
transaction_free(td);
|
transaction_free(td);
|
||||||
}
|
}
|
||||||
|
|
@ -548,9 +554,9 @@ candidate_commit(clicon_handle h,
|
||||||
retval = 1;
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
/* In case of failure (or error), call plugin transaction termination callbacks */
|
/* In case of failure (or error), call plugin transaction termination callbacks */
|
||||||
if (retval < 1 && td)
|
|
||||||
plugin_transaction_abort(h, td);
|
|
||||||
if (td){
|
if (td){
|
||||||
|
if (retval < 1)
|
||||||
|
plugin_transaction_abort(h, td);
|
||||||
xmldb_get_free(h, &td->td_target);
|
xmldb_get_free(h, &td->td_target);
|
||||||
xmldb_get_free(h, &td->td_src);
|
xmldb_get_free(h, &td->td_src);
|
||||||
transaction_free(td);
|
transaction_free(td);
|
||||||
|
|
@ -730,33 +736,37 @@ from_client_validate(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
/* Common steps (with commit) */
|
/* Common steps (with commit) */
|
||||||
if ((ret = from_validate_common(h, db, td, cbret)) < 1){
|
if ((ret = from_validate_common(h, db, td, cbret)) < 1){
|
||||||
clicon_debug(1, "Validate %s failed", db);
|
plugin_transaction_abort(h, td);
|
||||||
if (ret < 0){
|
|
||||||
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
|
if (netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
/* Clear cached trees from default values and marking */
|
/* Clear cached trees from default values and marking */
|
||||||
if (xmldb_get_clear(h, td->td_target) < 0)
|
if (xmldb_get_clear(h, td->td_target) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xmldb_get_clear(h, td->td_src) < 0)
|
if (xmldb_get_clear(h, td->td_src) < 0 ||
|
||||||
|
xmldb_get_clear(h, td->td_target) < 0){
|
||||||
|
plugin_transaction_abort(h, td);
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
/* Optionally write (potentially modified) tree back to candidate */
|
/* Optionally write (potentially modified) tree back to candidate */
|
||||||
if (clicon_option_bool(h, "CLICON_TRANSACTION_MOD")){
|
if (clicon_option_bool(h, "CLICON_TRANSACTION_MOD")){
|
||||||
|
plugin_transaction_abort(h, td);
|
||||||
if ((ret = xmldb_put(h, "candidate", OP_REPLACE, td->td_target,
|
if ((ret = xmldb_put(h, "candidate", OP_REPLACE, td->td_target,
|
||||||
clicon_username_get(h), cbret)) < 0)
|
clicon_username_get(h), cbret)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
cprintf(cbret, "<rpc-reply><ok/></rpc-reply>");
|
cprintf(cbret, "<rpc-reply><ok/></rpc-reply>");
|
||||||
|
/* Call plugin transaction end callbacks */
|
||||||
|
plugin_transaction_end(h, td);
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (retval < 0 && td)
|
|
||||||
plugin_transaction_abort(h, td);
|
|
||||||
if (td){
|
if (td){
|
||||||
|
if (retval < 0)
|
||||||
|
plugin_transaction_abort(h, td);
|
||||||
xmldb_get_free(h, &td->td_target);
|
xmldb_get_free(h, &td->td_target);
|
||||||
xmldb_get_free(h, &td->td_src);
|
xmldb_get_free(h, &td->td_src);
|
||||||
transaction_free(td);
|
transaction_free(td);
|
||||||
|
|
|
||||||
|
|
@ -295,28 +295,14 @@ plugin_transaction_revert(clicon_handle h,
|
||||||
int nr)
|
int nr)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
transaction_data_t tr; /* revert transaction */
|
|
||||||
clixon_plugin *cp = NULL;
|
clixon_plugin *cp = NULL;
|
||||||
trans_cb_t *fn;
|
trans_cb_t *fn;
|
||||||
|
|
||||||
/* Create a new reversed transaction from the original where src and target
|
|
||||||
are swapped */
|
|
||||||
memcpy(&tr, td, sizeof(tr));
|
|
||||||
tr.td_src = td->td_target;
|
|
||||||
tr.td_target = td->td_src;
|
|
||||||
tr.td_dlen = td->td_alen;
|
|
||||||
tr.td_dvec = td->td_avec;
|
|
||||||
tr.td_alen = td->td_dlen;
|
|
||||||
tr.td_avec = td->td_dvec;
|
|
||||||
tr.td_clen = td->td_clen;
|
|
||||||
tr.td_scvec = td->td_tcvec;
|
|
||||||
tr.td_tcvec = td->td_scvec;
|
|
||||||
|
|
||||||
while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) {
|
while ((cp = clixon_plugin_each_revert(h, cp, nr)) != NULL) {
|
||||||
if ((fn = cp->cp_api.ca_trans_commit) == NULL)
|
if ((fn = cp->cp_api.ca_trans_revert) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval = fn(h, (transaction_data)&tr)) < 0){
|
if ((retval = fn(h, (transaction_data)td)) < 0){
|
||||||
clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_commit revert callback failed",
|
clicon_log(LOG_NOTICE, "%s: Plugin '%s' trans_revert callback failed",
|
||||||
__FUNCTION__, cp->cp_name);
|
__FUNCTION__, cp->cp_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
40
doc/FAQ.md
40
doc/FAQ.md
|
|
@ -15,7 +15,8 @@
|
||||||
* [How do I use restconf?](#how-do-i-use-restconf)
|
* [How do I use restconf?](#how-do-i-use-restconf)
|
||||||
* [What about reference documentation?](#what-about-reference-documentation)
|
* [What about reference documentation?](#what-about-reference-documentation)
|
||||||
* [How is configuration data stored?](#how-is-configuration-data-stored)
|
* [How is configuration data stored?](#how-is-configuration-data-stored)
|
||||||
* [What is validate and commit?](#what-is-validate-and-commit)
|
* [What is validate and commit?](#what-is-validate-and-commi)t
|
||||||
|
* [Does Clixon support transactions?](#does-clixon-support-transactions)
|
||||||
* [What is a Clixon configuration file?](#what-is-a-clixon-configuration-file)
|
* [What is a Clixon configuration file?](#what-is-a-clixon-configuration-file)
|
||||||
* [How are Clixon configuration files found?](#how-are-clixon-configuration-files-found)
|
* [How are Clixon configuration files found?](#how-are-clixon-configuration-files-found)
|
||||||
* [Can I modify clixon options at runtime?](#can-i-modify-clixon-options-at-runtime)
|
* [Can I modify clixon options at runtime?](#can-i-modify-clixon-options-at-runtime)
|
||||||
|
|
@ -227,6 +228,42 @@ A clixon developer writes commit functions to incrementaly upgrade a
|
||||||
system state based on configuration changes. Writing commit callbacks
|
system state based on configuration changes. Writing commit callbacks
|
||||||
is the core functionality of a clixon system.
|
is the core functionality of a clixon system.
|
||||||
|
|
||||||
|
## Does Clixon support transactions?
|
||||||
|
|
||||||
|
Yes. The netconf validation and commit operation is implemented in
|
||||||
|
Clixon by a transaction mechanism, which ensures that user-written
|
||||||
|
plugin callbacks are invoked atomically and revert on error. If you
|
||||||
|
have two plugins, for example, a transaction sequence looks like the
|
||||||
|
following:
|
||||||
|
```
|
||||||
|
Backend Plugin1 Plugin2
|
||||||
|
| | |
|
||||||
|
+--------->+--------->+ begin
|
||||||
|
| | |
|
||||||
|
+--------->+--------->+ validate
|
||||||
|
| | |
|
||||||
|
+--------->+--------->+ commit
|
||||||
|
| | |
|
||||||
|
+--------->+--------->+ end
|
||||||
|
```
|
||||||
|
|
||||||
|
If an error occurs in the commit call of Plugin2, for example,
|
||||||
|
the transaction is aborted and the commit reverted:
|
||||||
|
```
|
||||||
|
Backend Plugin1 Plugin2
|
||||||
|
| | |
|
||||||
|
+--------->+--------->+ begin
|
||||||
|
| | |
|
||||||
|
+--------->+--------->+ validate
|
||||||
|
| | |
|
||||||
|
+--------->+---->X + commit error
|
||||||
|
| | |
|
||||||
|
+--------->+ + revert
|
||||||
|
| | |
|
||||||
|
+--------->+--------->+ abort
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## What is a Clixon configuration file?
|
## What is a Clixon configuration file?
|
||||||
|
|
||||||
Clixon options are stored in an XML configuration file. The default
|
Clixon options are stored in an XML configuration file. The default
|
||||||
|
|
@ -430,7 +467,6 @@ Each plugin is initiated with an API struct followed by a plugin init function a
|
||||||
```
|
```
|
||||||
For more info see [../example/main/README.md]
|
For more info see [../example/main/README.md]
|
||||||
|
|
||||||
|
|
||||||
## How do I write a commit function?
|
## How do I write a commit function?
|
||||||
In the example, you write a commit function in example_backend.c.
|
In the example, you write a commit function in example_backend.c.
|
||||||
Every time a commit is made, transaction_commit() is called in the
|
Every time a commit is made, transaction_commit() is called in the
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
## Content
|
## Content
|
||||||
|
|
||||||
This directory contains a Clixon example which includes a simple example. It contains the following files:
|
This directory contains a Clixon example used primarily for testing. It can be used as a basis for making new Clixon applications. But please consider also the minimal [hello](../hello) example as well. It contains the following files:
|
||||||
* `example.xml` The configuration file. See [yang/clixon-config@<date>.yang](../../yang/clixon-config@2019-03-05.yang) for the documentation of all available fields.
|
* `example.xml` The configuration file. See [yang/clixon-config@<date>.yang](../../yang/clixon-config@2019-03-05.yang) for the documentation of all available fields.
|
||||||
* `clixon-example@2019-01-13.yang` The yang spec of the example.
|
* `clixon-example@2019-01-13.yang` The yang spec of the example.
|
||||||
* `example_cli.cli` CLIgen specification.
|
* `example_cli.cli` CLIgen specification.
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,7 @@ main_begin(clicon_handle h,
|
||||||
transaction_data td)
|
transaction_data td)
|
||||||
{
|
{
|
||||||
if (_transaction_log)
|
if (_transaction_log)
|
||||||
transaction_log(h, td, LOG_NOTICE, "begin");
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*! This is called on validate (and commit). Check validity of candidate
|
/*! This is called on validate (and commit). Check validity of candidate
|
||||||
|
|
@ -96,7 +95,7 @@ main_validate(clicon_handle h,
|
||||||
transaction_data td)
|
transaction_data td)
|
||||||
{
|
{
|
||||||
if (_transaction_log)
|
if (_transaction_log)
|
||||||
transaction_log(h, td, LOG_NOTICE, "validate");
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,7 +104,7 @@ main_complete(clicon_handle h,
|
||||||
transaction_data td)
|
transaction_data td)
|
||||||
{
|
{
|
||||||
if (_transaction_log)
|
if (_transaction_log)
|
||||||
transaction_log(h, td, LOG_NOTICE, "complete");
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +120,8 @@ main_commit(clicon_handle h,
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (_transaction_log)
|
if (_transaction_log)
|
||||||
transaction_log(h, td, LOG_NOTICE, "commit");
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
|
||||||
/* Get all added i/fs */
|
/* Get all added i/fs */
|
||||||
if (xpath_vec_flag(target, "//interface", XML_FLAG_ADD, &vec, &len) < 0)
|
if (xpath_vec_flag(target, "//interface", XML_FLAG_ADD, &vec, &len) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -134,12 +134,21 @@ main_commit(clicon_handle h,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main_revert(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
if (_transaction_log)
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main_end(clicon_handle h,
|
main_end(clicon_handle h,
|
||||||
transaction_data td)
|
transaction_data td)
|
||||||
{
|
{
|
||||||
if (_transaction_log)
|
if (_transaction_log)
|
||||||
transaction_log(h, td, LOG_NOTICE, "end");
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,7 +157,7 @@ main_abort(clicon_handle h,
|
||||||
transaction_data td)
|
transaction_data td)
|
||||||
{
|
{
|
||||||
if (_transaction_log)
|
if (_transaction_log)
|
||||||
transaction_log(h, td, LOG_NOTICE, "abort");
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -568,6 +577,7 @@ static clixon_plugin_api api = {
|
||||||
.ca_trans_validate=main_validate, /* trans validate */
|
.ca_trans_validate=main_validate, /* trans validate */
|
||||||
.ca_trans_complete=main_complete, /* trans complete */
|
.ca_trans_complete=main_complete, /* trans complete */
|
||||||
.ca_trans_commit=main_commit, /* trans commit */
|
.ca_trans_commit=main_commit, /* trans commit */
|
||||||
|
.ca_trans_revert=main_revert, /* trans revert */
|
||||||
.ca_trans_end=main_end, /* trans end */
|
.ca_trans_end=main_end, /* trans end */
|
||||||
.ca_trans_abort=main_abort /* trans abort */
|
.ca_trans_abort=main_abort /* trans abort */
|
||||||
};
|
};
|
||||||
|
|
@ -594,7 +604,7 @@ clixon_plugin_init(clicon_handle h)
|
||||||
goto done;
|
goto done;
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
optind = 1;
|
optind = 1;
|
||||||
while ((c = getopt(argc, argv, "rsut")) != -1)
|
while ((c = getopt(argc, argv, "rsut:")) != -1)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'r':
|
case 'r':
|
||||||
_reset = 1;
|
_reset = 1;
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,16 @@
|
||||||
***** END LICENSE BLOCK *****
|
***** END LICENSE BLOCK *****
|
||||||
|
|
||||||
*
|
*
|
||||||
* IETF yang routing example
|
* Secondary backend for testing more than one backend plugin, with the following
|
||||||
* Secondary backend for testing more than one backend plugin
|
* features:
|
||||||
|
* - nacm
|
||||||
|
* - transaction test
|
||||||
|
* The transaction test is test/test_transaction.sh where a user-error is triggered
|
||||||
|
* by this plugin if started with -- -t <xpath>. _transaction_xpath is then set
|
||||||
|
* and triggers a validation error if it matches. The error also toggles between
|
||||||
|
* validation and commit errors.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -55,6 +60,97 @@
|
||||||
/* These include signatures for plugin and transaction callbacks. */
|
/* These include signatures for plugin and transaction callbacks. */
|
||||||
#include <clixon/clixon_backend.h>
|
#include <clixon/clixon_backend.h>
|
||||||
|
|
||||||
|
/*! Variable to control transaction logging (for debug)
|
||||||
|
* If set, call syslog for every transaction callback
|
||||||
|
*/
|
||||||
|
static int _transaction_log = 0;
|
||||||
|
|
||||||
|
/*! Variable for failing validate and commit, if set, fail on validate vs commit
|
||||||
|
*/
|
||||||
|
static char * _transaction_xpath = NULL;
|
||||||
|
static int _transaction_error_toggle = 0; /* fail at validate vs commit */
|
||||||
|
|
||||||
|
int
|
||||||
|
nacm_begin(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
if (_transaction_log)
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*! This is called on validate (and commit). Check validity of candidate
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
nacm_validate(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
if (_transaction_log){
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
if (_transaction_error_toggle==0 &&
|
||||||
|
xpath_first(transaction_target(td), "%s", _transaction_xpath)){
|
||||||
|
_transaction_error_toggle=1; /* toggle if triggered */
|
||||||
|
clicon_err(OE_XML, 0, "User error");
|
||||||
|
return -1; /* induce fail */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
nacm_complete(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
if (_transaction_log)
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! This is called on commit. Identify modifications and adjust machine state
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
nacm_commit(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
cxobj *target = transaction_target(td); /* wanted XML tree */
|
||||||
|
|
||||||
|
if (_transaction_log){
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
if (_transaction_error_toggle==1 &&
|
||||||
|
xpath_first(target, "%s", _transaction_xpath)){
|
||||||
|
_transaction_error_toggle=0; /* toggle if triggered */
|
||||||
|
clicon_err(OE_XML, 0, "User error");
|
||||||
|
return -1; /* induce fail */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
nacm_revert(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
if (_transaction_log)
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
nacm_end(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
if (_transaction_log)
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
nacm_abort(clicon_handle h,
|
||||||
|
transaction_data td)
|
||||||
|
{
|
||||||
|
if (_transaction_log)
|
||||||
|
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Called to get NACM state data
|
/*! Called to get NACM state data
|
||||||
* @param[in] h Clicon handle
|
* @param[in] h Clicon handle
|
||||||
|
|
@ -88,21 +184,21 @@ nacm_statedata(clicon_handle h,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
plugin_start(clicon_handle h)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
|
||||||
|
|
||||||
static clixon_plugin_api api = {
|
static clixon_plugin_api api = {
|
||||||
"nacm", /* name */ /*--- Common fields. ---*/
|
"nacm", /* name */ /*--- Common fields. ---*/
|
||||||
clixon_plugin_init, /* init */
|
clixon_plugin_init, /* init */
|
||||||
plugin_start, /* start */
|
NULL, /* start */
|
||||||
NULL, /* exit */
|
NULL, /* exit */
|
||||||
.ca_reset=NULL, /* reset */
|
|
||||||
.ca_statedata=nacm_statedata, /* statedata */
|
.ca_statedata=nacm_statedata, /* statedata */
|
||||||
|
.ca_trans_begin=nacm_begin, /* trans begin */
|
||||||
|
.ca_trans_validate=nacm_validate, /* trans validate */
|
||||||
|
.ca_trans_complete=nacm_complete, /* trans complete */
|
||||||
|
.ca_trans_commit=nacm_commit, /* trans commit */
|
||||||
|
.ca_trans_revert=nacm_revert, /* trans revert */
|
||||||
|
.ca_trans_end=nacm_end, /* trans end */
|
||||||
|
.ca_trans_abort=nacm_abort /* trans abort */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! Backend plugin initialization
|
/*! Backend plugin initialization
|
||||||
|
|
@ -114,12 +210,33 @@ clixon_plugin_api *
|
||||||
clixon_plugin_init(clicon_handle h)
|
clixon_plugin_init(clicon_handle h)
|
||||||
{
|
{
|
||||||
char *nacm_mode;
|
char *nacm_mode;
|
||||||
|
int argc; /* command-line options (after --) */
|
||||||
|
char **argv;
|
||||||
|
int c;
|
||||||
|
|
||||||
clicon_debug(1, "%s backend nacm", __FUNCTION__);
|
clicon_debug(1, "%s backend nacm", __FUNCTION__);
|
||||||
|
/* Get user command-line options (after --) */
|
||||||
|
if (clicon_argv_get(h, &argc, &argv) < 0)
|
||||||
|
goto done;
|
||||||
|
opterr = 0;
|
||||||
|
optind = 1;
|
||||||
|
while ((c = getopt(argc, argv, "rsut:")) != -1)
|
||||||
|
switch (c) {
|
||||||
|
case 't': /* transaction log */
|
||||||
|
_transaction_log = 1;
|
||||||
|
_transaction_xpath = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
|
nacm_mode = clicon_option_str(h, "CLICON_NACM_MODE");
|
||||||
if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){
|
if (nacm_mode==NULL || strcmp(nacm_mode, "disabled") == 0){
|
||||||
clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__);
|
clicon_log(LOG_DEBUG, "%s CLICON_NACM_MODE not enabled: example nacm module disabled", __FUNCTION__);
|
||||||
|
/* Skip nacm module if not enabled _unless_ we use transaction tests */
|
||||||
|
if (_transaction_log == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* Return plugin API */
|
||||||
return &api;
|
return &api;
|
||||||
|
done:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,7 @@ struct clixon_plugin_api{
|
||||||
trans_cb_t *cb_trans_validate; /* Transaction validation */
|
trans_cb_t *cb_trans_validate; /* Transaction validation */
|
||||||
trans_cb_t *cb_trans_complete; /* Transaction validation complete */
|
trans_cb_t *cb_trans_complete; /* Transaction validation complete */
|
||||||
trans_cb_t *cb_trans_commit; /* Transaction commit */
|
trans_cb_t *cb_trans_commit; /* Transaction commit */
|
||||||
|
trans_cb_t *cb_trans_revert; /* Transaction revert */
|
||||||
trans_cb_t *cb_trans_end; /* Transaction completed */
|
trans_cb_t *cb_trans_end; /* Transaction completed */
|
||||||
trans_cb_t *cb_trans_abort; /* Transaction aborted */
|
trans_cb_t *cb_trans_abort; /* Transaction aborted */
|
||||||
|
|
||||||
|
|
@ -195,6 +196,7 @@ struct clixon_plugin_api{
|
||||||
#define ca_trans_validate u.cau_backend.cb_trans_validate
|
#define ca_trans_validate u.cau_backend.cb_trans_validate
|
||||||
#define ca_trans_complete u.cau_backend.cb_trans_complete
|
#define ca_trans_complete u.cau_backend.cb_trans_complete
|
||||||
#define ca_trans_commit u.cau_backend.cb_trans_commit
|
#define ca_trans_commit u.cau_backend.cb_trans_commit
|
||||||
|
#define ca_trans_revert u.cau_backend.cb_trans_revert
|
||||||
#define ca_trans_end u.cau_backend.cb_trans_end
|
#define ca_trans_end u.cau_backend.cb_trans_end
|
||||||
#define ca_trans_abort u.cau_backend.cb_trans_abort
|
#define ca_trans_abort u.cau_backend.cb_trans_abort
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Transaction functionality
|
# Transaction functionality
|
||||||
# The test uses a backend that logs to a file and a netconf client to push
|
# The test uses two backend plugins (main and nacm) that logs to a file and a
|
||||||
# changes. The main example backend plugin logs to the file, and the test
|
# netconf client to push operation. The tests then look at the log.
|
||||||
# verifies the logs.
|
# The tests are as follows (first five only callbacks per se; then data vector tests)
|
||||||
# The yang is a list with three members, so that you can do add/delete/change
|
# 1. Validate-only transaction
|
||||||
# in a single go.
|
# 2. Commit transaction
|
||||||
|
# 3. Validate system-error (invalid type detected by system)
|
||||||
|
# 4. Validate user-error (invalidation by user callback)
|
||||||
|
# 5. Commit user-error (invalidation by user callback)
|
||||||
|
# -- to here only basic callback tests (that they occur). Below transaction data
|
||||||
|
# 6. Detailed transaction vector add/del/change tests
|
||||||
|
# For the last test, the yang is a list with three members, so that you can do
|
||||||
|
# add/delete/change in a single go.
|
||||||
|
# The user-error uses a trick feature in the example nacm plugin which is started
|
||||||
|
# with an "error-trigger" xpath which triggers an error. This also toggles between
|
||||||
|
# validation and commit errors
|
||||||
|
|
||||||
# Magic line must be first in script (see README.md)
|
# Magic line must be first in script (see README.md)
|
||||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||||
|
|
@ -19,6 +29,9 @@ fyang=$dir/trans.yang
|
||||||
flog=$dir/backend.log
|
flog=$dir/backend.log
|
||||||
touch $flog
|
touch $flog
|
||||||
|
|
||||||
|
# Used as a trigger for user-validittion errors, eg <a>$errnr</a> is invalid
|
||||||
|
errnr=42
|
||||||
|
|
||||||
cat <<EOF > $fyang
|
cat <<EOF > $fyang
|
||||||
module trans{
|
module trans{
|
||||||
yang-version 1.1;
|
yang-version 1.1;
|
||||||
|
|
@ -31,8 +44,10 @@ module trans{
|
||||||
type int32;
|
type int32;
|
||||||
}
|
}
|
||||||
leaf b {
|
leaf b {
|
||||||
description "change this";
|
description "change this (also use to check invalid)";
|
||||||
type int32;
|
type int32{
|
||||||
|
range "0..100";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
leaf c {
|
leaf c {
|
||||||
description "del this";
|
description "del this";
|
||||||
|
|
@ -54,7 +69,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||||
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
|
<!--CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP-->
|
||||||
<CLICON_NETCONF_DIR>/usr/local/lib/$APPNAME/netconf</CLICON_NETCONF_DIR>
|
<CLICON_NETCONF_DIR>/usr/local/lib/$APPNAME/netconf</CLICON_NETCONF_DIR>
|
||||||
<CLICON_RESTCONF_DIR>/usr/local/lib/$APPNAME/restconf</CLICON_RESTCONF_DIR>
|
<CLICON_RESTCONF_DIR>/usr/local/lib/$APPNAME/restconf</CLICON_RESTCONF_DIR>
|
||||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||||
|
|
@ -70,8 +85,9 @@ EOF
|
||||||
# Check statements in log
|
# Check statements in log
|
||||||
checklog(){
|
checklog(){
|
||||||
s=$1 # statement
|
s=$1 # statement
|
||||||
|
l0=$2 # linenr
|
||||||
new "Check $s in log"
|
new "Check $s in log"
|
||||||
t=$(grep "$s" $flog)
|
t=$(grep -n "transaction_log $s" $flog)
|
||||||
if [ -z "$t" ]; then
|
if [ -z "$t" ]; then
|
||||||
echo -e "\e[31m\nError in Test$testnr [$testname]:"
|
echo -e "\e[31m\nError in Test$testnr [$testname]:"
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
|
|
@ -81,9 +97,19 @@ checklog(){
|
||||||
echo -e "\e[0m"
|
echo -e "\e[0m"
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
l1=$(echo "$t" | awk -F ":" '{print $1}')
|
||||||
|
if [ $l1 -ne $l0 ]; then
|
||||||
|
echo -e "\e[31m\nError in Test$testnr [$testname]:"
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
echo "Expected match on line $l0, found on $l1"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
echo -e "\e[0m"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
new "test params: -f $cfg -l f$flog -- -t"
|
new "test params: -f $cfg -l f$flog -- -t /x/y[a=$errnr]" # Fail on this
|
||||||
# Bring your own backend
|
# Bring your own backend
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
# kill old backend (if any)
|
# kill old backend (if any)
|
||||||
|
|
@ -92,47 +118,190 @@ if [ $BE -ne 0 ]; then
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
err
|
err
|
||||||
fi
|
fi
|
||||||
new "start backend -s init -f $cfg -l f$flog -- -t"
|
new "start backend -s init -f $cfg -l f$flog -- -t /x/y[a=$errnr]"
|
||||||
start_backend -s init -f $cfg -l f$flog -- -t # -t means transaction logging
|
start_backend -s init -f $cfg -l f$flog -- -t /x/y[a=$errnr] # -t means transaction logging
|
||||||
new "waiting"
|
new "waiting"
|
||||||
sleep $RCWAIT
|
sleep $RCWAIT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "netconf base config (0) a,b,c"
|
let nr=1
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><y><a>0</a><b>0</b><c>0</c></y></x></config></edit-config></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
|
||||||
|
new "Basic transaction to add top-level x"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$nr</a></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Commit base"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
let line=12 # Skipping basic transaction
|
||||||
|
|
||||||
|
# 1. validate(-only) transaction
|
||||||
|
let nr++
|
||||||
|
let line
|
||||||
|
new "1. Validate-only transaction"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$nr</a></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Validate-only validate"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
xml="<y><a>$nr</a></y>"
|
||||||
|
for op in begin validate complete end; do
|
||||||
|
checklog "$nr main_$op add: $xml" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: $xml" $line
|
||||||
|
let line++
|
||||||
|
done
|
||||||
|
|
||||||
|
new "Validate-only discard-changes"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
# 2. Commit transaction
|
||||||
|
let nr++
|
||||||
|
new "2. Commit transaction config"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$nr</a></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Commit transaction: commit"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
xml="<y><a>$nr</a></y>"
|
||||||
|
for op in begin validate complete commit end; do
|
||||||
|
checklog "$nr main_$op add: $xml" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: $xml" $line
|
||||||
|
let line++
|
||||||
|
done
|
||||||
|
|
||||||
|
# 3. Validate only system-error (invalid type detected by system)
|
||||||
|
let nr++
|
||||||
|
new "3. Validate system-error config (9999 not in range)"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$nr</a><b>9999</b></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Validate system-error validate (should fail)"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>' '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>b</bad-element></error-info><error-severity>error</error-severity><error-message>Number out of range: 9999</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Validate system-error discard-changes"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
for op in begin abort; do
|
||||||
|
checklog "$nr main_$op add: <y><a>$nr</a><b>9999</b></y>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: <y><a>$nr</a><b>9999</b></y>" $line
|
||||||
|
let line++
|
||||||
|
done
|
||||||
|
|
||||||
|
# 4. Validate only user-error (invalidation by user callback)
|
||||||
|
let nr++
|
||||||
|
new "4. Validate user-error config ($errnr is invalid)"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$errnr</a></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Validate user-error validate (should fail)"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>' '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-severity>error</error-severity><error-message>User error</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Validate user-error discard-changes"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
for op in begin validate; do
|
||||||
|
checklog "$nr main_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
done
|
||||||
|
let line++ # error message
|
||||||
|
for op in abort; do
|
||||||
|
checklog "$nr main_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
done
|
||||||
|
|
||||||
|
# 5. Commit user-error (invalidation by user callback)
|
||||||
|
# XXX Note Validate-only user-error must immediately preceede this due to toggling
|
||||||
|
# in nacm/transaction example test module
|
||||||
|
let nr++
|
||||||
|
new "5. Commit user-error ($errnr is invalid)"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$errnr</a></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Commit user-error commit"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-severity>error</error-severity><error-message>User error</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "Commit user-error discard-changes"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
for op in begin validate complete commit; do
|
||||||
|
checklog "$nr main_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
done
|
||||||
|
let line++ # error message
|
||||||
|
checklog "$nr main_revert add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
for op in abort; do
|
||||||
|
checklog "$nr main_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: <y><a>$errnr</a></y>" $line
|
||||||
|
let line++
|
||||||
|
done
|
||||||
|
|
||||||
|
# 6. Detailed transaction vector add/del/change tests
|
||||||
|
let nr++
|
||||||
|
let base=nr
|
||||||
|
new "Add base <a>$base entry"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$base</a><b>0</b><c>0</c></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
new "netconf commit base"
|
new "netconf commit base"
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
#Ignore
|
#Ignore
|
||||||
|
let line+=10
|
||||||
|
|
||||||
new "netconf mixed change: change b, del c, add d"
|
let nr++
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><y><a>0</a><b>42</b><d>0</d></y></x></config></edit-config></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
new "6. netconf mixed change: change b, del c, add d"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$base</a><b>42</b><d>0</d></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
new "netconf commit change"
|
new "netconf commit change"
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
# Check complete transaction 2:
|
# Check complete transaction $nr:
|
||||||
for op in begin validate complete commit; do
|
for op in begin validate complete commit; do
|
||||||
checklog "transaction_log 2 $op add: <d>0</d>"
|
checklog "$nr main_$op add: <d>0</d>" $line
|
||||||
checklog "transaction_log 2 $op change: <b>0</b><b>42</b>"
|
let line++
|
||||||
|
checklog "$nr main_$op change: <b>0</b><b>42</b>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op add: <d>0</d>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr nacm_$op change: <b>0</b><b>42</b>" $line
|
||||||
|
let line++
|
||||||
done
|
done
|
||||||
# End is special
|
|
||||||
checklog "transaction_log 2 end add: <d>0</d>"
|
|
||||||
checklog "transaction_log 2 end change: <b>42</b>"
|
|
||||||
|
|
||||||
new "netconf config (1) end-points a,d "
|
# End is special because change does not haveold element
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><y><a>1</a><d>1</d></y></x></config></edit-config></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
checklog "$nr main_end add: <d>0</d>" $line
|
||||||
|
let line++
|
||||||
|
checklog "$nr main_end change: <b>42</b>" $line
|
||||||
|
let line+=3 # skip nacm
|
||||||
|
|
||||||
|
let nr++
|
||||||
|
let base=nr
|
||||||
|
new "Add base <a>$base entry"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$base</a><d>1</d></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
|
new "netconf commit base"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
let line+=10
|
||||||
|
|
||||||
|
# Variant check that only b,c
|
||||||
|
let nr++
|
||||||
|
new "7. netconf insert b,c between end-points"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config><x xmlns='urn:example:clixon'><y><a>$base</a><b>1</b><c>1</c></y></x></config></edit-config></rpc>]]>]]>" '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
new "netconf commit base"
|
new "netconf commit base"
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
new "netconf insert b,c between end-points"
|
# check complete
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><y><a>1</a><b>1</b><c>1</c></y></x></config></edit-config></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
for op in begin validate complete commit end; do
|
||||||
|
checklog "$nr main_$op add: <b>1</b><c>1</c>" $line
|
||||||
new "netconf commit base"
|
let line++
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><commit/></rpc>]]>]]>' '^<rpc-reply><ok/></rpc-reply>]]>]]>$'
|
checklog "$nr nacm_$op add: <b>1</b><c>1</c>" $line
|
||||||
|
let line++
|
||||||
checklog "transaction_log 4 validate add: <b>1</b><c>1</c>"
|
done
|
||||||
|
|
||||||
if [ $BE -eq 0 ]; then
|
if [ $BE -eq 0 ]; then
|
||||||
exit # BE
|
exit # BE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue