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