diff --git a/CHANGELOG.md b/CHANGELOG.md index 51fb753e..76f532d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Expected: September 2022 ### Corrected Bugs +* Fixed: [Issues with ietf-snmp modules](https://github.com/clicon/clixon/issues/353) * Fixed: [Missing/no namespace error in YANG augments with default values](https://github.com/clicon/clixon/issues/354) * Fixed: [Validation of mandatory in choice/case does not work in some cases](https://github.com/clicon/clixon/issues/349) diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index 281274d6..ce72361f 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -66,6 +66,11 @@ #define YANG_FLAG_CONFIG_VALUE 0x20 /* Ancestor config cache value */ #endif +#define YANG_FLAG_DISABLED 0x40 /* Disabled due to if-feature evaluate to false + * Transformed to ANYDATA but some code may need to check + * why it is an ANYDATA + */ + /* * Types */ diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index a1532442..20033bd7 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -2789,7 +2789,7 @@ ys_populate2(yang_stmt *ys, * @retval -1 Error * @retval 0 Feature not enabled: remove yt * @retval 1 OK - * @note On return 1 the over-lying function need to remove yt from its parent + * @note On return 0 the over-lying function need to remove yt from its parent * @note cannot use yang_apply here since child-list is modified (destructive) * @note if-features is parsed in full context here, previous restricted pass in ys_parse_sub */ @@ -2835,6 +2835,7 @@ yang_features(clicon_handle h, ys->ys_keyword = Y_ANYDATA; ys_freechildren(ys); ys->ys_len = 0; + yang_flag_set(ys, YANG_FLAG_DISABLED); break; } for (j=i+1; jys_len; j++) diff --git a/lib/src/clixon_yang_parse_lib.c b/lib/src/clixon_yang_parse_lib.c index 8d6947d4..01b16bc3 100644 --- a/lib/src/clixon_yang_parse_lib.c +++ b/lib/src/clixon_yang_parse_lib.c @@ -289,10 +289,13 @@ yang_augment_node(clicon_handle h, if (childkey != Y_ACTION && childkey != Y_NOTIFICATION && childkey != Y_UNKNOWN && childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST && childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE){ - clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s", + /* Special case if yc0 is disabled by if-feature=false, then it is transformed to ANYDATA + */ + if (yang_flag_get(yc0, YANG_FLAG_DISABLED) == 0) + clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s of type %s cannot be added to target node %s (see RFC 7950 Sec 17)", yang_argument_get(ys_module(ys)), + yang_argument_get(yc0), yang_key2str(childkey), - childkey, schema_nodeid); goto ok; } diff --git a/test/test_augment_default.sh b/test/test_augment_default.sh new file mode 100755 index 00000000..0a62f02e --- /dev/null +++ b/test/test_augment_default.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash +# yang augment and default values +# See https://github.com/clicon/clixon/issues/354 +# +# Magic line must be first in script (see README.md) +s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi + +APPNAME=example + +cfg=$dir/conf_yang.xml +fyang=$dir/augment.yang +fyang2=$dir/example.yang + +cat < $cfg + + $cfg + ietf-netconf:startup + $dir + ${YANG_INSTALLDIR} + $fyang + /usr/local/lib/$APPNAME/clispec + /usr/local/lib/$APPNAME/cli + $APPNAME + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + $dir + true + +EOF + +cat < $fyang2 +module example { + yang-version 1.1; + namespace "urn:example:clixon"; + prefix ex; + revision "2019-03-04"; + container table{ + } +} +EOF + +cat < $fyang +module augment { + yang-version 1.1; + namespace "urn:example:augment"; + prefix aug; + import example { + prefix ex; + } + revision "2019-03-04"; + augment "/ex:table" { + container map{ + leaf name{ + type string; + } + leaf enable { + type boolean; + default true; + } + } + } +} + +EOF + +cat < $dir/startup_db +<${DATASTORE_TOP}> + + + me + +
+ +EOF + +new "test params: -f $cfg" + +if [ $BE -ne 0 ]; then + new "kill old backend" + sudo clixon_backend -zf $cfg + if [ $? -ne 0 ]; then + err + fi + new "start backend -s startup -f $cfg" + start_backend -s startup -f $cfg +fi + +new "wait backend" +wait_backend + +new "cli show config startup" +#expectpart "$($clixon_cli -1 -f $cfg -l o show config xml)" 0 '' '' 'true' +expectpart "$($clixon_cli -1 -f $cfg -l o show config xml)" 0 '
' '' 'true' + +new "cli delete map name" +expectpart "$($clixon_cli -1 -f $cfg -l o delete table map name me)" 0 "" + +new "cli show config deleted" +#expectpart "$($clixon_cli -1 -f $cfg -l o show config xml)" 0 '
' '' 'true' +expectpart "$($clixon_cli -1 -f $cfg -l o show config xml)" 0 '
' '' 'true' + +new "cli set map name" +expectpart "$($clixon_cli -1 -f $cfg -l o set table map name x)" 0 "" + +new "cli show config set" +#expectpart "$($clixon_cli -1 -f $cfg -l o show config xml)" 0 '
' '' 'true' +expectpart "$($clixon_cli -1 -f $cfg -l o show config xml)" 0 '
' '' 'true' + +if [ $BE -ne 0 ]; then + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + # kill backend + stop_backend -f $cfg +fi + +rm -rf $dir + +new "endtest" +endtest