tests: use common function to check for file existence

This addresses issue with "docker cp" in some systems.
This commit is contained in:
Nikos Mavrogiannopoulos
2015-05-20 15:51:25 +02:00
parent 76f2c91e6b
commit f4e9b2e698
6 changed files with 79 additions and 114 deletions

View File

@@ -38,6 +38,56 @@ if test -z $FEDORA && test -z $DEBIAN;then
exit 77
fi
check_for_file() {
FILENAME=$1
rm -f out$TMP
$DOCKER exec -i -t $IMAGE_NAME ls $FILENAME >out$TMP
grep "$FILENAME" out$TMP|grep -v "cannot access"
if test $? != 0;then
echo "could not find $FILENAME"
return 1
else
rm -f out$TMP
return 0
fi
}
retrieve_user_info() {
USERNAME=$1
MATCH=$2
counter=0
ret=1
while [ $counter -lt 4 ]
do
$DOCKER exec -i -t $IMAGE_NAME occtl show user $USERNAME >out$TMP 2>&1
if test -z "$MATCH";then
grep "Username" out$TMP
else
grep "$MATCH" out$TMP
fi
ret=$?
if test $ret == 0;then
break
fi
counter=`expr $counter + 1`
sleep 2
done
if test $ret != 0;then
kill $PID
cat out$TMP
echo "could not find user information"
stop
else
rm -f out$TMP
fi
}
retrieve_route_info() {
retrieve_user_info $1 $2
}
stop() {
$DOCKER stop $IMAGE_NAME
$DOCKER rm $IMAGE_NAME

View File

@@ -101,18 +101,7 @@ if test $? != 0;then
stop
fi
$DOCKER exec -i -t $IMAGE_NAME occtl show users
$DOCKER exec -i -t $IMAGE_NAME occtl show user test >out$TMP 2>&1
grep "Username" out$TMP
if test $? != 0;then
kill $PID
cat out$TMP
echo "could not find user information"
stop
fi
rm -f out$TMP
retrieve_user_info test
# There is an issue in nuttcp that makes it crash under docker if
# /proc/sys/net/ipv4/tcp_adv_win_scale does not exist.
@@ -139,25 +128,16 @@ kill $PID
sleep 4
#check whether /tmp/disconnect/ok was created
rm -f ./not-ok
$DOCKER cp $IMAGE_NAME:/tmp/disconnect/not-ok ./
if test -f ./not-ok;then
echo "There was an issue getting stats"
check_for_file /tmp/disconnect/not-ok
if test $? = 0;then
echo "There was an issue"
stop
fi
rm -f ./not-ok
ret=0
rm -f ./tmp-full/ok
$DOCKER cp $IMAGE_NAME:/tmp/disconnect/ok ./tmp-full/
if ! test -f ./tmp-full/ok;then
echo "Don't know if stats were received"
check_for_file /tmp/disconnect/ok
if test $? != 0;then
echo "There was an issue getting stats"
ret=77
else
echo -n "stats: "
echo `cat ./tmp-full/ok`
rm -rf ./tmp-full/
fi
$DOCKER stop $IMAGE_NAME

View File

@@ -116,18 +116,7 @@ if test $? != 0;then
stop
fi
$DOCKER exec -i -t $IMAGE_NAME occtl show users
$DOCKER exec -i -t $IMAGE_NAME occtl show user testuser >out$TMP 2>&1
grep "Username" out$TMP
if test $? != 0;then
cat out$TMP
kill $PID
echo "could not find user information"
stop
fi
rm -f out$TMP
retrieve_user_info test
# There is an issue in nuttcp that makes it crash under docker if
# /proc/sys/net/ipv4/tcp_adv_win_scale does not exist.
@@ -153,26 +142,16 @@ kill $PID
sleep 4
#check whether /tmp/disconnect/ok was created
rm -f ./not-ok
$DOCKER cp $IMAGE_NAME:/tmp/disconnect/not-ok ./
if test -f ./not-ok;then
echo "There was an issue getting stats"
check_for_file /tmp/disconnect/not-ok
if test $? = 0;then
echo "There was an issue"
stop
fi
rm -f ./not-ok
ret=0
rm -f ./tmp-full/ok
$DOCKER cp $IMAGE_NAME:/tmp/disconnect/ok ./tmp-full/
if ! test -f ./tmp-full/ok;then
echo "Don't know if stats were received"
check_for_file /tmp/disconnect/ok
if test $? != 0;then
echo "There was an issue getting stats"
ret=77
else
echo -n "stats: "
echo `cat ./tmp-full/ok`
rm -rf ./tmp-full/
fi
$DOCKER stop $IMAGE_NAME

View File

@@ -102,18 +102,7 @@ if test $? != 0;then
stop
fi
$DOCKER exec -i -t $IMAGE_NAME occtl show users
$DOCKER exec -i -t $IMAGE_NAME occtl show user test >out$TMP 2>&1
grep "Username" out$TMP
if test $? != 0;then
cat out$TMP
kill $PID
echo "could not find user information"
stop
fi
rm -f out$TMP
retrieve_user_info test
# There is an issue in nuttcp that makes it crash under docker if
# /proc/sys/net/ipv4/tcp_adv_win_scale does not exist.
@@ -140,16 +129,11 @@ kill -INT $PID
sleep 4
TMPDIR=radius-$TMP
mkdir -p $TMPDIR
#check whether /tmp/disconnect/ok was created
rm -f $TMPDIR/not-ok
$DOCKER cp $IMAGE_NAME:/tmp/disconnect/not-ok $TMPDIR/
if test -f $TMPDIR/not-ok;then
echo "There was an issue getting stats"
check_for_file /tmp/disconnect/not-ok
if test $? = 0;then
echo "There was an issue"
stop
fi
rm -f $TMPDIR/not-ok
rm -f $TMPDIR/stats
@@ -163,15 +147,10 @@ if test -z "$OCTETS" || test "$OCTETS" = 0;then
stop
fi
rm -f $TMPDIR/ok
$DOCKER cp $IMAGE_NAME:/tmp/disconnect/ok $TMPDIR/
if ! test -f $TMPDIR/ok;then
echo "Don't know if stats were received"
ret=77
else
echo -n "stats: "
echo `cat $TMPDIR/ok`
rm -rf $TMPDIR/
check_for_file /tmp/disconnect/ok
if test $? != 0;then
echo "There was an issue getting stats"
stop
fi
ret=0

View File

@@ -73,18 +73,7 @@ if test $? != 0;then
fi
#check whether the routes have been applied
$DOCKER exec -i -t $IMAGE_NAME occtl show users
$DOCKER exec -i -t $IMAGE_NAME occtl show user testtime >out$TMP 2>&1
grep '192.168.155.0/255.255.255.0' out$TMP
if test $? != 0;then
cat out$TMP
kill $PID
echo "routes have not been applied"
stop
fi
rm -f out$TMP
retrieve_route_info testtime '192.168.155.0/255.255.255.0'
echo "Waiting for accounting report"
@@ -93,11 +82,8 @@ sleep 60
TMPDIR=radius-$TMP
mkdir -p $TMPDIR
#check whether /tmp/disconnect/ok was created
FILE=`$DOCKER exec $IMAGE_NAME ls /var/log/radius/radacct/127.0.0.1/`
#echo $DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/127.0.0.1/$FILE"
#$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/127.0.0.1/$FILE"
OCTETS=`$DOCKER exec $IMAGE_NAME cat "/var/log/radius/radacct/127.0.0.1/$FILE"|grep Acct-Input-Octets|tail -1|sed 's/Acct-Input-Octets = //g'`
if test -z "$OCTETS" || test "$OCTETS" = 0;then

View File

@@ -111,25 +111,16 @@ kill $PID
sleep 4
#check whether /tmp/disconnect/ok was created
rm -f ./not-ok
$DOCKER cp test_unix:/tmp/disconnect/not-ok ./
if test -f ./not-ok;then
echo "There was an issue getting stats"
check_for_file /tmp/disconnect/not-ok
if test $? = 0;then
echo "There was an issue"
stop
fi
rm -f ./not-ok
ret=0
rm -f ./tmp-unix/ok
$DOCKER cp test_unix:/tmp/disconnect/ok ./tmp-unix/
if ! test -f ./tmp-unix/ok;then
echo "Don't know if stats were received"
check_for_file /tmp/disconnect/ok
if test $? != 0;then
echo "There was an issue getting stats"
ret=77
else
echo -n "stats: "
echo `cat ./tmp-unix/ok`
rm -rf ./tmp-unix/
fi
$DOCKER stop test_unix