* New clixon-config@2020-12-30.yang revision
* New clixon-lib@2020-12-30.yang revision * Added callback to process-control RPC feature in clixon-lib.yang to manage processes * Changed behavior of starting restconf internally using `CLICON_BACKEND_RESTCONF_PROCESS` monitoring changes in enable flag, not only the RPC. * Changed: RPC process-control output parameter status to pid
This commit is contained in:
parent
7459925bd0
commit
cf63d0f761
21 changed files with 741 additions and 280 deletions
|
|
@ -1,6 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
# Restconf direct start/stop using RPC (as alternative to systemd or other)
|
||||
# Also try ip netns
|
||||
# Restconf direct start/stop using RPC and config enable flag (as alternative to systemd or other)
|
||||
# According tot he following behaviour:
|
||||
# - on RPC start, if enable is true, start the service, if false, error or ignore it
|
||||
# - on RPC stop, stop the service
|
||||
# - on backend start make the state as configured
|
||||
# - on enable change, make the state as configured
|
||||
# - No restconf config means enable: false (extra rule)
|
||||
# Also work-in-progress network namespaces, ip netns
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -8,17 +14,12 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
|||
APPNAME=example
|
||||
|
||||
cfg=$dir/conf.xml
|
||||
|
||||
# Cant get it to work in the general case, single tests work fine
|
||||
# More specifically, if mem.sh background netconf, netconf crashes which is valgrindtest 1
|
||||
if [ $valgrindtest -eq 1 ]; then
|
||||
echo "...skipped "
|
||||
return 0 # skip
|
||||
fi
|
||||
startupdb=$dir/startup_db
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
|
||||
|
|
@ -31,7 +32,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<!-- start restconf from backend -->
|
||||
<CLICON_BACKEND_RESTCONF_PROCESS>true</CLICON_BACKEND_RESTCONF_PROCESS>
|
||||
|
|
@ -39,6 +40,72 @@ cat <<EOF > $cfg
|
|||
</clixon-config>
|
||||
EOF
|
||||
|
||||
# Subroutine send a process control RPC and tricks to echo process-id returned
|
||||
# Args:
|
||||
# 1: operation
|
||||
# 2: expectret 0: means expect pi 0 as return, else something else
|
||||
testrpc()
|
||||
{
|
||||
operation=$1
|
||||
expectret=$2
|
||||
|
||||
new "send rpc $operation"
|
||||
ret=$($clixon_netconf -qf $cfg<<EOF
|
||||
<rpc $DEFAULTNS>
|
||||
<process-control xmlns="http://clicon.org/lib">
|
||||
<name>restconf</name>
|
||||
<operation>$operation</operation>
|
||||
</process-control>
|
||||
</rpc>]]>]]>
|
||||
EOF
|
||||
)
|
||||
|
||||
expect1="<rpc-reply $DEFAULTNS><pid xmlns=\"http://clicon.org/lib\">"
|
||||
match=$(echo "$ret" | grep --null -Go "$expect1")
|
||||
if [ -z "$match" ]; then
|
||||
err "$expect1" "$ret"
|
||||
fi
|
||||
|
||||
expect2="</pid></rpc-reply>]]>]]>"
|
||||
match=$(echo "$ret" | grep --null -Go "$expect2")
|
||||
if [ -z "$match" ]; then
|
||||
err "$expect2" "$ret"
|
||||
fi
|
||||
|
||||
new "check rpc $operation get pid"
|
||||
pid=$(echo "$ret" | awk -F'[<>]' '{print $5}')
|
||||
if [ -z "$pid" ]; then
|
||||
err "Running process" "$ret"
|
||||
fi
|
||||
|
||||
new "check restconf retvalue"
|
||||
if [ $expectret -eq 0 ]; then
|
||||
if [ $pid -ne 0 ]; then
|
||||
err "No process" "$pid"
|
||||
fi
|
||||
else
|
||||
if [ $pid -eq 0 ]; then
|
||||
err "Running process"
|
||||
fi
|
||||
fi
|
||||
|
||||
>&2 echo "pid:$pid" # debug
|
||||
echo $pid # cant use return that only uses 0-255
|
||||
}
|
||||
|
||||
new "ENABLE true"
|
||||
# First basic operation with restconf enable is true
|
||||
cat<<EOF > $startupdb
|
||||
<config>
|
||||
<restconf xmlns="http://clicon.org/restconf">
|
||||
<enable>true</enable>
|
||||
</restconf>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
new "kill old restconf"
|
||||
stop_restconf_pre
|
||||
|
||||
new "test params: -f $cfg"
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
|
|
@ -46,92 +113,82 @@ if [ $BE -ne 0 ]; then
|
|||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
new "start backend -s init -f $cfg"
|
||||
start_backend -s init -f $cfg
|
||||
|
||||
new "waiting"
|
||||
new "start backend -s startup -f $cfg"
|
||||
start_backend -s startup -f $cfg
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
fi
|
||||
|
||||
new "kill old restconf"
|
||||
stop_restconf_pre
|
||||
# Get pid of running process and check return xml
|
||||
new "Get rpc status"
|
||||
pid0=$(testrpc status 1)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "1)check no restconf"
|
||||
ps=$(ps aux|grep "$WWWDIR/clixon_restconf" | grep -v grep)
|
||||
if [ -n "$ps" ]; then
|
||||
err "No restconf running" "$ps"
|
||||
fi
|
||||
new "check restconf process running using ps pid0:$pid0"
|
||||
ps=$(ps -hp $pid0)
|
||||
|
||||
new "2)check status off"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>status</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><status xmlns=\"http://clicon.org/lib\">false</status></rpc-reply>]]>]]>"
|
||||
|
||||
new "start restconf"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>start</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>"
|
||||
|
||||
new "3)check restconf on"
|
||||
if [ $valgrindtest -eq 0 ]; then # Cant get pgrep to work properly
|
||||
sleep $DEMWAIT # Slows the tests down considerably, but needed in eg docker test
|
||||
fi
|
||||
ps=$(ps aux|grep "$WWWDIR/clixon_restconf -f $cfg" | grep -v grep)
|
||||
if [ -z "$ps" ]; then
|
||||
err "restconf running"
|
||||
fi
|
||||
|
||||
new "4)check status on"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>status</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><status xmlns=\"http://clicon.org/lib\">true</status></rpc-reply>]]>]]>"
|
||||
|
||||
new "stop restconf"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>stop</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>"
|
||||
|
||||
new "start restconf again"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>start</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>"
|
||||
|
||||
new "5)check restconf on"
|
||||
if [ $valgrindtest -eq 0 ]; then # Cant get pgrep to work properly
|
||||
sleep $DEMWAIT # Slows the tests down considerably, but needed in eg docker test
|
||||
fi
|
||||
ps=$(ps aux|grep "$WWWDIR/clixon_restconf -f $cfg" | grep -v grep)
|
||||
if [ -z "$ps" ]; then
|
||||
err "A restconf running"
|
||||
fi
|
||||
|
||||
new "stop restconf RPC"
|
||||
pid1=$(testrpc stop 0)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "Get rpc status stopped"
|
||||
pid2=$(testrpc status 0)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "Start rpc again"
|
||||
pid3=$(testrpc start 1)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "check restconf process running using ps"
|
||||
ps=$(ps -hp $pid3)
|
||||
if [ -z "$ps" ]; then
|
||||
err "A restconf running"
|
||||
fi
|
||||
|
||||
if [ $pid0 -eq $pid3 ]; then
|
||||
err "A different pid" "$pid3"
|
||||
fi
|
||||
|
||||
new "kill restconf"
|
||||
stop_restconf_pre
|
||||
|
||||
new "6)check no restconf"
|
||||
ps=$(ps aux|grep "$WWWDIR/clixon_restconf" | grep -v grep)
|
||||
if [ -n "$ps" ]; then
|
||||
err "No restconf running" "$ps"
|
||||
new "start restconf RPC"
|
||||
pid4=$(testrpc start 1)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "check status RPC on"
|
||||
pid5=$(testrpc status 1)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "restart restconf RPC"
|
||||
pid6=$(testrpc restart 1)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "Get restconf status rpc"
|
||||
pid7=$(testrpc status 1)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
if [ $pid5 -eq $pid7 ]; then
|
||||
err "A different pid" "$pid7"
|
||||
fi
|
||||
|
||||
new "restart restconf"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>restart</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>"
|
||||
|
||||
new "7)check status on"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>status</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><status xmlns=\"http://clicon.org/lib\">true</status></rpc-reply>]]>]]>"
|
||||
|
||||
if [ $valgrindtest -eq 0 ]; then # Cant get pgrep to work properly
|
||||
sleep $DEMWAIT # Slows the tests down considerably, but needed in eg docker test
|
||||
fi
|
||||
pid0=$(pgrep clixon_restconf)
|
||||
|
||||
new "restart restconf"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>restart</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>"
|
||||
|
||||
new "8)check status on"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><process-control xmlns=\"http://clicon.org/lib\"><name>restconf</name><operation>status</operation></process-control></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><status xmlns=\"http://clicon.org/lib\">true</status></rpc-reply>]]>]]>"
|
||||
|
||||
if [ $valgrindtest -eq 0 ]; then # Cant get pgrep to work properly
|
||||
new "9)check new pid"
|
||||
sleep $DEMWAIT # Slows the tests down considerably, but needed in eg docker test
|
||||
pid1=$(pgrep clixon_restconf)
|
||||
if [ -z "$pid0" -o -z "$pid1" ]; then
|
||||
err "Pids expected" "pid0:$pid0 = pid1:$pid1"
|
||||
fi
|
||||
if [ $pid0 -eq $pid1 ]; then
|
||||
err "Different pids" "pid0:$pid0 = pid1:$pid1"
|
||||
fi
|
||||
fi
|
||||
#if [ $valgrindtest -eq 0 ]; then # Cant get pgrep to work properly
|
||||
# new "check new pid"
|
||||
# sleep $DEMWAIT # Slows the tests down considerably, but needed in eg docker test
|
||||
# pid1=$(pgrep clixon_restconf)
|
||||
# if [ -z "$pid0" -o -z "$pid1" ]; then
|
||||
# err "Pids expected" "pid0:$pid0 = pid1:$pid1"
|
||||
# fi
|
||||
# if [ $pid0 -eq $pid1 ]; then#
|
||||
# err "Different pids" "pid0:$pid0 = pid1:$pid1"
|
||||
# fi
|
||||
#fi
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "Kill backend"
|
||||
|
|
@ -142,19 +199,70 @@ if [ $BE -ne 0 ]; then
|
|||
fi
|
||||
# kill backend
|
||||
stop_backend -f $cfg
|
||||
fi
|
||||
|
||||
# XXX Cant get this to work in docker/alpine
|
||||
if false; then
|
||||
new "10)check no restconf"
|
||||
sleep $DEMWAIT
|
||||
ps=$(ps aux|grep "$WWWDIR/clixon_restconf" | grep -v grep)
|
||||
if [ -n "$ps" ]; then
|
||||
err "No restconf running" "$ps"
|
||||
fi
|
||||
# So far, no restconf config enable flag has been true. Now change enable flag.
|
||||
|
||||
new "ENABLE false"
|
||||
# Second basic operation with restconf enable is false
|
||||
cat<<EOF > $startupdb
|
||||
<config>
|
||||
<restconf xmlns="http://clicon.org/restconf">
|
||||
<enable>false</enable>
|
||||
</restconf>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
new "kill old restconf"
|
||||
stop_restconf_pre
|
||||
|
||||
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
|
||||
|
||||
if false; then # Work in progress
|
||||
new "check status RPC off"
|
||||
pid=$(testrpc status 0)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "start restconf RPC"
|
||||
pid=$(testrpc start 0)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "check status RPC off"
|
||||
pid=$(testrpc status 0)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "Enable restconf"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><edit-config><default-operation>merge</default-operation><target><candidate/></target><config><restconf xmlns=\"http://clicon.org/restconf\"><enable>true</enable></restconf></config></edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
new "netconf commit"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><commit/></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
new "check status RPC on"
|
||||
pid=$(testrpc status 1)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
new "Disable restconf"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><edit-config><default-operation>merge</default-operation><target><candidate/></target><config><restconf xmlns=\"http://clicon.org/restconf\"><enable>false</enable></restconf></config></edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
new "netconf commit"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><commit/></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
new "check status RPC off"
|
||||
pid=$(testrpc status 0)
|
||||
if [ $? -ne 0 ]; then exit -1; fi
|
||||
|
||||
if false; then # Work in progress - namespace
|
||||
#-------------------------------
|
||||
# Now in a separate network namespace
|
||||
new "restconf rpc in network namespace"
|
||||
|
|
@ -207,3 +315,4 @@ sudo ip netns delete $netns
|
|||
fi # namespaces
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue