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