Skip to content

Commit

Permalink
Fixed: [cl:autocli-op hide has no effect in yang submodule](#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Nov 4, 2021
1 parent d335a72 commit 5297ebe
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Developers may need to change their code

### Corrected Bugs

* [cl:autocli-op hide has no effect in yang submodule](https://github.com/clicon/clixon/issues/282)
* [Doxygen - Typo in Input #275](https://github.com/clicon/clixon/issues/275)

## 5.3.0
Expand Down
11 changes: 11 additions & 0 deletions lib/src/clixon_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,14 @@ ys_populate_unique(clicon_handle h,
* RFC 7950 Sec 7.19:
* If no "argument" statement is present, the keyword expects no argument when
* it is used.
* Note there is some complexity in different yang modules with unknown-statements.
* y0) The location of the extension definition. E.g. extension autocli-op
* y1) The location of the unknown-statement (ys). This is for example: cl:autocli-op hide.
* Lookup of "cl" is lexically scoped in this context (to find (y0)).
* y2) The unknown statement may be used by uses/grouping of (y1). But "cl" is declared
* in y1 context. This is fixed by setting ys_mymodule to y1 which is then used in
* lookups such as in yang_extension_value().
* @see yang_extension_value Called on expanded YANG, eg in context of (y2)
*/
static int
ys_populate_unknown(clicon_handle h,
Expand All @@ -2376,6 +2384,8 @@ ys_populate_unknown(clicon_handle h,
clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\", module not found", prefix, id);
goto done;
}
/* To find right binding eg after grouping/uses */
ys->ys_mymodule = ys_module(ys);
if ((yext = yang_find(ymod, Y_EXTENSION, id)) == NULL){
clicon_err(OE_YANG, ENOENT, "Extension \"%s:%s\" not found", prefix, id);
goto done;
Expand Down Expand Up @@ -3572,6 +3582,7 @@ yang_anydata_add(yang_stmt *yp,
* // use extension value
* }
* @endcode
* @see ys_populate_unknown Called when parsing YANGo
*/
int
yang_extension_value(yang_stmt *ys,
Expand Down
10 changes: 7 additions & 3 deletions lib/src/clixon_yang_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ struct yang_stmt{

char *ys_argument; /* String / argument depending on keyword */
uint16_t ys_flags; /* Flags according to YANG_FLAG_MARK and others */
yang_stmt *ys_mymodule; /* Shortcut to "my" module. Augmented
nodes can belong to other
modules than the ancestor module */
yang_stmt *ys_mymodule; /* Shortcut to "my" module. Used by:
1) Augmented nodes "belong" to the module where the
augment is declared, which may be differnt from
the direct ancestor module
2) Unknown nodes "belong" to where the extension is
declared
*/
cg_var *ys_cv; /* cligen variable. See ys_populate()
Following stmts have cv:s:
leaf: for default value
Expand Down
55 changes: 54 additions & 1 deletion test/test_cli_auto_extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ wait_backend

function testparam()
{

# Try hidden parameter list
new "query table parameter hidden"
expectpart "$(echo "set table ?" | $clixon_cli -f $cfg 2>&1)" 0 "set table" "<cr>" --not-- "parameter"
Expand Down Expand Up @@ -282,6 +281,60 @@ EOF
new "Test hidden parameter in table/param/value augment"
testvalue

# Example using imported module where clixon-lib is NOT declared in main module
# see discussion in ys_populate_unknown (y1 vs y2) and
# https://github.com/clicon/clixon/issues/282
cat <<EOF > $fyang
module example {
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import example-augment{
prefix aug;
}
container table{
list parameter{
key name;
leaf name{
type string;
}
uses aug:pg;
}
}
}
EOF

# Use this as grouping (not annotate)
cat <<EOF > $fyang2
module example-augment {
namespace "urn:example:augment";
prefix aug;
import clixon-lib{
prefix cl;
}
grouping pg {
cl:autocli-op hide; /* This is the extension */
leaf value{
description "a value";
type string;
}
list index{
key i;
leaf i{
type string;
}
leaf iv{
type string;
}
}
}
}
EOF

new "Test hidden parameter in imported module"
testparam

new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
Expand Down

0 comments on commit 5297ebe

Please sign in to comment.