Skip to content

Commit

Permalink
[CICD]add autotest and document
Browse files Browse the repository at this point in the history
  • Loading branch information
danfu3000 authored and qdongxu committed Nov 22, 2019
1 parent bd78bcb commit ead388d
Show file tree
Hide file tree
Showing 41 changed files with 3,022 additions and 5 deletions.
173 changes: 173 additions & 0 deletions scripts/autotest-adaptor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/bin/bash
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd -P`
popd > /dev/null
SCRIPTFILE=`basename $0`

if [ -f ${SCRIPTPATH}/deploy.env ];
then
source ${SCRIPTPATH}/deploy.env
else
echo "Can't found deploy.env file"
exit 1
fi

if [ -f ${SCRIPTPATH}/autotest.env ];
then
source ${SCRIPTPATH}/autotest.env
else
echo "Can't found autotest.env file"
exit 1
fi

function checkports(){
for port in ${TESTPORTS}
do
isconflict=`netstat -an|grep ":${port} "|grep LISTEN|wc -l`
if [ $isconflict -ne 0 ];then
echo "port: ${port} conflict, please adjust."
return 1
fi
done
if [ $? -ne 0 ];then
return 1
fi
return 0
}
function buildbackend(){
cd ${BACKENDDIR}
go build adaptor.go
if [ $? -ne 0 ];then
echo "build adaptor error"
return 1
fi
mv adaptor backend_adaptor
echo "build backend successed."
return 0
}

function runbackend(){
cd ${BACKENDDIR}
nohup ./backend_adaptor -t server>${BACKENDDIR}/adaptor.res 2>&1 &
if [ $? -ne 0 ];then
echo "run adaptor error"
return 1
fi
return 0
}

function termbackend(){
PID=`ps -ef|grep backend_adaptor|grep -v grep|awk '{print $2}'`
if [ "$PID" != "" ];then
echo $PID|xargs kill -9
fi
echo "term adaptor successed."
return 0
}

function createobject(){
cd ${CONFIGDIR}
rm -f generate*.yaml
grep "^name:" adaptor*.yaml|sed -E 's/.*name: (.*)/\1/'|while read objname
do
sed -E "s#http:https://127.0.0.1#${BACKENDHOST}#" ${objname}.yaml > generate-${objname}.yaml
if [ $? -ne 0 ];then
echo "generate yaml error"
return 1
fi
${EG1_EGCTL} --server ${EG1_API} object create -f generate-${objname}.yaml
if [ $? -ne 0 ];then
echo "create ${objname} error"
return 1
fi
done
if [ $? -ne 0 ];then
return 1
fi
echo "create object success"
return 0
}

function deleteobject(){
cd ${CONFIGDIR}
rm -f generate*.yaml
grep "^name:" adaptor*.yaml|sed -E 's/.*name: (.*)/\1/'|while read objname
do
${EG1_EGCTL} --server ${EG1_API} object delete ${objname}
if [ $? -ne 0 ];then
echo "delete ${objname} error"
return 1
fi
done
if [ $? -ne 0 ];then
return 1
fi
echo "delete object success"
return 0
}

function checkobject(){
curl -v ${TESTHOST}:10080/
if [ $? -ne 0 ];then
echo "check object adaptor error"
return 1
fi
echo "check object success"
return 0
}

function testobject(){
cd ${BUILDDIR}/scripts
./autotest-cotest-adaptor.sh
if [ $? -ne 0 ];then
return 1
fi
echo "test success"
return 0
}

function pipeline(){
checkports
if [ $? -ne 0 ];then
exit 1
fi

buildbackend
if [ $? -ne 0 ];then
exit 1
fi

runbackend
if [ $? -ne 0 ];then
exit 1
fi

createobject
if [ $? -ne 0 ];then
deleteobject
termbackend
exit 1
fi

checkobject
if [ $? -ne 0 ];then
deleteobject
termbackend
exit 1
fi

testobject
if [ $? -ne 0 ];then
deleteobject
termbackend
exit 1
fi

deleteobject

termbackend

exit 0
}

pipeline
179 changes: 179 additions & 0 deletions scripts/autotest-backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/bin/bash
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd -P`
popd > /dev/null
SCRIPTFILE=`basename $0`

if [ -f ${SCRIPTPATH}/deploy.env ];
then
source ${SCRIPTPATH}/deploy.env
else
echo "Can't found deploy.env file"
exit 1
fi

if [ -f ${SCRIPTPATH}/autotest.env ];
then
source ${SCRIPTPATH}/autotest.env
else
echo "Can't found autotest.env file"
exit 1
fi

function checkports(){
for port in ${TESTPORTS}
do
isconflict=`netstat -an|grep ":${port} "|grep LISTEN|wc -l`
if [ $isconflict -ne 0 ];then
echo "port: ${port} conflict, please adjust."
return 1
fi
done
if [ $? -ne 0 ];then
return 1
fi
return 0
}
function buildbackend(){
cd ${BACKENDDIR}
go build ratelimit.go
if [ $? -ne 0 ];then
echo "build mirror error"
return 1
fi
mv ratelimit backend_ratelimit
echo "build backend successed."
return 0
}

function runbackend(){
cd ${BACKENDDIR}
nohup ./backend_ratelimit>${BACKENDDIR}/backend1.res 2>&1 &
if [ $? -ne 0 ];then
echo "run backend1 error"
return 1
fi
# backend2 for mirrorPool
nohup ./backend_ratelimit -p 9099 >${BACKENDDIR}/backend2.res 2>&1 &
if [ $? -ne 0 ];then
echo "run backend2 error"
return 1
fi
return 0
}

function termbackend(){
PID=`ps -ef|grep backend_ratelimit|grep -v grep|awk '{print $2}'`
if [ "$PID" != "" ];then
echo $PID|xargs kill -9
fi
echo "term backend successed."
return 0
}

function createobject(){
cd ${CONFIGDIR}
rm -f generate*.yaml
grep "^name:" backend*.yaml|sed -E 's/.*name: (.*)/\1/'|while read objname
do
sed -E "s#http:https://127.0.0.1#${BACKENDHOST}#" ${objname}.yaml > generate-${objname}.yaml
if [ $? -ne 0 ];then
echo "generate yaml error"
return 1
fi
${EG1_EGCTL} --server ${EG1_API} object create -f generate-${objname}.yaml
if [ $? -ne 0 ];then
echo "create ${objname} error"
return 1
fi
done
if [ $? -ne 0 ];then
return 1
fi
echo "create object success"
return 0
}

function deleteobject(){
cd ${CONFIGDIR}
rm -f generate*.yaml
grep "^name:" backend*.yaml|sed -E 's/.*name: (.*)/\1/'|while read objname
do
${EG1_EGCTL} --server ${EG1_API} object delete ${objname}
if [ $? -ne 0 ];then
echo "delete ${objname} error"
return 1
fi
done
if [ $? -ne 0 ];then
return 1
fi
echo "delete object success"
return 0
}

function checkobject(){
curl -v ${TESTHOST}:10080/retelimit
if [ $? -ne 0 ];then
echo "check object retelimit error"
return 1
fi
echo "check object success"
return 0
}

function testobject(){
cd ${BUILDDIR}/scripts
./autotest-cotest-backend.sh
if [ $? -ne 0 ];then
return 1
fi
echo "test success"
return 0
}

function pipeline(){
checkports
if [ $? -ne 0 ];then
exit 1
fi

buildbackend
if [ $? -ne 0 ];then
exit 1
fi

runbackend
if [ $? -ne 0 ];then
exit 1
fi

createobject
if [ $? -ne 0 ];then
deleteobject
termbackend
exit 1
fi

checkobject
if [ $? -ne 0 ];then
deleteobject
termbackend
exit 1
fi

testobject
if [ $? -ne 0 ];then
deleteobject
termbackend
exit 1
fi

deleteobject

termbackend

exit 0
}

pipeline
Loading

0 comments on commit ead388d

Please sign in to comment.