Merge "Created system test job for genius project."
[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=100GB/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 "Starting controller..."
89 /tmp/${BUNDLEFOLDER}/bin/start
90
91 echo "Waiting for controller to come up..."
92 COUNT="0"
93 while true; do
94     RESP="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null )"
95     echo \$RESP
96     if [[ \$RESP == *"200"* ]]; then
97         echo Controller is UP
98         break
99     elif (( "\$COUNT" > "600" )); then
100         echo Timeout Controller DOWN
101         echo "Dumping first 500K bytes of karaf log..."
102         head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
103         echo "Dumping last 500K bytes of karaf log..."
104         tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
105         echo "Listing all open ports on controller system"
106         netstat -natu
107         exit 1
108     else
109         COUNT=\$(( \${COUNT} + 5 ))
110         sleep 5
111         echo waiting \$COUNT secs...
112     fi
113 done
114
115 echo "Cool down for ${COOLDOWN_PERIOD} seconds :)..."
116 sleep ${COOLDOWN_PERIOD}
117
118 echo "Listing all open ports on controller system..."
119 netstat -natu
120
121 function exit_on_log_file_message {
122     echo "looking for \"\$1\" in log file"
123     if grep --quiet "\$1" /tmp/${BUNDLEFOLDER}/data/log/karaf.log; then
124         echo ABORTING: found "\$1"
125         echo "Dumping first 500K bytes of karaf log..."
126         head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
127         echo "Dumping last 500K bytes of karaf log..."
128         tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
129         exit 1
130     fi
131 }
132
133 exit_on_log_file_message 'BindException: Address already in use'
134 exit_on_log_file_message 'server is unhealthy'
135
136 EOF
137
138 # Execute the configuration script on controller.
139 scp ${WORKSPACE}/configuration-script.sh ${ODL_SYSTEM_IP}:/tmp
140 ssh ${ODL_SYSTEM_IP} 'bash /tmp/configuration-script.sh'
141
142 # Run config plan in case it exists
143 if [ -f ${WORKSPACE}/test/csit/configplans/${TESTPLAN} ]; then
144     echo "configplan exists!!!"
145     echo "Reading the configplan:"
146     cat ${WORKSPACE}/test/csit/configplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > configplan.txt
147     cat configplan.txt
148     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' configplan.txt ); do
149         echo "Executing ${line}..."
150         source ${line}
151     done
152 fi
153
154 # Copy over the startup script to controller and execute it.
155 scp ${WORKSPACE}/startup-script.sh ${ODL_SYSTEM_IP}:/tmp
156 ssh ${ODL_SYSTEM_IP} 'bash /tmp/startup-script.sh'
157
158 if [ ${NUM_OPENSTACK_SYSTEM} -gt 0 ]; then
159    echo "Exiting without running tests to deploy openstack for testing"
160    exit
161 fi
162
163 echo "Lets's take the karaf thread dump"
164 KARAF_PID=$(ssh ${ODL_SYSTEM_IP} "ps aux | grep 'distribution-karaf' | grep -v grep | tr -s ' ' | cut -f2 -d' '")
165 ssh ${ODL_SYSTEM_IP} "jstack $KARAF_PID"> ${WORKSPACE}/karaf_threads_before.log
166
167 echo "Locating test plan to use..."
168 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
169 if [ ! -f "${testplan_filepath}" ]; then
170     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
171 fi
172
173 echo "Changing the testplan path..."
174 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
175 cat testplan.txt
176 SUITES=$( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' ' )
177
178 echo "Starting Robot test suites ${SUITES} ..."
179 pybot -N ${TESTPLAN} -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp \
180 -v JAVA_HOME:${JAVA_HOME} -v BUNDLE_URL:${ACTUALBUNDLEURL} -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
181 -v CONTROLLER:${ODL_SYSTEM_IP} -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_IP} \
182 -v CONTROLLER_USER:${USER} -v ODL_SYSTEM_USER:${USER} \
183 -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} \
184 -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} \
185 -v TOOLS_SYSTEM_USER:${USER} -v JDKVERSION:${JDKVERSION} -v ODL_STREAM:${DISTROSTREAM} -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
186 -v MININET:${TOOLS_SYSTEM_IP} -v MININET1:${TOOLS_SYSTEM_2_IP} -v MININET2:${TOOLS_SYSTEM_3_IP} \
187 -v MININET3:${TOOLS_SYSTEM_4_IP} -v MININET4:${TOOLS_SYSTEM_5_IP} -v MININET5:${TOOLS_SYSTEM_6_IP} \
188 -v MININET_USER:${USER} -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
189 # FIXME: Sort (at least -v) options alphabetically.
190
191 echo "Lets's take the karaf thread dump again"
192 KARAF_PID=$(ssh ${ODL_SYSTEM_IP} "ps aux | grep 'distribution-karaf' | grep -v grep | tr -s ' ' | cut -f2 -d' '")
193 ssh ${ODL_SYSTEM_IP} "jstack $KARAF_PID"> ${WORKSPACE}/karaf_threads_after.log
194
195 echo "Killing ODL and fetching Karaf log..."
196 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
197 ssh "${ODL_SYSTEM_IP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
198 sleep 5
199 scp "${ODL_SYSTEM_IP}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log" .
200 true  # perhaps Jenkins is testing last exit code
201
202 # vim: ts=4 sw=4 sts=4 et ft=sh :