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