Merge "Fix typo in branch cutting script"
[releng/builder.git] / jjb / integration / integration-deploy-controller-run-test.sh
1 #@IgnoreInspection BashAddShebang
2 # Activate robotframework virtualenv
3 # ${ROBOT_VENV} comes from the integration-install-robotframework.sh
4 # script.
5 # shellcheck source=${ROBOT_VENV}/bin/activate disable=SC1091
6 source ${ROBOT_VENV}/bin/activate
7 source /tmp/common-functions.sh ${BUNDLEFOLDER}
8
9 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
10     echo "Configure cluster"
11     AKKACONF=/tmp/${BUNDLEFOLDER}/configuration/initial/akka.conf
12     MODULESCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/modules.conf
13     MODULESHARDSCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/module-shards.conf
14 fi
15
16 if [ ${CONTROLLERSCOPE} == 'all' ]; then
17     ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
18     export CONTROLLERMEM="3072m"
19     COOLDOWN_PERIOD="180"
20 else
21     ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
22     COOLDOWN_PERIOD="60"
23 fi
24
25 # Some versions of jenkins job builder result in feature list containing spaces
26 # and ending in newline. Remove all that.
27 ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
28 echo "ACTUALFEATURES: ${ACTUALFEATURES}"
29
30 # In the case that we want to install features via karaf shell, a space separated list of
31 # ACTUALFEATURES IS NEEDED
32 SPACE_SEPARATED_FEATURES=$(echo "${ACTUALFEATURES}" | tr ',' ' ')
33 echo "SPACE_SEPARATED_FEATURES: ${SPACE_SEPARATED_FEATURES}"
34
35 if [ -f "${WORKSPACE}/test/csit/scriptplans/${TESTPLAN}" ]; then
36     echo "scriptplan exists!!!"
37     echo "Changing the scriptplan path..."
38     cat ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > scriptplan.txt
39     cat scriptplan.txt
40     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' scriptplan.txt ); do
41         echo "Executing ${line}..."
42         # shellcheck source=${line} disable=SC1091
43         source ${line}
44     done
45 fi
46
47 cat > ${WORKSPACE}/configuration-script.sh <<EOF
48 set -x
49 source /tmp/common-functions.sh ${BUNDLEFOLDER}
50
51 echo "Changing to /tmp"
52 cd /tmp
53
54 echo "Downloading the distribution..."
55 wget --progress=dot:mega '${ACTUAL_BUNDLE_URL}'
56
57 echo "Extracting the new controller..."
58 unzip -q ${BUNDLE}
59
60 echo "Adding external repositories..."
61 sed -ie "s%org.ops4j.pax.url.mvn.repositories=%org.ops4j.pax.url.mvn.repositories=http://repo1.maven.org/maven2@id=central, http://repository.springsource.com/maven/bundles/release@id=spring.ebr.release, http://repository.springsource.com/maven/bundles/external@id=spring.ebr.external, http://zodiac.springsource.com/maven/bundles/release@id=gemini, http://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases, https://oss.sonatype.org/content/repositories/snapshots@id=sonatype.snapshots.deploy@snapshots@noreleases, https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases%g" ${MAVENCONF}
62 cat ${MAVENCONF}
63
64 if [[ "$USEFEATURESBOOT" == "True" ]]; then
65     echo "Configuring the startup features..."
66     sed -ie "s/\(featuresBoot=\|featuresBoot =\)/featuresBoot = ${ACTUALFEATURES},/g" ${FEATURESCONF}
67 fi
68
69 FEATURE_TEST_STRING="features-integration-test"
70 if [[ "$KARAF_VERSION" == "karaf4" ]]; then
71     FEATURE_TEST_STRING="features-test"
72 fi
73
74 sed -ie "s%\(featuresRepositories=\|featuresRepositories =\)%featuresRepositories = mvn:org.opendaylight.integration/\${FEATURE_TEST_STRING}/${BUNDLEVERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.0.0/xml/features,%g" ${FEATURESCONF}
75 cat ${FEATURESCONF}
76
77 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
78     echo "Enable the l3.fwd in custom.properties..."
79     echo "ovsdb.l3.fwd.enabled=yes" >> ${CUSTOMPROP}
80 fi
81 cat ${CUSTOMPROP}
82
83 configure_karaf_log "${KARAF_VERSION}" "${CONTROLLERDEBUGMAP}"
84
85 set_java_vars "${JAVA_HOME}" "${CONTROLLERMEM}" "${MEMCONF}"
86
87 echo "Listing all open ports on controller system..."
88 netstat -pnatu
89
90 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
91
92     # Copy shard file if exists
93     if [ -f /tmp/custom_shard_config.txt ]; then
94         echo "Custom shard config exists!!!"
95         echo "Copying the shard config..."
96         cp /tmp/custom_shard_config.txt /tmp/${BUNDLEFOLDER}/bin/
97     fi
98
99     echo "Configuring cluster"
100     /tmp/${BUNDLEFOLDER}/bin/configure_cluster.sh \$1 \$2
101
102     echo "Dump akka.conf"
103     cat ${AKKACONF}
104
105     echo "Dump modules.conf"
106     cat ${MODULESCONF}
107
108      echo "Dump module-shards.conf"
109      cat ${MODULESHARDSCONF}
110 fi
111
112 EOF
113 # cat > ${WORKSPACE}/configuration-script.sh <<EOF
114
115 # Create the startup script to be run on controller.
116 cat > ${WORKSPACE}/startup-script.sh <<EOF
117
118 echo "Redirecting karaf console output to karaf_console.log"
119 export KARAF_REDIRECT="/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log"
120 mkdir -p /tmp/${BUNDLEFOLDER}/data/log
121
122 echo "Starting controller..."
123 /tmp/${BUNDLEFOLDER}/bin/start
124
125 EOF
126 # cat > ${WORKSPACE}/startup-script.sh <<EOF
127
128 cat > ${WORKSPACE}/post-startup-script.sh <<EOF
129
130 if [[ "$USEFEATURESBOOT" != "True" ]]; then
131
132     # wait up to 60s for karaf port 8101 to be opened, polling every 5s
133     loop_count=0;
134     until [[ \$loop_count -ge 12 ]]; do
135         netstat -na | grep 8101 && break;
136         loop_count=\$[\$loop_count+1];
137         sleep 5;
138     done
139
140     echo "going to feature:install --no-auto-refresh ${SPACE_SEPARATED_FEATURES} one at a time"
141     for feature in ${SPACE_SEPARATED_FEATURES}; do
142         sshpass -p karaf ssh -o StrictHostKeyChecking=no \
143                              -o UserKnownHostsFile=/dev/null \
144                              -o LogLevel=error \
145                              -p 8101 karaf@localhost \
146                              feature:install --no-auto-refresh \$feature;
147     done
148
149     echo "ssh to karaf console to list -i installed features"
150     sshpass -p karaf ssh -o StrictHostKeyChecking=no \
151                          -o UserKnownHostsFile=/dev/null \
152                          -o LogLevel=error \
153                          -p 8101 karaf@localhost \
154                          feature:list -i
155 fi
156
157 echo "Waiting for controller to come up..."
158 COUNT="0"
159 while true; do
160     RESP="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null )"
161     echo \$RESP
162     if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
163         SHARD="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/jolokia/read/org.opendaylight.controller:Category=Shards,name=\member-\$1-shard-inventory-config,type=DistributedConfigDatastore)"
164         echo \$SHARD
165     fi
166     if ([[ \$RESP == *"200"* ]] && ([[ "${ENABLE_HAPROXY_FOR_NEUTRON}" != "yes" ]] || [[ \$SHARD  == *'"status":200'* ]])); then
167         echo Controller is UP
168         break
169     elif (( "\$COUNT" > "600" )); then
170         echo Timeout Controller DOWN
171         echo "Dumping first 500K bytes of karaf log..."
172         head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
173         echo "Dumping last 500K bytes of karaf log..."
174         tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
175         echo "Listing all open ports on controller system"
176         netstat -pnatu
177         exit 1
178     else
179         COUNT=\$(( \${COUNT} + 1 ))
180         sleep 1
181         if [[ \$((\$COUNT % 5)) == 0 ]]; then
182             echo already waited \${COUNT} seconds...
183         fi
184     fi
185 done
186
187 echo "Listing all open ports on controller system..."
188 netstat -pnatu
189
190 function exit_on_log_file_message {
191     echo "looking for \"\$1\" in log file"
192     if grep --quiet "\$1" "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"; then
193         echo ABORTING: found "\$1"
194         echo "Dumping first 500K bytes of karaf log..."
195         head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
196         echo "Dumping last 500K bytes of karaf log..."
197         tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
198         exit 1
199     fi
200 }
201
202 exit_on_log_file_message 'BindException: Address already in use'
203 exit_on_log_file_message 'server is unhealthy'
204
205 EOF
206 # cat > ${WORKSPACE}/post-startup-script.sh <<EOF
207
208 [ "$NUM_OPENSTACK_SITES" ] || NUM_OPENSTACK_SITES=1
209 NUM_ODLS_PER_SITE=$((NUM_ODL_SYSTEM / NUM_OPENSTACK_SITES))
210 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
211 do
212     # Get full list of ODL nodes for this site
213     odl_node_list=
214     for j in `seq 1 ${NUM_ODLS_PER_SITE}`
215     do
216         odl_ip=ODL_SYSTEM_$(((i - 1) * NUM_ODLS_PER_SITE + j))_IP
217         odl_node_list="${odl_node_list} ${!odl_ip}"
218     done
219
220     for j in `seq 1 ${NUM_ODLS_PER_SITE}`
221     do
222         odl_ip=ODL_SYSTEM_$(((i - 1) * NUM_ODLS_PER_SITE + j))_IP
223         # Copy over the config script to controller and execute it (parameters are used only for cluster)
224         echo "Execute the configuration script on controller ${!odl_ip} for index $j with node list ${odl_node_list}"
225         scp ${WORKSPACE}/configuration-script.sh ${!odl_ip}:/tmp
226         ssh ${!odl_ip} "bash /tmp/configuration-script.sh ${j} '${odl_node_list}'"
227     done
228 done
229
230 echo "Locating config plan to use..."
231 configplan_filepath="${WORKSPACE}/test/csit/configplans/${STREAMTESTPLAN}"
232 if [ ! -f "${configplan_filepath}" ]; then
233     configplan_filepath="${WORKSPACE}/test/csit/configplans/${TESTPLAN}"
234 fi
235
236 if [ -f "${configplan_filepath}" ]; then
237     echo "configplan exists!!!"
238     echo "Changing the configplan path..."
239     cat ${configplan_filepath} | sed "s:integration:${WORKSPACE}:" > configplan.txt
240     cat configplan.txt
241     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' configplan.txt ); do
242         echo "Executing ${line}..."
243         # shellcheck source=${line} disable=SC1091
244         source ${line}
245     done
246 fi
247
248 # Copy over the startup script to controller and execute it.
249 for i in `seq 1 ${NUM_ODL_SYSTEM}`
250 do
251     CONTROLLERIP=ODL_SYSTEM_${i}_IP
252     echo "Execute the startup script on controller ${!CONTROLLERIP}"
253     scp ${WORKSPACE}/startup-script.sh ${!CONTROLLERIP}:/tmp
254     ssh ${!CONTROLLERIP} "bash /tmp/startup-script.sh"
255 done
256
257 seed_index=1
258 for i in `seq 1 ${NUM_ODL_SYSTEM}`
259 do
260     CONTROLLERIP=ODL_SYSTEM_${i}_IP
261     echo "Execute the post startup script on controller ${!CONTROLLERIP}"
262     scp ${WORKSPACE}/post-startup-script.sh ${!CONTROLLERIP}:/tmp
263     ssh ${!CONTROLLERIP} "bash /tmp/post-startup-script.sh $(( seed_index++ ))"
264     if [ $(( $i % (${NUM_ODL_SYSTEM} / ${NUM_OPENSTACK_SITES}) )) == 0 ]; then
265         seed_index=1
266     fi
267 done
268
269 echo "Cool down for ${COOLDOWN_PERIOD} seconds :)..."
270 sleep ${COOLDOWN_PERIOD}
271
272 echo "Generating controller variables..."
273 for i in `seq 1 ${NUM_ODL_SYSTEM}`
274 do
275     CONTROLLERIP=ODL_SYSTEM_${i}_IP
276     odl_variables=${odl_variables}" -v ${CONTROLLERIP}:${!CONTROLLERIP}"
277     echo "Lets's take the karaf thread dump"
278     ssh ${!CONTROLLERIP} "sudo ps aux" > ${WORKSPACE}/ps_before.log
279     pid=$(grep org.apache.karaf.main.Main ${WORKSPACE}/ps_before.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
280     echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
281     ssh ${!CONTROLLERIP} "jstack ${pid}" > ${WORKSPACE}/karaf_${i}_${pid}_threads_before.log || true
282 done
283
284 if [ ${NUM_OPENSTACK_SYSTEM} -gt 0 ]; then
285    echo "Exiting without running tests to deploy openstack for testing"
286    exit
287 fi
288
289 echo "Generating mininet variables..."
290 for i in `seq 1 ${NUM_TOOLS_SYSTEM}`
291 do
292     MININETIP=TOOLS_SYSTEM_${i}_IP
293     tools_variables=${tools_variables}" -v ${MININETIP}:${!MININETIP}"
294 done
295
296 echo "Locating test plan to use..."
297 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
298 if [ ! -f "${testplan_filepath}" ]; then
299     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
300 fi
301
302 echo "Changing the testplan path..."
303 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
304 cat testplan.txt
305
306 # Use the testplan if specific SUITES are not defined.
307 if [ -z "${SUITES}" ]; then
308     SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
309 else
310     newsuites=""
311     workpath="${WORKSPACE}/test/csit/suites"
312     for suite in ${SUITES}; do
313         fullsuite="${workpath}/${suite}"
314         if [ -z "${newsuites}" ]; then
315             newsuites+=${fullsuite}
316         else
317             newsuites+=" "${fullsuite}
318         fi
319     done
320     SUITES=${newsuites}
321 fi
322
323 echo "Starting Robot test suites ${SUITES} ..."
324 pybot -N ${TESTPLAN} \
325       --removekeywords wuks -c critical -e exclude -e skip_if_${DISTROSTREAM} \
326       -v BUNDLEFOLDER:${BUNDLEFOLDER} \
327       -v BUNDLE_URL:${ACTUAL_BUNDLE_URL} \
328       -v CONTROLLER:${ODL_SYSTEM_IP} \
329       -v CONTROLLER_USER:${USER} \
330       -v JAVA_HOME:${JAVA_HOME} \
331       -v JDKVERSION:${JDKVERSION} \
332       -v MININET1:${TOOLS_SYSTEM_2_IP} \
333       -v MININET2:${TOOLS_SYSTEM_3_IP} \
334       -v MININET3:${TOOLS_SYSTEM_4_IP} \
335       -v MININET4:${TOOLS_SYSTEM_5_IP} \
336       -v MININET5:${TOOLS_SYSTEM_6_IP} \
337       -v MININET:${TOOLS_SYSTEM_IP} \
338       -v MININET_USER:${USER} \
339       -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
340       -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
341       -v ODL_STREAM:${DISTROSTREAM} \
342       -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_IP} \
343       -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} \
344       -v ODL_SYSTEM_USER:${USER} \
345       -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} \
346       -v TOOLS_SYSTEM_3_IP:${TOOLS_SYSTEM_3_IP} \
347       -v TOOLS_SYSTEM_4_IP:${TOOLS_SYSTEM_4_IP} \
348       -v TOOLS_SYSTEM_5_IP:${TOOLS_SYSTEM_5_IP} \
349       -v TOOLS_SYSTEM_6_IP:${TOOLS_SYSTEM_6_IP} \
350       -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_IP} \
351       -v TOOLS_SYSTEM_USER:${USER} \
352       -v USER_HOME:${HOME} \
353       -v WORKSPACE:/tmp \
354       ${TESTOPTIONS} ${SUITES} || true
355
356 echo "Examining the files in data/log and checking filesize"
357 ssh ${ODL_SYSTEM_IP} "ls -altr /tmp/${BUNDLEFOLDER}/data/log/"
358 ssh ${ODL_SYSTEM_IP} "du -hs /tmp/${BUNDLEFOLDER}/data/log/*"
359
360 for i in `seq 1 ${NUM_ODL_SYSTEM}`
361 do
362     CONTROLLERIP=ODL_SYSTEM_${i}_IP
363     echo "Lets's take the karaf thread dump again..."
364     ssh ${!CONTROLLERIP} "sudo ps aux" > ${WORKSPACE}/ps_after.log
365     pid=$(grep org.apache.karaf.main.Main ${WORKSPACE}/ps_after.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
366     echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
367     ssh ${!CONTROLLERIP} "jstack ${pid}" > ${WORKSPACE}/karaf_${i}_${pid}_threads_after.log || true
368     echo "Killing ODL"
369     set +e  # We do not want to create red dot just because something went wrong while fetching logs.
370     ssh "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
371 done
372
373 sleep 5
374 # FIXME: Unify the copy process between various scripts.
375 # TODO: Use rsync.
376 for i in `seq 1 ${NUM_ODL_SYSTEM}`
377 do
378     CONTROLLERIP=ODL_SYSTEM_${i}_IP
379     echo "Compressing karaf.log ${i}"
380     ssh ${!CONTROLLERIP} gzip --best /tmp/${BUNDLEFOLDER}/data/log/karaf.log
381     echo "Fetching compressed karaf.log ${i}"
382     scp "${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log.gz" "odl${i}_karaf.log.gz" && ssh ${!CONTROLLERIP} rm -f "/tmp/${BUNDLEFOLDER}/data/log/karaf.log.gz"
383     # TODO: Should we compress the output log file as well?
384     scp "${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log" "odl${i}_karaf_console.log" && ssh ${!CONTROLLERIP} rm -f "/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log"
385     echo "Fetch GC logs"
386     # FIXME: Put member index in filename, instead of directory name.
387     mkdir -p "gclogs-${i}"
388     scp "${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/data/log/*.log" "gclogs-${i}/" && ssh ${!CONTROLLERIP} rm -f "/tmp/${BUNDLEFOLDER}/data/log/*.log"
389 done
390
391 echo "Examine copied files"
392 ls -lt
393
394 true  # perhaps Jenkins is testing last exit code
395
396 # vim: ts=4 sw=4 sts=4 et ft=sh :