Merge "Add --removekeywords wuks option to pybot command"
[releng/builder.git] / jjb / integration / include-raw-integration-deploy-controller-run-test.sh
1 #@IgnoreInspection BashAddShebang
2 # Activate robotframework virtualenv
3 # ${ROBOT_VENV} comes from the include-raw-integration-install-robotframework.sh
4 # script.
5 source ${ROBOT_VENV}/bin/activate
6
7 CONTROLLERMEM="2048m"
8
9 if [ ${CONTROLLERSCOPE} == 'all' ]; then
10     ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
11     CONTROLLERMEM="3072m"
12     COOLDOWN_PERIOD="180"
13 else
14     ACTUALFEATURES="${CONTROLLERFEATURES}"
15     COOLDOWN_PERIOD="60"
16 fi
17 # Some versions of jenkins job builder result in feature list containing spaces
18 # and ending in newline. Remove all that.
19 ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
20
21 if [ -f ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} ]; then
22     echo "scriptplan exists!!!"
23     echo "Changing the scriptplan path..."
24     cat ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > scriptplan.txt
25     cat scriptplan.txt
26     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' scriptplan.txt ); do
27         echo "Executing ${line}..."
28         source ${line}
29     done
30 fi
31
32 cat > ${WORKSPACE}/configuration-script.sh <<EOF
33
34 echo "Changing to /tmp"
35 cd /tmp
36
37 echo "Downloading the distribution..."
38 wget --progress=dot:mega '${ACTUALBUNDLEURL}'
39
40 echo "Extracting the new controller..."
41 unzip -q ${BUNDLE}
42
43 echo "Configuring the startup features..."
44 FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg
45 CUSTOMPROP=/tmp/${BUNDLEFOLDER}/etc/custom.properties
46 sed -ie "s/featuresBoot=.*/featuresBoot=config,standard,region,package,kar,ssh,management,${ACTUALFEATURES}/g" \${FEATURESCONF}
47 sed -ie "s%mvn:org.opendaylight.integration/features-integration-index/${BUNDLEVERSION}/xml/features%mvn:org.opendaylight.integration/features-integration-index/${BUNDLEVERSION}/xml/features,mvn:org.opendaylight.integration/features-integration-test/${BUNDLEVERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.0.0/xml/features%g" \${FEATURESCONF}
48 cat \${FEATURESCONF}
49
50 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
51   echo "ovsdb.l3.fwd.enabled=yes" >> \${CUSTOMPROP}
52 fi
53 cat \${CUSTOMPROP}
54
55 echo "Configuring the log..."
56 LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
57 sed -ie 's/log4j.appender.out.maxBackupIndex=10/log4j.appender.out.maxBackupIndex=1/g' \${LOGCONF}
58 # FIXME: Make log size limit configurable from build parameter.
59 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=30GB/g' \${LOGCONF}
60 cat \${LOGCONF}
61
62 echo "Configure java home and max memory..."
63 MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv
64 sed -ie 's%^# export JAVA_HOME%export JAVA_HOME="\${JAVA_HOME:-${JAVA_HOME}}"%g' \${MEMCONF}
65 sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' \${MEMCONF}
66 cat \${MEMCONF}
67
68 echo "Listing all open ports on controller system..."
69 netstat -natu
70
71 echo "Set Java version"
72 sudo /usr/sbin/alternatives --install /usr/bin/java java ${JAVA_HOME}/bin/java 1
73 sudo /usr/sbin/alternatives --set java ${JAVA_HOME}/bin/java
74 echo "JDK default version ..."
75 java -version
76
77 echo "Set JAVA_HOME"
78 export JAVA_HOME="$JAVA_HOME"
79 # Did you know that in HERE documents, single quote is an ordinary character, but backticks are still executing?
80 JAVA_RESOLVED=\`readlink -e "\${JAVA_HOME}/bin/java"\`
81 echo "Java binary pointed at by JAVA_HOME: \${JAVA_RESOLVED}"
82
83 EOF
84
85 # Create the startup script to be run on controller.
86 cat > ${WORKSPACE}/startup-script.sh <<EOF
87
88 echo "Redirecting karaf console output to karaf_console.log"
89 export KARAF_REDIRECT="/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log"
90
91 echo "Starting controller..."
92 /tmp/${BUNDLEFOLDER}/bin/start
93
94 echo "Waiting for controller to come up..."
95 COUNT="0"
96 while true; do
97     RESP="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null )"
98     echo \$RESP
99     if [[ \$RESP == *"200"* ]]; then
100         echo Controller is UP
101         break
102     elif (( "\$COUNT" > "600" )); then
103         echo Timeout Controller DOWN
104         echo "Dumping first 500K bytes of karaf log..."
105         head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
106         echo "Dumping last 500K bytes of karaf log..."
107         tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
108         echo "Listing all open ports on controller system"
109         netstat -natu
110         exit 1
111     else
112         COUNT=\$(( \${COUNT} + 5 ))
113         sleep 5
114         echo waiting \$COUNT secs...
115     fi
116 done
117
118 echo "Cool down for ${COOLDOWN_PERIOD} seconds :)..."
119 sleep ${COOLDOWN_PERIOD}
120
121 echo "Listing all open ports on controller system..."
122 netstat -natu
123
124 function exit_on_log_file_message {
125     echo "looking for \"\$1\" in log file"
126     if grep --quiet "\$1" /tmp/${BUNDLEFOLDER}/data/log/karaf.log; then
127         echo ABORTING: found "\$1"
128         echo "Dumping first 500K bytes of karaf log..."
129         head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
130         echo "Dumping last 500K bytes of karaf log..."
131         tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
132         exit 1
133     fi
134 }
135
136 exit_on_log_file_message 'BindException: Address already in use'
137 exit_on_log_file_message 'server is unhealthy'
138
139 EOF
140
141 # Execute the configuration script on controller.
142 scp ${WORKSPACE}/configuration-script.sh ${ODL_SYSTEM_IP}:/tmp
143 ssh ${ODL_SYSTEM_IP} 'bash /tmp/configuration-script.sh'
144
145 # Run config plan in case it exists
146 if [ -f ${WORKSPACE}/test/csit/configplans/${TESTPLAN} ]; then
147     echo "configplan exists!!!"
148     echo "Reading the configplan:"
149     cat ${WORKSPACE}/test/csit/configplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > configplan.txt
150     cat configplan.txt
151     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' configplan.txt ); do
152         echo "Executing ${line}..."
153         source ${line}
154     done
155 fi
156
157 # Copy over the startup script to controller and execute it.
158 scp ${WORKSPACE}/startup-script.sh ${ODL_SYSTEM_IP}:/tmp
159 ssh ${ODL_SYSTEM_IP} 'bash /tmp/startup-script.sh'
160
161 if [ ${NUM_OPENSTACK_SYSTEM} -gt 0 ]; then
162    echo "Exiting without running tests to deploy openstack for testing"
163    exit
164 fi
165
166 echo "Lets's take the karaf thread dump"
167 KARAF_PID=$(ssh ${ODL_SYSTEM_IP} "ps aux | grep 'distribution-karaf' | grep -v grep | tr -s ' ' | cut -f2 -d' '")
168 ssh ${ODL_SYSTEM_IP} "jstack $KARAF_PID"> ${WORKSPACE}/karaf_threads_before.log || true
169
170 echo "Locating test plan to use..."
171 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
172 if [ ! -f "${testplan_filepath}" ]; then
173     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
174 fi
175
176 echo "Changing the testplan path..."
177 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
178 cat testplan.txt
179 SUITES=$( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' ' )
180
181 echo "Starting Robot test suites ${SUITES} ..."
182 pybot -N ${TESTPLAN} --removekeywords wuks -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp \
183 -v JAVA_HOME:${JAVA_HOME} -v BUNDLE_URL:${ACTUALBUNDLEURL} -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
184 -v CONTROLLER:${ODL_SYSTEM_IP} -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_IP} \
185 -v CONTROLLER_USER:${USER} -v ODL_SYSTEM_USER:${USER} \
186 -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_IP} -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} -v TOOLS_SYSTEM_3_IP:${TOOLS_SYSTEM_3_IP} \
187 -v TOOLS_SYSTEM_4_IP:${TOOLS_SYSTEM_4_IP} -v TOOLS_SYSTEM_5_IP:${TOOLS_SYSTEM_5_IP} -v TOOLS_SYSTEM_6_IP:${TOOLS_SYSTEM_6_IP} \
188 -v TOOLS_SYSTEM_USER:${USER} -v JDKVERSION:${JDKVERSION} -v ODL_STREAM:${DISTROSTREAM} -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
189 -v MININET:${TOOLS_SYSTEM_IP} -v MININET1:${TOOLS_SYSTEM_2_IP} -v MININET2:${TOOLS_SYSTEM_3_IP} \
190 -v MININET3:${TOOLS_SYSTEM_4_IP} -v MININET4:${TOOLS_SYSTEM_5_IP} -v MININET5:${TOOLS_SYSTEM_6_IP} \
191 -v MININET_USER:${USER} -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
192 # FIXME: Sort (at least -v) options alphabetically.
193
194 echo "Lets's take the karaf thread dump again"
195 KARAF_PID=$(ssh ${ODL_SYSTEM_IP} "ps aux | grep 'distribution-karaf' | grep -v grep | tr -s ' ' | cut -f2 -d' '")
196 ssh ${ODL_SYSTEM_IP} "jstack $KARAF_PID"> ${WORKSPACE}/karaf_threads_after.log || true
197
198 echo "Killing ODL"
199 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
200 ssh "${ODL_SYSTEM_IP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
201 sleep 5
202 echo "Compressing karaf.log"
203 ssh ${ODL_SYSTEM_IP} gzip --best "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
204 echo "Fetching compressed karaf.log"
205 scp "${ODL_SYSTEM_IP}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log.gz" .
206 # TODO: Should we compress the output log file as well?
207 scp "${ODL_SYSTEM_IP}:/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log" .
208 true  # perhaps Jenkins is testing last exit code
209
210 # vim: ts=4 sw=4 sts=4 et ft=sh :