#!/usr/bin/env bash # Tests for generating clispec from a yang subtree, ie not the whole yang # 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 # Must be defined by a call: yang2cli_sub(h, ..., "datamodelexample", ...) fin=$dir/in cfg=$dir/conf_yang.xml fyang=$dir/$APPNAME.yang clidir=$dir/cli if [ -d $clidir ]; then rm -rf $clidir/* else mkdir $clidir fi # Use yang in example cat < $cfg $cfg ietf-netconf:startup /usr/local/share/clixon $dir $fyang /usr/local/lib/$APPNAME/backend $clidir /usr/local/lib/$APPNAME/cli $APPNAME 2 VARS /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir false clixon-restconf EOF cat < $fyang module $APPNAME { namespace "urn:example:clixon"; prefix ex; container table{ list parameter{ key name; leaf name{ type string; } leaf value{ type string; } list index{ key i; leaf i{ type string; } leaf iv{ type string; } } } } } EOF cat < $clidir/ex.cli CLICON_MODE="example"; CLICON_PROMPT="%U@%H %W> "; # Manual command form where a sub-mode is created from @datamodel # It gives: cvv eg: # 0 : cmd = parameter 123 # 1 : string = "123" enter0 , cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/"); enter1 , cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/index=%s/", "p1"); leave, cli_auto_top("datamodel", "candidate"); # Autocli syntax tree operations edit @datamodel, cli_auto_edit("datamodel"); up, cli_auto_up("datamodel"); top, cli_auto_top("datamodel"); set @datamodel, cli_auto_set(); merge @datamodel, cli_auto_merge(); create @datamodel, cli_auto_create(); delete("Delete a configuration item") { @datamodel, cli_auto_del(); all("Delete whole candidate configuration"), delete_all("candidate"); } show("Show a particular state of the system"){ configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);{ xml("Show configuration as XML"), cli_auto_show("datamodel", "candidate", "xml", false, false); } } EOF cat < $dir/startup_db <${DATASTORE_TOP}> p1 42 i1 abc
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 startup -f $cfg" start_backend -s startup -f $cfg new "waiting" wait_backend fi cat < $fin enter0 p1 # table/parameter=p1 show config xml leave EOF new "enter; show config; leave" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter0 p1' 'leave' 'p142i1abc' --not-- '' '' cat < $fin enter0 p1 # table/parameter=p1 leave show config xml EOF new "enter; leave; show config" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter0 p1' 'leave' '
p142i1abc
' cat < $fin enter0 p1 # table/parameter=p1 set set index i2 iv def leave show config xml EOF new "set p1 i2" expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'p142i1abc
' 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 rm -rf $dir new "endtest" endtest