* Fixed: YANG when was not properly implemented for LEAF default values

This commit is contained in:
Olof hagsand 2021-08-03 13:38:31 +02:00 committed by Alan Yaniger
parent 8675620d22
commit dc2b3a80ca
4 changed files with 35 additions and 17 deletions

View file

@ -76,6 +76,6 @@ int assign_namespace_body(cxobj *x0, cxobj *x1);
int xml_merge(cxobj *x0, cxobj *x1, yang_stmt *yspec, char **reason);
int yang_enum_int_value(cxobj *node, int32_t *val);
int xml_copy_marked(cxobj *x0, cxobj *x1);
int yang_when_xpath(cxobj *xn, cxobj *xp, yang_stmt *yn, int *hit, int *nrp, char **xpathp);
int yang_check_when_xpath(cxobj *xn, cxobj *xp, yang_stmt *yn, int *hit, int *nrp, char **xpathp);
#endif /* _CLIXON_XML_MAP_H_ */

View file

@ -1247,7 +1247,7 @@ xml_yang_validate_all(clicon_handle h,
nsc = NULL;
}
}
if (yang_when_xpath(xt, xml_parent(xt), ys, &hit, &nr, &xpath) < 0)
if (yang_check_when_xpath(xt, xml_parent(xt), ys, &hit, &nr, &xpath) < 0)
goto done;
if (hit && nr == 0){
if ((cb = cbuf_new()) == NULL){

View file

@ -1164,13 +1164,11 @@ xml_default1(yang_stmt *yt,
switch (yang_keyword_get(yc)){
case Y_LEAF:
if (!cv_flag(yang_cv_get(yc), V_UNSET)){ /* Default value exists */
/* Check when statement from uses or augment */
if ((xpath = yang_when_xpath_get(yc)) != NULL){
if ((nr = xpath_vec_bool(xt, yang_when_nsc_get(yc), "%s", xpath)) < 0)
/* Check when condition */
if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
goto done;
if (nr == 0)
if (hit && nr == 0)
break; /* Do not create default if xpath fails */
}
if (xml_find_type(xt, NULL, yang_argument_get(yc), CX_ELMNT) == NULL){
/* No such child exist, create this leaf */
if (xml_default_create(yc, xt, top) < 0)
@ -1181,8 +1179,8 @@ xml_default1(yang_stmt *yt,
break;
case Y_CONTAINER:
if (yang_find(yc, Y_PRESENCE, NULL) == NULL){
/* Check when statement from uses or augment */
if (yang_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
/* Check when condition */
if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
goto done;
if (hit && nr == 0)
break; /* Do not create default if xpath fails */
@ -2266,7 +2264,7 @@ xml_copy_marked(cxobj *x0,
* Second variant of when, actual "when" sub-node RFC 7950 Sec 7.21.5. Can only be one.
*/
int
yang_when_xpath(cxobj *xn,
yang_check_when_xpath(cxobj *xn,
cxobj *xp,
yang_stmt *yn,
int *hit,

View file

@ -67,6 +67,19 @@ module example{
default 31; /* should be set on startup */
}
}
/* Extra rules to check when condition */
leaf npleaf{
when "../s3 = '99'";
type uint32;
default 98;
}
container npcont{
when "../s3 = '99'";
leaf npext{
type uint32;
default 99;
}
}
}
container p4{
presence "A presence container";
@ -144,6 +157,13 @@ expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><edit-confi
new "get config (should contain y/inside+outside)"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><get-config><source><candidate/></source></get-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data>$XML<xs-config xmlns=\"urn:example:clixon\"><x><name>a</name><y><inside>false</inside></y><outside>false</outside></x></xs-config></data></rpc-reply>]]>]]>$"
# Set s3 leaf to 99 triggering when condition for default values
new "Set s3 to 99"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><np3 xmlns=\"urn:example:clixon\"><s3>99</s3></np3></config></edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
new "get config np3 with npleaf and npext"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/ex:np3\" xmlns:ex=\"urn:example:clixon\" /></get-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data><np3 xmlns=\"urn:example:clixon\"><s3>99</s3><np31><s31>31</s31></np31><npleaf>98</npleaf><npcont><npext>99</npext></npcont></np3></data></rpc-reply>]]>]]>$"
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill