#!/usr/bin/env bash # Tests for @datamodel tree references # See also test_cli_auto_genmodel.sh # XXX: cant do "show leaf" only "show leaf " # 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 # include err() and new() functions and creates $dir cfg=$dir/conf_yang.xml fyang=$dir/$APPNAME.yang fstate=$dir/state.xml clidir=$dir/cli if [ -d $clidir ]; then rm -rf $clidir/* else mkdir $clidir fi # Generate autocli for these modules AUTOCLI=$(autocli_config ${APPNAME}\* kw-nokey true) cat < $cfg $cfg ${YANG_INSTALLDIR} $dir $fyang /usr/local/lib/$APPNAME/backend $clidir /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/run/$APPNAME.sock /usr/local/var/run/$APPNAME.pidfile /usr/local/var/$APPNAME false ${AUTOCLI} EOF # Four different trees in terms of "config none": none, under container, list, leaf respectively cat < $fyang module $APPNAME { namespace "urn:example:clixon"; prefix ex; container config{ list parameter{ key name; leaf name{ type string; } leaf value{ type string; } } } container statecontainer{ config false; list parameter{ key name; leaf name{ type string; } leaf value{ type string; } } } container stateleaf{ list parameter{ key name; leaf name{ type string; } leaf value{ config false; type string; } } } container statelist{ list parameter{ config false; key name; leaf name{ type string; } leaf value{ type string; } } } } EOF # This is state data written to file that backend reads from (on request) cat < $fstate a 42 EOF cat < $clidir/ex.cli CLICON_MODE="example"; CLICON_PROMPT="%U@%H> "; show { base @datamodel, cli_show_auto("running", "cli", true, true, "report-all","set "); add-nonconfig @datamodelstate, cli_show_auto("running", "cli", true, true, "report-all","set "); add-show @datamodelshow, cli_show_auto("running", "cli", true, true, "report-all","set "); } auto { set @datamodel, cli_auto_set(); show, cli_show_auto_mode("candidate", "text", true, false); } EOF new "test params: -f $cfg" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -z -f $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg -- -sS $fstate" start_backend -s init -f $cfg -- -sS $fstate fi new "wait backend" wait_backend #------ base top=base new "Show $top" expectpart "$(echo "show $top ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 config stateleaf statelist --not-- statecontainer '' new "Show $top config" expectpart "$(echo "show $top config ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 parameter '' new "Show $top config parameter" expectpart "$(echo "show $top config parameter ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 parameter '' --not-- '' new "Show $top config parameter " expectpart "$(echo "show $top config parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '' --not-- '' new "Show $top config parameter value ?" expectpart "$(echo "show $top config parameter a value ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 '' --not-- '' new "Show $top statelist" expectpart "$(echo "show $top statelist ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 '' --not-- parameter new "Show $top stateleaf parameter" expectpart "$(echo "show $top stateleaf parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 '' --not-- value #--------- @add:nonconfig (check state rules) top=add-nonconfig new "Show $top" expectpart "$(echo "show $top ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 config statecontainer stateleaf statelist --not-- '' new "Show $top config parameter a" expectpart "$(echo "show $top config parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '' new "Show $top statecontainer parameter" expectpart "$(echo "show $top statecontainer parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '' new "Show $top statelist parameter" expectpart "$(echo "show $top statelist parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '' new "Show $top stateleaf parameter" expectpart "$(echo "show $top stateleaf parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '' #--------- @add:show (compare with config: add at list and leaf) top=add-show new "Show $top" expectpart "$(echo "show $top ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 config stateleaf statelist --not-- statecontainer '' new "Show $top config" expectpart "$(echo "show $top config ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 parameter '' # is enabled on lists new "Show $top config parameter" expectpart "$(echo "show $top config parameter ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 parameter '' '' new "Show $top config parameter " expectpart "$(echo "show $top config parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '' --not-- '' # Special mode, to do "show leaf", but not "show leaf " # is enabled but no value on leafs new "Show $top config parameter value" expectpart "$(echo "show $top config parameter a value ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 '' --not-- '' #--------- @add:show+@add:nonconfig 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