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) |
| 81 | while true; do |
| 82 | RUN_TS=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 83 | echo "START RUN $RUN @ $RUN_TS" | tee -a $LOG |
David Bainbridge | 76514a0 | 2019-10-08 01:50:35 +0000 | [diff] [blame] | 84 | DEPLOY_K8S=y WITH_BBSIM=y WITH_SADIS=y WITH_RADIUS=y ./voltha up |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 85 | # because BBSIM needs time |
| 86 | sleep 60 |
| 87 | ETCD=$(kubectl -n voltha get pods | grep etcd-cluster | awk '{print $1}') |
| 88 | BEFORE_KEY_COUNT=$(kubectl -n voltha exec -ti $ETCD \ |
| 89 | -- sh -c 'ETCDCTL_API=3 etcdctl get --command-timeout=60s --from-key=true --keys-only . | sed -e "/^$/d" | wc -l | tr -d "\r\n"') |
| 90 | BEFORE_SIZE=$(numfmt --to=iec \ |
| 91 | $(kubectl -n voltha exec -ti $ETCD \ |
| 92 | -- sh -c 'ETCDCTL_API=3 etcdctl endpoint status -w json' | tr -d '\r\n' | jq .[].Status.dbSize)) |
| 93 | 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^] | 94 | (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] | 95 | FAIL=$? |
| 96 | AFTER_KEY_COUNT=$(kubectl -n voltha exec -ti $ETCD \ |
| 97 | -- sh -c 'ETCDCTL_API=3 etcdctl get --command-timeout=60s --from-key=true --keys-only . | sed -e "/^$/d" | wc -l | tr -d "\r\n"') |
| 98 | AFTER_SIZE=$(numfmt --to=iec \ |
| 99 | $(kubectl -n voltha exec -ti $ETCD \ |
| 100 | -- sh -c 'ETCDCTL_API=3 etcdctl endpoint status -w json' | tr -d '\r\n' | jq .[].Status.dbSize)) |
| 101 | AFTER_RSS=$(ps -eo rss,pid,cmd | grep /usr/local/bin/etcd | grep -v grep | cut -d\ -f1 | numfmt --to=iec) |
| 102 | if [ $FAIL -eq 0 ]; then |
| 103 | COUNT_OK=$(expr $COUNT_OK + 1) |
| 104 | COUNT_SINCE_FAIL=$(expr $COUNT_SINCE_FAIL + 1) |
| 105 | helm delete --purge bbsim |
| 106 | while [ $(kubectl get --all-namespaces pods,svc 2>&1 | grep -c bbsim) -gt 0 ]; do |
| 107 | sleep 3 |
| 108 | done |
| 109 | else |
| 110 | COUNT_FAIL=$(expr $COUNT_FAIL + 1) |
| 111 | FAILURE_LIST+=($COUNT_SINCE_FAIL) |
| 112 | COUNT_SINCE_FAIL=0 |
| 113 | DUMP_FROM=$RUN_TS ./voltha dump |
David Bainbridge | 76514a0 | 2019-10-08 01:50:35 +0000 | [diff] [blame] | 114 | C_TS=$(echo $RUN_TS | sed -e 's/[:-]//g') |
| 115 | |
| 116 | if [ ! -z "$INCLUDE_LOG_DIR" ]; then |
| 117 | # Now that we have the dump compressed tar file, expand it into a temp |
| 118 | # area, augment it with the extended (combined) log files and then |
| 119 | # repackage it |
| 120 | WORK=$(mktemp -d) |
| 121 | tar -C $WORK -zxf voltha-debug-dump-$NAME-$C_TS.tgz |
| 122 | mkdir $WORK/voltha-debug-dump-$NAME-$C_TS/logs |
| 123 | for LOG in $(ls -1 $INCLUDE_LOG_DIR/*.log.[0-9]*); do |
| 124 | LOG_NAME=$(basename $LOG) |
| 125 | WORK_LOG=$(mktemp) |
| 126 | cat $LOG | awk "{if ( \$1 >= \"$RUN_TS\" ) print}" > $WORK_LOG |
| 127 | if [ $(stat -c %s $WORK_LOG) -eq 0 ]; then |
| 128 | rm -f $WORK_LOG |
| 129 | else |
| 130 | mv $WORK_LOG $WORK/voltha-debug-dump-$NAME-$C_TS/logs/$LOG_NAME |
| 131 | fi |
| 132 | done |
| 133 | |
| 134 | tar -C $WORK -czf voltha-debug-dump-$NAME-$C_TS.tgz ./voltha-debug-dump-$NAME-$C_TS |
| 135 | fi |
| 136 | |
| 137 | if [ "$EXIT_ON_FAIL" == "yes" ]; then |
| 138 | exit |
| 139 | fi |
| 140 | |
| 141 | DEPLOY_K8S=n ./voltha down |
David Bainbridge | cfd7ca1 | 2019-10-06 03:31:41 +0000 | [diff] [blame] | 142 | fi |
| 143 | echo "END RUN: $RUN @ $(date -u +%Y-%m-%dT%H:%M:%SZ)" | tee -a $LOG |
| 144 | COMPLETED=$(expr $COMPLETED + 1) |
| 145 | MTBF=0 |
| 146 | if [ ${#FAILURE_LIST[@]} -gt 0 ]; then |
| 147 | for V in ${FAILURE_LIST[@]}; do |
| 148 | MTBF=$(expr $MTBF + $V) |
| 149 | done |
| 150 | MTBF=$(expr $MTBF \/ ${#FAILURE_LIST[@]}) |
| 151 | fi |
| 152 | |
| 153 | RSS_DIFFS+=($(delta $AFTER_RSS $BEFORE_RSS)) |
| 154 | KEY_DIFFS+=($(delta $AFTER_KEY_COUNT $BEFORE_KEY_COUNT)) |
| 155 | SIZE_DIFFS+=($(delta $AFTER_SIZE $BEFORE_SIZE)) |
| 156 | |
| 157 | echo "{" | tee -a $LOG |
| 158 | echo " NumberOfRuns: $COMPLETED," | tee -a $LOG |
| 159 | echo " Success: $COUNT_OK," | tee -a $LOG |
| 160 | echo " Failed: $COUNT_FAIL," | tee -a $LOG |
| 161 | echo " SinceLastFail: $COUNT_SINCE_FAIL," | tee -a $LOG |
| 162 | echo " MTBF: $MTBF," | tee -a $LOG |
| 163 | echo " FAILURES: ${FAILURE_LIST[@]}," | tee -a $LOG |
| 164 | echo " ETCd: {" | tee -a $LOG |
| 165 | echo " KeyCount: {" | tee -a $LOG |
| 166 | echo " Before: $BEFORE_KEY_COUNT," | tee -a $LOG |
| 167 | echo " After: $AFTER_KEY_COUNT," | tee -a $LOG |
| 168 | echo " Average: $(average ${KEY_DIFFS[@]})," | tee -a $LOG |
| 169 | echo " }," | tee -a $LOG |
| 170 | echo " DbSize: {" | tee -a $LOG |
| 171 | echo " Before: $BEFORE_SIZE," | tee -a $LOG |
| 172 | echo " After: $AFTER_SIZE," | tee -a $LOG |
| 173 | echo " Average: $(numfmt --to=iec $(average ${SIZE_DIFFS[@]}))," | tee -a $LOG |
| 174 | echo " }" | tee -a $LOG |
| 175 | echo " RSS: {" | tee -a $LOG |
| 176 | echo " Before: $BEFORE_RSS," | tee -a $LOG |
| 177 | echo " After: $AFTER_RSS," | tee -a $LOG |
| 178 | echo " Average: $(numfmt --to=iec $(average ${RSS_DIFFS[@]}))," | tee -a $LOG |
| 179 | echo " }" | tee -a $LOG |
| 180 | echo " }" | tee -a $LOG |
| 181 | echo "}" | tee -a $LOG |
| 182 | if [ $FAIL -ne 0 ]; then |
| 183 | mkdir -p failures |
| 184 | cp $LOG failures/$(date -u +"%Y%m%dT%H%M%SZ")-fail-output.log |
| 185 | fi |
| 186 | done |