From 9e4c4ff1e7b20e2c1fb7ac9f0137001ea06490f1 Mon Sep 17 00:00:00 2001 From: jayunit100 Date: Fri, 1 May 2015 14:28:30 -0400 Subject: [PATCH] Update K8Petstore.sh to support external invocation --- examples/k8petstore/k8petstore.sh | 73 ++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/examples/k8petstore/k8petstore.sh b/examples/k8petstore/k8petstore.sh index 612640f21f..fc4110e34b 100755 --- a/examples/k8petstore/k8petstore.sh +++ b/examples/k8petstore/k8petstore.sh @@ -16,16 +16,32 @@ echo "WRITING KUBE FILES , will overwrite the jsons, then testing pods. is kube clean ready to go?" + +#Args below can be overriden when calling from cmd line. +#Just send all the args in order. #for dev/test you can use: #kubectl=$GOPATH/src/github.com/GoogleCloudPlatform/kubernetes/cluster/kubectl.sh" kubectl="kubectl" VERSION="r.2.8.19" PUBLIC_IP="10.1.4.89" # ip which we use to access the Web server. -SECONDS=1000 # number of seconds to measure throughput. +_SECONDS=1000 # number of seconds to measure throughput. FE="1" # amount of Web server LG="1" # amount of load generators SLAVE="1" # amount of redis slaves +TEST="1" # 0 = Dont run tests, 1 = Do run tests. +NS="k8petstore" # namespace +kubectl="${1:-$kubectl}" +VERSION="${2:-$VERSION}" +PUBLIC_IP="${3:-$PUBLIC_IP}" # ip which we use to access the Web server. +_SECONDS="${4:-$_SECONDS}" # number of seconds to measure throughput. +FE="${5:-$FE}" # amount of Web server +LG="${6:-$LG}" # amount of load generators +SLAVE="${7:-$SLAVE}" # amount of redis slaves +TEST="${8:-$TEST}" # 0 = Dont run tests, 1 = Do run tests. +NS="${9:-$NS}" # namespace + +echo "Running w/ args: kubectl $kubectl version $VERSION ip $PUBLIC_IP sec $_SECONDS fe $FE lg $LG slave $SLAVE test $TEST NAMESPACE $NS" function create { cat << EOF > fe-rc.json @@ -188,53 +204,70 @@ cat << EOF > slave-rc.json "labels": {"name": "redisslave"} } EOF -$kubectl create -f rm.json --api-version=v1beta1 -$kubectl create -f rm-s.json --api-version=v1beta1 +$kubectl create -f rm.json --api-version=v1beta1 --namespace=$NS +$kubectl create -f rm-s.json --api-version=v1beta1 --namespace=$NS sleep 3 # precaution to prevent fe from spinning up too soon. -$kubectl create -f slave-rc.json --api-version=v1beta1 -$kubectl create -f rs-s.json --api-version=v1beta1 +$kubectl create -f slave-rc.json --api-version=v1beta1 --namespace=$NS +$kubectl create -f rs-s.json --api-version=v1beta1 --namespace=$NS sleep 3 # see above comment. -$kubectl create -f fe-rc.json --api-version=v1beta1 -$kubectl create -f fe-s.json --api-version=v1beta1 -$kubectl create -f bps-load-gen-rc.json --api-version=v1beta1 +$kubectl create -f fe-rc.json --api-version=v1beta1 --namespace=$NS +$kubectl create -f fe-s.json --api-version=v1beta1 --namespace=$NS +$kubectl create -f bps-load-gen-rc.json --api-version=v1beta1 --namespace=$NS } -function test { +function pollfor { pass_http=0 ### Test HTTP Server comes up. for i in `seq 1 150`; do ### Just testing that the front end comes up. Not sure how to test total entries etc... (yet) - echo "Trying curl ... $i . expect a few failures while pulling images... " + echo "Trying curl ... $PUBLIC_IP:3000 , attempt $i . expect a few failures while pulling images... " curl "$PUBLIC_IP:3000" > result cat result cat result | grep -q "k8-bps" if [ $? -eq 0 ]; then - echo "TEST PASSED after $i tries !" - i=1000 - break + echo "TEST PASSED after $i tries !" + i=1000 + break else echo "the above RESULT didn't contain target string for trial $i" fi - sleep 5 + sleep 3 done if [ $i -eq 1000 ]; then - pass_http=-1 + pass_http=1 fi + +} +function tests { pass_load=0 ### Print statistics of db size, every second, until $SECONDS are up. - for i in `seq 1 $SECONDS`; - do - echo "curl : $i" - curl "$PUBLIC_IP:3000/llen" >> result + for i in `seq 1 $_SECONDS`; + do + echo "curl : $PUBLIC_IP:3000 , $i of $_SECONDS" + curr_cnt="`curl "$PUBLIC_IP:3000/llen"`" + ### Write CSV File of # of trials / total transcations. + echo "$i $curr_cnt" >> result + echo "total transactions so far : $curr_cnt" sleep 1 done } create -test +pollfor + +if [[ $pass_http -eq 1 ]]; then + echo "Passed..." +else + exit 1 +fi + +if [[ $TEST -eq 1 ]]; then + echo "running polling tests now" + tests +fi