#!/usr/bin/env bash # Yang deviate tests # See RFC 7950 5.6.3 and 7.20.3 # Four examples: not supported, add, replace, delete # 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 /usr/local/share/clixon $dir $IETFRFC $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 true EOF cat < $fyangbase module example-base{ yang-version 1.1; prefix base; namespace "urn:example:base"; container system { must "daytime or time"; leaf daytime{ /* not supported removes this */ type string; } list name-server { key name; leaf name { type string; } } list user { key name; leaf name { type string; } leaf type { type string; /* add rule adds default here */ } } } } EOF # Args: # 0: daytime implemented: true/false # 1: admin type default: true/false function testrun() { daytime=$1 admindefault=$2 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 if ! $daytime; then # Not supported - dont continue new "Add example-base daytime - should not be 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]]>]]" else new "Add example-base daytime - supported" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOSept17]]>]]>" "]]>]]" new "Add user bob" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLObob]]>]]>" "]]>]]" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" if $admindefault; then new "Get type admin expected" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^bobadmin]]>]]>$" # XXX Cannot select a default value?? # expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" foo else new "Get type none expected" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" fi 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 "daytime supported" testrun true false # 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; } } EOF new "daytime not supported" testrun false false # 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"; // new users are 'admin' by default } } } EOF new "deviate add, check admin default" testrun true true rm -rf "$dir" new "endtest" endtest