diff options
author | Todd Malsbary <todd.malsbary@intel.com> | 2021-04-28 12:51:42 -0700 |
---|---|---|
committer | Todd Malsbary <todd.malsbary@intel.com> | 2021-04-29 11:07:19 -0700 |
commit | 201a95507e2743beba871f51ffae55aaa5ed5ff4 (patch) | |
tree | 6cba58a84fa4b258d41990e2a1741319362a1ee4 /kud | |
parent | 4ff7900c3c74fa6b497af6d1e36f81e08a193d83 (diff) |
Exit cmk test script on error
Issue-ID: MULTICLOUD-1335
Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
Change-Id: I83336983475bab25867c44153657d31b1bacb933
Diffstat (limited to 'kud')
-rwxr-xr-x | kud/tests/cmk.sh | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/kud/tests/cmk.sh b/kud/tests/cmk.sh index 1a14b5b8..e8e77c6c 100755 --- a/kud/tests/cmk.sh +++ b/kud/tests/cmk.sh @@ -1,4 +1,7 @@ #!/bin/bash + +source _common.sh + ENV=$(kubectl get nodes --all-namespaces | wc -l) if [[ $ENV -gt 2 ]]; then COMPUTE_NODE=$(kubectl get nodes --all-namespaces | grep -v master | awk 'NR==2{print $1}') @@ -31,13 +34,11 @@ function wait_for_pod_up { done } - function start_nginx_pod { kubectl delete deployment -n default nginx --ignore-not-found=true kubectl create deployment nginx --image=nginx - sleep 2 + kubectl wait deployment nginx --for=condition=available nginx_pod=$(kubectl get pods --all-namespaces| grep nginx | awk 'NR==1{print $2}') - wait_for_pod_up $nginx_pod kubectl delete deployment -n default nginx --ignore-not-found=true pod_status="Running" until [[ $pod_status == "" ]]; do @@ -59,8 +60,8 @@ for ((i=0;i<$num;i++)); do echo "##################################" if [ "${case[$POOL]}" == "exclusive" ]; then echo "TC: to allocate ${case[$CORE]} CPU(s) from pool of ${case[$POOL]} on node of ${case[$NODE]}" - TOTAL=$(kubectl get cmk-nodereport ${case[$NODE]} -o json | jq .spec.report.description.pools.${case[$POOL]} | jq .cpuLists | awk -F '{' '{print $(NF)}' | awk -F '}' '{print $(NF)}' | awk -F ',' '{print $(NF)}' | grep "\"tasks\": \[" | wc -l) - echo "ready to generate yaml" + TOTAL=$(kubectl get cmk-nodereport ${case[$NODE]} -o json | jq --arg pool "${case[$POOL]}" '.spec.report.description.pools[$pool].cpuLists|length') + echo "ready to generate yaml" cat << EOF > $DIR/$pod_name.yaml apiVersion: v1 kind: Pod @@ -113,8 +114,11 @@ EOF done echo "waiting for CPU allocation finished ..." rest=$TOTAL - until [[ $TOTAL -gt $rest ]]; do - rest=$(kubectl get cmk-nodereport ${case[$NODE]} -o json | jq .spec.report.description.pools.exclusive | jq .cpuLists | awk -F '{' '{print $(NF)}' | awk -F '}' '{print $(NF)}' | awk -F ',' '{print $(NF)}' | grep "\"tasks\": \[\]" | wc -l) + timeout=0 + until [[ $TOTAL -gt $rest || $timeout == 180 ]]; do + sleep 1 + rest=$(kubectl get cmk-nodereport ${case[$NODE]} -o json | jq '.spec.report.description.pools.exclusive.cpuLists[].tasks|select(type=="array" and length==0)' | wc -l) || echo "$TOTAL" + timeout=$((timeout+1)) done let allocated=`expr $TOTAL - $rest` echo "The allocated CPU amount is:" $allocated @@ -123,7 +127,7 @@ EOF if [[ $allocated == ${case[$CORE]} ]]; then echo "CPU was allocated as expected, TC passed !!" else - echo "failed to allocate CPU, TC failed !!" + echo "failed to allocate CPU ($allocated != ${case[$CORE]}), TC failed !!" fi rm -f $DIR/$pod_name.yaml echo "ready to delete pod" @@ -132,6 +136,7 @@ EOF echo "##################################" echo echo + [[ $allocated == ${case[$CORE]} ]] else echo "TC: to allocate CPU(s) from pool of ${case[$POOL]} on node of ${case[$NODE]}" echo "ready to generate yaml" @@ -207,10 +212,10 @@ EOF echo "waiting for CPU allocation finished ..." rest=0 timeout=0 - until [ $rest == 2 -o $timeout == 180 ]; do - rest=$(kubectl get cmk-nodereport ${case[$NODE]} -o json | jq .spec.report.description.pools.shared | jq .cpuLists | awk -F '{' '{print $(NF)}' | awk -F '}' '{print $(NF)}' | grep -v "cpus" | grep " "| grep -v "tasks"| grep -v "\]" | wc -l) - sleep -- 1 - let timeout++ + until [[ $rest == 2 || $timeout == 180 ]]; do + sleep 1 + rest=$(kubectl get cmk-nodereport ${case[$NODE]} -o json | jq '.spec.report.description.pools.shared.cpuLists[].tasks' | jq length) || echo "0" + timeout=$((timeout+1)) done echo "The CPU allocated in shared pool for 2 tasks" echo "deploy a nginx pod" @@ -218,7 +223,7 @@ EOF if [[ $rest == 2 ]]; then echo "CPU was allocated as expected, TC passed !!" else - echo "failed to allocate CPU, TC failed !!" + echo "failed to allocate CPU ($rest != 2), TC failed !!" fi rm -f $DIR/$pod_name.yaml echo "ready to delete pod" @@ -227,5 +232,6 @@ EOF echo "##################################" echo echo + [[ $rest == 2 ]] fi done |