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