#!/usr/bin/env bash # Tests for Netconf event streams using notifications # See RFC5277 NETCONF Event Notifications # # Testing of streams is quite complicated. # Here are some testing dimensions in restconf alone: # - start/stop subscription # - start-time/stop-time in subscription # - stream retention time # - native vs nchan implementation # Focussing on 1-3 # @see test_restconf_notifications.sh # 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 NCWAIT=10 # Wait (netconf valgrind may need more time) # Ensure UTC DATE=$(date -u +"%Y-%m-%d") cfg=$dir/conf.xml fyang=$dir/stream.yang xml=$dir/xml.xml # example cat < $cfg $cfg ${YANG_INSTALLDIR} $fyang /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/$APPNAME/backend example_backend.so$ /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME true streams 60 EOF # For nchan testing add this line to above config # http://localhost/pub # RFC5277 NETCONF Event Notifications # using reportingEntity (rfc5277) not reporting-entity (rfc8040) cat < $fyang module example { namespace "urn:example:clixon"; prefix ex; organization "Example, Inc."; contact "support at example.com"; description "Example Notification Data Model Module."; revision "2016-07-07" { description "Initial version."; reference "example.com document 2-9976."; } notification event { description "Example notification event."; leaf event-class { type string; description "Event class identifier."; } container reportingEntity { description "Event specific information."; leaf card { type string; description "Line card identifier."; } } leaf severity { type string; description "Event severity description."; } } container state { config false; description "state data for the example application (must be here for example get operation)"; leaf-list op { type string; } } } EOF 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 -- -n" start_backend -s init -f $cfg -- -n # create example notification stream fi new "waiting" wait_backend # # 1. Netconf RFC5277 stream testing new "1. Netconf RFC5277 stream testing" # 1.1 Stream discovery new "netconf event stream discovery RFC5277 Sec 3.2.5" expecteof_netconf "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "" "" "EXAMPLEExample event streamtrue" new "netconf EXAMPLE subscription" expectwait "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "EXAMPLE" $NCWAIT "" "20" new "netconf subscription with empty startTime" expecteof_netconf "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "EXAMPLE" "applicationbad-elementstartTimeerrorregexp match fail:" "" new "netconf EXAMPLE subscription with simple filter" expectwait "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "EXAMPLE" $NCWAIT "" "20" new "netconf EXAMPLE subscription with filter classifier" expectwait "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "EXAMPLE" $NCWAIT "" "20" new "netconf NONEXIST subscription" expectwait "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "NONEXIST" $NCWAIT "applicationinvalid-valueerrorNo such stream" new "netconf EXAMPLE subscription with wrong date" expectwait "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "EXAMPLEkallekaka" 0 "applicationbad-elementstartTimeerrorregexp match fail:" #new "netconf EXAMPLE subscription with replay" #NOW=$(date +"%Y-%m-%dT%H:%M:%S") #sleep 10 #expectwait "$clixon_netconf -D $DBG -qef $cfg" 0 "$DEFAULTHELLO" "EXAMPLE$NOW" 10 "^]]>]]>20" 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