Merge "Ovsdb 3 node Clustering job"
[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 else
13     ACTUALFEATURES="${CONTROLLERFEATURES}"
14 fi
15
16 if [ -f ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} ]; then
17     echo "scriptplan exists!!!"
18     echo "Changing the scriptplan path..."
19     cat ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > scriptplan.txt
20     cat scriptplan.txt
21     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' scriptplan.txt ); do
22         echo "Executing ${line}..."
23         source ${line}
24     done
25 fi
26
27 cat > ${WORKSPACE}/controller-script.sh <<EOF
28
29 if [ ${JDKVERSION} == 'openjdk8' ]; then
30     echo "Setting the JDK Version to 8"
31     sudo /usr/sbin/alternatives --set java /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.60-2.b27.el7_1.x86_64/jre/bin/java
32     export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.60-2.b27.el7_1.x86_64
33     java -version
34 fi
35 if [ ${JDKVERSION} == 'openjdk7' ]; then
36     echo "Setting the JDK Version to 7"
37     sudo /usr/sbin/alternatives --set java /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85-2.6.1.2.el7_1.x86_64/jre/bin/java
38     export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85-2.6.1.2.el7_1.x86_64
39     java -version
40 fi
41
42 echo "Changing to /tmp"
43 cd /tmp
44
45 echo "Downloading the distribution..."
46 wget --no-verbose '${ACTUALBUNDLEURL}'
47
48 echo "Extracting the new controller..."
49 unzip -q ${BUNDLE}
50
51 echo "Configuring the startup features..."
52 FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg
53 sed -ie "s/featuresBoot=.*/featuresBoot=config,standard,region,package,kar,ssh,management,${ACTUALFEATURES}/g" \${FEATURESCONF}
54 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%g" \${FEATURESCONF}
55 cat \${FEATURESCONF}
56
57 echo "Configuring the log..."
58 LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
59 sed -ie 's/log4j.appender.out.maxBackupIndex=10/log4j.appender.out.maxBackupIndex=1/g' \${LOGCONF}
60 # FIXME: Make log size limit configurable from build parameter.
61 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=100GB/g' \${LOGCONF}
62 cat \${LOGCONF}
63
64 echo "Configure max memory..."
65 MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv
66 sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' \${MEMCONF}
67 cat \${MEMCONF}
68
69 echo "Listing all open ports on controller system..."
70 netstat -natu
71
72 echo "JDK Version ..."
73 java -version
74
75 echo "Starting controller..."
76 /tmp/${BUNDLEFOLDER}/bin/start
77
78 echo "Waiting for controller to come up..."
79 COUNT="0"
80 while true; do
81     RESP="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null )"
82     echo \$RESP
83     if [[ \$RESP == *"200"* ]]; then
84         echo Controller is UP
85         break
86     elif (( "\$COUNT" > "600" )); then
87         echo Timeout Controller DOWN
88         echo "Dumping Karaf log..."
89         head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
90         echo "Listing all open ports on controller system"
91         netstat -natu
92         exit 1
93     else
94         COUNT=\$(( \${COUNT} + 5 ))
95         sleep 5
96         echo waiting \$COUNT secs...
97     fi
98 done
99
100 echo "Cool down for 1 min :)..."
101 sleep 60
102
103 echo "Listing all open ports on controller system..."
104 netstat -natu
105
106 function exit_on_log_file_message {
107     echo "looking for \"\$1\" in log file"
108     if grep --quiet "\$1" /tmp/${BUNDLEFOLDER}/data/log/karaf.log; then
109         echo ABORTING: found "\$1"
110         echo "Dumping Karaf log..."
111         head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
112         exit 1
113     fi
114 }
115
116 exit_on_log_file_message 'BindException: Address already in use'
117 exit_on_log_file_message 'server is unhealthy'
118
119 EOF
120
121 scp ${WORKSPACE}/controller-script.sh ${ODL_SYSTEM_IP}:/tmp
122 ssh ${ODL_SYSTEM_IP} 'bash /tmp/controller-script.sh'
123
124 echo "Changing the testplan path..."
125 cat ${WORKSPACE}/test/csit/testplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > testplan.txt
126 cat testplan.txt
127
128 SUITES=$( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' ' )
129
130 echo "Starting Robot test suites ${SUITES} ..."
131 pybot -N ${TESTPLAN} -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp \
132 -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
133 -v CONTROLLER:${ODL_SYSTEM_IP} -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} -v CONTROLLER_USER:${USER} -v ODL_SYSTEM_USER:${USER} \
134 -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} \
135 -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} \
136 -v TOOLS_SYSTEM_USER:${USER} \
137 -v MININET:${TOOLS_SYSTEM_IP} -v MININET1:${TOOLS_SYSTEM_2_IP} -v MININET2:${TOOLS_SYSTEM_3_IP} \
138 -v MININET3:${TOOLS_SYSTEM_4_IP} -v MININET4:${TOOLS_SYSTEM_5_IP} -v MININET5:${TOOLS_SYSTEM_6_IP} \
139 -v MININET_USER:${USER} -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
140
141 echo "Killing ODL and fetching Karaf log..."
142 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
143 ssh "${ODL_SYSTEM_IP}" head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log" > "karaf.log"
144 ssh "${ODL_SYSTEM_IP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
145 sleep 5
146 ssh "${ODL_SYSTEM_IP}" xz -9ekvv "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
147 scp "${ODL_SYSTEM_IP}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log.xz" .
148 true  # perhaps Jenkins is testing last exit code
149
150 # vim: ts=4 sw=4 sts=4 et ft=sh :
151