#!/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}')
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
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
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
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"
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"
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"
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"
echo "##################################"
echo
echo
+ [[ $rest == 2 ]]
fi
done