#!/usr/bin/env bash # Yang deviate tests # See RFC 7950 5.6.3 and 7.20.3 # Four examples: not supported, add, replace, delete # Also: # - keyword with/without string # - use grouping # 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 fyangbase=$dir/example-base.yang fyangdev=$dir/example-deviations.yang cat < $cfg $cfg ${YANG_INSTALLDIR} $dir $dir /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME 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; } EOF # Args: # 1: daytime implemented: true/false # 2: admin type default: true/false # 3: mustdate default: true/false # 4: maxelement of name-server is 1: true/false (if false the # is 3) function testrun() { daytime=$1 admindefault=$2 mustdate=$3 maxel1=$4 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 init -f $cfg" start_backend -s init -f "$cfg" fi new "wait backend" wait_backend new "Add user bob" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLObob]]>]]>" "]]>]]" if $mustdate; then # fail since there is neither date or daytime (delete rule) new "netconf validate expect error" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationoperation-failederrorFailed MUST xpath 'daytime or time' of 'system' in module example-base]]>]]>$" else new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "]]>]]" fi new "Add time" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "]]>]]" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "]]>]]" if $daytime; then # not-supported rule new "Add example-base daytime - supported" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOSept17]]>]]>" "]]>]]" else # Not supported new "Add example-base daytime - expect error not supported" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOSept17]]>]]>" "applicationunknown-elementdaytimeerrorFailed to find YANG spec of XML node: daytime with parent: system in namespace: urn:example:base]]>]]" fi # daytime supported new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" if $admindefault; then # add rule new "Get type admin expected" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^bobadmin]]>]]>$" else new "Get type none expected" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" fi # Add 2 name-servers new "Add two name-servers" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOaabb]]>]]>" "]]>]]" if $maxel1; then # add two and check if it fails new "netconf validate 2 element fail" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^protocoloperation-failedtoo-many-elementserror/system/name-server]]>]]>$" else new "netconf validate 2 elements ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "]]>]]" fi 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 } # testrun # 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; } } EOF new "1. Baseline: no deviations" testrun true false true true # 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:daytime { deviate "not-supported"; // Note a string } } EOF new "2. daytime not supported" testrun false false true true # Add 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:user/base:type { deviate add { default "admin"; } } } EOF new "3. deviate add, check admin default" testrun true true true true # Delete 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:name-server { deviate replace { max-elements 3; } } } EOF new "4. deviate replace" testrun true false true false # 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 { deviate delete { must "daytime or time"; } } } EOF new "5. deviate delete" testrun true false false true rm -rf "$dir" new "endtest" endtest