#!/usr/bin/env bash # List pagination tests loosely based on draft-wwlh-netconf-list-pagination-00 # The example-social yang file is used # Three tests to get state pagination data: # 1. NETCONF get a specific list (alice->numbers) # 2. NETCONF get two listsspecific list (alice+bob->numbers) # 3. CLI get audit logs (only interactive) # This tests contains a large state list: audit-logs from the example # Only CLI is used # 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.xml fexample=$dir/example-social.yang fstate=$dir/mystate.xml # For 1M test,m use an external file since the generation takes considerable time #fstate=~/tmp/mystate.xml # Common example-module spec (fexample must be set) . ./example_social.sh # Validate internal state xml : ${validatexml:=false} # Number of audit-log entries : ${perfnr:=1000} cat < $cfg $cfg ietf-netconf:startup clixon-restconf:allow-auth-none /usr/local/share/clixon $IETFRFC $dir /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/$APPNAME/backend $dir/restconf.pidfile $dir json true $APPNAME /usr/local/lib/$APPNAME/cli /usr/local/lib/$APPNAME/clispec $validatexml EOF # See draft-wwlh-netconf-list-pagination-00 A.2 (only stats and audit-log) cat< $fstate alice 3 4 5 6 7 8 bob 13 14 15 16 17 18 EOF # Append generated state data to $fstate file # Generation of random timestamps (not used) # and succesive bob$i member-ids new "generate state with $perfnr list entries" echo "" >> $fstate for (( i=0; i<$perfnr; i++ )); do echo " " >> $fstate echo " 2021-09-05T018:48:11Z" >> $fstate echo " bob$i" >> $fstate echo " 192.168.1.32" >> $fstate echo " POST" >> $fstate echo " " >> $fstate done echo -n "" >> $fstate # No CR # start backend with specific xpath function testrun_start() { xpath=$1 new "test params: -f $cfg -s init -- -siS $fstate -x $xpath" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi sudo pkill -f clixon_backend # to be sure new "start backend -s init -f $cfg -- -siS $fstate -x $xpath" start_backend -s init -f $cfg -- -siS $fstate -x $xpath fi new "wait backend" wait_backend } function testrun_stop() { 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 } xpath0="/es:members/es:member[es:member-id='alice']/es:stats" xpath="$xpath0/es:numbers" testrun_start $xpath new "NETCONF get leaf-list member/numbers 0-10 alice" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO010]]>]]>" "^alice345678]]>]]>$" # negative new "NETCONF get container, expect fail" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO010]]>]]>" "^applicationinvalid-valueerrorlist-pagination is enabled but target is not list or leaf-list]]>]]>$" xpath="/es:members/es:member[es:member-id='bob']/es:stats/es:numbers" new "NETCONF get leaf-list member/numbers 0-10 bob" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO010]]>]]>" "^bob131415161718]]>]]>$" testrun_stop #---------------------------- xpath="/es:members/es:member/es:stats/es:numbers" testrun_start $xpath new "NETCONF get leaf-list member/numbers all" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO010]]>]]>" "^alice345678bob13141516]]>]]>$" testrun_stop #---------------------------- echo "...skipped: Must run interactively" if false; then testrun_start "/es:audit-logs/es:audit-log" # XXX How to run without using a terminal? Maybe use expect/unbuffer new "cli show" $clixon_cli -1 -f $cfg -l o show pagination xpath $xpath cli #expectpart "$(echo -n | unbuffer -p $clixon_cli -1 -f $cfg -l o show pagination xpath $xpath cli)" 0 foo testrun_stop fi # interactive unset validatexml unset perfnr unset xpath unset xpath0 rm -rf $dir new "endtest" endtest