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