Skip to content

Commit

Permalink
Fixed: [Autocli: error when empty YANG group and grouping-treeref=true](
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Dec 5, 2024
1 parent 21476c1 commit 3332dfe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Developers may need to change their code

### Corrected Bugs

* Fixed: [Autocli: error when empty YANG group and grouping-treeref=true](https://github.com/clicon/clixon/issues/579)
* Fixed: [Mem error when more multiple uses on top level with multiple statements in grouping](https://github.com/clicon/clixon/issues/583)
* Fixed: [Change CLICON_NETCONF_DUPLICATE_ALLOW to remove duplicates](https://github.com/clicon/clixon-controller/issues/160)
* Fixed: Segv in canonical xpath transform
Expand Down
59 changes: 38 additions & 21 deletions apps/cli/cli_generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,29 @@ yang2cli_post(clixon_handle h,
return retval;
}

/*! Helper function: add parsetree header and add parsetree
*/
static int
ph_add_set(cligen_handle h,
char *treename,
parse_tree *pt)
{
int retval = -1;
pt_head *ph;

if ((ph = cligen_ph_add(h, treename)) == NULL){
clixon_err(OE_UNIX, 0, "cligen_ph_add");
goto done;
}
if (cligen_ph_parsetree_set(ph, pt) < 0){
clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
goto done;
}
retval = 0;
done:
return retval;
}

/*! Generate clispec for all modules in a grouping
*
* Called in cli main function for top-level yangs. But may also be called dynamically for
Expand All @@ -1625,7 +1648,7 @@ yang2cli_post(clixon_handle h,
* @see yang2cli_yspec and yang2cli_stmt for original
* XXX merge with yang2cli_yspec
*/
int
static int
yang2cli_grouping(clixon_handle h,
yang_stmt *ys,
char *treename)
Expand All @@ -1634,7 +1657,6 @@ yang2cli_grouping(clixon_handle h,
parse_tree *pt0 = NULL;
parse_tree *pt = NULL;
yang_stmt *yc;
pt_head *ph;
cbuf *cb = NULL;
int treeref_state = 0;
char *prefix;
Expand Down Expand Up @@ -1668,8 +1690,13 @@ yang2cli_grouping(clixon_handle h,
if (yang2cli_stmt(h, yc, 1, cb) < 0)
goto done;
}
if (cbuf_len(cb) == 0)
goto empty;
if (cbuf_len(cb) == 0){
/* Create empty tree */
if (ph_add_set(cli_cligen(h), treename, pt0) < 0)
goto done;
pt0 = NULL;
goto ok;
}
/* Note Tie-break of same top-level symbol: prefix is NYI
* Needs to move cligen_parse_str() call here instead of later
*/
Expand Down Expand Up @@ -1726,15 +1753,10 @@ yang2cli_grouping(clixon_handle h,
if (cligen_expandv_str2fn(pt0, (expandv_str2fn_t*)clixon_str2fn, NULL) < 0)
goto done;
/* Append cligen tree and name it */
if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){
clixon_err(OE_UNIX, 0, "cligen_ph_add");
if (ph_add_set(cli_cligen(h), treename, pt0) < 0)
goto done;
}
if (cligen_ph_parsetree_set(ph, pt0) < 0){
clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
goto done;
}
pt0 = NULL;
ok:
retval = 1;
done:
if (pt)
Expand Down Expand Up @@ -1769,7 +1791,6 @@ yang2cli_yspec(clixon_handle h,
parse_tree *pt0 = NULL;
parse_tree *pt = NULL;
yang_stmt *ymod;
pt_head *ph;
int enable;
cbuf *cb = NULL;
char *prefix;
Expand Down Expand Up @@ -1858,14 +1879,8 @@ yang2cli_yspec(clixon_handle h,
if (cligen_expandv_str2fn(pt0, (expandv_str2fn_t*)clixon_str2fn, NULL) < 0)
goto done;
/* Append cligen tree and name it */
if ((ph = cligen_ph_add(cli_cligen(h), treename)) == NULL){
clixon_err(OE_UNIX, 0, "cligen_ph_add");
goto done;
}
if (cligen_ph_parsetree_set(ph, pt0) < 0){
clixon_err(OE_UNIX, 0, "cligen_ph_parsetree_set");
if (ph_add_set(cli_cligen(h), treename, pt0) < 0)
goto done;
}
pt0 = NULL;
#if 0
if (clicon_data_int_get(h, "autocli-print-debug") == 1){
Expand Down Expand Up @@ -1956,8 +1971,10 @@ yang2cli_grouping_wrap(cligen_handle ch,
goto ok;
if ((ret = yang2cli_grouping(h, ygrouping, name)) < 0)
goto done;
if (ret == 0) /* tree empty */
goto ok;
if (ret == 0){ /* tree empty */
clixon_err(OE_UNIX, 0, "Tree empty %s", name);
goto done;
}
*namep = strdup(name);
ok:
retval = 0;
Expand Down
1 change: 0 additions & 1 deletion apps/cli/cli_generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
*/
int yang2cli_cmd_encode(cbuf *cb, const char *delim, char *tag, char *domain, char *spec, char *modname, char *id);
int yang2cli_cmd_decode(char *cmd, const char *delim, char **tag, char **domain, char **spec, char **modname, char **id);
int yang2cli_grouping(clixon_handle h, yang_stmt *ys, char *treename);
int yang2cli_yspec(clixon_handle h, yang_stmt *yspec, char *treename);
int yang2cli_grouping_wrap(cligen_handle ch, char *name, cvec *cvt, void *arg, char **namep);
int yang2cli_init(clixon_handle h);
Expand Down
5 changes: 5 additions & 0 deletions test/test_autocli_grouping.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ module example {
type string;
}
}
grouping pg5 {
description "Empty, see https://github.com/clicon/clixon/issues/579";
action reset;
}
container table{
list parameter{
key name;
Expand All @@ -119,6 +123,7 @@ module example {
}
uses pg1;
uses ext:pg2;
uses pg5;
}
}
uses pg1;
Expand Down

0 comments on commit 3332dfe

Please sign in to comment.