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)
|
||||
goto done;
|
||||
/* Remove global defaults and empty non-presence containers */
|
||||
if (xml_defaults_nopresence(x, 1) < 0)
|
||||
if (xml_defaults_nopresence(x, 2) < 0)
|
||||
goto done;
|
||||
if (xml_default_recurse(x, 1) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -890,7 +890,7 @@ xmldb_get_cache(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
/* Remove global defaults and empty non-presence containers */
|
||||
if (xml_defaults_nopresence(x0t, 1) < 0)
|
||||
if (xml_defaults_nopresence(x0t, 2) < 0)
|
||||
goto done;
|
||||
if (yb != YB_NONE){
|
||||
/* Add default global values */
|
||||
|
|
@ -1163,7 +1163,7 @@ xmldb_get0_clear(clicon_handle h,
|
|||
if (x == NULL)
|
||||
goto ok;
|
||||
/* Remove global defaults and empty non-presence containers */
|
||||
if (xml_defaults_nopresence(x, 1) < 0)
|
||||
if (xml_defaults_nopresence(x, 2) < 0)
|
||||
goto done;
|
||||
/* Clear XML tree of defaults */
|
||||
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)
|
||||
goto done;
|
||||
/* Remove global defaults and empty non-presence containers */
|
||||
if (xml_defaults_nopresence(x0, 1) < 0)
|
||||
if (xml_defaults_nopresence(x0, 2) < 0)
|
||||
goto done;
|
||||
#if 0 /* debug */
|
||||
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
|
||||
*
|
||||
* @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 0 Other node
|
||||
* @retval -1 Error
|
||||
* @note xn is not itself removed if purge
|
||||
* @note for purge=1 are removed only if config or no yang spec(!)
|
||||
*/
|
||||
int
|
||||
xml_defaults_nopresence(cxobj *xn,
|
||||
|
|
@ -1117,9 +1120,11 @@ xml_defaults_nopresence(cxobj *xn,
|
|||
cxobj *x;
|
||||
cxobj *xprev;
|
||||
yang_stmt *yn;
|
||||
yang_stmt *y;
|
||||
int rmx = 0; /* If set, remove this xn */
|
||||
int ret;
|
||||
enum rfc_6020 keyw;
|
||||
int config = 0;
|
||||
|
||||
if ((yn = xml_spec(xn)) != NULL){
|
||||
keyw = yang_keyword_get(yn);
|
||||
|
|
@ -1129,6 +1134,7 @@ xml_defaults_nopresence(cxobj *xn,
|
|||
else if (keyw == Y_LEAF &&
|
||||
xml_flag(xn, XML_FLAG_DEFAULT))
|
||||
rmx = 1;
|
||||
config = yang_config_ancestor(yn);
|
||||
}
|
||||
/* Loop thru children */
|
||||
x = NULL;
|
||||
|
|
@ -1137,13 +1143,25 @@ xml_defaults_nopresence(cxobj *xn,
|
|||
if ((ret = xml_defaults_nopresence(x, purge)) < 0)
|
||||
goto done;
|
||||
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)
|
||||
goto done;
|
||||
x = xprev;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (rmx)
|
||||
/* May switch an empty non-presence container (rmx=1) to non-empty non-presence container (rmx=0) */
|
||||
rmx = 0;
|
||||
}
|
||||
retval = rmx;
|
||||
|
|
|
|||
|
|
@ -249,8 +249,12 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
|||
<error-message>Data already exists; cannot create new resource</error-message>\
|
||||
</rpc-error></rpc-reply>"
|
||||
# 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>"
|
||||
|
||||
# verify no change
|
||||
new "2.3.3 (part 1) verify"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||
"<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>" \
|
||||
"" \
|
||||
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||
|
||||
# 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>"
|
||||
|
||||
# verify that the mtu value has changed
|
||||
new "2.3.3 (part 2) verify"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||
"<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>" \
|
||||
"" \
|
||||
"<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||
|
||||
# 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>"
|
||||
# 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" \
|
||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
||||
|
|
@ -325,9 +337,13 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
|||
<error-severity>error</error-severity>\
|
||||
<error-message>Data does not exist; cannot delete resource</error-message>\
|
||||
</rpc-error></rpc-reply>"
|
||||
|
||||
# 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>"
|
||||
|
||||
# verify that the configuration has not changed
|
||||
new "2.3.3 (part 4) verify"
|
||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
||||
"<rpc $DEFAULTNS><get><filter type=\"subtree\"><interfaces $EXAMPLENS/></filter></get></rpc>" "" \
|
||||
"<rpc-reply $DEFAULTNS><data><interfaces $EXAMPLENS>\
|
||||
|
|
@ -411,13 +427,15 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" \
|
|||
</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)" \
|
||||
0 \
|
||||
"HTTP/$HVER 200" \
|
||||
"Content-Type: application/yang-data+json" \
|
||||
"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"}\]}}'
|
||||
|
||||
new "rfc8040 4.3. RESTCONF GET xml"
|
||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example:interfaces)" \
|
||||
0 \
|
||||
"HTTP/$HVER 200" \
|
||||
|
|
@ -425,13 +443,15 @@ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPR
|
|||
"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>'
|
||||
|
||||
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)" \
|
||||
0 \
|
||||
"HTTP/$HVER 200" \
|
||||
"Content-Type: application/yang-data+json" \
|
||||
"Cache-Control: no-cache" \
|
||||
'{"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)" \
|
||||
0 \
|
||||
"HTTP/$HVER 200" \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue