Tests for function update (#550)
Tests for updates to a function of new deployment executor type. Tests check for changes in the environment, scale, secrets etc. Also checks conversion of function executor type from new deployment to pool manager and vice versa
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# global variables
|
||||
pkg=""
|
||||
http_status=""
|
||||
url=""
|
||||
|
||||
|
||||
cleanup() {
|
||||
if [ -e "test-deploy-pkg.zip" ]; then
|
||||
rm -rf test-deploy-pkg.zip test_dir
|
||||
fi
|
||||
if [ -e "/tmp/file" ]; then
|
||||
rm -rf /tmp/file
|
||||
fi
|
||||
}
|
||||
|
||||
create_archive() {
|
||||
log "Creating an archive"
|
||||
mkdir test_dir
|
||||
printf 'def main():\n return "Hello, world!"' > test_dir/hello.py
|
||||
zip -jr test-deploy-pkg.zip test_dir/
|
||||
}
|
||||
|
||||
create_env() {
|
||||
log "Creating environment"
|
||||
fission env create --name $1 --image fission/python-env:latest --builder fission/python-builder:latest --mincpu 40 --maxcpu 80 --minmemory 64 --maxmemory 128 --poolsize 2
|
||||
}
|
||||
|
||||
create_fn() {
|
||||
log "Creating functiom"
|
||||
fission fn create --name $1 --env $2 --deploy test-deploy-pkg.zip --entrypoint "hello.main" --executortype newdeploy --minscale 1 --maxscale 4 --targetcpu 50
|
||||
}
|
||||
|
||||
create_route() {
|
||||
log "Creating route"
|
||||
fission route create --function $1 --url /$1 --method GET
|
||||
|
||||
log "Waiting for router & newdeploy deployment creation"
|
||||
sleep 5
|
||||
}
|
||||
|
||||
update_archive() {
|
||||
log "Updating the archive"
|
||||
sed -i 's/world/fission/' test_dir/hello.py
|
||||
zip -jr test-deploy-pkg.zip test_dir/
|
||||
}
|
||||
|
||||
update_fn() {
|
||||
log "Updating function with updated package"
|
||||
fission fn update --name $1 --env $2 --deploy test-deploy-pkg.zip --entrypoint "hello.main" --executortype newdeploy --minscale 1 --maxscale 4 --targetcpu 50
|
||||
|
||||
log "Waiting for deployment to update"
|
||||
sleep 5
|
||||
}
|
||||
|
||||
test_fn() {
|
||||
echo "Doing an HTTP GET on the function's route"
|
||||
echo "Checking for valid response"
|
||||
|
||||
while true; do
|
||||
response0=$(curl http://$FISSION_ROUTER/$1)
|
||||
echo $response0 | grep -i $2
|
||||
if [[ $? -eq 0 ]]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
export -f test_fn
|
||||
|
||||
# This test only tests one path of execution: updating package and checking results of function
|
||||
# There might be potential future tests where one can test changes in:
|
||||
# environment, min & max scale, secrets and configmaps etc.
|
||||
|
||||
# This test in summary:
|
||||
# Creates a archive, env. with builder and a function and tests for response
|
||||
# Then updates archive with a different word and udpates functions to check for new string in response
|
||||
main() {
|
||||
# trap
|
||||
trap cleanup EXIT
|
||||
|
||||
env=python-$(date +%N)
|
||||
fn_name="hellopython"
|
||||
|
||||
create_archive
|
||||
create_env $env
|
||||
create_fn $fn_name $env
|
||||
create_route $fn_name
|
||||
timeout 60 bash -c "test_fn $fn_name 'world'"
|
||||
update_archive
|
||||
update_fn $fn_name $env
|
||||
timeout 60 bash -c "test_fn $fn_name 'fission'"
|
||||
log "Update function for new deployment executor passed"
|
||||
}
|
||||
|
||||
main
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Common methods used for testing function update
|
||||
#
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
test_fn() {
|
||||
echo "Doing an HTTP GET on the function's route"
|
||||
echo "Checking for valid response"
|
||||
|
||||
while true; do
|
||||
response0=$(curl http://$FISSION_ROUTER/$1)
|
||||
echo $response0 | grep -i $2
|
||||
if [[ $? -eq 0 ]]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
export -f test_fn
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname $0)/fnupdate_utils.sh
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
env=python-$(date +%N)
|
||||
fn_name=hellopy-$(date +%N)
|
||||
|
||||
old_cfgmap=old-cfgmap-$(date +%N)
|
||||
new_cfgmap=new-cfgmap-$(date +%N)
|
||||
|
||||
cp ../test_secret_cfgmap/cfgmap.py.template cfgmap.py
|
||||
sed -i "s/{{ FN_CFGMAP }}/${old_cfgmap}/g" cfgmap.py
|
||||
|
||||
log "Creating env $env"
|
||||
fission env create --name $env --image fission/python-env
|
||||
trap "fission env delete --name $env" EXIT
|
||||
|
||||
log "Creating configmap $old_cfgmap"
|
||||
kubectl create configmap ${old_cfgmap} --from-literal=TEST_KEY="TESTVALUE" -n default
|
||||
trap "kubectl delete configmap ${old_cfgmap} -n default" EXIT
|
||||
|
||||
log "Creating NewDeploy function spec: $fn_name"
|
||||
fission spec init
|
||||
trap "rm -rf specs" EXIT
|
||||
fission fn create --spec --name $fn_name --env $env --code cfgmap.py --configmap $old_cfgmap --minscale 1 --maxscale 4 --executortype newdeploy
|
||||
fission spec apply ./specs/
|
||||
trap "fission spec destroy" EXIT
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn_name} --url /${fn_name} --method GET
|
||||
|
||||
log "Waiting for router to catch up"
|
||||
sleep 5
|
||||
|
||||
log "Testing function"
|
||||
timeout 60 bash -c "test_fn $fn_name 'TESTVALUE'"
|
||||
|
||||
log "Creating a new cfgmap"
|
||||
kubectl create configmap ${new_cfgmap} --from-literal=TEST_KEY="TESTVALUE_NEW" -n default
|
||||
trap "kubectl delete configmap ${new_cfgmap} -n default" EXIT
|
||||
|
||||
log "Updating cfgmap and code for the function"
|
||||
sed -i "s/${old_cfgmap}/${new_cfgmap}/g" cfgmap.py
|
||||
sed -i "s/${old_cfgmap}/${new_cfgmap}/g" specs/function-$fn_name.yaml
|
||||
|
||||
log "Applying function changes"
|
||||
fission spec apply ./specs/
|
||||
trap "fission spec destroy" EXIT
|
||||
|
||||
log "Waiting for changes to take effect"
|
||||
sleep 5
|
||||
|
||||
log "Testing function for cfgmap value"
|
||||
timeout 60 bash -c "test_fn $fn_name 'TESTVALUE_NEW'"
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname $0)/fnupdate_utils.sh
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
env_old=python-$(date +%N)
|
||||
env_new=python-$(date +%N)
|
||||
fn=hellopy-$(date +%N)
|
||||
|
||||
log "Creating env $env_old"
|
||||
fission env create --name $env_old --image fission/python-env
|
||||
trap "fission env delete --name $env_old" EXIT
|
||||
|
||||
log "Creating function $fn"
|
||||
fission fn create --name $fn --env $env_old --code $ROOT/examples/python/hello.py --minscale 1 --maxscale 4 --executortype newdeploy --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
|
||||
trap "fission fn delete --name $fn" EXIT
|
||||
|
||||
log "Creating route for function $fn"
|
||||
fission route create --function ${fn} --url /${fn} --method GET
|
||||
|
||||
log "Waiting for router to catch up"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
|
||||
log "Creating a new env $env_new"
|
||||
fission env create --name $env_new --image fission/python-env
|
||||
trap "fission env delete --name $env_old" EXIT
|
||||
|
||||
log "Updating function with a new environment"
|
||||
fission fn update --name $fn --env $env_new --code $ROOT/examples/python/hello.py --minscale 1 --maxscale 4 --executortype newdeploy --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
|
||||
|
||||
log "Waiting for update to catch up"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# global variables
|
||||
pkg=""
|
||||
http_status=""
|
||||
url=""
|
||||
|
||||
source $(dirname $0)/fnupdate_utils.sh
|
||||
|
||||
cleanup() {
|
||||
if [ -e "test-deploy-pkg.zip" ]; then
|
||||
rm -rf test-deploy-pkg.zip test_dir
|
||||
fi
|
||||
if [ -e "/tmp/file" ]; then
|
||||
rm -rf /tmp/file
|
||||
fi
|
||||
}
|
||||
|
||||
# This test tests updating package and checking results of function, it does:
|
||||
# Creates a archive, env. with builder and a function and tests for response
|
||||
# Then updates archive with a different word and udpates functions to check for new string in response
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
env=python-$(date +%N)
|
||||
fn_name=hellopython-$(date +%N)
|
||||
|
||||
log "Creating an archive"
|
||||
mkdir test_dir
|
||||
printf 'def main():\n return "Hello, world!"' > test_dir/hello.py
|
||||
zip -jr test-deploy-pkg.zip test_dir/
|
||||
|
||||
log "Creating environment"
|
||||
fission env create --name $env --image fission/python-env:latest --builder fission/python-builder:latest --mincpu 40 --maxcpu 80 --minmemory 64 --maxmemory 128 --poolsize 2
|
||||
|
||||
log "Creating functiom"
|
||||
fission fn create --name $fn_name --env $env --deploy test-deploy-pkg.zip --entrypoint "hello.main" --executortype newdeploy --minscale 1 --maxscale 4 --targetcpu 50
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function $fn_name --url /$fn_name --method GET
|
||||
|
||||
log "Waiting for router & newdeploy deployment creation"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn_name 'world'"
|
||||
|
||||
log "Updating the archive"
|
||||
sed -i 's/world/fission/' test_dir/hello.py
|
||||
zip -jr test-deploy-pkg.zip test_dir/
|
||||
|
||||
log "Updating function with updated package"
|
||||
fission fn update --name $fn_name --env $env --deploy test-deploy-pkg.zip --entrypoint "hello.main" --executortype newdeploy --minscale 1 --maxscale 4 --targetcpu 50
|
||||
|
||||
log "Waiting for deployment to update"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn_name 'fission'"
|
||||
|
||||
log "Update function for new deployment executor passed"
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname $0)/fnupdate_utils.sh
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
env=python-$(date +%N)
|
||||
fn=hellopython-$(date +%N)
|
||||
|
||||
log "Creating Python env $env"
|
||||
fission env create --name $env --image fission/python-env --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
|
||||
trap "fission env delete --name $env" EXIT
|
||||
|
||||
log "Creating function $fn"
|
||||
fission fn create --name $fn --env $env --code $ROOT/examples/python/hello.py
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function $fn --url /$fn --method GET
|
||||
|
||||
log "Waiting for router to catch up"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
|
||||
log "Updating function $fn executor type to new deployment"
|
||||
fission fn update --name $fn --env $env --code $ROOT/examples/python/hello.py --minscale 1 --maxscale 4 --executortype newdeploy
|
||||
|
||||
log "Waiting for router to catch up"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
|
||||
log "Updating function $fn executor type back to pool manager"
|
||||
fission fn update --name $fn --env $env --code $ROOT/examples/python/hello.py --executortype poolmgr
|
||||
|
||||
log "Waiting for router to catch up"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname $0)/fnupdate_utils.sh
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
env=python-$(date +%N)
|
||||
fn=hellopython-$(date +%N)
|
||||
|
||||
mincpu1=40
|
||||
maxcpu1=140
|
||||
minmem1=256
|
||||
maxmem1=512
|
||||
|
||||
mincpu2=80
|
||||
maxcpu2=200
|
||||
minmem2=512
|
||||
maxmem2=768
|
||||
|
||||
log "Creating Python env $env"
|
||||
fission env create --name $env --image fission/python-env --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
|
||||
trap "fission env delete --name $env" EXIT
|
||||
|
||||
log "Creating function $fn"
|
||||
fission fn create --name $fn --env $env --code $ROOT/examples/python/hello.py --minscale 1 --maxscale 4 --executortype newdeploy --mincpu $mincpu1 --maxcpu $maxcpu1 --minmemory $minmem1 --maxmemory $maxmem1
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn} --url /${fn} --method GET
|
||||
|
||||
log "Waiting for updates to take effect"
|
||||
sleep 5
|
||||
|
||||
#If variable not used, shell assumes 'function' to be a real function
|
||||
func=function
|
||||
|
||||
maxcpu_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.limits.cpu}'|tr -dc '0-9')
|
||||
mincpu_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.requests.cpu}'|tr -dc '0-9')
|
||||
maxmem_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.limits.memory}'|tr -dc '0-9')
|
||||
minmem_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.requests.memory}'|tr -dc '0-9')
|
||||
|
||||
if [ "$maxcpu_actual" -ne "$maxcpu1" ] || [ "$mincpu_actual" -ne "$mincpu1" ]
|
||||
then
|
||||
log "Failed to override CPU of function from environment defaults"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$maxmem_actual" -ne "$maxmem1" ] || [ "$minmem_actual" -ne "$minmem1" ]
|
||||
then
|
||||
log "Failed to override Memory of function from environment defaults"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
|
||||
log "Updating function $fn with new resource values"
|
||||
fission fn update --name $fn --env $env --code $ROOT/examples/python/hello.py --minscale 1 --maxscale 4 --executortype newdeploy --mincpu $mincpu2 --maxcpu $maxcpu2 --minmemory $minmem2 --maxmemory $maxmem2
|
||||
|
||||
maxcpu_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.limits.cpu}'|tr -dc '0-9')
|
||||
mincpu_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.requests.cpu}'|tr -dc '0-9')
|
||||
maxmem_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.limits.memory}'|tr -dc '0-9')
|
||||
minmem_actual=$(kubectl get $func $fn -n default -ojsonpath='{.spec.resources.requests.memory}'|tr -dc '0-9')
|
||||
|
||||
if [ "$maxcpu_actual" -ne "$maxcpu2" ] || [ "$mincpu_actual" -ne "$mincpu2" ]
|
||||
then
|
||||
log "Failed to update CPU on updated function"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$maxmem_actual" -ne "$maxmem2" ] || [ "$minmem_actual" -ne "$minmem2" ]
|
||||
then
|
||||
log "Failed to update memory on updated function"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname $0)/fnupdate_utils.sh
|
||||
|
||||
env=python-$(date +%N)
|
||||
fn=hellopython-$(date +%N)
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
targetMinScale=2
|
||||
targetMaxScale=6
|
||||
targetCpuPercent=60
|
||||
|
||||
log "Creating Python env $env"
|
||||
fission env create --name $env --image fission/python-env --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
|
||||
trap "fission env delete --name $env" EXIT
|
||||
|
||||
log "Creating function $fn"
|
||||
fission fn create --name $fn --env $env --code $ROOT/examples/python/hello.py --minscale 1 --maxscale 4 --executortype newdeploy --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
|
||||
|
||||
log "Creating route for function $fn"
|
||||
fission route create --function ${fn} --url /${fn} --method GET
|
||||
|
||||
log "Waiting for update to catch up"
|
||||
sleep 5
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
|
||||
log "Updating function scale and target CPU percent for $fn"
|
||||
fission fn update --name $fn --env $env --code $ROOT/examples/python/hello.py --minscale $targetMinScale --maxscale $targetMaxScale --targetcpu $targetCpuPercent --executortype newdeploy --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
|
||||
|
||||
log "Waiting for update to catch up"
|
||||
sleep 5
|
||||
|
||||
#If variable not used, shell assumes 'function' to be a real function
|
||||
func=function
|
||||
actualMinScale=$(kubectl -n default get $func $fn -ojsonpath='{.spec.InvokeStrategy.ExecutionStrategy.MinScale}')
|
||||
actualMaxScale=$(kubectl -n default get $func $fn -ojsonpath='{.spec.InvokeStrategy.ExecutionStrategy.MaxScale}')
|
||||
actualTargetCPU=$(kubectl -n default get $func $fn -ojsonpath='{.spec.InvokeStrategy.ExecutionStrategy.TargetCPUPercent}')
|
||||
|
||||
if [ "$actualMinScale" -ne "$targetMinScale" ]
|
||||
then
|
||||
log "Failed to update min scale for function"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$actualMaxScale" -ne "$targetMaxScale" ]
|
||||
then
|
||||
log "Failed to update max scale for function"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$actualTargetCPU" -ne "$targetCpuPercent" ]
|
||||
then
|
||||
log "Failed to update target CPU for the function"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
timeout 60 bash -c "test_fn $fn 'world'"
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source $(dirname $0)/fnupdate_utils.sh
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
env=python-$(date +%N)
|
||||
fn_name=hellopython-$(date +%N)
|
||||
|
||||
old_secret=old-secret-$(date +%N)
|
||||
new_secret=new-secret-$(date +%N)
|
||||
|
||||
cp ../test_secret_cfgmap/secret.py.template secret.py
|
||||
sed -i "s/{{ FN_SECRET }}/${old_secret}/g" secret.py
|
||||
|
||||
log "Creating env $env"
|
||||
fission env create --name $env --image fission/python-env
|
||||
trap "fission env delete --name $env" EXIT
|
||||
|
||||
log "Creating secret $old_secret"
|
||||
kubectl create secret generic ${old_secret} --from-literal=TEST_KEY="TESTVALUE" -n default
|
||||
trap "kubectl delete secret ${old_secret} -n default" EXIT
|
||||
|
||||
log "Creating NewDeploy function spec: $fn_name"
|
||||
fission spec init
|
||||
trap "rm -rf specs" EXIT
|
||||
fission fn create --spec --name $fn_name --env $env --code secret.py --secret $old_secret --minscale 1 --maxscale 4 --executortype newdeploy
|
||||
fission spec apply ./specs/
|
||||
trap "fission spec destroy" EXIT
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn_name} --url /${fn_name} --method GET
|
||||
|
||||
log "Waiting for router to catch up"
|
||||
sleep 5
|
||||
|
||||
log "Testing function"
|
||||
timeout 60 bash -c "test_fn $fn_name 'TESTVALUE'"
|
||||
|
||||
log "Creating a new secret"
|
||||
kubectl create secret generic ${new_secret} --from-literal=TEST_KEY="TESTVALUE_NEW" -n default
|
||||
trap "kubectl delete secret ${new_secret} -n default" EXIT
|
||||
|
||||
log "Updating secret and code for the function"
|
||||
sed -i "s/${old_secret}/${new_secret}/g" secret.py
|
||||
sed -i "s/${old_secret}/${new_secret}/g" specs/function-$fn_name.yaml
|
||||
|
||||
log "Applying function changes"
|
||||
fission spec apply ./specs/
|
||||
trap "fission spec destroy" EXIT
|
||||
|
||||
log "Waiting for changes to take effect"
|
||||
sleep 5
|
||||
|
||||
log "Testing function for secret value"
|
||||
timeout 60 bash -c "test_fn $fn_name 'TESTVALUE_NEW'"
|
||||
@@ -47,7 +47,7 @@ sleep 60
|
||||
fission function logs --name $fn --detail > /tmp/logfile
|
||||
|
||||
size=$(wc -c </tmp/logfile)
|
||||
if [ $size = 0 ]
|
||||
if [ $size == 0 ]
|
||||
then
|
||||
fission function logs --name $fn --detail > /tmp/logfile
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user