Addressing review comments.

This commit is contained in:
smruthi2187
2018-02-09 14:26:32 -08:00
parent 841c7ef845
commit 281a492149
18 changed files with 176 additions and 209 deletions
+16
View File
@@ -18,9 +18,25 @@ package fission
import ( import (
"fmt" "fmt"
"os"
"os/signal"
"runtime/debug"
"syscall"
) )
func UrlForFunction(name string) string { func UrlForFunction(name string) string {
prefix := "/fission-function" prefix := "/fission-function"
return fmt.Sprintf("%v/%v", prefix, name) return fmt.Sprintf("%v/%v", prefix, name)
} }
func SetupStackTraceHandler() {
// register signal handler for dumping stack trace.
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
fmt.Println("Received SIGTERM : Dumping stack trace")
debug.PrintStack()
os.Exit(1)
}()
}
+3 -17
View File
@@ -18,28 +18,14 @@ package controller
import ( import (
"log" "log"
"os"
"os/signal"
"runtime/debug"
"syscall"
"github.com/fission/fission"
"github.com/fission/fission/crd" "github.com/fission/fission/crd"
) )
func dumpStackTrace() {
debug.PrintStack()
}
func Start(port int) { func Start(port int) {
// register signal handler for dumping stack trace. // setup a signal handler for SIGTERM
c := make(chan os.Signal, 1) fission.SetupStackTraceHandler()
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
log.Println("Received SIGTERM : Dumping stack trace")
dumpStackTrace()
os.Exit(1)
}()
fc, _, apiExtClient, err := crd.MakeFissionClient() fc, _, apiExtClient, err := crd.MakeFissionClient()
if err != nil { if err != nil {
+2 -12
View File
@@ -18,12 +18,9 @@ package executor
import ( import (
"log" "log"
"os"
"os/signal"
"runtime/debug" "runtime/debug"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
"github.com/dchest/uniuri" "github.com/dchest/uniuri"
@@ -192,15 +189,8 @@ func dumpStackTrace() {
// StartExecutor Starts executor and the executor components such as Poolmgr, // StartExecutor Starts executor and the executor components such as Poolmgr,
// deploymgr and potential future executor types // deploymgr and potential future executor types
func StartExecutor(fissionNamespace string, functionNamespace string, port int) error { func StartExecutor(fissionNamespace string, functionNamespace string, port int) error {
// register signal handler for dumping stack trace. // setup a signal handler for SIGTERM
c := make(chan os.Signal, 1) fission.SetupStackTraceHandler()
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
log.Println("Received SIGTERM : Dumping stack trace")
dumpStackTrace()
os.Exit(1)
}()
fissionClient, kubernetesClient, _, err := crd.MakeFissionClient() fissionClient, kubernetesClient, _, err := crd.MakeFissionClient()
restClient := fissionClient.GetCrdClient() restClient := fissionClient.GetCrdClient()
+3 -16
View File
@@ -45,14 +45,12 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"os/signal"
"runtime/debug"
"syscall"
"time" "time"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/fission/fission"
"github.com/fission/fission/crd" "github.com/fission/fission/crd"
executorClient "github.com/fission/fission/executor/client" executorClient "github.com/fission/fission/executor/client"
) )
@@ -74,20 +72,9 @@ func serve(ctx context.Context, port int, httpTriggerSet *HTTPTriggerSet, resolv
http.ListenAndServe(url, handlers.LoggingHandler(os.Stdout, mr)) http.ListenAndServe(url, handlers.LoggingHandler(os.Stdout, mr))
} }
func dumpStackTrace() {
debug.PrintStack()
}
func Start(port int, executorUrl string) { func Start(port int, executorUrl string) {
// register signal handler for dumping stack trace. // setup a signal handler for SIGTERM
c := make(chan os.Signal, 1) fission.SetupStackTraceHandler()
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
log.Println("Received SIGTERM : Dumping stack trace")
dumpStackTrace()
os.Exit(1)
}()
fmap := makeFunctionServiceMap(time.Minute) fmap := makeFunctionServiceMap(time.Minute)
+3 -16
View File
@@ -22,12 +22,10 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"os/signal"
"runtime/debug"
"strconv" "strconv"
"syscall"
"time" "time"
"github.com/fission/fission"
"github.com/gorilla/handlers" "github.com/gorilla/handlers"
"github.com/gorilla/mux" "github.com/gorilla/mux"
_ "github.com/graymeta/stow/local" _ "github.com/graymeta/stow/local"
@@ -174,20 +172,9 @@ func (ss *StorageService) Start(port int) {
log.Fatal(http.ListenAndServe(address, handlers.LoggingHandler(os.Stdout, r))) log.Fatal(http.ListenAndServe(address, handlers.LoggingHandler(os.Stdout, r)))
} }
func dumpStackTrace() {
debug.PrintStack()
}
func RunStorageService(storageType StorageType, storagePath string, containerName string, port int, enablePruner bool) *StorageService { func RunStorageService(storageType StorageType, storagePath string, containerName string, port int, enablePruner bool) *StorageService {
// register signal handler for dumping stack trace. // setup a signal handler for SIGTERM
c := make(chan os.Signal, 1) fission.SetupStackTraceHandler()
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
log.Println("Received SIGTERM : Dumping stack trace")
dumpStackTrace()
os.Exit(1)
}()
// initialize logger // initialize logger
log.SetLevel(log.InfoLevel) log.SetLevel(log.InfoLevel)
-2
View File
@@ -60,7 +60,6 @@ var (
) )
func MakeStowClient(storageType StorageType, storagePath string, containerName string) (*StowClient, error) { func MakeStowClient(storageType StorageType, storagePath string, containerName string) (*StowClient, error) {
log.Infof("start : MakeStowClient")
if storageType != StorageTypeLocal { if storageType != StorageTypeLocal {
return nil, errors.New("Storage types other than 'local' are not implemented") return nil, errors.New("Storage types other than 'local' are not implemented")
} }
@@ -105,7 +104,6 @@ func MakeStowClient(storageType StorageType, storagePath string, containerName s
} }
stowClient.container = con stowClient.container = con
log.Infof("end : MakeStowClient")
return stowClient, nil return stowClient, nil
} }
+13 -10
View File
@@ -174,8 +174,11 @@ helm_install_fission() {
echo "Deleting old releases" echo "Deleting old releases"
helm list -q|xargs -I@ bash -c "helm_uninstall_fission @" helm list -q|xargs -I@ bash -c "helm_uninstall_fission @"
# deleting ns does take a while after command is issued. # deleting ns does take a while after command is issued
sleep 45 while `kubectl get ns| grep fission-builder`
do
sleep 5
done
echo "Installing fission" echo "Installing fission"
helm install \ helm install \
@@ -352,7 +355,7 @@ dump_env_pods() {
describe_pods_ns() { describe_pods_ns() {
echo "--- describe pods $1---" echo "--- describe pods $1---"
kubect describe pods -n $1 kubectl describe pods -n $1
echo "--- End describe pods $1 ---" echo "--- End describe pods $1 ---"
} }
@@ -405,11 +408,11 @@ dump_logs() {
dump_fission_crds dump_fission_crds
} }
echo_log() { log() {
echo `date +%Y/%m/%d:%H:%M:%S`" $1" echo `date +%Y/%m/%d:%H:%M:%S`" $1"
} }
export -f echo_log export -f log
export FAILURES=0 export FAILURES=0
run_all_tests() { run_all_tests() {
@@ -464,9 +467,9 @@ install_and_test() {
trap "helm_uninstall_fission $id" EXIT trap "helm_uninstall_fission $id" EXIT
if ! helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval if ! helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval
then then
describe_all_pods $id describe_all_pods $id
dump_kubernetes_events $id dump_kubernetes_events $id
dump_tiller_logs dump_tiller_logs
exit 1 exit 1
fi fi
@@ -481,8 +484,8 @@ install_and_test() {
if [ $FAILURES -ne 0 ] if [ $FAILURES -ne 0 ]
then then
# describe each pod in fission ns and function namespace # describe each pod in fission ns and function namespace
describe_all_pods $id describe_all_pods $id
exit 1 exit 1
fi fi
} }
+18 -18
View File
@@ -16,7 +16,7 @@ cleanup() {
} }
create_archive() { create_archive() {
echo_log "Creating an archive" log "Creating an archive"
mkdir test_dir mkdir test_dir
dd if=/dev/urandom of=test_dir/dynamically_generated_file bs=256k count=1 dd if=/dev/urandom of=test_dir/dynamically_generated_file bs=256k count=1
printf 'def main():\n return "Hello, world!"' > test_dir/hello.py printf 'def main():\n return "Hello, world!"' > test_dir/hello.py
@@ -24,17 +24,17 @@ create_archive() {
} }
create_package() { create_package() {
echo_log "Creating package" log "Creating package"
pkg=$(fission package create --deploy "test-deploy-pkg.zip" --env python| cut -f2 -d' '| tr -d \') pkg=$(fission package create --deploy "test-deploy-pkg.zip" --env python| cut -f2 -d' '| tr -d \')
} }
delete_package() { delete_package() {
echo_log "Deleting package: $1" log "Deleting package: $1"
fission package delete --name $1 fission package delete --name $1
} }
get_archive_url_from_package() { get_archive_url_from_package() {
echo_log "Getting archive URL from package: $1" log "Getting archive URL from package: $1"
url=`kubectl get package $1 -ojsonpath='{.spec.deployment.url}'` url=`kubectl get package $1 -ojsonpath='{.spec.deployment.url}'`
} }
@@ -55,63 +55,63 @@ main() {
# create a huge archive # create a huge archive
create_archive create_archive
echo_log "created archive test-deploy-pkg.zip" log "created archive test-deploy-pkg.zip"
# create packages with the huge archive # create packages with the huge archive
create_package create_package
pkg_1=$pkg pkg_1=$pkg
get_archive_url_from_package $pkg_1 get_archive_url_from_package $pkg_1
url_1=$url url_1=$url
echo_log "pkg: $pkg_1, archive_url : $url_1" log "pkg: $pkg_1, archive_url : $url_1"
create_package create_package
pkg_2=$pkg pkg_2=$pkg
get_archive_url_from_package $pkg_2 get_archive_url_from_package $pkg_2
url_2=$url url_2=$url
echo_log "pkg: $pkg_2, archive_url : $url_2" log "pkg: $pkg_2, archive_url : $url_2"
# delete packages # delete packages
delete_package $pkg_1 delete_package $pkg_1
delete_package $pkg_2 delete_package $pkg_2
echo_log "deleted packages : $pkg_1 $pkg_2" log "deleted packages : $pkg_1 $pkg_2"
# curl on the archive url # curl on the archive url
get_archive_from_storage $url_1 get_archive_from_storage $url_1
echo_log "http_status for $url_1 : $http_status" log "http_status for $url_1 : $http_status"
if [ "$http_status" -ne "200" ]; then if [ "$http_status" -ne "200" ]; then
echo_log "Archive $url_1 absent on storage, while expected to be present" log "Archive $url_1 absent on storage, while expected to be present"
exit 1 exit 1
fi fi
# curl on the archive url # curl on the archive url
get_archive_from_storage $url_2 get_archive_from_storage $url_2
echo_log "http_status for $url_2 : $http_status" log "http_status for $url_2 : $http_status"
if [ "$http_status" -ne "200" ]; then if [ "$http_status" -ne "200" ]; then
echo_log "Archive $url_2 absent on storage, while expected to be present" log "Archive $url_2 absent on storage, while expected to be present"
exit 1 exit 1
fi fi
# archivePruner is set to run every minute for test. In production, its set to run every hour. # archivePruner is set to run every minute for test. In production, its set to run every hour.
echo_log "waiting for packages to get recycled" log "waiting for packages to get recycled"
sleep 120 sleep 120
# curl on the archive url # curl on the archive url
get_archive_from_storage $url_1 get_archive_from_storage $url_1
echo_log "http_status for $url_1 : $http_status" log "http_status for $url_1 : $http_status"
if [ "$http_status" -ne "404" ]; then if [ "$http_status" -ne "404" ]; then
echo_log "Archive $url_1 should have been recycled, but curl returned $http_status, while expected status is 404." log "Archive $url_1 should have been recycled, but curl returned $http_status, while expected status is 404."
exit 1 exit 1
fi fi
# curl on the archive url # curl on the archive url
get_archive_from_storage $url_2 get_archive_from_storage $url_2
echo_log "http_status for $url_2 : $http_status" log "http_status for $url_2 : $http_status"
if [ "$http_status" -ne "404" ]; then if [ "$http_status" -ne "404" ]; then
echo_log "Archive $url_2 should have been recycled, but curl returned $http_status, while expected status is 404." log "Archive $url_2 should have been recycled, but curl returned $http_status, while expected status is 404."
exit 1 exit 1
fi fi
echo_log "Test archive pruner PASSED" log "Test archive pruner PASSED"
} }
main main
+13 -13
View File
@@ -5,51 +5,51 @@ set -euo pipefail
ROOT=$(dirname $0)/../.. ROOT=$(dirname $0)/../..
# Create a hello world function in nodejs, test it with an http trigger # Create a hello world function in nodejs, test it with an http trigger
echo_log "NewDeploy ExecutorType: Pre-test cleanup" log "NewDeploy ExecutorType: Pre-test cleanup"
fission env delete --name nodejs || true fission env delete --name nodejs || true
echo_log "Creating nodejs env" log "Creating nodejs env"
fission env create --name nodejs --image fission/node-env --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256 fission env create --name nodejs --image fission/node-env --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
trap "fission env delete --name nodejs" EXIT trap "fission env delete --name nodejs" EXIT
# TODO Imporve test code by reusing common blocks # TODO Imporve test code by reusing common blocks
echo_log "Creating function, testing for cold start with MinScale 0" log "Creating function, testing for cold start with MinScale 0"
fn0=nodejs-hello-$(date +%N) fn0=nodejs-hello-$(date +%N)
fission fn create --name $fn0 --env nodejs --code $ROOT/examples/nodejs/hello.js --minscale 0 --maxscale 4 --executortype newdeploy fission fn create --name $fn0 --env nodejs --code $ROOT/examples/nodejs/hello.js --minscale 0 --maxscale 4 --executortype newdeploy
trap "fission fn delete --name $fn0" EXIT trap "fission fn delete --name $fn0" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn0 --url /$fn0 --method GET fission route create --function $fn0 --url /$fn0 --method GET
echo_log "Waiting for router & newdeploy deployment creation" log "Waiting for router & newdeploy deployment creation"
sleep 5 sleep 5
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response0=$(curl http://$FISSION_ROUTER/$fn0) response0=$(curl http://$FISSION_ROUTER/$fn0)
echo_log "Checking for valid response" log "Checking for valid response"
echo $response0 | grep -i hello echo $response0 | grep -i hello
echo_log "Creating function, testing for warm start with MinScale 1" log "Creating function, testing for warm start with MinScale 1"
fn1=nodejs-hello-$(date +%N) fn1=nodejs-hello-$(date +%N)
fission fn create --name $fn1 --env nodejs --code $ROOT/examples/nodejs/hello.js --minscale 1 --maxscale 4 --executortype newdeploy fission fn create --name $fn1 --env nodejs --code $ROOT/examples/nodejs/hello.js --minscale 1 --maxscale 4 --executortype newdeploy
trap "fission fn delete --name $fn1" EXIT trap "fission fn delete --name $fn1" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn1 --url /$fn1 --method GET fission route create --function $fn1 --url /$fn1 --method GET
echo_log "Waiting for router & newdeploy deployment creation" log "Waiting for router & newdeploy deployment creation"
sleep 5 sleep 5
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response1=$(curl http://$FISSION_ROUTER/$fn0) response1=$(curl http://$FISSION_ROUTER/$fn0)
echo_log "Checking for valid response" log "Checking for valid response"
echo $response1 | grep -i hello echo $response1 | grep -i hello
# crappy cleanup, improve this later # crappy cleanup, improve this later
kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger
echo_log "NewDeploy ExecutorType: All done." log "NewDeploy ExecutorType: All done."
+8 -8
View File
@@ -7,30 +7,30 @@ ROOT=$(dirname $0)/../..
fn=nodejs-hello-$(date +%N) fn=nodejs-hello-$(date +%N)
# Create a hello world function in nodejs, test it with an http trigger # Create a hello world function in nodejs, test it with an http trigger
echo_log "Poolmgr ExecutorType: Pre-test cleanup" log "Poolmgr ExecutorType: Pre-test cleanup"
fission env delete --name nodejs || true fission env delete --name nodejs || true
echo_log "Creating nodejs env" log "Creating nodejs env"
fission env create --name nodejs --image fission/node-env --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256 fission env create --name nodejs --image fission/node-env --mincpu 20 --maxcpu 100 --minmemory 128 --maxmemory 256
trap "fission env delete --name nodejs" EXIT trap "fission env delete --name nodejs" EXIT
echo_log "Creating function" log "Creating function"
fission fn create --name $fn --env nodejs --code $ROOT/examples/nodejs/hello.js --executortype poolmgr fission fn create --name $fn --env nodejs --code $ROOT/examples/nodejs/hello.js --executortype poolmgr
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn --url /$fn --method GET fission route create --function $fn --url /$fn --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 5 sleep 5
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/$fn) response=$(curl http://$FISSION_ROUTER/$fn)
echo_log "Checking for valid response" log "Checking for valid response"
echo $response | grep -i hello echo $response | grep -i hello
# crappy cleanup, improve this later # crappy cleanup, improve this later
kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger
echo_log "Poolmgr ExecutorType: All done." log "Poolmgr ExecutorType: All done."
+13 -13
View File
@@ -15,16 +15,16 @@ PYTHON_BUILDER_IMAGE=gcr.io/fission-ci/python-env-builder:test
fn=python-srcbuild-$(date +%s) fn=python-srcbuild-$(date +%s)
checkFunctionResponse() { checkFunctionResponse() {
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/$1) response=$(curl http://$FISSION_ROUTER/$1)
echo_log "Checking for valid response" log "Checking for valid response"
echo_log $response log $response
echo $response | grep -i "a: 1 b: {c: 3, d: 4}" echo $response | grep -i "a: 1 b: {c: 3, d: 4}"
} }
waitBuild() { waitBuild() {
echo_log "Waiting for builder manager to finish the build" log "Waiting for builder manager to finish the build"
while true; do while true; do
kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded
@@ -39,7 +39,7 @@ waitEnvBuilder() {
env=$1 env=$1
envRV=$(kubectl -n default get environments ${env} -o jsonpath='{.metadata.resourceVersion}') envRV=$(kubectl -n default get environments ${env} -o jsonpath='{.metadata.resourceVersion}')
echo_log "Waiting for env builder to catch up" log "Waiting for env builder to catch up"
while true; do while true; do
kubectl -n fission-builder get pod -l envName=${env},envResourceVersion=${envRV} \ kubectl -n fission-builder get pod -l envName=${env},envResourceVersion=${envRV} \
@@ -51,27 +51,27 @@ waitEnvBuilder() {
} }
export -f waitEnvBuilder export -f waitEnvBuilder
echo_log "Pre-test cleanup" log "Pre-test cleanup"
fission env delete --name python || true fission env delete --name python || true
kubectl --namespace default get packages|grep -v NAME|awk '{print $1}'|xargs -I@ bash -c 'kubectl --namespace default delete packages @' || true kubectl --namespace default get packages|grep -v NAME|awk '{print $1}'|xargs -I@ bash -c 'kubectl --namespace default delete packages @' || true
echo_log "Creating python env" log "Creating python env"
fission env create --name python --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE fission env create --name python --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE
trap "fission env delete --name python" EXIT trap "fission env delete --name python" EXIT
timeout 180s bash -c "waitEnvBuilder python" timeout 180s bash -c "waitEnvBuilder python"
echo_log "Creating source pacakage" log "Creating source pacakage"
zip -jr demo-src-pkg.zip $ROOT/examples/python/sourcepkg/ zip -jr demo-src-pkg.zip $ROOT/examples/python/sourcepkg/
echo_log "Creating function " $fn log "Creating function " $fn
fission fn create --name $fn --env python --src demo-src-pkg.zip --entrypoint "user.main" --buildcmd "./build.sh" fission fn create --name $fn --env python --src demo-src-pkg.zip --entrypoint "user.main" --buildcmd "./build.sh"
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn --url /$fn --method GET fission route create --function $fn --url /$fn --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 3 sleep 3
pkg=$(kubectl --namespace default get functions $fn -o jsonpath='{.spec.package.packageref.name}') pkg=$(kubectl --namespace default get functions $fn -o jsonpath='{.spec.package.packageref.name}')
@@ -81,7 +81,7 @@ timeout 60s bash -c "waitBuild $pkg"
checkFunctionResponse $fn checkFunctionResponse $fn
echo_log "Updating function " $fn log "Updating function " $fn
fission fn update --name $fn --src demo-src-pkg.zip fission fn update --name $fn --src demo-src-pkg.zip
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
@@ -95,4 +95,4 @@ checkFunctionResponse $fn
# crappy cleanup, improve this later # crappy cleanup, improve this later
kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger
echo_log "All done." log "All done."
+12 -12
View File
@@ -10,28 +10,28 @@ fn=nodejs-hello-$(date +%s)
# Update it and check it's output, the output should be # Update it and check it's output, the output should be
# different from the previous one. # different from the previous one.
echo_log "Pre-test cleanup" log "Pre-test cleanup"
fission env delete --name nodejs || true fission env delete --name nodejs || true
echo_log "Creating nodejs env" log "Creating nodejs env"
fission env create --name nodejs --image fission/node-env fission env create --name nodejs --image fission/node-env
trap "fission env delete --name nodejs" EXIT trap "fission env delete --name nodejs" EXIT
echo_log "Creating function" log "Creating function"
echo 'module.exports = function(context, callback) { callback(200, "foo!\n"); }' > foo.js echo 'module.exports = function(context, callback) { callback(200, "foo!\n"); }' > foo.js
fission fn create --name $fn --env nodejs --code foo.js fission fn create --name $fn --env nodejs --code foo.js
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn --url /$fn --method GET fission route create --function $fn --url /$fn --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 10 sleep 10
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/$fn) response=$(curl http://$FISSION_ROUTER/$fn)
echo_log "Checking for valid response" log "Checking for valid response"
echo $response | grep -i foo echo $response | grep -i foo
# Running a background process to keep access the # Running a background process to keep access the
@@ -40,18 +40,18 @@ echo $response | grep -i foo
( watch -n1 curl http://$FISSION_ROUTER/$fn ) > /dev/null 2>&1 & ( watch -n1 curl http://$FISSION_ROUTER/$fn ) > /dev/null 2>&1 &
pid=$! pid=$!
echo_log "Updating function" log "Updating function"
echo 'module.exports = function(context, callback) { callback(200, "bar!\n"); }' > bar.js echo 'module.exports = function(context, callback) { callback(200, "bar!\n"); }' > bar.js
fission fn update --name $fn --code bar.js fission fn update --name $fn --code bar.js
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Waiting for router to update cache" log "Waiting for router to update cache"
sleep 10 sleep 10
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/$fn) response=$(curl http://$FISSION_ROUTER/$fn)
echo_log "Checking for valid response again" log "Checking for valid response again"
echo $response | grep -i bar echo $response | grep -i bar
kill -15 $pid kill -15 $pid
@@ -59,4 +59,4 @@ kill -15 $pid
# crappy cleanup, improve this later # crappy cleanup, improve this later
kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger
echo_log "All done." log "All done."
+8 -8
View File
@@ -9,38 +9,38 @@ set -euo pipefail
ROOT=$(dirname $0)/../.. ROOT=$(dirname $0)/../..
echo_log "Pre-test cleanup" log "Pre-test cleanup"
fission env delete --name nodejs || true fission env delete --name nodejs || true
echo_log "Creating nodejs env" log "Creating nodejs env"
fission env create --name nodejs --image fission/node-env fission env create --name nodejs --image fission/node-env
trap "fission env delete --name nodejs" EXIT trap "fission env delete --name nodejs" EXIT
echo_log "Writing functions" log "Writing functions"
f1=f1-$(date +%s) f1=f1-$(date +%s)
f2=f2-$(date +%s) f2=f2-$(date +%s)
echo_log $f1 $f2 log $f1 $f2
for f in $f1 $f2 for f in $f1 $f2
do do
echo "module.exports = function(context, callback) { callback(200, \"$f\n\"); }" > $f.js echo "module.exports = function(context, callback) { callback(200, \"$f\n\"); }" > $f.js
done done
echo_log "Creating functions" log "Creating functions"
for f in $f1 $f2 for f in $f1 $f2
do do
fission fn create --name $f --env nodejs --code $f.js fission fn create --name $f --env nodejs --code $f.js
trap "fission fn delete --name $f" EXIT trap "fission fn delete --name $f" EXIT
done done
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 2 sleep 2
echo_log "Testing internal routes" log "Testing internal routes"
for f in $f1 $f2 for f in $f1 $f2
do do
response=$(curl http://$FISSION_ROUTER/fission-function/$f) response=$(curl http://$FISSION_ROUTER/fission-function/$f)
echo $response | grep $f echo $response | grep $f
done done
echo_log "All done." log "All done."
+14 -14
View File
@@ -8,39 +8,39 @@ ROOT=$(dirname $0)/../..
fn=nodejs-logtest-$(date +%N) fn=nodejs-logtest-$(date +%N)
function cleanup { function cleanup {
echo_log "Cleanup route" log "Cleanup route"
var=$(fission route list | grep $fn | awk '{print $1;}') var=$(fission route list | grep $fn | awk '{print $1;}')
fission route delete --name $var fission route delete --name $var
echo_log "delete logfile" log "delete logfile"
rm "/tmp/logfile" rm "/tmp/logfile"
} }
# Create a hello world function in nodejs, test it with an http trigger # Create a hello world function in nodejs, test it with an http trigger
echo_log "Pre-test cleanup" log "Pre-test cleanup"
fission env delete --name nodejs || true fission env delete --name nodejs || true
echo_log "Creating nodejs env" log "Creating nodejs env"
fission env create --name nodejs --image fission/node-env fission env create --name nodejs --image fission/node-env
trap "fission env delete --name nodejs" EXIT trap "fission env delete --name nodejs" EXIT
echo_log "Creating function" log "Creating function"
fission fn create --name $fn --env nodejs --code log.js fission fn create --name $fn --env nodejs --code log.js
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn --url /$fn --method GET fission route create --function $fn --url /$fn --method GET
trap cleanup EXIT trap cleanup EXIT
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 15 sleep 15
echo_log "Doing 4 HTTP GETs on the function's route" log "Doing 4 HTTP GETs on the function's route"
for i in 1 2 3 4 for i in 1 2 3 4
do do
curl -s http://$FISSION_ROUTER/$fn curl -s http://$FISSION_ROUTER/$fn
done done
echo_log "Grabbing logs, should have 4 calls in logs" log "Grabbing logs, should have 4 calls in logs"
sleep 15 sleep 15
@@ -52,15 +52,15 @@ then
fission function logs --name $fn --detail > /tmp/logfile fission function logs --name $fn --detail > /tmp/logfile
fi fi
echo_log "---function logs---" log "---function logs---"
cat /tmp/logfile cat /tmp/logfile
echo_log "------" log "------"
num=$(grep 'log test' /tmp/logfile | wc -l) num=$(grep 'log test' /tmp/logfile | wc -l)
echo_log $num logs found log $num logs found
if [ $num -ne 4 ] if [ $num -ne 4 ]
then then
echo_log "Test Failed: expected 4, found $num logs" log "Test Failed: expected 4, found $num logs"
fi fi
echo_log "All done." log "All done."
+8 -8
View File
@@ -7,30 +7,30 @@ ROOT=$(dirname $0)/../..
fn=nodejs-hello-$(date +%N) fn=nodejs-hello-$(date +%N)
# Create a hello world function in nodejs, test it with an http trigger # Create a hello world function in nodejs, test it with an http trigger
echo_log "Pre-test cleanup" log "Pre-test cleanup"
fission env delete --name nodejs || true fission env delete --name nodejs || true
echo_log "Creating nodejs env" log "Creating nodejs env"
fission env create --name nodejs --image fission/node-env fission env create --name nodejs --image fission/node-env
trap "fission env delete --name nodejs" EXIT trap "fission env delete --name nodejs" EXIT
echo_log "Creating function" log "Creating function"
fission fn create --name $fn --env nodejs --code $ROOT/examples/nodejs/hello.js fission fn create --name $fn --env nodejs --code $ROOT/examples/nodejs/hello.js
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn --url /$fn --method GET fission route create --function $fn --url /$fn --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 3 sleep 3
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/$fn) response=$(curl http://$FISSION_ROUTER/$fn)
echo_log "Checking for valid response" log "Checking for valid response"
echo $response | grep -i hello echo $response | grep -i hello
# crappy cleanup, improve this later # crappy cleanup, improve this later
kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger
echo_log "All done." log "All done."
+15 -15
View File
@@ -14,7 +14,7 @@ PYTHON_BUILDER_IMAGE=gcr.io/fission-ci/python-env-builder:test
fn=python-srcbuild-$(date +%s) fn=python-srcbuild-$(date +%s)
waitBuild() { waitBuild() {
echo_log "Waiting for builder manager to finish the build" log "Waiting for builder manager to finish the build"
while true; do while true; do
kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded
@@ -26,11 +26,11 @@ waitBuild() {
export -f waitBuild export -f waitBuild
checkFunctionResponse() { checkFunctionResponse() {
echo_log "Doing an HTTP GET on the function's route" log "Doing an HTTP GET on the function's route"
response=$(curl http://$FISSION_ROUTER/$1) response=$(curl http://$FISSION_ROUTER/$1)
echo_log "Checking for valid response" log "Checking for valid response"
echo_log $response log $response
echo $response | grep -i "$2" echo $response | grep -i "$2"
} }
@@ -38,7 +38,7 @@ waitEnvBuilder() {
env=$1 env=$1
envRV=$(kubectl -n default get environments ${env} -o jsonpath='{.metadata.resourceVersion}') envRV=$(kubectl -n default get environments ${env} -o jsonpath='{.metadata.resourceVersion}')
echo_log "Waiting for env builder to catch up" log "Waiting for env builder to catch up"
while true; do while true; do
kubectl -n fission-builder get pod -l envName=${env},envResourceVersion=${envRV} \ kubectl -n fission-builder get pod -l envName=${env},envResourceVersion=${envRV} \
@@ -50,46 +50,46 @@ waitEnvBuilder() {
} }
export -f waitEnvBuilder export -f waitEnvBuilder
echo_log "Pre-test cleanup" log "Pre-test cleanup"
fission env delete --name python || true fission env delete --name python || true
echo_log "Creating python env" log "Creating python env"
fission env create --name python --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE fission env create --name python --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE
trap "fission env delete --name python" EXIT trap "fission env delete --name python" EXIT
timeout 180s bash -c "waitEnvBuilder python" timeout 180s bash -c "waitEnvBuilder python"
echo_log "Creating pacakage with source archive" log "Creating pacakage with source archive"
zip -jr demo-src-pkg.zip $ROOT/examples/python/sourcepkg/ zip -jr demo-src-pkg.zip $ROOT/examples/python/sourcepkg/
pkgName=$(fission package create --src demo-src-pkg.zip --env python --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \') pkgName=$(fission package create --src demo-src-pkg.zip --env python --buildcmd "./build.sh"| cut -f2 -d' '| tr -d \')
# wait for build to finish at most 60s # wait for build to finish at most 60s
timeout 60s bash -c "waitBuild $pkgName" timeout 60s bash -c "waitBuild $pkgName"
echo_log "Creating function " $fn log "Creating function " $fn
fission fn create --name $fn --pkg $pkgName --entrypoint "user.main" fission fn create --name $fn --pkg $pkgName --entrypoint "user.main"
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function $fn --url /$fn --method GET fission route create --function $fn --url /$fn --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 3 sleep 3
checkFunctionResponse $fn 'a: 1 b: {c: 3, d: 4}' checkFunctionResponse $fn 'a: 1 b: {c: 3, d: 4}'
echo_log "Creating package with deploy archive" log "Creating package with deploy archive"
mkdir testDir mkdir testDir
touch testDir/__init__.py touch testDir/__init__.py
printf 'def main():\n return "Hello, world!"' > testDir/hello.py printf 'def main():\n return "Hello, world!"' > testDir/hello.py
zip -jr demo-deploy-pkg.zip testDir/ zip -jr demo-deploy-pkg.zip testDir/
pkgName=$(fission package create --deploy demo-deploy-pkg.zip --env python| cut -f2 -d' '| tr -d \') pkgName=$(fission package create --deploy demo-deploy-pkg.zip --env python| cut -f2 -d' '| tr -d \')
echo_log "Updating function " $fn log "Updating function " $fn
fission fn update --name $fn --pkg $pkgName --entrypoint "hello.main" fission fn update --name $fn --pkg $pkgName --entrypoint "hello.main"
trap "fission fn delete --name $fn" EXIT trap "fission fn delete --name $fn" EXIT
echo_log "Waiting for router to update cache" log "Waiting for router to update cache"
sleep 3 sleep 3
checkFunctionResponse $fn 'Hello, world!' checkFunctionResponse $fn 'Hello, world!'
@@ -97,4 +97,4 @@ checkFunctionResponse $fn 'Hello, world!'
# crappy cleanup, improve this later # crappy cleanup, improve this later
kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger kubectl get httptrigger -o name | tail -1 | cut -f2 -d'/' | xargs kubectl delete httptrigger
echo_log "All done." log "All done."
+3 -3
View File
@@ -5,8 +5,8 @@ set -euo pipefail
# This doesn't test fission, just the test framework. It ensures we # This doesn't test fission, just the test framework. It ensures we
# have the right environment, that's all. # have the right environment, that's all.
echo_log "Test test, please ignore." log "Test test, please ignore."
echo_log $FISSION_URL log $FISSION_URL
echo_log $FISSION_ROUTER log $FISSION_ROUTER
which fission which fission
@@ -15,7 +15,7 @@ cp cfgmap.py.template cfgmap.py
sed -i "s/{{ FN_CFGMAP }}/${fn_cfgmap}/g" cfgmap.py sed -i "s/{{ FN_CFGMAP }}/${fn_cfgmap}/g" cfgmap.py
function cleanup { function cleanup {
echo_log "Cleanup everything" log "Cleanup everything"
kubectl delete secret -n default ${fn_secret} kubectl delete secret -n default ${fn_secret}
kubectl delete configmap -n default ${fn_cfgmap} kubectl delete configmap -n default ${fn_cfgmap}
fission function delete --name ${fn_secret} fission function delete --name ${fn_secret}
@@ -30,84 +30,84 @@ function cleanup {
} }
# Create a hello world function in nodejs, test it with an http trigger # Create a hello world function in nodejs, test it with an http trigger
echo_log "Pre-test cleanup" log "Pre-test cleanup"
fission env delete --name python || true fission env delete --name python || true
echo_log "Creating python env" log "Creating python env"
fission env create --name python --image fission/python-env fission env create --name python --image fission/python-env
trap "fission env delete --name python" EXIT trap "fission env delete --name python" EXIT
echo_log "Creating secret" log "Creating secret"
kubectl create secret generic ${fn_secret} --from-literal=TEST_KEY="TESTVALUE" -n default kubectl create secret generic ${fn_secret} --from-literal=TEST_KEY="TESTVALUE" -n default
trap "kubectl delete secret ${fn_secret} -n default" EXIT trap "kubectl delete secret ${fn_secret} -n default" EXIT
echo_log "Creating function with secret" log "Creating function with secret"
fission fn create --name ${fn_secret} --env python --code secret.py --secret ${fn_secret} fission fn create --name ${fn_secret} --env python --code secret.py --secret ${fn_secret}
trap "fission fn delete --name ${fn_secret}" EXIT trap "fission fn delete --name ${fn_secret}" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function ${fn_secret} --url /${fn_secret} --method GET fission route create --function ${fn_secret} --url /${fn_secret} --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 5 sleep 5
echo_log "HTTP GET on the function's route" log "HTTP GET on the function's route"
res=$(curl http://${FISSION_ROUTER}/${fn_secret}) res=$(curl http://${FISSION_ROUTER}/${fn_secret})
val='TESTVALUE' val='TESTVALUE'
if [[ ${res} != ${val} ]] if [[ ${res} != ${val} ]]
then then
echo_log "test secret failed" log "test secret failed"
cleanup cleanup
exit 1 exit 1
fi fi
echo_log "test secret passed" log "test secret passed"
echo_log "Creating configmap" log "Creating configmap"
kubectl create configmap ${fn_cfgmap} --from-literal=TEST_KEY=TESTVALUE -n default kubectl create configmap ${fn_cfgmap} --from-literal=TEST_KEY=TESTVALUE -n default
trap "kubectl delete configmap ${fn_cfgmap} -n default" EXIT trap "kubectl delete configmap ${fn_cfgmap} -n default" EXIT
echo_log "creating function with configmap" log "creating function with configmap"
fission fn create --name ${fn_cfgmap} --env python --code cfgmap.py --configmap ${fn_cfgmap} fission fn create --name ${fn_cfgmap} --env python --code cfgmap.py --configmap ${fn_cfgmap}
trap "fission fn delete --name ${fn_cfgmap}" EXIT trap "fission fn delete --name ${fn_cfgmap}" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function ${fn_cfgmap} --url /${fn_cfgmap} --method GET fission route create --function ${fn_cfgmap} --url /${fn_cfgmap} --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 5 sleep 5
echo_log "HTTP GET on the function's route" log "HTTP GET on the function's route"
rescfg=$(curl http://${FISSION_ROUTER}/${fn_cfgmap}) rescfg=$(curl http://${FISSION_ROUTER}/${fn_cfgmap})
if [ ${rescfg} != ${val} ] if [ ${rescfg} != ${val} ]
then then
echo_log "test cfgmap failed" log "test cfgmap failed"
cleanup cleanup
exit 1 exit 1
fi fi
echo_log "test configmap passed" log "test configmap passed"
echo_log "testing creating a function without a secret or configmap" log "testing creating a function without a secret or configmap"
fission function create --name ${fn} --env python --code empty.py fission function create --name ${fn} --env python --code empty.py
trap "fission fn delete --name ${fn}" EXIT trap "fission fn delete --name ${fn}" EXIT
echo_log "Creating route" log "Creating route"
fission route create --function ${fn} --url /${fn} --method GET fission route create --function ${fn} --url /${fn} --method GET
echo_log "Waiting for router to catch up" log "Waiting for router to catch up"
sleep 5 sleep 5
echo_log "HTTP GET on the function's route" log "HTTP GET on the function's route"
resnormal=$(curl http://${FISSION_ROUTER}/${fn}) resnormal=$(curl http://${FISSION_ROUTER}/${fn})
if [ ${resnormal} != "yes" ] if [ ${resnormal} != "yes" ]
then then
echo_log "test empty failed" log "test empty failed"
cleanup cleanup
exit 1 exit 1
fi fi
echo_log "test empty passed" log "test empty passed"
echo_log "All done." log "All done."
trap "cleanup" EXIT trap "cleanup" EXIT