blob: f34120b49085db4c0b48dca0d34de495a1306ce8 [file] [log] [blame]
David Bainbridgecfd7ca12019-10-06 03:31:41 +00001#!/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 Bainbridge76514a02019-10-08 01:50:35 +000018NAME=${NAME:-minimal}
19EXIT_ON_FAIL=${EXIT_ON_FAIL:-no}
20INCLUDE_LOG_DIR=${INCLUDE_LOG_DIR:-}
David Bainbridge2daf5552019-10-08 20:29:34 +000021BBSIM_ONU_SN=${BBSIM_ONIU_SN:-BBSM00000001}
22BBSIM_OLT_SN=${BBSIM_OLT_SN:-BBSIM_OLT_0}
David Bainbridge76514a02019-10-08 01:50:35 +000023
24# === END OF CONFIGURATION ===
25
David Bainbridgecfd7ca12019-10-06 03:31:41 +000026set -o pipefail
27
28if [ ! -r voltha-system-tests ]; then
29 git clone http://gerrit.opencord.org/voltha-system-tests voltha-system-tests
30fi
31
32delta() {
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
39average() {
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
69export WAIT_FOR_DOWN=y
70export TERM=
71
72COMPLETED=0
73COUNT_OK=0
74COUNT_FAIL=0
75COUNT_SINCE_FAIL=0
76FAILURE_LIST=()
77RSS_DIFFS=()
78KEY_DIFFS=()
79SIZE_DIFFS=()
80LOG=$(mktemp)
81while true; do
82 RUN_TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)
83 echo "START RUN $RUN @ $RUN_TS" | tee -a $LOG
David Bainbridge76514a02019-10-08 01:50:35 +000084 DEPLOY_K8S=y WITH_BBSIM=y WITH_SADIS=y WITH_RADIUS=y ./voltha up
David Bainbridgecfd7ca12019-10-06 03:31:41 +000085 # 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 Bainbridge2daf5552019-10-08 20:29:34 +000094 (cd voltha-system-tests; BBSIM_OLT_SN=$BBSIM_OLT_SN BBSIM_ONU_SN=$BBSIM_ONU_SN make sanity-kind 2>&1 | tee $LOG)
David Bainbridgecfd7ca12019-10-06 03:31:41 +000095 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 Bainbridge76514a02019-10-08 01:50:35 +0000114 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 Bainbridgecfd7ca12019-10-06 03:31:41 +0000142 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
186done