* Fixed: YANG when was not properly implemented for LEAF default values
This commit is contained in:
parent
8675620d22
commit
dc2b3a80ca
4 changed files with 35 additions and 17 deletions
|
|
@ -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 xml_merge(cxobj *x0, cxobj *x1, yang_stmt *yspec, char **reason);
|
||||||
int yang_enum_int_value(cxobj *node, int32_t *val);
|
int yang_enum_int_value(cxobj *node, int32_t *val);
|
||||||
int xml_copy_marked(cxobj *x0, cxobj *x1);
|
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_ */
|
#endif /* _CLIXON_XML_MAP_H_ */
|
||||||
|
|
|
||||||
|
|
@ -1247,7 +1247,7 @@ xml_yang_validate_all(clicon_handle h,
|
||||||
nsc = NULL;
|
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;
|
goto done;
|
||||||
if (hit && nr == 0){
|
if (hit && nr == 0){
|
||||||
if ((cb = cbuf_new()) == NULL){
|
if ((cb = cbuf_new()) == NULL){
|
||||||
|
|
|
||||||
|
|
@ -1164,13 +1164,11 @@ xml_default1(yang_stmt *yt,
|
||||||
switch (yang_keyword_get(yc)){
|
switch (yang_keyword_get(yc)){
|
||||||
case Y_LEAF:
|
case Y_LEAF:
|
||||||
if (!cv_flag(yang_cv_get(yc), V_UNSET)){ /* Default value exists */
|
if (!cv_flag(yang_cv_get(yc), V_UNSET)){ /* Default value exists */
|
||||||
/* Check when statement from uses or augment */
|
/* Check when condition */
|
||||||
if ((xpath = yang_when_xpath_get(yc)) != NULL){
|
if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
|
||||||
if ((nr = xpath_vec_bool(xt, yang_when_nsc_get(yc), "%s", xpath)) < 0)
|
goto done;
|
||||||
goto done;
|
if (hit && nr == 0)
|
||||||
if (nr == 0)
|
break; /* Do not create default if xpath fails */
|
||||||
break; /* Do not create default if xpath fails */
|
|
||||||
}
|
|
||||||
if (xml_find_type(xt, NULL, yang_argument_get(yc), CX_ELMNT) == NULL){
|
if (xml_find_type(xt, NULL, yang_argument_get(yc), CX_ELMNT) == NULL){
|
||||||
/* No such child exist, create this leaf */
|
/* No such child exist, create this leaf */
|
||||||
if (xml_default_create(yc, xt, top) < 0)
|
if (xml_default_create(yc, xt, top) < 0)
|
||||||
|
|
@ -1181,8 +1179,8 @@ xml_default1(yang_stmt *yt,
|
||||||
break;
|
break;
|
||||||
case Y_CONTAINER:
|
case Y_CONTAINER:
|
||||||
if (yang_find(yc, Y_PRESENCE, NULL) == NULL){
|
if (yang_find(yc, Y_PRESENCE, NULL) == NULL){
|
||||||
/* Check when statement from uses or augment */
|
/* Check when condition */
|
||||||
if (yang_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
|
if (yang_check_when_xpath(NULL, xt, yc, &hit, &nr, &xpath) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (hit && nr == 0)
|
if (hit && nr == 0)
|
||||||
break; /* Do not create default if xpath fails */
|
break; /* Do not create default if xpath fails */
|
||||||
|
|
@ -2266,12 +2264,12 @@ xml_copy_marked(cxobj *x0,
|
||||||
* Second variant of when, actual "when" sub-node RFC 7950 Sec 7.21.5. Can only be one.
|
* Second variant of when, actual "when" sub-node RFC 7950 Sec 7.21.5. Can only be one.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
yang_when_xpath(cxobj *xn,
|
yang_check_when_xpath(cxobj *xn,
|
||||||
cxobj *xp,
|
cxobj *xp,
|
||||||
yang_stmt *yn,
|
yang_stmt *yn,
|
||||||
int *hit,
|
int *hit,
|
||||||
int *nrp,
|
int *nrp,
|
||||||
char **xpathp)
|
char **xpathp)
|
||||||
{
|
{
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
yang_stmt *yc;
|
yang_stmt *yc;
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,19 @@ module example{
|
||||||
default 31; /* should be set on startup */
|
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{
|
container p4{
|
||||||
presence "A presence container";
|
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)"
|
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>]]>]]>$"
|
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
|
if [ $BE -ne 0 ]; then
|
||||||
new "Kill backend"
|
new "Kill backend"
|
||||||
# Check if premature kill
|
# Check if premature kill
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue