* minor edits make datastore=nocache pass tests, and ensure generic copy-config works
This commit is contained in:
parent
99c570e278
commit
a71e8aaceb
6 changed files with 62 additions and 48 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
$RESTCONFIG
|
||||
</clixon-config>
|
||||
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 "<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>]]>]]>$"
|
||||
|
||||
if ! $YANG_UNKNOWN_ANYDATA ; then
|
||||
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>]]>]]>$"
|
||||
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>]]>]]>$"
|
||||
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
|
||||
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>]]>]]>$"
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue