#!/usr/bin/env bash # Netconf callhome RFC 8071 # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Skip it no openssh if ! [ -x "$(command -v ssh)" ]; then echo "...ssh not installed" if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi : ${clixon_netconf_ssh_callhome:="clixon_netconf_ssh_callhome"} : ${clixon_netconf_ssh_callhome_client:="clixon_netconf_ssh_callhome_client"} APPNAME=example cfg=$dir/conf_yang.xml sshdcfg=$dir/sshd.conf rpccmd=$dir/rpccmd.xml # Use yang in example cat < $cfg $cfg 42 /usr/local/share/clixon $IETFRFC clixon-example /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/backend example_backend.so$ /usr/local/lib/$APPNAME/netconf $dir/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF cat < $rpccmd ]]>]]> ]]>]]> EOF # Make the callback after a sleep in separate thread simulating the server # The result is not checked, only the client-side function callhomefn() { sleep 1 new "Start Callhome in background" expectpart "$(sudo ${clixon_netconf_ssh_callhome} -a 127.0.0.1 -c $cfg)" 255 "" } new "test params: -f $cfg" # Bring your own backend if [ $BE -ne 0 ]; then # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" wait_backend fi # Start callhome server-side in background thread callhomefn & new "Start Listener client" expectpart "$(ssh -s -v -o ProxyUseFdpass=yes -o ProxyCommand="${clixon_netconf_ssh_callhome_client} -a 127.0.0.1" . netconf < $rpccmd)" 0 "urn:ietf:params:netconf:base:1.0urn:ietf:params:netconf:capability:yang-library:1.0?revision=2019-01-04&module-set-id=42urn:ietf:params:netconf:capability:candidate:1.0urn:ietf:params:netconf:capability:validate:1.1urn:ietf:params:netconf:capability:startup:1.0urn:ietf:params:netconf:capability:xpath:1.0urn:ietf:params:netconf:capability:notification:1.02]]>]]>" "]]>]]>" # Wait wait 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 new "Endtest" endtest rm -rf $dir