* startup_extraxml triggers unnecessary validation
* Renamed startup_db_reset -> xmldb_db_reset (its a general function) * In startup_extraxml(), check if reset callbacks or extraxml file actually makes and changes to the tmp db.
This commit is contained in:
parent
daa01b3a5e
commit
3bad8bc874
8 changed files with 48 additions and 28 deletions
|
|
@ -191,6 +191,9 @@
|
|||
|
||||
### Minor changes
|
||||
|
||||
* `startup_extraxml` triggers unnecessary validation
|
||||
* Renamed startup_db_reset -> xmldb_db_reset (its a general function)
|
||||
* In startup_extraxml(), check if reset callbacks or extraxml file actually makes and changes to the tmp db.
|
||||
* Print CLICON_YANG_DIR and CLICON_FEATURE lists on startup with debug flag
|
||||
* Extended `util/clixon_util_xml` with yang and validate functionality so it can be used as a stand-alone utility for validating XML/JSON files
|
||||
* JSON parse and print improvements
|
||||
|
|
|
|||
|
|
@ -642,7 +642,7 @@ main(int argc,
|
|||
switch (startup_mode){
|
||||
case SM_INIT: /* Scratch running and start from empty */
|
||||
/* [Delete and] create running db */
|
||||
if (startup_db_reset(h, "running") < 0)
|
||||
if (xmldb_db_reset(h, "running") < 0)
|
||||
goto done;
|
||||
case SM_NONE: /* Fall through *
|
||||
* Load plugins and call plugin_init() */
|
||||
|
|
|
|||
|
|
@ -70,22 +70,6 @@
|
|||
#include "backend_commit.h"
|
||||
#include "backend_startup.h"
|
||||
|
||||
/*! Create an XML database. If it exists already, delete it before creating
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] db Symbolic database name, eg "candidate", "running"
|
||||
*/
|
||||
int
|
||||
startup_db_reset(clicon_handle h,
|
||||
char *db)
|
||||
{
|
||||
if (xmldb_exists(h, db) == 1){
|
||||
if (xmldb_delete(h, db) != 0 && errno != ENOENT)
|
||||
return -1;
|
||||
}
|
||||
if (xmldb_create(h, db) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Merge db1 into db2 without commit
|
||||
* @retval -1 Error
|
||||
|
|
@ -235,34 +219,45 @@ startup_extraxml(clicon_handle h,
|
|||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
char *db = "tmp";
|
||||
char *tmp_db = "tmp";
|
||||
int ret;
|
||||
cxobj *xt = NULL; /* Potentially upgraded XML */
|
||||
|
||||
/* Clear tmp db */
|
||||
if (startup_db_reset(h, db) < 0)
|
||||
if (xmldb_db_reset(h, tmp_db) < 0)
|
||||
goto done;
|
||||
/* Application may define extra xml in its reset function*/
|
||||
if (clixon_plugin_reset(h, db) < 0)
|
||||
if (clixon_plugin_reset(h, tmp_db) < 0)
|
||||
goto done;
|
||||
/* Extra XML can also be added via file */
|
||||
if (file){
|
||||
/* Parse and load file into tmp db */
|
||||
if ((ret = load_extraxml(h, file, db, cbret)) < 0)
|
||||
if ((ret = load_extraxml(h, file, tmp_db, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
}
|
||||
/*
|
||||
* Check if tmp db is empty.
|
||||
* It should be empty if extra-xml is null and reset plugins did nothing
|
||||
* then skip validation.
|
||||
*/
|
||||
if (xmldb_get(h, tmp_db, NULL, &xt) < 0)
|
||||
goto done;
|
||||
if (xt==NULL || xml_child_nr(xt)==0)
|
||||
goto ok;
|
||||
xml_free(xt);
|
||||
xt = NULL;
|
||||
/* Validate the tmp db and return possibly upgraded xml in xt
|
||||
*/
|
||||
if ((ret = startup_validate(h, db, &xt, cbret)) < 0)
|
||||
if ((ret = startup_validate(h, tmp_db, &xt, cbret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
if (xt==NULL || xml_child_nr(xt)==0)
|
||||
goto ok;
|
||||
/* Merge tmp into running (no commit) */
|
||||
if ((ret = db_merge(h, db, "running", cbret)) < 0)
|
||||
if ((ret = db_merge(h, tmp_db, "running", cbret)) < 0)
|
||||
goto fail;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
|
|
@ -270,7 +265,7 @@ startup_extraxml(clicon_handle h,
|
|||
retval = 1;
|
||||
done:
|
||||
xmldb_get0_free(h, &xt);
|
||||
if (xmldb_delete(h, db) != 0 && errno != ENOENT)
|
||||
if (xmldb_delete(h, tmp_db) != 0 && errno != ENOENT)
|
||||
return -1;
|
||||
return retval;
|
||||
fail:
|
||||
|
|
@ -306,7 +301,7 @@ startup_failsafe(clicon_handle h)
|
|||
/* Copy original running to tmp as backup (restore if error) */
|
||||
if (xmldb_copy(h, "running", "tmp") < 0)
|
||||
goto done;
|
||||
if (startup_db_reset(h, "running") < 0)
|
||||
if (xmldb_db_reset(h, "running") < 0)
|
||||
goto done;
|
||||
ret = candidate_commit(h, db, cbret);
|
||||
if (ret != 1)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int startup_db_reset(clicon_handle h, char *db);
|
||||
int startup_mode_startup(clicon_handle h, char *db, cbuf *cbret);
|
||||
int startup_extraxml(clicon_handle h, char *file, cbuf *cbret);
|
||||
int startup_failsafe(clicon_handle h);
|
||||
|
|
|
|||
|
|
@ -62,5 +62,7 @@ int xmldb_islocked(clicon_handle h, const char *db);
|
|||
int xmldb_exists(clicon_handle h, const char *db);
|
||||
int xmldb_delete(clicon_handle h, const char *db);
|
||||
int xmldb_create(clicon_handle h, const char *db);
|
||||
/* utility functions */
|
||||
int xmldb_db_reset(clicon_handle h, char *db);
|
||||
|
||||
#endif /* _CLIXON_DATASTORE_H */
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@
|
|||
#include "clixon_datastore_write.h"
|
||||
#include "clixon_datastore_read.h"
|
||||
|
||||
|
||||
/*! Translate from symbolic database name to actual filename in file-system
|
||||
* @param[in] th text handle handle
|
||||
* @param[in] db Symbolic database name, eg "candidate", "running"
|
||||
|
|
@ -446,3 +447,21 @@ xmldb_create(clicon_handle h,
|
|||
close(fd);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Create an XML database. If it exists already, delete it before creating
|
||||
* Utility function.
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] db Symbolic database name, eg "candidate", "running"
|
||||
*/
|
||||
int
|
||||
xmldb_db_reset(clicon_handle h,
|
||||
char *db)
|
||||
{
|
||||
if (xmldb_exists(h, db) == 1){
|
||||
if (xmldb_delete(h, db) != 0 && errno != ENOENT)
|
||||
return -1;
|
||||
}
|
||||
if (xmldb_create(h, db) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -641,7 +641,8 @@ xmldb_get_zerocopy(clicon_handle h,
|
|||
* @param[in] db Name of database to search in (filename including dir path
|
||||
* @param[in] xpath String with XPATH syntax. or NULL for all
|
||||
* @param[out] xret Single return XML tree. Free with xml_free()
|
||||
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @code
|
||||
* if (xmldb_get(xh, "running", "/interfaces/interface[name="eth"]", &xt) < 0)
|
||||
* err;
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ checklog(){
|
|||
s=$1 # statement
|
||||
l0=$2 # linenr
|
||||
new "Check $s in log"
|
||||
# echo "grep \"transaction_log $s\" $flog"
|
||||
t=$(grep -n "transaction_log $s" $flog)
|
||||
if [ -z "$t" ]; then
|
||||
echo -e "\e[31m\nError in Test$testnr [$testname]:"
|
||||
|
|
@ -124,7 +125,7 @@ if [ $BE -ne 0 ]; then
|
|||
sleep $RCWAIT
|
||||
fi
|
||||
|
||||
let nr=1
|
||||
let nr=0
|
||||
|
||||
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>]]>]]>$'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue