#!/usr/bin/env bash # Yang extensions and unknown statements. # 1) First test syntax # Assuming the following extension definition: # prefix p; # extension keyw { # argument arg; # optional # } # there are four forms of unknown statement as follows: # p:keyw; # p:keyw arg; # p:keyw { stmt;* } # p:keyw arg { stmt;* } # # 2) The extensions results in in a node data definition. # Second, the example is run without the extension enabled, then it is enabled. # # @see test_cli_auto_extension # 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/$APPNAME.yang cat < $cfg $cfg /usr/local/share/clixon $dir $IETFRFC $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli /usr/local/lib/$APPNAME/netconf /usr/local/lib/$APPNAME/backend $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME true EOF cat < $fyang module $APPNAME{ yang-version 1.1; prefix ex; namespace "urn:example:clixon"; extension e1 { description "no argument, no statements"; } extension e2 { description "with argument, no statements"; argument arg; } extension e3 { description "no argument, with statement"; } extension e4 { description "with argument, with statement"; argument arg; } grouping foo { leaf foo{ type string; } } grouping bar { leaf bar{ type string; } } ex:e1; ex:e2 arg1; ex:e3 { uses foo; } ex:e4 arg1{ uses bar; } extension posix-pattern { argument "pattern"; } typedef dotted-quad { description "Only present for complex parsing of unknown-stmt"; type string { pattern "[a-f]" + "[0-9]"; ex:posix-pattern // Strictly this comment is not supported if you see RFC syntax with only a SEP // in unknwon-stmt: identifier [sep string] '[f-w]' + '[o-q]'; } } } EOF XML='a string' 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 # The main example implements ex:e4 new "Add extension foo (not implemented)" expecteof "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLOa string]]>]]>" "^applicationunknown-elementfooerror" new "Add extension bar (is implemented)" expecteof "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLOa string]]>]]>" "^]]>]]>" new "netconf get config" expecteof "$clixon_netconf -qf $cfg -D $DBG" 0 "$DEFAULTHELLO]]>]]>" "^a string]]>]]>" 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 sudo pkill -u root -f clixon_backend fi rm -rf $dir new "endtest" endtest