From f4e9b2e69877326e91c156cf52101df693a7f1be Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 20 May 2015 15:51:25 +0200 Subject: [PATCH] tests: use common function to check for file existence This addresses issue with "docker cp" in some systems. --- tests/docker-common.sh | 50 ++++++++++++++++++++++++++++++++++++++++ tests/full-test | 34 ++++++--------------------- tests/pam-test | 35 ++++++---------------------- tests/radius-test | 37 +++++++---------------------- tests/radius-test-config | 16 +------------ tests/unix-test | 21 +++++------------ 6 files changed, 79 insertions(+), 114 deletions(-) diff --git a/tests/docker-common.sh b/tests/docker-common.sh index 8c283137..802fbd6e 100755 --- a/tests/docker-common.sh +++ b/tests/docker-common.sh @@ -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 diff --git a/tests/full-test b/tests/full-test index b9c6991f..0950672d 100755 --- a/tests/full-test +++ b/tests/full-test @@ -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 diff --git a/tests/pam-test b/tests/pam-test index 653d4fdf..7336aad9 100755 --- a/tests/pam-test +++ b/tests/pam-test @@ -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 diff --git a/tests/radius-test b/tests/radius-test index aee67efa..d9586bdf 100755 --- a/tests/radius-test +++ b/tests/radius-test @@ -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 diff --git a/tests/radius-test-config b/tests/radius-test-config index 962b9c29..4b136a9a 100755 --- a/tests/radius-test-config +++ b/tests/radius-test-config @@ -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 diff --git a/tests/unix-test b/tests/unix-test index 2432f92d..a4304228 100755 --- a/tests/unix-test +++ b/tests/unix-test @@ -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