diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index 5ea5b340..b21dc430 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -94,7 +94,10 @@ * augment/grouping */ #define YANG_FLAG_MYMODULE 0x800 /* Use external map to access my-module for * UNKNOWNS and augment/grouping */ -#define YANG_FLAG_NOORIG 0x1000 /* Node different from orig, do not use orig-link */ +#define YANG_FLAG_REFINE 0x1000 /* In derived trees from grouping and augments, this node + * may be different from orig, therefore do not use link to + * original. May also be due to deviations of derived trees + */ /* * Types diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index f2875739..affd9068 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -2416,6 +2416,8 @@ yang_deviation(yang_stmt *ys, /* Make a copy of deviate child and insert. */ if ((yc1 = ys_dup(yc)) == NULL) goto done; + if (yang_apply(yc1, -1, (yang_applyfn_t*)yang_flag_set, -1, (void*)YANG_FLAG_REFINE) < 0) + goto done; if (yn_insert(ytarget, yc1) < 0) goto done; } @@ -2449,7 +2451,8 @@ yang_deviation(yang_stmt *ys, /* Make a copy of deviate child and insert. */ if ((yc1 = ys_dup(yc)) == NULL) goto done; - yang_flag_set(yc1, YANG_FLAG_NOORIG); + if (yang_apply(yc1, -1, (yang_applyfn_t*)yang_flag_set, -1, (void*)YANG_FLAG_REFINE) < 0) + goto done; if (yn_insert(ytarget, yc1) < 0) goto done; } diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index f8cedd21..22b6c62d 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -1486,7 +1486,7 @@ yang_type_get(yang_stmt *ys, clixon_err(OE_DB, ENOENT, "mandatory type object is not found"); goto done; } - if ((yorig = yang_orig_get(ys)) != NULL && yang_flag_get(ytype, YANG_FLAG_NOORIG) == 0){ + if ((yorig = yang_orig_get(ys)) != NULL && yang_flag_get(ytype, YANG_FLAG_REFINE) == 0){ ys = yorig; if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){ clixon_err(OE_DB, ENOENT, "mandatory type object is not found"); diff --git a/test/test_openconfig.sh b/test/test_openconfig.sh index 90ec0e92..1c6911a8 100755 --- a/test/test_openconfig.sh +++ b/test/test_openconfig.sh @@ -81,56 +81,6 @@ EOF fi done -# The following test is a special case: A deviation of a grouped type did not appear in -# type resolution -f=$dir/my.yang -cat < $f -module my { - namespace "urn:example:clixon"; - prefix "ex"; - - import "openconfig-network-instance" { - prefix "oc-netinst"; - } - deviation "/oc-netinst:network-instances/oc-netinst:network-instance/oc-netinst:protocols/oc-netinst:protocol/oc-netinst:isis/oc-netinst:interfaces/oc-netinst:interface/oc-netinst:levels/oc-netinst:level/oc-netinst:afi-safi/oc-netinst:af/oc-netinst:config/oc-netinst:metric" { - description "metric range is restricted"; - deviate "replace" { - type "union" { - type "uint32"; - type "enumeration" { - enum "MYTEXT"; - } - } - default "MYTEXT"; - } - } -} -EOF - -modname=$(basename $f | awk -F "." '{print $1}') -# Generate autocli for these modules -AUTOCLI=$(autocli_config openconfig-* kw-nokey false) - -cat < $cfg - - $cfg - ietf-netconf:startup - ${OPENCONFIG} - ${YANG_INSTALLDIR} - true - /usr/local/lib/$APPNAME/clispec - /usr/local/lib/$APPNAME/cli - $APPNAME - /usr/local/var/run/$APPNAME.sock - /usr/local/var/run/$APPNAME.pidfile - $dir - ${AUTOCLI} - -EOF - -new "deviation: $clixon_cli -D $DBG -1f $cfg -y $f show version" -expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}" - rm -rf $dir new "endtest" diff --git a/test/test_yang_deviation.sh b/test/test_yang_deviation.sh index de4586fa..84aad67f 100755 --- a/test/test_yang_deviation.sh +++ b/test/test_yang_deviation.sh @@ -32,38 +32,42 @@ EOF cat < $fyangbase module example-base{ - yang-version 1.1; - prefix base; - namespace "urn:example:base"; - grouping system-top { - container system { - must "daytime or time"; /* deviate delete removes this */ - leaf daytime{ /* deviate not-supported removes this */ - type string; - } - leaf time{ - type string; - } - list name-server { - max-elements 1; /* deviate replace replaces to "max.elements 3" here */ - key name; - leaf name { - type string; - } - } - list user { - key name; - leaf name { - type string; - } - leaf type { - type string; - /* deviate add adds "default admin" here */ - } - } - } - } - uses system-top; + yang-version 1.1; + prefix base; + namespace "urn:example:base"; + grouping system-top { + container system { + must "daytime or time"; /* deviate delete removes this */ + leaf daytime{ /* deviate not-supported removes this */ + type string; + } + leaf time{ + type string; + } + list name-server { + max-elements 1; /* deviate replace replaces to "max.elements 3" here */ + key name; + leaf name { + type string; + } + } + list user { + key name; + leaf name { + type string; + } + leaf type { + type string; + /* deviate add adds "default admin" here */ + } + } + leaf my { + /* deviate replaces with int and default -42 */ + type uint16; + } + } + } + uses system-top; } EOF @@ -242,6 +246,69 @@ EOF new "5. deviate delete" testrun true false false true +# Replace example from RFC 7950 Sec 7.20.3.3 +cat < $fyangdev +module example-deviations{ + yang-version 1.1; + prefix md; + namespace "urn:example:deviations"; + import example-base { + prefix base; + } + deviation /base:system/base:my { + deviate replace { + type int8; + } + } + deviation /base:system/base:my { + deviate add { + default -42; + } + } +} +EOF + +new "6. deviate replace default" + +if [ "$BE" -ne 0 ]; then + new "kill old backend" + sudo clixon_backend -zf "$cfg" + if [ $? -ne 0 ]; then + err + fi + new "start backend -s init -f $cfg" + start_backend -s init -f "$cfg" +fi + +new "wait backend" +wait_backend + +new "show default value, expect deviated" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "-42" + +new "set negative value" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "Sept17-77" "" "" + +new "netconf validate ok" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" + +new "set large value" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "98735" "" "" + +new "netconf validate expect fail" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationbad-elementmyerrorNumber 98735 out of range: -128 - 127" + +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"