Merge "Remove all refs to nitrogen from int/dist"
[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}/${BUNDLE_VERSION}/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 echo "Waiting up to 3 minutes for controller to come up, checking every 5 seconds..."
159 for i in {1..36};
160     do sleep 5;
161     grep 'org.opendaylight.infrautils.ready-impl.*System ready' /tmp/${BUNDLEFOLDER}/data/log/karaf.log
162     if [ \$? -eq 0 ]
163     then
164       echo "Controller is UP"
165       break
166     fi
167 done;
168
169 # if we ended up not finding ready status in the above loop, we can output some debugs
170 grep 'org.opendaylight.infrautils.ready-impl.*System ready' /tmp/${BUNDLEFOLDER}/data/log/karaf.log
171 if [ $? -ne 0 ]
172 then
173     echo "Timeout Controller DOWN"
174     echo "Dumping first 500K bytes of karaf log..."
175     head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
176     echo "Dumping last 500K bytes of karaf log..."
177     tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
178     echo "Listing all open ports on controller system"
179     netstat -pnatu
180     exit 1
181 fi
182
183 echo "Listing all open ports on controller system..."
184 netstat -pnatu
185
186 function exit_on_log_file_message {
187     echo "looking for \"\$1\" in log file"
188     if grep --quiet "\$1" "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"; then
189         echo ABORTING: found "\$1"
190         echo "Dumping first 500K bytes of karaf log..."
191         head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
192         echo "Dumping last 500K bytes of karaf log..."
193         tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
194         exit 1
195     fi
196 }
197
198 exit_on_log_file_message 'BindException: Address already in use'
199 exit_on_log_file_message 'server is unhealthy'
200
201 EOF
202 # cat > ${WORKSPACE}/post-startup-script.sh <<EOF
203
204 [ "$NUM_OPENSTACK_SITES" ] || NUM_OPENSTACK_SITES=1
205 NUM_ODLS_PER_SITE=$((NUM_ODL_SYSTEM / NUM_OPENSTACK_SITES))
206 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
207 do
208     # Get full list of ODL nodes for this site
209     odl_node_list=
210     for j in `seq 1 ${NUM_ODLS_PER_SITE}`
211     do
212         odl_ip=ODL_SYSTEM_$(((i - 1) * NUM_ODLS_PER_SITE + j))_IP
213         odl_node_list="${odl_node_list} ${!odl_ip}"
214     done
215
216     for j in `seq 1 ${NUM_ODLS_PER_SITE}`
217     do
218         odl_ip=ODL_SYSTEM_$(((i - 1) * NUM_ODLS_PER_SITE + j))_IP
219         # Copy over the config script to controller and execute it (parameters are used only for cluster)
220         echo "Execute the configuration script on controller ${!odl_ip} for index $j with node list ${odl_node_list}"
221         scp ${WORKSPACE}/configuration-script.sh ${!odl_ip}:/tmp
222         ssh ${!odl_ip} "bash /tmp/configuration-script.sh ${j} '${odl_node_list}'"
223     done
224 done
225
226 echo "Locating config plan to use..."
227 configplan_filepath="${WORKSPACE}/test/csit/configplans/${STREAMTESTPLAN}"
228 if [ ! -f "${configplan_filepath}" ]; then
229     configplan_filepath="${WORKSPACE}/test/csit/configplans/${TESTPLAN}"
230 fi
231
232 if [ -f "${configplan_filepath}" ]; then
233     echo "configplan exists!!!"
234     echo "Changing the configplan path..."
235     cat ${configplan_filepath} | sed "s:integration:${WORKSPACE}:" > configplan.txt
236     cat configplan.txt
237     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' configplan.txt ); do
238         echo "Executing ${line}..."
239         # shellcheck source=${line} disable=SC1091
240         source ${line}
241     done
242 fi
243
244 # Copy over the startup script to controller and execute it.
245 for i in `seq 1 ${NUM_ODL_SYSTEM}`
246 do
247     CONTROLLERIP=ODL_SYSTEM_${i}_IP
248     echo "Execute the startup script on controller ${!CONTROLLERIP}"
249     scp ${WORKSPACE}/startup-script.sh ${!CONTROLLERIP}:/tmp
250     ssh ${!CONTROLLERIP} "bash /tmp/startup-script.sh"
251 done
252
253 seed_index=1
254 for i in `seq 1 ${NUM_ODL_SYSTEM}`
255 do
256     CONTROLLERIP=ODL_SYSTEM_${i}_IP
257     echo "Execute the post startup script on controller ${!CONTROLLERIP}"
258     scp ${WORKSPACE}/post-startup-script.sh ${!CONTROLLERIP}:/tmp
259     ssh ${!CONTROLLERIP} "bash /tmp/post-startup-script.sh $(( seed_index++ ))"
260     if [ $(( $i % (${NUM_ODL_SYSTEM} / ${NUM_OPENSTACK_SITES}) )) == 0 ]; then
261         seed_index=1
262     fi
263 done
264
265 echo "Generating controller variables..."
266 for i in `seq 1 ${NUM_ODL_SYSTEM}`
267 do
268     CONTROLLERIP=ODL_SYSTEM_${i}_IP
269     odl_variables=${odl_variables}" -v ${CONTROLLERIP}:${!CONTROLLERIP}"
270     echo "Lets's take the karaf thread dump"
271     ssh ${!CONTROLLERIP} "sudo ps aux" > ${WORKSPACE}/ps_before.log
272     pid=$(grep org.apache.karaf.main.Main ${WORKSPACE}/ps_before.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
273     echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
274     ssh ${!CONTROLLERIP} "jstack ${pid}" > ${WORKSPACE}/karaf_${i}_${pid}_threads_before.log || true
275 done
276
277 if [ ${NUM_OPENSTACK_SYSTEM} -gt 0 ]; then
278    echo "Exiting without running tests to deploy openstack for testing"
279    exit
280 fi
281
282 echo "Generating mininet variables..."
283 for i in `seq 1 ${NUM_TOOLS_SYSTEM}`
284 do
285     MININETIP=TOOLS_SYSTEM_${i}_IP
286     tools_variables=${tools_variables}" -v ${MININETIP}:${!MININETIP}"
287 done
288
289 echo "Locating test plan to use..."
290 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
291 if [ ! -f "${testplan_filepath}" ]; then
292     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
293 fi
294
295 echo "Changing the testplan path..."
296 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
297 cat testplan.txt
298
299 # Use the testplan if specific SUITES are not defined.
300 if [ -z "${SUITES}" ]; then
301     SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
302 else
303     newsuites=""
304     workpath="${WORKSPACE}/test/csit/suites"
305     for suite in ${SUITES}; do
306         fullsuite="${workpath}/${suite}"
307         if [ -z "${newsuites}" ]; then
308             newsuites+=${fullsuite}
309         else
310             newsuites+=" "${fullsuite}
311         fi
312     done
313     SUITES=${newsuites}
314 fi
315
316 echo "Starting Robot test suites ${SUITES} ..."
317 pybot -N ${TESTPLAN} \
318       --removekeywords wuks -c critical -e exclude -e skip_if_${DISTROSTREAM} \
319       -v BUNDLEFOLDER:${BUNDLEFOLDER} \
320       -v BUNDLE_URL:${ACTUAL_BUNDLE_URL} \
321       -v CONTROLLER:${ODL_SYSTEM_IP} \
322       -v CONTROLLER_USER:${USER} \
323       -v JAVA_HOME:${JAVA_HOME} \
324       -v JDKVERSION:${JDKVERSION} \
325       -v MININET1:${TOOLS_SYSTEM_2_IP} \
326       -v MININET2:${TOOLS_SYSTEM_3_IP} \
327       -v MININET3:${TOOLS_SYSTEM_4_IP} \
328       -v MININET4:${TOOLS_SYSTEM_5_IP} \
329       -v MININET5:${TOOLS_SYSTEM_6_IP} \
330       -v MININET:${TOOLS_SYSTEM_IP} \
331       -v MININET_USER:${USER} \
332       -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
333       -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
334       -v ODL_STREAM:${DISTROSTREAM} \
335       -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_IP} \
336       -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} \
337       -v ODL_SYSTEM_USER:${USER} \
338       -v TOOLS_SYSTEM_1_IP:${TOOLS_SYSTEM_IP} \
339       -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} \
340       -v TOOLS_SYSTEM_3_IP:${TOOLS_SYSTEM_3_IP} \
341       -v TOOLS_SYSTEM_4_IP:${TOOLS_SYSTEM_4_IP} \
342       -v TOOLS_SYSTEM_5_IP:${TOOLS_SYSTEM_5_IP} \
343       -v TOOLS_SYSTEM_6_IP:${TOOLS_SYSTEM_6_IP} \
344       -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_IP} \
345       -v TOOLS_SYSTEM_USER:${USER} \
346       -v USER_HOME:${HOME} \
347       -v WORKSPACE:/tmp \
348       ${TESTOPTIONS} ${SUITES} || true
349
350 echo "Examining the files in data/log and checking filesize"
351 ssh ${ODL_SYSTEM_IP} "ls -altr /tmp/${BUNDLEFOLDER}/data/log/"
352 ssh ${ODL_SYSTEM_IP} "du -hs /tmp/${BUNDLEFOLDER}/data/log/*"
353
354 for i in `seq 1 ${NUM_ODL_SYSTEM}`
355 do
356     CONTROLLERIP=ODL_SYSTEM_${i}_IP
357     echo "Lets's take the karaf thread dump again..."
358     ssh ${!CONTROLLERIP} "sudo ps aux" > ${WORKSPACE}/ps_after.log
359     pid=$(grep org.apache.karaf.main.Main ${WORKSPACE}/ps_after.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
360     echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
361     ssh ${!CONTROLLERIP} "jstack ${pid}" > ${WORKSPACE}/karaf_${i}_${pid}_threads_after.log || true
362     echo "Killing ODL"
363     set +e  # We do not want to create red dot just because something went wrong while fetching logs.
364     ssh "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
365 done
366
367 sleep 5
368 # FIXME: Unify the copy process between various scripts.
369 # TODO: Use rsync.
370 for i in `seq 1 ${NUM_ODL_SYSTEM}`
371 do
372     CONTROLLERIP=ODL_SYSTEM_${i}_IP
373     echo "Compressing karaf.log ${i}"
374     ssh ${!CONTROLLERIP} gzip --best /tmp/${BUNDLEFOLDER}/data/log/karaf.log
375     echo "Fetching compressed karaf.log ${i}"
376     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"
377     # TODO: Should we compress the output log file as well?
378     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"
379     echo "Fetch GC logs"
380     # FIXME: Put member index in filename, instead of directory name.
381     mkdir -p "gclogs-${i}"
382     scp "${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/data/log/*.log" "gclogs-${i}/" && ssh ${!CONTROLLERIP} rm -f "/tmp/${BUNDLEFOLDER}/data/log/*.log"
383 done
384
385 echo "Examine copied files"
386 ls -lt
387
388 true  # perhaps Jenkins is testing last exit code
389
390 # vim: ts=4 sw=4 sts=4 et ft=sh :