Sorting error cornercase with invalid two choices, and also sort attributes first.
This commit is contained in:
parent
b31297cb21
commit
e1bccfa2a7
5 changed files with 45 additions and 15 deletions
|
|
@ -1130,8 +1130,9 @@ _json_parse(char *str,
|
||||||
cxobj *x;
|
cxobj *x;
|
||||||
cbuf *cberr = NULL;
|
cbuf *cberr = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
int failed = 0; /* yang assignment */
|
||||||
|
|
||||||
clicon_debug(1, "%s %s", __FUNCTION__, str);
|
clicon_debug(1, "%s %d %s", __FUNCTION__, yb, str);
|
||||||
jy.jy_parse_string = str;
|
jy.jy_parse_string = str;
|
||||||
jy.jy_linenum = 1;
|
jy.jy_linenum = 1;
|
||||||
jy.jy_current = xt;
|
jy.jy_current = xt;
|
||||||
|
|
@ -1174,12 +1175,16 @@ _json_parse(char *str,
|
||||||
case YB_NONE:
|
case YB_NONE:
|
||||||
break;
|
break;
|
||||||
case YB_PARENT:
|
case YB_PARENT:
|
||||||
if (xml_spec_populate0_parent(x, NULL) < 0)
|
if ((ret = xml_spec_populate0_parent(x, xerr)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
if (ret == 0)
|
||||||
|
failed++;
|
||||||
break;
|
break;
|
||||||
case YB_TOP:
|
case YB_TOP:
|
||||||
if (xml_spec_populate0(x, yspec, NULL) < 0)
|
if (xml_spec_populate0(x, yspec, xerr) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
if (ret == 0)
|
||||||
|
failed++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Now find leafs with identityrefs (+transitive) and translate
|
/* Now find leafs with identityrefs (+transitive) and translate
|
||||||
|
|
@ -1191,7 +1196,7 @@ _json_parse(char *str,
|
||||||
}
|
}
|
||||||
if (xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0)
|
if (xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 1;
|
retval = (failed==0) ? 1 : 0;
|
||||||
done:
|
done:
|
||||||
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
|
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
|
||||||
if (cberr)
|
if (cberr)
|
||||||
|
|
|
||||||
|
|
@ -196,9 +196,22 @@ xml_cmp(cxobj *x1,
|
||||||
int nr2 = 0;
|
int nr2 = 0;
|
||||||
cxobj *x1b;
|
cxobj *x1b;
|
||||||
cxobj *x2b;
|
cxobj *x2b;
|
||||||
|
enum cxobj_type xt1;
|
||||||
|
enum cxobj_type xt2;
|
||||||
|
|
||||||
if (x1==NULL || x2==NULL)
|
if (x1==NULL || x2==NULL)
|
||||||
goto done; /* shouldnt happen */
|
goto done; /* shouldnt happen */
|
||||||
|
/* Sort according to attributes first */
|
||||||
|
if ((xt1 = xml_type(x1)) != (xt2 = xml_type(x2))){
|
||||||
|
if (xt1 == CX_ATTR){
|
||||||
|
equal = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
else if (xt2 == CX_ATTR){
|
||||||
|
equal = 1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
y1 = xml_spec(x1);
|
y1 = xml_spec(x1);
|
||||||
y2 = xml_spec(x2);
|
y2 = xml_spec(x2);
|
||||||
if (same){
|
if (same){
|
||||||
|
|
@ -301,10 +314,14 @@ xml_cmp(cxobj *x1,
|
||||||
} /* while cvi */
|
} /* while cvi */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
/* This is a very special case such as for two choices - which is not validation correct, but we
|
||||||
|
should sort them according to nr1, nr2 since their yang is equal order */
|
||||||
|
if (same)
|
||||||
|
equal = nr1-nr2;
|
||||||
break;
|
break;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
done:
|
done:
|
||||||
clicon_debug(2, "%s %s %s %d nr: %d %d yi: %d %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal, nr1, nr2, yi1, yi2);
|
clicon_debug(2, "%s %s %s eq:%d nr: %d %d yi: %d %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal, nr1, nr2, yi1, yi2);
|
||||||
return equal;
|
return equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,14 +119,16 @@ fi
|
||||||
new "waiting"
|
new "waiting"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "kill old restconf daemon"
|
if [ $RC -ne 0 ]; then
|
||||||
sudo pkill -u $wwwuser -f clixon_restconf
|
new "kill old restconf daemon"
|
||||||
|
sudo pkill -u $wwwuser -f clixon_restconf
|
||||||
|
|
||||||
new "start restconf daemon"
|
new "start restconf daemon"
|
||||||
start_restconf -f $cfg
|
start_restconf -f $cfg
|
||||||
|
|
||||||
new "waiting"
|
new "waiting"
|
||||||
wait_restconf
|
wait_restconf
|
||||||
|
fi
|
||||||
|
|
||||||
# First vanilla (protocol) case
|
# First vanilla (protocol) case
|
||||||
new "netconf validate empty"
|
new "netconf validate empty"
|
||||||
|
|
@ -279,8 +281,10 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
|
||||||
new "netconf validate multiple error"
|
new "netconf validate multiple error"
|
||||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>mc</bad-element></error-info><error-severity>error</error-severity><error-message>Element in choice statement already exists</error-message></rpc-error></rpc-reply>]]>]]>$'
|
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>mc</bad-element></error-info><error-severity>error</error-severity><error-message>Element in choice statement already exists</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||||
|
|
||||||
new "Kill restconf daemon"
|
if [ $RC -ne 0 ]; then
|
||||||
stop_restconf
|
new "Kill restconf daemon"
|
||||||
|
stop_restconf
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $BE -eq 0 ]; then
|
if [ $BE -eq 0 ]; then
|
||||||
exit # BE
|
exit # BE
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,11 @@ expectpart "$(curl -s -i -X DELETE http://localhost/restconf/data/example:crypt
|
||||||
|
|
||||||
# 2. set identity in other module with restconf , read it with restconf and netconf
|
# 2. set identity in other module with restconf , read it with restconf and netconf
|
||||||
new "restconf add POST instead of PUT (should fail)"
|
new "restconf add POST instead of PUT (should fail)"
|
||||||
expectpart "$(curl -s -i -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:crypto -d '{"example:crypto":"example-des:des3"}')" 0 'HTTP/1.1 400 Bad Request' '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"unknown-element","error-info":{"bad-element":"crypto"},"error-severity":"error","error-message":"Leaf contains sub-element"}}}'
|
expectpart "$(curl -s -i -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/example:crypto -d '{"example:crypto":"example-des:des3"}')" 0 'HTTP/1.1 400 Bad Request' '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"bad-element","error-info":{"bad-element":"crypto"},"error-severity":"error","error-message":"Missing matching yang node"}}}'
|
||||||
|
|
||||||
|
# Alternative error:
|
||||||
|
#'{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"unknown-element","error-info":{"bad-element":"crypto"},"error-severity":"error","error-message":"Leaf contains sub-element"}}}'
|
||||||
|
|
||||||
new "restconf add other (des) identity using POST"
|
new "restconf add other (des) identity using POST"
|
||||||
expectpart "$(curl -s -i -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/data -d '{"example:crypto":"example-des:des3"}')" 0 'HTTP/1.1 201 Created' 'Location: http://localhost/restconf/data/example:crypto'
|
expectpart "$(curl -s -i -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/data -d '{"example:crypto":"example-des:des3"}')" 0 'HTTP/1.1 201 Created' 'Location: http://localhost/restconf/data/example:crypto'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ new "restconf PUT list-list"
|
||||||
expecteq "$(curl -s -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/list:c/a=x,y/e=z -d '{"list:e":{"f":"z","nonkey":"0"}}')" 0 ''
|
expecteq "$(curl -s -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/list:c/a=x,y/e=z -d '{"list:e":{"f":"z","nonkey":"0"}}')" 0 ''
|
||||||
|
|
||||||
new "restconf PUT change list-lst entry (wrong keys)(expect fail)"
|
new "restconf PUT change list-lst entry (wrong keys)(expect fail)"
|
||||||
expecteq "$(curl -s -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/list:c/a=x,y/e=z -d '{"list:e":{"f":"wrong","nonley":"0"}}')" 0 '{"ietf-restconf:errors":{"error":{"error-type":"protocol","error-tag":"operation-failed","error-severity":"error","error-message":"api-path keys do not match data keys"}}}
'
|
expecteq "$(curl -s -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/list:c/a=x,y/e=z -d '{"list:e":{"f":"wrong","nonkey":"0"}}')" 0 '{"ietf-restconf:errors":{"error":{"error-type":"protocol","error-tag":"operation-failed","error-severity":"error","error-message":"api-path keys do not match data keys"}}}
'
|
||||||
|
|
||||||
new "restconf PUT list-list sub non-key"
|
new "restconf PUT list-list sub non-key"
|
||||||
expecteq "$(curl -s -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/list:c/a=x,y/e=z/nonkey -d '{"list:nonkey":"u"}')" 0 ''
|
expecteq "$(curl -s -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/list:c/a=x,y/e=z/nonkey -d '{"list:nonkey":"u"}')" 0 ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue