|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +SCRIPT_DIR=$(readlink -f `dirname "${BASH_SOURCE[0]}"`) |
| 4 | + |
| 5 | +function help() { |
| 6 | + echo "usage: perf.sh [-h]" |
| 7 | + echo |
| 8 | + echo "Description: Runs Appwrapper performance test script(s) in subdirectories under $SCRIPT_DIR." |
| 9 | + echo |
| 10 | + echo "Preconditions: " |
| 11 | + echo " - The script assumes you've logged into your cluster already. If not, it will tell you to login." |
| 12 | + echo " - The script checks that you have the mcad-controller installed, otherwise it'll tell you to install it first." |
| 13 | + echo |
| 14 | + echo "Options:" |
| 15 | + echo " -h Print this help message" |
| 16 | + echo |
| 17 | +} |
| 18 | + |
| 19 | +function check_kubectl_login_status() { |
| 20 | + set +e |
| 21 | + kubectl get ns default &> /dev/null |
| 22 | + res="$?" |
| 23 | + set -e |
| 24 | + OCP="$res" |
| 25 | + if [ $OCP == 1 ] |
| 26 | + then |
| 27 | + echo "You need to login to your Kubernetes Cluster" |
| 28 | + exit 1 |
| 29 | + else |
| 30 | + echo |
| 31 | + echo "Nice, looks like you're logged in" |
| 32 | + fi |
| 33 | +} |
| 34 | + |
| 35 | +function check_mcad_installed_status() { |
| 36 | + set +e |
| 37 | + kubectl get pod -A |grep mcad-controller &> /dev/null |
| 38 | + res2="$?" |
| 39 | + kubectl get crd |grep appwrapper &> /dev/null |
| 40 | + res3="$?" |
| 41 | + set -e |
| 42 | + MCAD="$res2" |
| 43 | + CRD="$res3" |
| 44 | + if [[ $MCAD == 1 ]] || [[ $CRD == 1 ]] |
| 45 | + then |
| 46 | + echo "You need Install MCAD Controller first before running this script" |
| 47 | + exit 1 |
| 48 | + else |
| 49 | + echo "Nice, MCAD Controller is installed" |
| 50 | + fi |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +while getopts hf: option; do |
| 55 | + case $option in |
| 56 | + h) |
| 57 | + help |
| 58 | + exit 0 |
| 59 | + ;; |
| 60 | + *) |
| 61 | + ;; |
| 62 | + esac |
| 63 | +done |
| 64 | +shift $((OPTIND-1)) |
| 65 | + |
| 66 | +# Track whether we have a valid kubectl login |
| 67 | +echo "Checking whether we have a valid cluster login or not..." |
| 68 | +check_kubectl_login_status |
| 69 | + |
| 70 | +# Track whether you have the MCAD controller installed |
| 71 | +echo "Checking MCAD Controller installation status" |
| 72 | +echo |
| 73 | +check_mcad_installed_status |
| 74 | + |
| 75 | +echo |
| 76 | +read -p "How many appwrapper jobs do you want?" jobs |
| 77 | + |
| 78 | +# Start the timer now |
| 79 | +SECONDS=0 |
| 80 | + |
| 81 | +echo "jobs number is $jobs" |
| 82 | +export STARTTIME=`date +"%T"` |
| 83 | +echo " " |
| 84 | +echo "Jobs started at: $STARTTIME" |tee job-$STARTTIME.log |
| 85 | +echo " " |
| 86 | + |
| 87 | +# This fixes the number of jobs to be one less so the for loop gets the right amount |
| 88 | +((realjobs=$jobs-1)) |
| 89 | + |
| 90 | +for num in $(eval echo "{0.."$realjobs"}") |
| 91 | +do |
| 92 | + next_num=$(($num + 1)) |
| 93 | + echo "Submitting job $next_num" |
| 94 | +# Had to do this OSTYPE because sed acts differently on Linux versus Mac |
| 95 | + case "$OSTYPE" in |
| 96 | + linux-gnu*) |
| 97 | + sed -i "s/defaultaw-schd-spec-with-timeout-$num/defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp.yaml ;; |
| 98 | + darwin*) |
| 99 | + sed -i '' "s/defaultaw-schd-spec-with-timeout-$num/defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp.yaml ;; |
| 100 | + *) |
| 101 | + sed -i "s/defaultaw-schd-spec-with-timeout-$num/defaultaw-schd-spec-with-timeout-$next_num/g" ${SCRIPT_DIR}/preempt-exp.yaml ;; |
| 102 | + esac |
| 103 | + kubectl apply -f ${SCRIPT_DIR}/preempt-exp.yaml |
| 104 | +done |
| 105 | + |
| 106 | + # Let's reset the original preempt-exp.yaml file back to original value |
| 107 | + case "$OSTYPE" in |
| 108 | + linux-gnu*) |
| 109 | + sed -i "s/defaultaw-schd-spec-with-timeout-$next_num/defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp.yaml ;; |
| 110 | + darwin*) |
| 111 | + sed -i '' "s/defaultaw-schd-spec-with-timeout-$next_num/defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp.yaml ;; |
| 112 | + *) |
| 113 | + sed -i "s/defaultaw-schd-spec-with-timeout-$next_num/defaultaw-schd-spec-with-timeout-1/g" ${SCRIPT_DIR}/preempt-exp.yaml ;; |
| 114 | + esac |
| 115 | + |
| 116 | +# Check for all jobs to report complete |
| 117 | +jobstatus=`kubectl get jobs -n default --no-headers --field-selector status.successful=1 |wc -l` |
| 118 | + |
| 119 | +while [ $jobstatus -lt $jobs ] |
| 120 | +do |
| 121 | + echo "Number of completed jobs is: " $jobstatus " and the goal is: " $jobs |
| 122 | + sleep 10 |
| 123 | + jobstatus=`kubectl get jobs -n default --no-headers --field-selector status.successful=1 |wc -l` |
| 124 | +done |
| 125 | + |
| 126 | +echo " " |
| 127 | +export FINISHTIME=`date +"%T"` |
| 128 | +echo "All $jobstatus jobs finished: $FINISHTIME" |tee -a job-$STARTTIME.log |
| 129 | +echo "Total amount of time for $jobs appwrappers is: $SECONDS seconds" |tee -a ${SCRIPT_DIR}/job-$STARTTIME.log |
| 130 | +echo " " |
| 131 | +echo "Test results are stored in this file: ${SCRIPT_DIR}/job-$next_num-$STARTTIME.log" |
| 132 | + |
| 133 | +# Rename the log to show the number of jobs used |
| 134 | +mv ${SCRIPT_DIR}/job-$STARTTIME.log ${SCRIPT_DIR}/job-$next_num-$STARTTIME.log |
| 135 | + |
| 136 | +#Ask if you want to auto-cleanup the appwrapper jobs |
| 137 | +echo "Do you want to cleanup the most recently created appwrappers? [Y/n]" |
| 138 | +read DELETE |
| 139 | +if [[ $DELETE == "Y" || $DELETE == "y" ]]; then |
| 140 | + echo "OK, deleting" |
| 141 | + ${SCRIPT_DIR}/cleanup.sh |
| 142 | +else |
| 143 | + echo "OK, you'll need to cleanup yourself later using ./cleanup.sh" |
| 144 | +fi |
0 commit comments