* Fixed: Restconf failed put/post could leave residue in candidate causing errors in next put/post

* Added -v option for backend plugins to generate validation error
This commit is contained in:
Olof hagsand 2020-09-10 18:09:17 +02:00
parent a61bdffbab
commit 27bb0a1d2b
6 changed files with 79 additions and 31 deletions

View file

@ -42,6 +42,7 @@
* -u enable upgrade function - auto-upgrade testing
* -U general-purpose upgrade
* -t enable transaction logging (cal syslog for every transaction)
* -v <xpath> Failing validate and commit if <xpath> is present (synthetic error)
*/
#include <stdio.h>
#include <stdlib.h>
@ -65,7 +66,7 @@
#include <clixon/clixon_backend.h>
/* Command line options to be passed to getopt(3) */
#define BACKEND_EXAMPLE_OPTS "rsS:iuUt"
#define BACKEND_EXAMPLE_OPTS "rsS:iuUt:v:"
/*! Variable to control if reset code is run.
* The reset code inserts "extra XML" which assumes ietf-interfaces is
@ -111,6 +112,13 @@ static int _general_upgrade = 0;
*/
static int _transaction_log = 0;
/*! Variable to control transaction logging (for debug)
* If set, call syslog for every transaction callback
* Start backend with -- -v <xpath>
*/
static char *_validate_fail_xpath = NULL;
static int _validate_fail_toggle = 0; /* fail at validate and commit */
/* forward */
static int example_stream_timer_setup(clicon_handle h);
@ -130,6 +138,14 @@ main_validate(clicon_handle h,
{
if (_transaction_log)
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
if (_validate_fail_xpath){
if (_validate_fail_toggle==0 &&
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
_validate_fail_toggle = 1; /* toggle if triggered */
clicon_err(OE_XML, 0, "User error");
return -1; /* induce fail */
}
}
return 0;
}
@ -157,6 +173,15 @@ main_commit(clicon_handle h,
if (_transaction_log)
transaction_log(h, td, LOG_NOTICE, __FUNCTION__);
if (_validate_fail_xpath){
if (_validate_fail_toggle==1 &&
xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){
_validate_fail_toggle = 0; /* toggle if triggered */
clicon_err(OE_XML, 0, "User error");
return -1; /* induce fail */
}
}
/* Create namespace context for xpath */
if ((nsc = xml_nsctx_init(NULL, "urn:ietf:params:xml:ns:yang:ietf-interfaces")) == NULL)
goto done;
@ -1041,6 +1066,9 @@ clixon_plugin_init(clicon_handle h)
case 't': /* transaction log */
_transaction_log = 1;
break;
case 'v': /* validate fail */
_validate_fail_xpath = optarg;
break;
}
/* Example stream initialization: