cli_copy config bug; allow non-api-path expand_dbvar()
This commit is contained in:
parent
ed1c1e1495
commit
d8065551b6
6 changed files with 31 additions and 15 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
### Known issues
|
||||
* Please use text datastore, key-value datastore no up-to-date
|
||||
* Restconf RPC does not encode output correct
|
||||
* leafref occuring within lists: cli expansion does not work
|
||||
|
||||
### Major changes:
|
||||
* Added support for YANG anyxml.
|
||||
|
|
|
|||
|
|
@ -1195,6 +1195,7 @@ cli_copy_config(clicon_handle h,
|
|||
goto done;
|
||||
if (xml_copy(x1, x2) < 0)
|
||||
goto done;
|
||||
xml_name_set(x2, "config");
|
||||
cprintf(cb, "/%s", keyname);
|
||||
if ((x = xpath_first(x2, cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "Field %s not found in copy tree", keyname);
|
||||
|
|
|
|||
|
|
@ -165,6 +165,9 @@ expand_dbvar(void *h,
|
|||
if ((xtop = xml_new("config", NULL)) == NULL)
|
||||
goto done;
|
||||
xbot = xtop;
|
||||
/* This is primarily to get "y", XXX xbot can be broken (contains =%s)
|
||||
* xpath2xml would have worked!!
|
||||
*/
|
||||
if (api_path && api_path2xml(api_path, yspec, xtop, 0, &xbot, &y) < 0)
|
||||
goto done;
|
||||
/* Special case for leafref. Detect leafref via Yang-type,
|
||||
|
|
@ -182,7 +185,7 @@ expand_dbvar(void *h,
|
|||
goto done;
|
||||
}
|
||||
xpathcur = ypath->ys_argument;
|
||||
if (xml_merge(xt, xtop, yspec) < 0)
|
||||
if (xml_merge(xt, xtop, yspec) < 0) /* Merge xtop into xt */
|
||||
goto done;
|
||||
if ((xcur = xpath_first(xt, xpath)) == NULL){
|
||||
clicon_err(OE_DB, 0, "xpath %s should return merged content", xpath);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ debug("Debugging parts of the system"), cli_debug_cli((int32)1);{
|
|||
}
|
||||
copy("Copy and create a new object") {
|
||||
interface("Copy interface"){
|
||||
<name:string expand_dbvar("candidate","/interfaces/interface/name")>("name of interface to copy from") to("Copy to interface") <toname:string>("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s=%s]","name","name","toname");
|
||||
<name:string expand_dbvar("candidate","/interfaces/interface=%s/name")>("name of interface to copy from") to("Copy to interface") <toname:string>("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s=%s]","name","name","toname");
|
||||
}
|
||||
}
|
||||
discard("Discard edits (rollback 0)"), discard_changes();
|
||||
|
|
|
|||
|
|
@ -1725,18 +1725,22 @@ api_path2xml_vec(char **vec,
|
|||
/* The value is a list of keys: <key>[ <key>]* */
|
||||
if ((cvk = yang_arg2cvec(ykey, " ")) == NULL)
|
||||
goto done;
|
||||
if (restval==NULL){
|
||||
clicon_err(OE_XML, 0, "malformed key, expected '=<restval>'");
|
||||
goto done;
|
||||
}
|
||||
if (valvec)
|
||||
if (valvec){
|
||||
free(valvec);
|
||||
if ((valvec = clicon_strsep(restval, ",", &nvalvec)) == NULL)
|
||||
goto done;
|
||||
|
||||
if (cvec_len(cvk) != nvalvec){
|
||||
clicon_err(OE_XML, errno, "List %s key length mismatch", name);
|
||||
goto done;
|
||||
valvec = NULL;
|
||||
}
|
||||
if (restval==NULL){
|
||||
// XXX patch to allow for lists without restval tobe backward compat
|
||||
// clicon_err(OE_XML, 0, "malformed key, expected '=<restval>'");
|
||||
// goto done;
|
||||
}
|
||||
else{
|
||||
if ((valvec = clicon_strsep(restval, ",", &nvalvec)) == NULL)
|
||||
goto done;
|
||||
if (cvec_len(cvk) != nvalvec){
|
||||
clicon_err(OE_XML, errno, "List %s key length mismatch", name);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
cvi = NULL;
|
||||
/* create list object */
|
||||
|
|
@ -1747,13 +1751,14 @@ api_path2xml_vec(char **vec,
|
|||
/* Create keys */
|
||||
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
|
||||
keyname = cv_string_get(cvi);
|
||||
val2 = valvec[j++];
|
||||
|
||||
if ((xn = xml_new(keyname, x)) == NULL)
|
||||
goto done;
|
||||
xml_type_set(xn, CX_ELMNT);
|
||||
if ((xb = xml_new("body", xn)) == NULL)
|
||||
goto done;
|
||||
xml_type_set(xb, CX_BODY);
|
||||
val2 = valvec?valvec[j++]:NULL;
|
||||
if (xml_value_set(xb, val2) <0)
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ expectfn "$clixon_cli -1f $clixon_cf set interfaces interface eth/0/0" "^$"
|
|||
new "cli show configuration"
|
||||
expectfn "$clixon_cli -1f $clixon_cf show conf cli" "^interfaces interface name eth/0/0" "interfaces interface enabled true$"
|
||||
|
||||
|
||||
|
||||
new "cli failed validate"
|
||||
expectfn "$clixon_cli -1f $clixon_cf -l o validate" "Missing mandatory variable"
|
||||
|
||||
|
|
@ -63,6 +65,9 @@ expectfn "$clixon_cli -1f $clixon_cf -l o delete interfaces interface eth/0/0 de
|
|||
new "cli show xpath no description"
|
||||
expectfn "$clixon_cli -1f $clixon_cf -l o show xpath /interfaces/interface/description" "^$"
|
||||
|
||||
new "cli copy interface"
|
||||
expectfn "$clixon_cli -1f $clixon_cf copy interface eth/0/0 to eth99" "^$"
|
||||
|
||||
new "cli success validate"
|
||||
expectfn "$clixon_cli -1f $clixon_cf -l o validate" "^$"
|
||||
|
||||
|
|
@ -72,6 +77,8 @@ expectfn "$clixon_cli -1f $clixon_cf -l o commit" "^$"
|
|||
new "cli save"
|
||||
expectfn "$clixon_cli -1f $clixon_cf -l o save /tmp/foo" "^$"
|
||||
|
||||
|
||||
|
||||
new "cli delete all"
|
||||
expectfn "$clixon_cli -1f $clixon_cf -l o delete all" "^$"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue