David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2019 Ciena Corporation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | # this script repeatedly invokes the e2e system test on a VOLTHA instance |
| 17 | |
David Bainbridge | 76514a0 | 2019-10-08 01:50:35 +0000 | [diff] [blame] | 18 | NAME=${NAME:-minimal} |
| 19 | EXIT_ON_FAIL=${EXIT_ON_FAIL:-no} |
| 20 | INCLUDE_LOG_DIR=${INCLUDE_LOG_DIR:-} |
David Bainbridge | 2daf555 | 2019-10-08 20:29:34 +0000 | [diff] [blame] | 21 | BBSIM_ONU_SN=${BBSIM_ONIU_SN:-BBSM00000001} |
| 22 | BBSIM_OLT_SN=${BBSIM_OLT_SN:-BBSIM_OLT_0} |
David Bainbridge | 76514a0 | 2019-10-08 01:50:35 +0000 | [diff] [blame] | 23 | |
| 24 | # === END OF CONFIGURATION === |
| 25 | |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 26 | set -o pipefail |
| 27 | |
| 28 | if [ ! -r voltha-system-tests ]; then |
| 29 | git clone http://gerrit.opencord.org/voltha-system-tests voltha-system-tests |
| 30 | fi |
| 31 | |
| 32 | delta() { |
| 33 | local LEFT=$(echo $1 | numfmt --from=iec) |
| 34 | local RIGHT=$(echo $2 | numfmt --from=iec) |
| 35 | local V=$(expr $LEFT - $RIGHT) |
| 36 | echo ${V#-} |
| 37 | } |
| 38 | |
| 39 | average() { |
| 40 | local MIN=0 |
| 41 | local MAX=0 |
| 42 | local COUNT=0 |
| 43 | local SUM=0 |
| 44 | for V in $*; do |
| 45 | COUNT=$(expr $COUNT + 1) |
| 46 | SUM=$(expr $SUM + $V) |
| 47 | if [ $COUNT -eq 1 ]; then |
| 48 | MIN=$V |
| 49 | MAX=$V |
| 50 | else |
| 51 | if [ $V -lt $MIN ]; then |
| 52 | MIN=$V |
| 53 | elif [ $V -gt $MAX ]; then |
| 54 | MAX=$V |
| 55 | fi |
| 56 | fi |
| 57 | done |
| 58 | if [ $COUNT -gt 3 ]; then |
| 59 | SUM=$(expr $SUM - $MIN - $MAX) |
| 60 | COUNT=$(expr $COUNT - 2) |
| 61 | fi |
| 62 | if [ $COUNT -lt 1 ]; then |
| 63 | echo 0 |
| 64 | else |
| 65 | echo $(expr $SUM / $COUNT) |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | export WAIT_FOR_DOWN=y |
| 70 | export TERM= |
| 71 | |
| 72 | COMPLETED=0 |
| 73 | COUNT_OK=0 |
| 74 | COUNT_FAIL=0 |
| 75 | COUNT_SINCE_FAIL=0 |
| 76 | FAILURE_LIST=() |
| 77 | RSS_DIFFS=() |
| 78 | KEY_DIFFS=() |
| 79 | SIZE_DIFFS=() |
| 80 | LOG=$(mktemp) |
David Bainbridge | 8e768ac | 2019-10-16 22:04:47 +0000 | [diff] [blame^] | 81 | FIRST=1 |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 82 | while true; do |
| 83 | RUN_TS=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 84 | echo "START RUN $RUN @ $RUN_TS" | tee -a $LOG |
David Bainbridge | 8e768ac | 2019-10-16 22:04:47 +0000 | [diff] [blame^] | 85 | if [ $FIRST -eq 1 ]; then |
| 86 | DEPLOY_K8S=y WITH_BBSIM=y WITH_SADIS=y WITH_RADIUS=y CONFIG_SADIS=y ./voltha up |
| 87 | FIRST=0 |
| 88 | else |
| 89 | helm install --wait -f full-values.yaml --set defaults.log_level=WARN --namespace voltha --name bbsim onf/bbsim |
| 90 | fi |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 91 | # because BBSIM needs time |
| 92 | sleep 60 |
David Bainbridge | 8e768ac | 2019-10-16 22:04:47 +0000 | [diff] [blame^] | 93 | ETCD=$(kubectl -n voltha get pods | grep etcd-cluster | awk '{print $1}' | head -1) |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 94 | BEFORE_KEY_COUNT=$(kubectl -n voltha exec -ti $ETCD \ |
| 95 | -- sh -c 'ETCDCTL_API=3 etcdctl get --command-timeout=60s --from-key=true --keys-only . | sed -e "/^$/d" | wc -l | tr -d "\r\n"') |
| 96 | BEFORE_SIZE=$(numfmt --to=iec \ |
| 97 | $(kubectl -n voltha exec -ti $ETCD \ |
| 98 | -- sh -c 'ETCDCTL_API=3 etcdctl endpoint status -w json' | tr -d '\r\n' | jq .[].Status.dbSize)) |
| 99 | BEFORE_RSS=$(ps -eo rss,pid,cmd | grep /usr/local/bin/etcd | grep -v grep | cut -d\ -f1 | numfmt --to=iec) |
David Bainbridge | 2daf555 | 2019-10-08 20:29:34 +0000 | [diff] [blame] | 100 | (cd voltha-system-tests; BBSIM_OLT_SN=$BBSIM_OLT_SN BBSIM_ONU_SN=$BBSIM_ONU_SN make sanity-kind 2>&1 | tee $LOG) |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 101 | FAIL=$? |
| 102 | AFTER_KEY_COUNT=$(kubectl -n voltha exec -ti $ETCD \ |
| 103 | -- sh -c 'ETCDCTL_API=3 etcdctl get --command-timeout=60s --from-key=true --keys-only . | sed -e "/^$/d" | wc -l | tr -d "\r\n"') |
| 104 | AFTER_SIZE=$(numfmt --to=iec \ |
| 105 | $(kubectl -n voltha exec -ti $ETCD \ |
| 106 | -- sh -c 'ETCDCTL_API=3 etcdctl endpoint status -w json' | tr -d '\r\n' | jq .[].Status.dbSize)) |
| 107 | AFTER_RSS=$(ps -eo rss,pid,cmd | grep /usr/local/bin/etcd | grep -v grep | cut -d\ -f1 | numfmt --to=iec) |
| 108 | if [ $FAIL -eq 0 ]; then |
| 109 | COUNT_OK=$(expr $COUNT_OK + 1) |
| 110 | COUNT_SINCE_FAIL=$(expr $COUNT_SINCE_FAIL + 1) |
| 111 | helm delete --purge bbsim |
| 112 | while [ $(kubectl get --all-namespaces pods,svc 2>&1 | grep -c bbsim) -gt 0 ]; do |
| 113 | sleep 3 |
| 114 | done |
| 115 | else |
| 116 | COUNT_FAIL=$(expr $COUNT_FAIL + 1) |
| 117 | FAILURE_LIST+=($COUNT_SINCE_FAIL) |
| 118 | COUNT_SINCE_FAIL=0 |
| 119 | DUMP_FROM=$RUN_TS ./voltha dump |
David Bainbridge | 76514a0 | 2019-10-08 01:50:35 +0000 | [diff] [blame] | 120 | C_TS=$(echo $RUN_TS | sed -e 's/[:-]//g') |
| 121 | |
| 122 | if [ ! -z "$INCLUDE_LOG_DIR" ]; then |
| 123 | # Now that we have the dump compressed tar file, expand it into a temp |
| 124 | # area, augment it with the extended (combined) log files and then |
| 125 | # repackage it |
| 126 | WORK=$(mktemp -d) |
| 127 | tar -C $WORK -zxf voltha-debug-dump-$NAME-$C_TS.tgz |
| 128 | mkdir $WORK/voltha-debug-dump-$NAME-$C_TS/logs |
| 129 | for LOG in $(ls -1 $INCLUDE_LOG_DIR/*.log.[0-9]*); do |
| 130 | LOG_NAME=$(basename $LOG) |
| 131 | WORK_LOG=$(mktemp) |
| 132 | cat $LOG | awk "{if ( \$1 >= \"$RUN_TS\" ) print}" > $WORK_LOG |
| 133 | if [ $(stat -c %s $WORK_LOG) -eq 0 ]; then |
| 134 | rm -f $WORK_LOG |
| 135 | else |
| 136 | mv $WORK_LOG $WORK/voltha-debug-dump-$NAME-$C_TS/logs/$LOG_NAME |
| 137 | fi |
| 138 | done |
| 139 | |
| 140 | tar -C $WORK -czf voltha-debug-dump-$NAME-$C_TS.tgz ./voltha-debug-dump-$NAME-$C_TS |
| 141 | fi |
| 142 | |
| 143 | if [ "$EXIT_ON_FAIL" == "yes" ]; then |
| 144 | exit |
| 145 | fi |
| 146 | |
| 147 | DEPLOY_K8S=n ./voltha down |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 148 | fi |
| 149 | echo "END RUN: $RUN @ $(date -u +%Y-%m-%dT%H:%M:%SZ)" | tee -a $LOG |
| 150 | COMPLETED=$(expr $COMPLETED + 1) |
| 151 | MTBF=0 |
| 152 | if [ ${#FAILURE_LIST[@]} -gt 0 ]; then |
| 153 | for V in ${FAILURE_LIST[@]}; do |
| 154 | MTBF=$(expr $MTBF + $V) |
| 155 | done |
| 156 | MTBF=$(expr $MTBF \/ ${#FAILURE_LIST[@]}) |
| 157 | fi |
| 158 | |
| 159 | RSS_DIFFS+=($(delta $AFTER_RSS $BEFORE_RSS)) |
| 160 | KEY_DIFFS+=($(delta $AFTER_KEY_COUNT $BEFORE_KEY_COUNT)) |
| 161 | SIZE_DIFFS+=($(delta $AFTER_SIZE $BEFORE_SIZE)) |
| 162 | |
| 163 | echo "{" | tee -a $LOG |
| 164 | echo " NumberOfRuns: $COMPLETED," | tee -a $LOG |
| 165 | echo " Success: $COUNT_OK," | tee -a $LOG |
| 166 | echo " Failed: $COUNT_FAIL," | tee -a $LOG |
| 167 | echo " SinceLastFail: $COUNT_SINCE_FAIL," | tee -a $LOG |
| 168 | echo " MTBF: $MTBF," | tee -a $LOG |
| 169 | echo " FAILURES: ${FAILURE_LIST[@]}," | tee -a $LOG |
| 170 | echo " ETCd: {" | tee -a $LOG |
| 171 | echo " KeyCount: {" | tee -a $LOG |
| 172 | echo " Before: $BEFORE_KEY_COUNT," | tee -a $LOG |
| 173 | echo " After: $AFTER_KEY_COUNT," | tee -a $LOG |
| 174 | echo " Average: $(average ${KEY_DIFFS[@]})," | tee -a $LOG |
| 175 | echo " }," | tee -a $LOG |
| 176 | echo " DbSize: {" | tee -a $LOG |
| 177 | echo " Before: $BEFORE_SIZE," | tee -a $LOG |
| 178 | echo " After: $AFTER_SIZE," | tee -a $LOG |
| 179 | echo " Average: $(numfmt --to=iec $(average ${SIZE_DIFFS[@]}))," | tee -a $LOG |
| 180 | echo " }" | tee -a $LOG |
| 181 | echo " RSS: {" | tee -a $LOG |
| 182 | echo " Before: $BEFORE_RSS," | tee -a $LOG |
| 183 | echo " After: $AFTER_RSS," | tee -a $LOG |
| 184 | echo " Average: $(numfmt --to=iec $(average ${RSS_DIFFS[@]}))," | tee -a $LOG |
| 185 | echo " }" | tee -a $LOG |
| 186 | echo " }" | tee -a $LOG |
| 187 | echo "}" | tee -a $LOG |
| 188 | if [ $FAIL -ne 0 ]; then |
| 189 | mkdir -p failures |
| 190 | cp $LOG failures/$(date -u +"%Y%m%dT%H%M%SZ")-fail-output.log |
| 191 | fi |
| 192 | done |