Extended purge argument to xml_defaults_nopresence to handle non-config case
Test: with-defaults: added headings to all test cases
This commit is contained in:
parent
2d23c9656b
commit
38f501be19
5 changed files with 49 additions and 11 deletions
|
|
@ -388,7 +388,7 @@ clixon_plugin_statedata_all(clicon_handle h,
|
||||||
if (xml_sort_recurse(x) < 0)
|
if (xml_sort_recurse(x) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Remove global defaults and empty non-presence containers */
|
/* Remove global defaults and empty non-presence containers */
|
||||||
if (xml_defaults_nopresence(x, 1) < 0)
|
if (xml_defaults_nopresence(x, 2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xml_default_recurse(x, 1) < 0)
|
if (xml_default_recurse(x, 1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -890,7 +890,7 @@ xmldb_get_cache(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Remove global defaults and empty non-presence containers */
|
/* Remove global defaults and empty non-presence containers */
|
||||||
if (xml_defaults_nopresence(x0t, 1) < 0)
|
if (xml_defaults_nopresence(x0t, 2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (yb != YB_NONE){
|
if (yb != YB_NONE){
|
||||||
/* Add default global values */
|
/* Add default global values */
|
||||||
|
|
@ -1163,7 +1163,7 @@ xmldb_get0_clear(clicon_handle h,
|
||||||
if (x == NULL)
|
if (x == NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
/* Remove global defaults and empty non-presence containers */
|
/* Remove global defaults and empty non-presence containers */
|
||||||
if (xml_defaults_nopresence(x, 1) < 0)
|
if (xml_defaults_nopresence(x, 2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Clear XML tree of defaults */
|
/* Clear XML tree of defaults */
|
||||||
if (xml_tree_prune_flagged(x, XML_FLAG_TRANSIENT, 1) < 0)
|
if (xml_tree_prune_flagged(x, XML_FLAG_TRANSIENT, 1) < 0)
|
||||||
|
|
|
||||||
|
|
@ -1258,7 +1258,7 @@ xmldb_put(clicon_handle h,
|
||||||
(void*)(XML_FLAG_NONE|XML_FLAG_MARK)) < 0)
|
(void*)(XML_FLAG_NONE|XML_FLAG_MARK)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
/* Remove global defaults and empty non-presence containers */
|
/* Remove global defaults and empty non-presence containers */
|
||||||
if (xml_defaults_nopresence(x0, 1) < 0)
|
if (xml_defaults_nopresence(x0, 2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
#if 0 /* debug */
|
#if 0 /* debug */
|
||||||
if (xml_apply0(x0, -1, xml_sort_verify, NULL) < 0)
|
if (xml_apply0(x0, -1, xml_sort_verify, NULL) < 0)
|
||||||
|
|
|
||||||
|
|
@ -1103,11 +1103,14 @@ xml_global_defaults(clicon_handle h,
|
||||||
/*! Recursively find empty nopresence containers and default leaves, optionally purge
|
/*! Recursively find empty nopresence containers and default leaves, optionally purge
|
||||||
*
|
*
|
||||||
* @param[in] xn XML tree
|
* @param[in] xn XML tree
|
||||||
* @param[in] purge Remove sub-nodes that is empty non-presence container or default leaf
|
* @param[in] purge 0: Dont remove any nodes
|
||||||
|
* 1: Remove config sub-nodes that are empty non-presence container or default leaf
|
||||||
|
* 2: Remove all sub-nodes that are empty non-presence container or default leaf
|
||||||
* @retval 1 Node is an (recursive) empty non-presence container or default leaf
|
* @retval 1 Node is an (recursive) empty non-presence container or default leaf
|
||||||
* @retval 0 Other node
|
* @retval 0 Other node
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
* @note xn is not itself removed if purge
|
* @note xn is not itself removed if purge
|
||||||
|
* @note for purge=1 are removed only if config or no yang spec(!)
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xml_defaults_nopresence(cxobj *xn,
|
xml_defaults_nopresence(cxobj *xn,
|
||||||
|
|
@ -1117,9 +1120,11 @@ xml_defaults_nopresence(cxobj *xn,
|
||||||
cxobj *x;
|
cxobj *x;
|
||||||
cxobj *xprev;
|
cxobj *xprev;
|
||||||
yang_stmt *yn;
|
yang_stmt *yn;
|
||||||
|
yang_stmt *y;
|
||||||
int rmx = 0; /* If set, remove this xn */
|
int rmx = 0; /* If set, remove this xn */
|
||||||
int ret;
|
int ret;
|
||||||
enum rfc_6020 keyw;
|
enum rfc_6020 keyw;
|
||||||
|
int config = 0;
|
||||||
|
|
||||||
if ((yn = xml_spec(xn)) != NULL){
|
if ((yn = xml_spec(xn)) != NULL){
|
||||||
keyw = yang_keyword_get(yn);
|
keyw = yang_keyword_get(yn);
|
||||||
|
|
@ -1129,6 +1134,7 @@ xml_defaults_nopresence(cxobj *xn,
|
||||||
else if (keyw == Y_LEAF &&
|
else if (keyw == Y_LEAF &&
|
||||||
xml_flag(xn, XML_FLAG_DEFAULT))
|
xml_flag(xn, XML_FLAG_DEFAULT))
|
||||||
rmx = 1;
|
rmx = 1;
|
||||||
|
config = yang_config_ancestor(yn);
|
||||||
}
|
}
|
||||||
/* Loop thru children */
|
/* Loop thru children */
|
||||||
x = NULL;
|
x = NULL;
|
||||||
|
|
@ -1137,14 +1143,26 @@ xml_defaults_nopresence(cxobj *xn,
|
||||||
if ((ret = xml_defaults_nopresence(x, purge)) < 0)
|
if ((ret = xml_defaults_nopresence(x, purge)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 1){
|
if (ret == 1){
|
||||||
if (purge){
|
switch (purge){
|
||||||
|
case 1: /* config nodes only */
|
||||||
|
if (!config)
|
||||||
|
break;
|
||||||
|
if ((y = xml_spec(x)) != NULL &&
|
||||||
|
!yang_config(y))
|
||||||
|
break;
|
||||||
|
/* fall thru */
|
||||||
|
case 2: /* purge all nodes */
|
||||||
if (xml_purge(x) < 0)
|
if (xml_purge(x) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
x = xprev;
|
x = xprev;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (rmx)
|
else if (rmx)
|
||||||
rmx = 0;
|
/* May switch an empty non-presence container (rmx=1) to non-empty non-presence container (rmx=0) */
|
||||||
|
rmx = 0;
|
||||||
}
|
}
|
||||||
retval = rmx;
|
retval = rmx;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
|
|
@ -249,8 +249,12 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
<error-message>Data already exists; cannot create new resource</error-message>\
|
<error-message>Data already exists; cannot create new resource</error-message>\
|
||||||
</rpc-error></rpc-reply>"
|
</rpc-error></rpc-reply>"
|
||||||
# nothing to commit here, but just to verify
|
# nothing to commit here, but just to verify
|
||||||
|
|
||||||
|
new "2.3.3 (part 1) commit"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
# verify no change
|
# verify no change
|
||||||
|
new "2.3.3 (part 1) verify"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||||
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
||||||
|
|
@ -272,9 +276,13 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
</interfaces></config><default-operation>none</default-operation> </edit-config></rpc>" \
|
</interfaces></config><default-operation>none</default-operation> </edit-config></rpc>" \
|
||||||
"" \
|
"" \
|
||||||
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
# commit change
|
# commit change
|
||||||
|
new "2.3.3 (part 2) commit"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
# verify that the mtu value has changed
|
# verify that the mtu value has changed
|
||||||
|
new "2.3.3 (part 2) verify"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||||
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
||||||
|
|
@ -296,9 +304,13 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
</interfaces></config><default-operation>none</default-operation></edit-config></rpc>" \
|
</interfaces></config><default-operation>none</default-operation></edit-config></rpc>" \
|
||||||
"" \
|
"" \
|
||||||
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
# commit delete
|
# commit delete
|
||||||
|
new "2.3.3 (part 3) commit"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
# check thet the default mtu vale has been restored
|
|
||||||
|
# check that the default mtu vale has been restored
|
||||||
|
new "2.3.3 (part 3) verify"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||||
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
||||||
|
|
@ -325,9 +337,13 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
<error-severity>error</error-severity>\
|
<error-severity>error</error-severity>\
|
||||||
<error-message>Data does not exist; cannot delete resource</error-message>\
|
<error-message>Data does not exist; cannot delete resource</error-message>\
|
||||||
</rpc-error></rpc-reply>"
|
</rpc-error></rpc-reply>"
|
||||||
|
|
||||||
# nothing to commit
|
# nothing to commit
|
||||||
|
new "2.3.3 (part 4) commit"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS ><commit/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
# verify that the configuration has not changed
|
# verify that the configuration has not changed
|
||||||
|
new "2.3.3 (part 4) verify"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||||
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
||||||
|
|
@ -411,13 +427,15 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||||
</interfaces></data></rpc-reply>"
|
</interfaces></data></rpc-reply>"
|
||||||
|
|
||||||
|
|
||||||
new "rfc8040 4.3. RESTCONF GET"
|
new "rfc8040 4.3. RESTCONF GET json"
|
||||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces)" \
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces)" \
|
||||||
0 \
|
0 \
|
||||||
"HTTP/$HVER 200" \
|
"HTTP/$HVER 200" \
|
||||||
"Content-Type: application/yang-data+json" \
|
"Content-Type: application/yang-data+json" \
|
||||||
"Cache-Control: no-cache" \
|
"Cache-Control: no-cache" \
|
||||||
'{"example:interfaces":{"interface":\[{"name":"eth0","mtu":8192,"status":"ok"},{"name":"eth1","mtu":1500,"status":"ok"},{"name":"eth2","mtu":9000,"status":"not feeling so good"},{"name":"eth3","mtu":1500,"status":"waking up"}\]}}'
|
'{"example:interfaces":{"interface":\[{"name":"eth0","mtu":8192,"status":"ok"},{"name":"eth1","mtu":1500,"status":"ok"},{"name":"eth2","mtu":9000,"status":"not feeling so good"},{"name":"eth3","mtu":1500,"status":"waking up"}\]}}'
|
||||||
|
|
||||||
|
new "rfc8040 4.3. RESTCONF GET xml"
|
||||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces)" \
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces)" \
|
||||||
0 \
|
0 \
|
||||||
"HTTP/$HVER 200" \
|
"HTTP/$HVER 200" \
|
||||||
|
|
@ -425,13 +443,15 @@ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPR
|
||||||
"Cache-Control: no-cache" \
|
"Cache-Control: no-cache" \
|
||||||
'<interfaces xmlns="http://example.com/ns/interfaces"><interface><name>eth0</name><mtu>8192</mtu><status>ok</status></interface><interface><name>eth1</name><mtu>1500</mtu><status>ok</status></interface><interface><name>eth2</name><mtu>9000</mtu><status>not feeling so good</status></interface><interface><name>eth3</name><mtu>1500</mtu><status>waking up</status></interface></interfaces>'
|
'<interfaces xmlns="http://example.com/ns/interfaces"><interface><name>eth0</name><mtu>8192</mtu><status>ok</status></interface><interface><name>eth1</name><mtu>1500</mtu><status>ok</status></interface><interface><name>eth2</name><mtu>9000</mtu><status>not feeling so good</status></interface><interface><name>eth3</name><mtu>1500</mtu><status>waking up</status></interface></interfaces>'
|
||||||
|
|
||||||
new "rfc8040 B.3.9. RESTCONF with-defaults parameter = report-all"
|
new "rfc8040 B.3.9. RESTCONF with-defaults parameter = report-all json"
|
||||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=report-all)" \
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=report-all)" \
|
||||||
0 \
|
0 \
|
||||||
"HTTP/$HVER 200" \
|
"HTTP/$HVER 200" \
|
||||||
"Content-Type: application/yang-data+json" \
|
"Content-Type: application/yang-data+json" \
|
||||||
"Cache-Control: no-cache" \
|
"Cache-Control: no-cache" \
|
||||||
'{"example:interface":\[{"name":"eth1","mtu":1500,"status":"ok"}\]}'
|
'{"example:interface":\[{"name":"eth1","mtu":1500,"status":"ok"}\]}'
|
||||||
|
|
||||||
|
new "rfc8040 B.3.9. RESTCONF with-defaults parameter = report-all xml"
|
||||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=report-all)" \
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=report-all)" \
|
||||||
0 \
|
0 \
|
||||||
"HTTP/$HVER 200" \
|
"HTTP/$HVER 200" \
|
||||||
|
|
@ -439,7 +459,7 @@ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPR
|
||||||
"Cache-Control: no-cache" \
|
"Cache-Control: no-cache" \
|
||||||
'<interface xmlns="http://example.com/ns/interfaces"><name>eth1</name><mtu>1500</mtu><status>ok</status></interface>'
|
'<interface xmlns="http://example.com/ns/interfaces"><name>eth1</name><mtu>1500</mtu><status>ok</status></interface>'
|
||||||
|
|
||||||
new "rfc8040 B.3.9. RESTONF with-defaults parameter = explicit"
|
new "rfc8040 B.3.9. RESTONF with-defaults parameter = explicit "
|
||||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=explicit)" \
|
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/example:interfaces/interface=eth1?with-defaults=explicit)" \
|
||||||
0 \
|
0 \
|
||||||
"HTTP/$HVER 200" \
|
"HTTP/$HVER 200" \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue