Fix Java related issues
[releng/builder.git] / jjb / integration / include-raw-integration-deploy-controller-run-test.sh
index d350b0395693f7ff1fb1721dc0090214494ef7f1..8d25ebb5547d6b290c90cef291680fbb87905a50 100644 (file)
@@ -1,37 +1,22 @@
-export NEXUSURL_PREFIX=${ODLNEXUSPROXY:-https://nexus.opendaylight.org}
+#@IgnoreInspection BashAddShebang
+# Activate robotframework virtualenv
+# ${ROBOT_VENV} comes from the include-raw-integration-install-robotframework.sh
+# script.
+source ${ROBOT_VENV}/bin/activate
+
 CONTROLLERMEM="2048m"
 
 if [ ${CONTROLLERSCOPE} == 'all' ]; then
     ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
     CONTROLLERMEM="3072m"
+    COOLDOWN_PERIOD="180"
 else
     ACTUALFEATURES="${CONTROLLERFEATURES}"
+    COOLDOWN_PERIOD="60"
 fi
-
-if [ ${BUNDLEURL} == 'last' ]; then
-    NEXUSPATH="${NEXUSURL_PREFIX}/content/repositories/opendaylight.snapshot/org/opendaylight/integration/distribution-karaf"
-    # Extract the BUNDLEVERSION from the pom.xml
-    export BUNDLEVERSION=`xpath pom.xml '/project/version/text()' 2> /dev/null`
-    echo "Bundle version is ${BUNDLEVERSION}"
-    # Acquire the timestamp information from maven-metadata.xml
-    wget ${NEXUSPATH}/${BUNDLEVERSION}/maven-metadata.xml
-    TIMESTAMP=`xpath maven-metadata.xml "//snapshotVersion[extension='zip'][1]/value/text()" 2>/dev/null`
-    echo "Nexus timestamp is ${TIMESTAMP}"
-    export BUNDLEFOLDER="distribution-karaf-${BUNDLEVERSION}"
-    export BUNDLE="distribution-karaf-${TIMESTAMP}.zip"
-    export ACTUALBUNDLEURL="${NEXUSPATH}/${BUNDLEVERSION}/${BUNDLE}"
-else
-    export ACTUALBUNDLEURL="${BUNDLEURL}"
-    export BUNDLE="${BUNDLEURL##*/}"
-    export BUNDLEVERSION="$(basename $(dirname $BUNDLEURL))"
-    export BUNDLEFOLDER="distribution-karaf-${BUNDLEVERSION}"
-fi
-
-echo "Distribution bundle URL is ${ACTUALBUNDLEURL}"
-echo "Distribution bundle is ${BUNDLE}"
-echo "Distribution bundle version is ${BUNDLEVERSION}"
-echo "Distribution folder is ${BUNDLEFOLDER}"
-echo "Nexus prefix is ${NEXUSURL_PREFIX}"
+# Some versions of jenkins job builder result in feature list containing spaces
+# and ending in newline. Remove all that.
+ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
 
 if [ -f ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} ]; then
     echo "scriptplan exists!!!"
@@ -63,14 +48,32 @@ cat \${FEATURESCONF}
 
 echo "Configuring the log..."
 LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
-sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=20MB/g' \${LOGCONF}
+sed -ie 's/log4j.appender.out.maxBackupIndex=10/log4j.appender.out.maxBackupIndex=1/g' \${LOGCONF}
+# FIXME: Make log size limit configurable from build parameter.
+sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=100GB/g' \${LOGCONF}
 cat \${LOGCONF}
 
-echo "Configure max memory..."
+echo "Configure java home and max memory..."
 MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv
+sed -ie 's%^# export JAVA_HOME%export JAVA_HOME="\${JAVA_HOME:-${JAVA_HOME}}"%g' \${MEMCONF}
 sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' \${MEMCONF}
 cat \${MEMCONF}
 
+echo "Listing all open ports on controller system..."
+netstat -natu
+
+echo "Set Java version"
+sudo /usr/sbin/alternatives --install /usr/bin/java java ${JAVA_HOME}/bin/java 1
+sudo /usr/sbin/alternatives --set java ${JAVA_HOME}/bin/java
+echo "JDK default version ..."
+java -version
+
+echo "Set JAVA_HOME"
+export JAVA_HOME="$JAVA_HOME"
+# Did you know that in HERE documents, single quote is an ordinary character, but backticks are still executing?
+JAVA_RESOLVED=\`readlink -e "\${JAVA_HOME}/bin/java"\`
+echo "Java binary pointed at by JAVA_HOME: \${JAVA_RESOLVED}"
+
 echo "Starting controller..."
 /tmp/${BUNDLEFOLDER}/bin/start
 
@@ -84,8 +87,12 @@ while true; do
         break
     elif (( "\$COUNT" > "600" )); then
         echo Timeout Controller DOWN
-        echo "Dumping Karaf log..."
-        cat /tmp/${BUNDLEFOLDER}/data/log/karaf.log
+        echo "Dumping first 500K bytes of karaf log..."
+        head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+        echo "Dumping last 500K bytes of karaf log..."
+        tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+        echo "Listing all open ports on controller system"
+        netstat -natu
         exit 1
     else
         COUNT=\$(( \${COUNT} + 5 ))
@@ -94,30 +101,64 @@ while true; do
     fi
 done
 
-echo "Cool down for 1 min :)..."
-sleep 60
+echo "Cool down for ${COOLDOWN_PERIOD} seconds :)..."
+sleep ${COOLDOWN_PERIOD}
 
-echo "Checking OSGi bundles..."
-sshpass -p karaf /tmp/${BUNDLEFOLDER}/bin/client -u karaf 'bundle:list'
+echo "Listing all open ports on controller system..."
+netstat -natu
+
+function exit_on_log_file_message {
+    echo "looking for \"\$1\" in log file"
+    if grep --quiet "\$1" /tmp/${BUNDLEFOLDER}/data/log/karaf.log; then
+        echo ABORTING: found "\$1"
+        echo "Dumping first 500K bytes of karaf log..."
+        head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+        echo "Dumping last 500K bytes of karaf log..."
+        tail --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+        exit 1
+    fi
+}
+
+exit_on_log_file_message 'BindException: Address already in use'
+exit_on_log_file_message 'server is unhealthy'
 
 EOF
 
-scp ${WORKSPACE}/controller-script.sh ${CONTROLLER0}:/tmp
-ssh ${CONTROLLER0} 'bash /tmp/controller-script.sh'
+scp ${WORKSPACE}/controller-script.sh ${ODL_SYSTEM_IP}:/tmp
+ssh ${ODL_SYSTEM_IP} 'bash /tmp/controller-script.sh'
+
+echo "Locating test plan to use..."
+testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
+if [ ! -f "${testplan_filepath}" ]; then
+    testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
+fi
 
 echo "Changing the testplan path..."
-cat ${WORKSPACE}/test/csit/testplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > testplan.txt
+cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
 cat testplan.txt
 
 SUITES=$( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' ' )
 
 echo "Starting Robot test suites ${SUITES} ..."
 pybot -N ${TESTPLAN} -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp \
--v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} -v CONTROLLER:${CONTROLLER0} -v CONTROLLER_USER:${USER} \
--v MININET:${MININET0} -v MININET_USER:${USER} -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
-
-echo "Fetching Karaf log"
-scp ${CONTROLLER0}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log .
+-v JAVA_HOME:${JAVA_HOME} -v BUNDLE_URL:${ACTUALBUNDLEURL} -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
+-v CONTROLLER:${ODL_SYSTEM_IP} -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} -v CONTROLLER_USER:${USER} -v ODL_SYSTEM_USER:${USER} \
+-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} \
+-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} \
+-v TOOLS_SYSTEM_USER:${USER} -v JDKVERSION:${JDKVERSION} -v ODL_STREAM:${DISTROSTREAM} \
+-v MININET:${TOOLS_SYSTEM_IP} -v MININET1:${TOOLS_SYSTEM_2_IP} -v MININET2:${TOOLS_SYSTEM_3_IP} \
+-v MININET3:${TOOLS_SYSTEM_4_IP} -v MININET4:${TOOLS_SYSTEM_5_IP} -v MININET5:${TOOLS_SYSTEM_6_IP} \
+-v MININET_USER:${USER} -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
+# FIXME: Sort (at least -v) options alphabetically.
+
+echo "Killing ODL and fetching Karaf log..."
+set +e  # We do not want to create red dot just because something went wrong while fetching logs.
+ssh "${ODL_SYSTEM_IP}" tail --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log" > "karaf.log"
+ssh "${ODL_SYSTEM_IP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
+sleep 5
+ssh "${ODL_SYSTEM_IP}" xz -9ekvv "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
+scp "${ODL_SYSTEM_IP}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log.xz" .
+true  # perhaps Jenkins is testing last exit code
 
 # vim: ts=4 sw=4 sts=4 et ft=sh :