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