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 | |
| 18 | set -o pipefail |
| 19 | |
| 20 | if [ ! -r voltha-system-tests ]; then |
| 21 | git clone http://gerrit.opencord.org/voltha-system-tests voltha-system-tests |
| 22 | fi |
| 23 | |
| 24 | delta() { |
| 25 | local LEFT=$(echo $1 | numfmt --from=iec) |
| 26 | local RIGHT=$(echo $2 | numfmt --from=iec) |
| 27 | local V=$(expr $LEFT - $RIGHT) |
| 28 | echo ${V#-} |
| 29 | } |
| 30 | |
| 31 | average() { |
| 32 | local MIN=0 |
| 33 | local MAX=0 |
| 34 | local COUNT=0 |
| 35 | local SUM=0 |
| 36 | for V in $*; do |
| 37 | COUNT=$(expr $COUNT + 1) |
| 38 | SUM=$(expr $SUM + $V) |
| 39 | if [ $COUNT -eq 1 ]; then |
| 40 | MIN=$V |
| 41 | MAX=$V |
| 42 | else |
| 43 | if [ $V -lt $MIN ]; then |
| 44 | MIN=$V |
| 45 | elif [ $V -gt $MAX ]; then |
| 46 | MAX=$V |
| 47 | fi |
| 48 | fi |
| 49 | done |
| 50 | if [ $COUNT -gt 3 ]; then |
| 51 | SUM=$(expr $SUM - $MIN - $MAX) |
| 52 | COUNT=$(expr $COUNT - 2) |
| 53 | fi |
| 54 | if [ $COUNT -lt 1 ]; then |
| 55 | echo 0 |
| 56 | else |
| 57 | echo $(expr $SUM / $COUNT) |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | export WAIT_FOR_DOWN=y |
| 62 | export TERM= |
| 63 | |
| 64 | COMPLETED=0 |
| 65 | COUNT_OK=0 |
| 66 | COUNT_FAIL=0 |
| 67 | COUNT_SINCE_FAIL=0 |
| 68 | FAILURE_LIST=() |
| 69 | RSS_DIFFS=() |
| 70 | KEY_DIFFS=() |
| 71 | SIZE_DIFFS=() |
| 72 | LOG=$(mktemp) |
| 73 | while true; do |
| 74 | RUN_TS=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 75 | echo "START RUN $RUN @ $RUN_TS" | tee -a $LOG |
| 76 | DEPLOY_K8S=y WITH_BBSIM=y ./voltha up |
| 77 | # because BBSIM needs time |
| 78 | sleep 60 |
| 79 | ETCD=$(kubectl -n voltha get pods | grep etcd-cluster | awk '{print $1}') |
| 80 | BEFORE_KEY_COUNT=$(kubectl -n voltha exec -ti $ETCD \ |
| 81 | -- sh -c 'ETCDCTL_API=3 etcdctl get --command-timeout=60s --from-key=true --keys-only . | sed -e "/^$/d" | wc -l | tr -d "\r\n"') |
| 82 | BEFORE_SIZE=$(numfmt --to=iec \ |
| 83 | $(kubectl -n voltha exec -ti $ETCD \ |
| 84 | -- sh -c 'ETCDCTL_API=3 etcdctl endpoint status -w json' | tr -d '\r\n' | jq .[].Status.dbSize)) |
| 85 | BEFORE_RSS=$(ps -eo rss,pid,cmd | grep /usr/local/bin/etcd | grep -v grep | cut -d\ -f1 | numfmt --to=iec) |
| 86 | (cd voltha-system-tests; make sanity-kind 2>&1 | tee $LOG) |
| 87 | FAIL=$? |
| 88 | AFTER_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 | AFTER_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 | AFTER_RSS=$(ps -eo rss,pid,cmd | grep /usr/local/bin/etcd | grep -v grep | cut -d\ -f1 | numfmt --to=iec) |
| 94 | if [ $FAIL -eq 0 ]; then |
| 95 | COUNT_OK=$(expr $COUNT_OK + 1) |
| 96 | COUNT_SINCE_FAIL=$(expr $COUNT_SINCE_FAIL + 1) |
| 97 | helm delete --purge bbsim |
| 98 | while [ $(kubectl get --all-namespaces pods,svc 2>&1 | grep -c bbsim) -gt 0 ]; do |
| 99 | sleep 3 |
| 100 | done |
| 101 | else |
| 102 | COUNT_FAIL=$(expr $COUNT_FAIL + 1) |
| 103 | FAILURE_LIST+=($COUNT_SINCE_FAIL) |
| 104 | COUNT_SINCE_FAIL=0 |
| 105 | DUMP_FROM=$RUN_TS ./voltha dump |
| 106 | ./voltha down |
| 107 | fi |
| 108 | echo "END RUN: $RUN @ $(date -u +%Y-%m-%dT%H:%M:%SZ)" | tee -a $LOG |
| 109 | COMPLETED=$(expr $COMPLETED + 1) |
| 110 | MTBF=0 |
| 111 | if [ ${#FAILURE_LIST[@]} -gt 0 ]; then |
| 112 | for V in ${FAILURE_LIST[@]}; do |
| 113 | MTBF=$(expr $MTBF + $V) |
| 114 | done |
| 115 | MTBF=$(expr $MTBF \/ ${#FAILURE_LIST[@]}) |
| 116 | fi |
| 117 | |
| 118 | RSS_DIFFS+=($(delta $AFTER_RSS $BEFORE_RSS)) |
| 119 | KEY_DIFFS+=($(delta $AFTER_KEY_COUNT $BEFORE_KEY_COUNT)) |
| 120 | SIZE_DIFFS+=($(delta $AFTER_SIZE $BEFORE_SIZE)) |
| 121 | |
| 122 | echo "{" | tee -a $LOG |
| 123 | echo " NumberOfRuns: $COMPLETED," | tee -a $LOG |
| 124 | echo " Success: $COUNT_OK," | tee -a $LOG |
| 125 | echo " Failed: $COUNT_FAIL," | tee -a $LOG |
| 126 | echo " SinceLastFail: $COUNT_SINCE_FAIL," | tee -a $LOG |
| 127 | echo " MTBF: $MTBF," | tee -a $LOG |
| 128 | echo " FAILURES: ${FAILURE_LIST[@]}," | tee -a $LOG |
| 129 | echo " ETCd: {" | tee -a $LOG |
| 130 | echo " KeyCount: {" | tee -a $LOG |
| 131 | echo " Before: $BEFORE_KEY_COUNT," | tee -a $LOG |
| 132 | echo " After: $AFTER_KEY_COUNT," | tee -a $LOG |
| 133 | echo " Average: $(average ${KEY_DIFFS[@]})," | tee -a $LOG |
| 134 | echo " }," | tee -a $LOG |
| 135 | echo " DbSize: {" | tee -a $LOG |
| 136 | echo " Before: $BEFORE_SIZE," | tee -a $LOG |
| 137 | echo " After: $AFTER_SIZE," | tee -a $LOG |
| 138 | echo " Average: $(numfmt --to=iec $(average ${SIZE_DIFFS[@]}))," | tee -a $LOG |
| 139 | echo " }" | tee -a $LOG |
| 140 | echo " RSS: {" | tee -a $LOG |
| 141 | echo " Before: $BEFORE_RSS," | tee -a $LOG |
| 142 | echo " After: $AFTER_RSS," | tee -a $LOG |
| 143 | echo " Average: $(numfmt --to=iec $(average ${RSS_DIFFS[@]}))," | tee -a $LOG |
| 144 | echo " }" | tee -a $LOG |
| 145 | echo " }" | tee -a $LOG |
| 146 | echo "}" | tee -a $LOG |
| 147 | if [ $FAIL -ne 0 ]; then |
| 148 | mkdir -p failures |
| 149 | cp $LOG failures/$(date -u +"%Y%m%dT%H%M%SZ")-fail-output.log |
| 150 | fi |
| 151 | done |