CLI multi-key bug for ordered-by user

This commit is contained in:
Olof hagsand 2019-08-04 17:38:13 +02:00
parent df9e4734f9
commit aa653d0831
2 changed files with 65 additions and 6 deletions

View file

@ -111,6 +111,7 @@ expand_dbvar(void *h,
cxobj *xtop = NULL; /* xpath root */ cxobj *xtop = NULL; /* xpath root */
cxobj *xbot = NULL; /* xpath, NULL if datastore */ cxobj *xbot = NULL; /* xpath, NULL if datastore */
yang_stmt *y = NULL; /* yang spec of xpath */ yang_stmt *y = NULL; /* yang spec of xpath */
yang_stmt *yp;
yang_stmt *ytype; yang_stmt *ytype;
yang_stmt *ypath; yang_stmt *ypath;
cxobj *xcur; cxobj *xcur;
@ -167,11 +168,13 @@ expand_dbvar(void *h,
xbot = xtop; xbot = xtop;
/* This is primarily to get "y", /* This is primarily to get "y",
* xpath2xml would have worked!! * xpath2xml would have worked!!
* XXX: but y is just the first in this list, there could be other y:s?
*/ */
if (api_path && api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y) < 1) if (api_path && api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y) < 1)
goto done; goto done;
if (y==NULL) if (y==NULL)
goto ok; goto ok;
if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL) if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL)
goto done; goto done;
@ -203,7 +206,12 @@ expand_dbvar(void *h,
} }
if (xpath_vec_nsc(xcur, nsc, "%s", &xvec, &xlen, xpathcur) < 0) if (xpath_vec_nsc(xcur, nsc, "%s", &xvec, &xlen, xpathcur) < 0)
goto done; goto done;
bodystr0 = NULL; /* Assume sorted XML where duplicates are adjacent */ /* Loop for inserting into commands cvec.
* Detect duplicates: for ordered-by system assume list is ordered, so you need
* just remember previous
* but for ordered-by system, check the whole list
*/
bodystr0 = NULL;
for (i = 0; i < xlen; i++) { for (i = 0; i < xlen; i++) {
x = xvec[i]; x = xvec[i];
if (xml_type(x) == CX_BODY) if (xml_type(x) == CX_BODY)
@ -212,11 +220,27 @@ expand_dbvar(void *h,
bodystr = xml_body(x); bodystr = xml_body(x);
if (bodystr == NULL) if (bodystr == NULL)
continue; /* no body, cornercase */ continue; /* no body, cornercase */
if (bodystr0 && strcmp(bodystr, bodystr0) == 0) if ((y = xml_spec(x)) != NULL &&
continue; /* duplicate, assume sorted */ (yp = yang_parent_get(y)) != NULL &&
/* RFC3986 decode */ yang_keyword_get(yp) == Y_LIST &&
cvec_add_string(commands, NULL, bodystr); yang_find(yp, Y_ORDERED_BY, "user") != NULL){
bodystr0 = bodystr; /* Detect duplicates linearly in existing values */
{
cg_var *cv = NULL;
while ((cv = cvec_each(commands, cv)) != NULL)
if (strcmp(cv_string_get(cv), bodystr) == 0)
break;
if (cv == NULL)
cvec_add_string(commands, NULL, bodystr);
}
}
else{
if (bodystr0 && strcmp(bodystr, bodystr0) == 0)
continue; /* duplicate, assume sorted */
bodystr0 = bodystr;
/* RFC3986 decode */
cvec_add_string(commands, NULL, bodystr);
}
} }
ok: ok:
retval = 0; retval = 0;

View file

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
# CLI test for multi-key lists # CLI test for multi-key lists
# Had bugs in duplicate detection
# Magic line must be first in script (see README.md) # Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
@ -49,6 +50,20 @@ module $APPNAME{
} }
} }
} }
list y{
key "a b" ;
ordered-by user;
leaf a {
type string;
}
leaf b {
type enumeration{
enum v1;
enum v2;
enum v3;
}
}
}
} }
} }
EOF EOF
@ -91,6 +106,26 @@ expectfn "$clixon_cli -1 -f $cfg set ex x a 1 b v2" 0 ""
new "show conf" new "show conf"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' '^<rpc-reply><data><ex xmlns="urn:example:clixon"><x><a>1</a><b>v1</b></x><x><a>1</a><b>v2</b></x><x><a>1</a><b>v3</b></x><x><a>2</a><b>v1</b></x><x><a>2</a><b>v2</b></x><x><a>2</a><b>v3</b></x></ex></data></rpc-reply>]]>]]>$' expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' '^<rpc-reply><data><ex xmlns="urn:example:clixon"><x><a>1</a><b>v1</b></x><x><a>1</a><b>v2</b></x><x><a>1</a><b>v3</b></x><x><a>2</a><b>v1</b></x><x><a>2</a><b>v2</b></x><x><a>2</a><b>v3</b></x></ex></data></rpc-reply>]]>]]>$'
# ordered-by user
new "set 1 v1"
expectfn "$clixon_cli -1 -f $cfg set ex y a 1 b v1" 0 ""
new "set 2 v1"
expectfn "$clixon_cli -1 -f $cfg set ex y a 2 b v1" 0 ""
new "set 1 v2"
expectfn "$clixon_cli -1 -f $cfg set ex y a 1 b v2" 0 ""
new "set 1 v3"
expectfn "$clixon_cli -1 -f $cfg set ex y a 1 b v3" 0 ""
new "set 2 v2"
expectfn "$clixon_cli -1 -f $cfg set ex y a 2 b v2" 0 ""
new "show conf"
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' '^<rpc-reply><data><ex xmlns="urn:example:clixon"><x><a>1</a><b>v1</b></x><x><a>1</a><b>v2</b></x><x><a>1</a><b>v3</b></x><x><a>2</a><b>v1</b></x><x><a>2</a><b>v2</b></x><x><a>2</a><b>v3</b></x><y><a>1</a><b>v1</b></y><y><a>2</a><b>v1</b></y><y><a>1</a><b>v2</b></y><y><a>1</a><b>v3</b></y><y><a>2</a><b>v2</b></y></ex></data></rpc-reply>]]>]]>$'
if [ $BE -eq 0 ]; then if [ $BE -eq 0 ]; then
exit # BE exit # BE
fi fi