diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index e31c9ccd..6ac1a240 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -890,7 +890,8 @@ main(int argc, /* Initiate the shared candidate. */ if (xmldb_copy(h, "running", "candidate") < 0) goto done; - xmldb_modified_set(h, "candidate", 0); + if (xmldb_modified_set(h, "candidate", 0) <0) + goto done; /* Set startup status */ if (clicon_startup_status_set(h, status) < 0) diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index 84db9b4f..e347e158 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -244,7 +244,9 @@ startup_extraxml(clicon_handle h, */ if (xmldb_get(h, tmp_db, NULL, NULL, &xt0) < 0) goto done; - if (xmldb_empty_get(h, tmp_db)) + if ((ret = xmldb_empty_get(h, tmp_db)) < 0) + goto done; + if (ret == 1) goto ok; xt = NULL; /* Validate the tmp db and return possibly upgraded xml in xt diff --git a/lib/src/clixon_datastore.c b/lib/src/clixon_datastore.c index be771457..49537779 100644 --- a/lib/src/clixon_datastore.c +++ b/lib/src/clixon_datastore.c @@ -231,8 +231,9 @@ xmldb_copy(clicon_handle h, if (de2) de0 = *de2; de0.de_xml = x2; /* The new tree */ - clicon_db_elmnt_set(h, to, &de0); } + clicon_db_elmnt_set(h, to, &de0); + /* Copy the files themselves (above only in-memory cache) */ if (xmldb_db2file(h, from, &fromfile) < 0) goto done; @@ -382,12 +383,10 @@ xmldb_clear(clicon_handle h, cxobj *xt = NULL; db_elmnt *de = NULL; - if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){ - if ((de = clicon_db_elmnt_get(h, db)) != NULL){ - if ((xt = de->de_xml) != NULL){ - xml_free(xt); - de->de_xml = NULL; - } + if ((de = clicon_db_elmnt_get(h, db)) != NULL){ + if ((xt = de->de_xml) != NULL){ + xml_free(xt); + de->de_xml = NULL; } } return 0; @@ -439,12 +438,10 @@ xmldb_create(clicon_handle h, db_elmnt *de = NULL; cxobj *xt = NULL; - if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){ - if ((de = clicon_db_elmnt_get(h, db)) != NULL){ - if ((xt = de->de_xml) != NULL){ - xml_free(xt); - de->de_xml = NULL; - } + if ((de = clicon_db_elmnt_get(h, db)) != NULL){ + if ((xt = de->de_xml) != NULL){ + xml_free(xt); + de->de_xml = NULL; } } if (xmldb_db2file(h, db, &filename) < 0) diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index 015b9ae9..62729dba 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -262,7 +262,7 @@ parse_configfile_one(const char *filename, * * @param[in] h Clixon handle * @param[in] filename Main configuration file - * @param[in] extraconfig0 Override (if set use that, othewrwise get from main file) + * @param[in] extraconfig0 Override (if set use that, otherwise get from main file) * @param[in] yspec Yang spec * @param[out] xconfig Pointer to xml config tree. Should be freed by caller * @retval 0 OK @@ -335,10 +335,13 @@ parse_configfile(clicon_handle h, while ((xec = xml_child_i_type(xe, 0, CX_ELMNT)) != NULL) { name = xml_name(xec); body = xml_body(xec); + /* Ignore non-leafs */ + if (name == NULL || body == NULL) + continue; /* Ignored from file due to bootstrapping */ if (strcmp(name,"CLICON_CONFIGFILE")==0) continue; - /* List options for configure options that are leaf-lists: append to main */ + /* List options for configure options that are lists or leaf-lists: append to main */ if (strcmp(name,"CLICON_FEATURE")==0 || strcmp(name,"CLICON_YANG_DIR")==0){ if (xml_addsub(xt, xec) < 0) @@ -375,7 +378,7 @@ parse_configfile(clicon_handle h, while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) { name = xml_name(x); body = xml_body(x); - /* Ignored non-leafs */ + /* Ignore non-leafs */ if (name == NULL || body == NULL) continue; /* Ignored from file due to bootstrapping */ @@ -388,7 +391,6 @@ parse_configfile(clicon_handle h, continue; if (strcmp(name,"CLICON_YANG_DIR")==0) continue; - if (clicon_hash_add(copt, name, body, diff --git a/test/test_augment.sh b/test/test_augment.sh index ceb29ef1..c33cec49 100755 --- a/test/test_augment.sh +++ b/test/test_augment.sh @@ -171,7 +171,6 @@ fi if [ $RC -ne 0 ]; then - new "kill old restconf daemon" stop_restconf_pre @@ -263,17 +262,15 @@ if [ $RC -ne 0 ]; then stop_restconf fi -if [ $BE -eq 0 ]; then - exit # BE +if [ $BE -ne 0 ]; then + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + # kill backend + stop_backend -f $cfg fi -new "Kill backend" -# Check if premature kill -pid=$(pgrep -u root -f clixon_backend) -if [ -z "$pid" ]; then - err "backend already dead" -fi -# kill backend -stop_backend -f $cfg - rm -rf $dir diff --git a/test/test_copy_config.sh b/test/test_copy_config.sh index ec2f144b..f6f88e18 100755 --- a/test/test_copy_config.sh +++ b/test/test_copy_config.sh @@ -47,6 +47,7 @@ cat < $cfg $dir/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir + $RESTCONFIG EOF @@ -72,10 +73,21 @@ if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" start_backend -s init -f $cfg - new "waiting" + new "wait backend" wait_backend fi +if [ $RC -ne 0 ]; then + new "kill old restconf daemon" + stop_restconf_pre + + new "start restconf daemon" + start_restconf -f $cfg + + new "wait restconf" + wait_restconf +fi + new "Add config to candidate" expecteof "$clixon_netconf -qf $cfg" 0 "eth/0/0ex:ethnone ]]>]]>" "^]]>]]>$" @@ -150,28 +162,31 @@ new "copy startup->candidate" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" if ! $YANG_UNKNOWN_ANYDATA ; then -new "copy startup->running not allowed" -expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^applicationunknown-elementrunningerrorFailed to find YANG spec of XML node: running with parent: target in namespace: urn:ietf:params:xml:ns:netconf:base:1.0]]>]]>$" + new "copy startup->running not allowed" + expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^applicationunknown-elementrunningerrorFailed to find YANG spec of XML node: running with parent: target in namespace: urn:ietf:params:xml:ns:netconf:base:1.0]]>]]>$" fi +# restconf copy +new "restconf copy-config smoketest, json" +expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" http://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '{"ietf-netconf:input": {"target": {"startup": [null]},"source": {"running": [null]}}}')" 0 'HTTP/1.1 204 No Content' + +new "restconf copy-config smoketest, xml" +expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" http://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '')" 0 'HTTP/1.1 204 No Content' + # Here running is empty new "Check running empty" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" +exit -if [ $BE -eq 0 ]; then - exit # BE -fi - -new "Kill backend" -# Check if premature kill -pid=$(pgrep -u root -f clixon_backend) -if [ -z "$pid" ]; then - err "backend already dead" -fi -# kill backend -sudo clixon_backend -z -f $cfg -if [ $? -ne 0 ]; then - err "kill backend" +if [ $BE -ne 0 ]; then + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + # kill backend + stop_backend -f $cfg fi rm -rf $dir