#!/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 # Test also of list-pagination-partial-state 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.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 ${YANG_INSTALLDIR} $IETFRFC $dir /usr/local/var/run/$APPNAME.sock /usr/local/lib/$APPNAME/backend /usr/local/var/run/$APPNAME.pidfile $dir json true $APPNAME /usr/local/lib/$APPNAME/cli 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 " true" >> $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_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "010" "" "alice345678" # negative new "NETCONF get container, expect fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "010" "" "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_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "010" "" "bob131415161718" testrun_stop #---------------------------- xpath="/es:members/es:member/es:stats/es:numbers" testrun_start $xpath new "NETCONF get leaf-list member/numbers all" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "010" "" "alice345678bob13141516" testrun_stop #---------------------------- # Only if expect installed if [ -n "$(type expect 2> /dev/null)" ]; then testrun_start "/es:audit-logs/es:audit-log" new "CLI scroll test using expect" xpath="/es:audit-logs/es:audit-log" sudo="sudo -g ${CLICON_GROUP}" ## cheat clixon_cli_="${clixon_cli##$sudo }" # echo "$sudo --preserve-env=clixon_cli expect ./test_pagination_expect.exp $cfg $xpath bob3 bob4" clixon_cli="$clixon_cli_" $sudo --preserve-env=clixon_cli expect ./test_pagination_expect.exp "$cfg" "$xpath" bob3 bob4 if [ $? -ne 0 ]; then err1 "Failed: CLI show paginate state scroll using expect" fi testrun_stop fi # expect unset xpath0 rm -rf $dir new "endtest" endtest