diff --git a/CHANGELOG.md b/CHANGELOG.md index 21befc09..b5bcaaad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c index 0420b13f..a91933cb 100644 --- a/apps/cli/cli_generate.c +++ b/apps/cli/cli_generate.c @@ -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 @@ -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) @@ -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; @@ -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 */ @@ -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) @@ -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; @@ -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"); + 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; #if 0 if (clicon_data_int_get(h, "autocli-print-debug") == 1){ @@ -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; diff --git a/apps/cli/cli_generate.h b/apps/cli/cli_generate.h index c4995a24..2f365728 100644 --- a/apps/cli/cli_generate.h +++ b/apps/cli/cli_generate.h @@ -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); diff --git a/test/test_autocli_grouping.sh b/test/test_autocli_grouping.sh index 95ad8385..b24e85e7 100755 --- a/test/test_autocli_grouping.sh +++ b/test/test_autocli_grouping.sh @@ -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; @@ -119,6 +123,7 @@ module example { } uses pg1; uses ext:pg2; + uses pg5; } } uses pg1;