* minor edits make datastore=nocache pass tests, and ensure generic copy-config works

This commit is contained in:
Olof hagsand 2020-12-04 14:44:22 +01:00
parent 99c570e278
commit a71e8aaceb
6 changed files with 62 additions and 48 deletions

View file

@ -890,7 +890,8 @@ main(int argc,
/* Initiate the shared candidate. */ /* Initiate the shared candidate. */
if (xmldb_copy(h, "running", "candidate") < 0) if (xmldb_copy(h, "running", "candidate") < 0)
goto done; goto done;
xmldb_modified_set(h, "candidate", 0); if (xmldb_modified_set(h, "candidate", 0) <0)
goto done;
/* Set startup status */ /* Set startup status */
if (clicon_startup_status_set(h, status) < 0) if (clicon_startup_status_set(h, status) < 0)

View file

@ -244,7 +244,9 @@ startup_extraxml(clicon_handle h,
*/ */
if (xmldb_get(h, tmp_db, NULL, NULL, &xt0) < 0) if (xmldb_get(h, tmp_db, NULL, NULL, &xt0) < 0)
goto done; 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; goto ok;
xt = NULL; xt = NULL;
/* Validate the tmp db and return possibly upgraded xml in xt /* Validate the tmp db and return possibly upgraded xml in xt

View file

@ -231,8 +231,9 @@ xmldb_copy(clicon_handle h,
if (de2) if (de2)
de0 = *de2; de0 = *de2;
de0.de_xml = x2; /* The new tree */ 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) */ /* Copy the files themselves (above only in-memory cache) */
if (xmldb_db2file(h, from, &fromfile) < 0) if (xmldb_db2file(h, from, &fromfile) < 0)
goto done; goto done;
@ -382,14 +383,12 @@ xmldb_clear(clicon_handle h,
cxobj *xt = NULL; cxobj *xt = NULL;
db_elmnt *de = NULL; db_elmnt *de = NULL;
if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){
if ((de = clicon_db_elmnt_get(h, db)) != NULL){ if ((de = clicon_db_elmnt_get(h, db)) != NULL){
if ((xt = de->de_xml) != NULL){ if ((xt = de->de_xml) != NULL){
xml_free(xt); xml_free(xt);
de->de_xml = NULL; de->de_xml = NULL;
} }
} }
}
return 0; return 0;
} }
@ -439,14 +438,12 @@ xmldb_create(clicon_handle h,
db_elmnt *de = NULL; db_elmnt *de = NULL;
cxobj *xt = NULL; cxobj *xt = NULL;
if (clicon_datastore_cache(h) != DATASTORE_NOCACHE){
if ((de = clicon_db_elmnt_get(h, db)) != NULL){ if ((de = clicon_db_elmnt_get(h, db)) != NULL){
if ((xt = de->de_xml) != NULL){ if ((xt = de->de_xml) != NULL){
xml_free(xt); xml_free(xt);
de->de_xml = NULL; de->de_xml = NULL;
} }
} }
}
if (xmldb_db2file(h, db, &filename) < 0) if (xmldb_db2file(h, db, &filename) < 0)
goto done; goto done;
if ((fd = open(filename, O_CREAT|O_WRONLY, S_IRWXU)) == -1) { if ((fd = open(filename, O_CREAT|O_WRONLY, S_IRWXU)) == -1) {

View file

@ -262,7 +262,7 @@ parse_configfile_one(const char *filename,
* *
* @param[in] h Clixon handle * @param[in] h Clixon handle
* @param[in] filename Main configuration file * @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[in] yspec Yang spec
* @param[out] xconfig Pointer to xml config tree. Should be freed by caller * @param[out] xconfig Pointer to xml config tree. Should be freed by caller
* @retval 0 OK * @retval 0 OK
@ -335,10 +335,13 @@ parse_configfile(clicon_handle h,
while ((xec = xml_child_i_type(xe, 0, CX_ELMNT)) != NULL) { while ((xec = xml_child_i_type(xe, 0, CX_ELMNT)) != NULL) {
name = xml_name(xec); name = xml_name(xec);
body = xml_body(xec); body = xml_body(xec);
/* Ignore non-leafs */
if (name == NULL || body == NULL)
continue;
/* Ignored from file due to bootstrapping */ /* Ignored from file due to bootstrapping */
if (strcmp(name,"CLICON_CONFIGFILE")==0) if (strcmp(name,"CLICON_CONFIGFILE")==0)
continue; 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 || if (strcmp(name,"CLICON_FEATURE")==0 ||
strcmp(name,"CLICON_YANG_DIR")==0){ strcmp(name,"CLICON_YANG_DIR")==0){
if (xml_addsub(xt, xec) < 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) { while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
name = xml_name(x); name = xml_name(x);
body = xml_body(x); body = xml_body(x);
/* Ignored non-leafs */ /* Ignore non-leafs */
if (name == NULL || body == NULL) if (name == NULL || body == NULL)
continue; continue;
/* Ignored from file due to bootstrapping */ /* Ignored from file due to bootstrapping */
@ -388,7 +391,6 @@ parse_configfile(clicon_handle h,
continue; continue;
if (strcmp(name,"CLICON_YANG_DIR")==0) if (strcmp(name,"CLICON_YANG_DIR")==0)
continue; continue;
if (clicon_hash_add(copt, if (clicon_hash_add(copt,
name, name,
body, body,

View file

@ -171,7 +171,6 @@ fi
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
new "kill old restconf daemon" new "kill old restconf daemon"
stop_restconf_pre stop_restconf_pre
@ -263,17 +262,15 @@ if [ $RC -ne 0 ]; then
stop_restconf stop_restconf
fi fi
if [ $BE -eq 0 ]; then if [ $BE -ne 0 ]; then
exit # BE new "Kill backend"
fi # Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
new "Kill backend" if [ -z "$pid" ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
fi fi
# kill backend
stop_backend -f $cfg
rm -rf $dir rm -rf $dir

View file

@ -47,6 +47,7 @@ cat <<EOF > $cfg
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK> <CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE> <CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR> <CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
$RESTCONFIG
</clixon-config> </clixon-config>
EOF EOF
@ -72,10 +73,21 @@ if [ $BE -ne 0 ]; then
new "start backend -s init -f $cfg" new "start backend -s init -f $cfg"
start_backend -s init -f $cfg start_backend -s init -f $cfg
new "waiting" new "wait backend"
wait_backend wait_backend
fi 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" new "Add config to candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><interface nc:operation=\"create\"><name>eth/0/0</name><type>ex:eth</type></interface></interfaces></config><default-operation>none</default-operation> </edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><interface nc:operation=\"create\"><name>eth/0/0</name><type>ex:eth</type></interface></interfaces></config><default-operation>none</default-operation> </edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
@ -150,28 +162,31 @@ new "copy startup->candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><copy-config><target><candidate/></target><source><startup/></source></copy-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><copy-config><target><candidate/></target><source><startup/></source></copy-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
if ! $YANG_UNKNOWN_ANYDATA ; then if ! $YANG_UNKNOWN_ANYDATA ; then
new "copy startup->running not allowed" new "copy startup->running not allowed"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><copy-config><target><running/></target><source><startup/></source></copy-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>unknown-element</error-tag><error-info><bad-element>running</bad-element></error-info><error-severity>error</error-severity><error-message>Failed to find YANG spec of XML node: running with parent: target in namespace: urn:ietf:params:xml:ns:netconf:base:1.0</error-message></rpc-error></rpc-reply>]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><copy-config><target><running/></target><source><startup/></source></copy-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>unknown-element</error-tag><error-info><bad-element>running</bad-element></error-info><error-severity>error</error-severity><error-message>Failed to find YANG spec of XML node: running with parent: target in namespace: urn:ietf:params:xml:ns:netconf:base:1.0</error-message></rpc-error></rpc-reply>]]>]]>$"
fi 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 '<input xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><target><startup></startup></target><source><running></running></source></input>')" 0 'HTTP/1.1 204 No Content'
# Here running is empty # Here running is empty
new "Check running empty" new "Check running empty"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><get-config><source><running/></source></get-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data/></rpc-reply>]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><get-config><source><running/></source></get-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data/></rpc-reply>]]>]]>$"
exit
if [ $BE -eq 0 ]; then if [ $BE -ne 0 ]; then
exit # BE new "Kill backend"
fi # Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
new "Kill backend" if [ -z "$pid" ]; then
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
# kill backend # kill backend
sudo clixon_backend -z -f $cfg stop_backend -f $cfg
if [ $? -ne 0 ]; then
err "kill backend"
fi fi
rm -rf $dir rm -rf $dir