From 6d401cb9d15fd3b477a6cd99fb239f4469d4bc85 Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Sat, 29 Jul 2017 11:26:34 +0200 Subject: [PATCH 1/2] (sub)modules to schema nodeid:s --- lib/src/clixon_yang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 92585d2a..f61a6691 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -496,7 +496,7 @@ schema_nodeid_stmt(yang_node *yn, for (i=0; iyn_len; i++){ ys = yn->yn_stmt[i]; - if (!yang_schemanode(ys)) + if (!(yang_schemanode(ys) || ys->ys_keyword == Y_MODULE || ys->ys_keyword == Y_SUBMODULE)) continue; /* some keys dont have arguments, match on key */ if (ys->ys_keyword == Y_INPUT || ys->ys_keyword == Y_OUTPUT){ From d8065551b65b41fc3748611a74576fdf616e8371 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Thu, 3 Aug 2017 22:35:02 +0200 Subject: [PATCH 2/2] cli_copy config bug; allow non-api-path expand_dbvar() --- CHANGELOG.md | 2 +- apps/cli/cli_common.c | 1 + apps/cli/cli_show.c | 5 ++++- example/routing_cli.cli | 2 +- lib/src/clixon_xml_map.c | 29 +++++++++++++++++------------ test/test_cli.sh | 7 +++++++ 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f20b97b..0983d910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index c3a4314b..0c76b1ff 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -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); diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 8d42a328..82648bff 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -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); diff --git a/example/routing_cli.cli b/example/routing_cli.cli index 2edacd01..1b36c611 100644 --- a/example/routing_cli.cli +++ b/example/routing_cli.cli @@ -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 of interface to copy from") to("Copy to interface") ("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s=%s]","name","name","toname"); + ("name of interface to copy from") to("Copy to interface") ("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s=%s]","name","name","toname"); } } discard("Discard edits (rollback 0)"), discard_changes(); diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 007c68db..2f1ad129 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1725,18 +1725,22 @@ api_path2xml_vec(char **vec, /* The value is a list of keys: [ ]* */ if ((cvk = yang_arg2cvec(ykey, " ")) == NULL) goto done; - if (restval==NULL){ - clicon_err(OE_XML, 0, "malformed key, expected '='"); - 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 '='"); + // 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; } diff --git a/test/test_cli.sh b/test/test_cli.sh index de1674ff..e9ca8d3c 100755 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -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" "^$"