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