Test framework improvement (#1128)

This commit is contained in:
Chia-Chun Tai
2019-05-23 22:52:39 +08:00
committed by Ta-Ching Chen
parent 1e8dfa38da
commit c3177f9ebd
47 changed files with 1192 additions and 832 deletions
+36 -38
View File
@@ -1,6 +1,13 @@
#!/bin/bash
set -euo pipefail
source $(dirname $0)/../utils.sh
TEST_ID=$(generate_test_id)
echo "TEST_ID = $TEST_ID"
tmp_dir="/tmp/test-$TEST_ID"
mkdir -p $tmp_dir
# Use package command to create packages of type:
# 1) Multiple source files from a directory
@@ -13,25 +20,27 @@ set -euo pipefail
# Then create a function to test the packages created by package command are
# able to work.
# TODO: seperate to multiple tests
ROOT=$(dirname $0)/../..
PYTHON_RUNTIME_IMAGE=gcr.io/fission-ci/python-env:test
PYTHON_BUILDER_IMAGE=gcr.io/fission-ci/python-env-builder:test
fn1=python-srcbuild1-$(date +%s)
fn2=python-srcbuild2-$(date +%s)
env=python-$TEST_ID
fn1=python-srcbuild1-$TEST_ID
fn2=python-srcbuild2-$TEST_ID
fn4=python-deploy4-$(date +%s)
fn5=python-deploy5-$(date +%s)
fn4=python-deploy4-$TEST_ID
fn5=python-deploy5-$TEST_ID
waitBuild() {
log "Waiting for builder manager to finish the build"
while true; do
kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded
if [[ $? -eq 0 ]]; then
break
status=$(kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}')
if (echo $status | grep succeeded); then
break
else
log "status=$status Waiting for build to finish"
fi
log "Waiting for build to finish"
sleep 1
done
}
@@ -39,7 +48,7 @@ export -f waitBuild
checkFunctionResponse() {
log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/$1)
response=$(curl --retry 5 http://$FISSION_ROUTER/$1)
log "Checking for valid response"
log $response
@@ -54,24 +63,19 @@ waitEnvBuilder() {
while true; do
kubectl -n fission-builder get pod -l envName=${env},envResourceVersion=${envRV} \
-o jsonpath='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' | grep "Ready=True" | grep -i "$1"
-o jsonpath='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' | grep "Ready=True" | grep -i "$env"
if [[ $? -eq 0 ]]; then
break
fi
sleep 1
done
}
export -f waitEnvBuilder
cleanup() {
log "Cleaning up..."
fission env delete --name python || true
fission fn delete --name $fn1 || true
fission fn delete --name $fn2 || true
fission fn delete --name $fn4 || true
fission fn delete --name $fn5 || true
rm demo-src-pkg.zip || true
rm -rf testDir/ || true
rm demo-deploy-pkg.zip || true
clean_resource_by_id $TEST_ID
rm -rf $tmp_dir
}
if [ -z "${TEST_NOCLEANUP:-}" ]; then
@@ -80,17 +84,14 @@ else
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
fi
log "Pre-test cleanup"
fission env delete --name python || true
log "Creating python env"
fission env create --name python --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE
fission env create --name $env --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE
timeout 180s bash -c "waitEnvBuilder python"
timeout 180s bash -c "waitEnvBuilder $env"
# 1) Multiple source files (multiple inputs, Using * expression, from a directory)
# Currently only * expression implemented as a test
pushd $ROOT/examples/python/
pkg1=$(fission package create --src "sourcepkg/*" --env python --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \')
pkg1=$(fission package create --src "sourcepkg/*" --env $env --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \')
popd
# wait for build to finish at most 60s
timeout 60s bash -c "waitBuild $pkg1"
@@ -107,8 +108,8 @@ checkFunctionResponse $fn1 'a: 1 b: {c: 3, d: 4}'
# 2) Source archive file
log "Creating pacakage with source archive"
zip -jr demo-src-pkg.zip $ROOT/examples/python/sourcepkg/
pkg2=$(fission package create --src demo-src-pkg.zip --env python --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \')
zip -jr $tmp_dir/demo-src-pkg.zip $ROOT/examples/python/sourcepkg/
pkg2=$(fission package create --src $tmp_dir/demo-src-pkg.zip --env $env --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \')
# wait for build to finish at most 60s
timeout 60s bash -c "waitBuild $pkg2"
@@ -129,7 +130,7 @@ checkFunctionResponse $fn2 'a: 1 b: {c: 3, d: 4}'
# 4) Deployment files from a directory
pushd $ROOT/examples/python/
pkg4=$(fission package create --deploy "multifile/*" --env python| cut -f2 -d' '| tr -d \')
pkg4=$(fission package create --deploy "multifile/*" --env $env| cut -f2 -d' '| tr -d \')
popd
log "Creating function " $fn4
fission fn create --name $fn4 --pkg $pkg4 --entrypoint "main.main"
@@ -145,15 +146,15 @@ checkFunctionResponse $fn4 'Hello, world!'
# 5) Deployment archive
log "Creating package with deploy archive"
mkdir testDir
touch testDir/__init__.py
printf 'def main():\n return "Hello, world!"' > testDir/hello.py
zip -jr demo-deploy-pkg.zip testDir/
pkgName=$(fission package create --deploy demo-deploy-pkg.zip --env python| cut -f2 -d' '| tr -d \')
mkdir $tmp_dir/deploypkg
touch $tmp_dir/deploypkg/__init__.py
printf 'def main():\n return "Hello, world!"' > $tmp_dir/deploypkg/hello.py
zip -jr $tmp_dir/demo-deploy-pkg.zip $tmp_dir/deploypkg/
pkg5=$(fission package create --deploy $tmp_dir/demo-deploy-pkg.zip --env $env| cut -f2 -d' '| tr -d \')
log "Updating function " $fn5
fission fn create --name $fn5 --pkg $pkgName --entrypoint "hello.main"
fission fn create --name $fn5 --pkg $pkg5 --entrypoint "hello.main"
log "Creating route"
fission route create --function $fn5 --url /$fn5 --method GET
@@ -166,7 +167,4 @@ checkFunctionResponse $fn5 'Hello, world!'
# 6) Deployment archive from a HTTP location
# TBD
# crappy cleanup, improve this later
kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger
log "All done."