Add cleanup function to test scripts (#863)

This commit is contained in:
Ta-Ching Chen
2018-08-18 02:11:08 +08:00
committed by GitHub
parent d443f8b2ef
commit 2d01382a82
22 changed files with 339 additions and 99 deletions
@@ -8,16 +8,11 @@ fn=testnormal-$(date +%s)
fn_secret=testsecret-$(date +%s)
fn_cfgmap=testcfgmap-$(date +%s)
cp secret.py.template secret.py
sed -i "s/{{ FN_SECRET }}/${fn_secret}/g" secret.py
cp cfgmap.py.template cfgmap.py
sed -i "s/{{ FN_CFGMAP }}/${fn_cfgmap}/g" cfgmap.py
function cleanup {
log "Cleanup everything"
kubectl delete secret -n default ${fn_secret}
kubectl delete configmap -n default ${fn_cfgmap}
cleanup() {
log "Cleaning up..."
fission env delete --name python || true
kubectl delete secret -n default ${fn_secret} || true
kubectl delete configmap -n default ${fn_cfgmap} || true
# delete functions
for f in ${fn_secret} ${fn_cfgmap} ${fn}
do
@@ -30,6 +25,18 @@ function cleanup {
done
}
if [ -z "${TEST_NOCLEANUP:-}" ]; then
trap cleanup EXIT
else
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
fi
cp secret.py.template secret.py
sed -i "s/{{ FN_SECRET }}/${fn_secret}/g" secret.py
cp cfgmap.py.template cfgmap.py
sed -i "s/{{ FN_CFGMAP }}/${fn_cfgmap}/g" cfgmap.py
checkFunctionResponse() {
log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/${1})
@@ -54,15 +61,12 @@ fission env delete --name python || true
log "Creating python env"
fission env create --name python --image fission/python-env
trap "fission env delete --name python" EXIT
log "Creating secret"
kubectl create secret generic ${fn_secret} --from-literal=TEST_KEY="TESTVALUE" -n default
trap "kubectl delete secret ${fn_secret} -n default" EXIT
log "Creating function with secret"
fission fn create --name ${fn_secret} --env python --code secret.py --secret ${fn_secret}
trap "fission fn delete --name ${fn_secret}" EXIT
log "Creating route"
fission route create --function ${fn_secret} --url /${fn_secret} --method GET
@@ -75,7 +79,6 @@ checkFunctionResponse ${fn_secret} 'TESTVALUE' 'secret'
log "Creating function with newdeploy executorType and new secret value"
kubectl patch secrets ${fn_secret} -p '{"data":{"TEST_KEY":"TkVXVkFMCg=="}}' -n default
fission fn create --name ${fn_secret}-1 --env python --code secret.py --secret ${fn_secret} --executortype newdeploy
trap "fission fn delete --name ${fn_secret}-1" EXIT
log "Creating route"
fission route create --function ${fn_secret}-1 --url /${fn_secret}-1 --method GET
@@ -87,11 +90,9 @@ checkFunctionResponse ${fn_secret}-1 'NEWVAL' 'secret'
log "Creating configmap"
kubectl create configmap ${fn_cfgmap} --from-literal=TEST_KEY="TESTVALUE" -n default
trap "kubectl delete configmap ${fn_cfgmap} -n default" EXIT
log "creating function with configmap"
fission fn create --name ${fn_cfgmap} --env python --code cfgmap.py --configmap ${fn_cfgmap}
trap "fission fn delete --name ${fn_cfgmap}" EXIT
log "Creating route"
fission route create --function ${fn_cfgmap} --url /${fn_cfgmap} --method GET
@@ -104,7 +105,6 @@ checkFunctionResponse ${fn_cfgmap} 'TESTVALUE' 'configmap'
log "Creating function with newdeploy executorType and new configmap value"
kubectl patch configmap ${fn_cfgmap} -p '{"data":{"TEST_KEY":"NEWVAL"}}' -n default
fission fn create --name ${fn_cfgmap}-1 --env python --code cfgmap.py --configmap ${fn_cfgmap} --executortype newdeploy
trap "fission fn delete --name ${fn_cfgmap}-1" EXIT
log "Creating route"
fission route create --function ${fn_cfgmap}-1 --url /${fn_cfgmap}-1 --method GET
@@ -116,7 +116,6 @@ checkFunctionResponse ${fn_cfgmap}-1 'NEWVAL' 'configmap'
log "testing creating a function without a secret or configmap"
fission function create --name ${fn} --env python --code empty.py
trap "fission fn delete --name ${fn}" EXIT
log "Creating route"
fission route create --function ${fn} --url /${fn} --method GET
@@ -135,4 +134,3 @@ fi
log "test empty passed"
log "All done."
trap "cleanup" EXIT