Skip to content

Commit

Permalink
Test: stabilized test_restconf_internal* tests by looping
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Sep 27, 2023
1 parent 2d8567c commit 520f20d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 50 deletions.
56 changes: 32 additions & 24 deletions test/test_restconf_internal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,41 @@ function rpcstatus()
active=$1
status=$2

sleep $DEMSLEEP
new "send rpc status"
rpc=$(chunked_framing "<rpc $DEFAULTNS><process-control $LIBNS><name>restconf</name><operation>status</operation></process-control></rpc>")
retx=$($clixon_netconf -qef $cfg<<EOF
jmax=10
for j in $(seq 1 $jmax); do
new "send rpc status"
rpc=$(chunked_framing "<rpc $DEFAULTNS><process-control $LIBNS><name>restconf</name><operation>status</operation></process-control></rpc>")
retx=$($clixon_netconf -qef $cfg<<EOF
$DEFAULTHELLO$rpc
EOF
)
# Check pid
expect="<pid $LIBNS>[0-9]*</pid>"
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
pid=0
else
pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
fi
if [ -z "$pid" ]; then
err "No pid return value" "$retx"
fi
if $active; then
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status><starttime $LIBNS>20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z</starttime><pid $LIBNS>$pid</pid></rpc-reply>$"
else
# inactive, no startime or pid
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status></rpc-reply>$"
fi

match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
# Check pid
expect="<pid $LIBNS>[0-9]*</pid>"
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
pid=0
else
pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
fi
if [ -z "$pid" ]; then
err "No pid return value" "$retx"
fi
if $active; then
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status><starttime $LIBNS>20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z</starttime><pid $LIBNS>$pid</pid></rpc-reply>$"
else
# inactive, no startime or pid
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status></rpc-reply>$"
fi

match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
echo "retry after sleep"
sleep $DEMSLEEP
continue
fi
break
done
if [ $j -eq $jmax ]; then
err "$expect" "$retx"
fi
}
Expand Down
60 changes: 34 additions & 26 deletions test/test_restconf_internal_usecases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,42 @@ function rpcstatus()
active=$1
status=$2

sleep $DEMSLEEP
new "send rpc status"
rpc=$(chunked_framing "<rpc $DEFAULTNS><process-control $LIBNS><name>restconf</name><operation>status</operation></process-control></rpc>")
retx=$($clixon_netconf -qef $cfg<<EOF
jmax=10
for j in $(seq 1 $jmax); do
new "send rpc status"
rpc=$(chunked_framing "<rpc $DEFAULTNS><process-control $LIBNS><name>restconf</name><operation>status</operation></process-control></rpc>")
retx=$($clixon_netconf -qef $cfg<<EOF
$DEFAULTHELLO$rpc
EOF
)
# Check pid
expect="<pid $LIBNS>[0-9]*</pid>"
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
pid=0
else
pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
fi
if [ -z "$pid" ]; then
err "No pid return value" "$retx"
fi

if $active; then
# \- causes problems on some(alpine)
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status><starttime $LIBNS>20[0-9][0-9].[0-9][0-9].[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z</starttime><pid $LIBNS>$pid</pid></rpc-reply>$"
else
# inactive, no startime or pid
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status></rpc-reply>$"
fi
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
)
# Check pid
expect="<pid $LIBNS>[0-9]*</pid>"
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
pid=0
else
pid=$(echo "$match" | awk -F'[<>]' '{print $3}')
fi
if [ -z "$pid" ]; then
err "No pid return value" "$retx"
fi

if $active; then
# \- causes problems on some(alpine)
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status><starttime $LIBNS>20[0-9][0-9].[0-9][0-9].[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z</starttime><pid $LIBNS>$pid</pid></rpc-reply>$"
else
# inactive, no startime or pid
expect="^<rpc-reply $DEFAULTNS><active $LIBNS>$active</active><description $LIBNS>Clixon RESTCONF process</description><command $LIBNS>/.*/clixon_restconf -f $cfg -D [0-9] .*</command><status $LIBNS>$status</status></rpc-reply>$"
fi
match=$(echo "$retx" | grep --null -Go "$expect")
if [ -z "$match" ]; then
echo "retry after sleep"
sleep $DEMSLEEP
continue
fi
break
done
if [ $j -eq $jmax ]; then
err "$expect" "$retx"
fi
}
Expand Down

0 comments on commit 520f20d

Please sign in to comment.