Merge "Correct nitrogen and carbon streams in CSIT"
[releng/builder.git] / jjb / integration / include-raw-integration-distribution-check.sh
1 CONTROLLERMEM="3072m"
2 ACTUALFEATURES="odl-integration-all"
3 BUNDLEVERSION=`xpath distribution/pom.xml '/project/version/text()' 2> /dev/null`
4 BUNDLEFOLDER="distribution-karaf-${BUNDLEVERSION}"
5 BUNDLE="${BUNDLEFOLDER}.zip"
6 BUNDLEURL="/tmp/r/org/opendaylight/integration/distribution-karaf/${BUNDLEVERSION}/${BUNDLE}"
7
8 echo "Kill any controller running"
9 ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sh
10
11 echo "Clean workspace"
12 rm -rf *
13
14 echo "Copying the distribution..."
15 cp  ${BUNDLEURL} .
16
17 echo "Extracting the new controller..."
18 unzip -q ${BUNDLE}
19
20 echo "Configuring the startup features..."
21 FEATURESCONF=${WORKSPACE}/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg
22 sed -ie "s/\(featuresBoot=\|featuresBoot =\)/featuresBoot = ${ACTUALFEATURES},/g" ${FEATURESCONF}
23 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}
24 cat ${FEATURESCONF}
25
26 echo "Configuring the log..."
27 LOGCONF=${WORKSPACE}/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
28 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=20MB/g' ${LOGCONF}
29 cat ${LOGCONF}
30
31 echo "Configure max memory..."
32 MEMCONF=${WORKSPACE}/${BUNDLEFOLDER}/bin/setenv
33 sed -ie "s/2048m/${CONTROLLERMEM}/g" ${MEMCONF}
34 cat ${MEMCONF}
35
36 echo "Listing all open ports on controller system"
37 netstat -pnatu
38
39 echo "redirected karaf console output to karaf_console.log"
40 export KARAF_REDIRECT=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log
41
42 if [ ${JDKVERSION} == 'openjdk8' ]; then
43     echo "Setting the JRE Version to 8"
44     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
45     # 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
46     export JAVA_HOME=/usr/lib/jvm/java-1.8.0
47 elif [ ${JDKVERSION} == 'openjdk7' ]; then
48     echo "Setting the JRE Version to 7"
49     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
50     # 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
51     export JAVA_HOME=/usr/lib/jvm/java-1.7.0
52 fi
53 readlink -e "${JAVA_HOME}/bin/java"
54 echo "JDK Version should be overriden by JAVA_HOME"
55 java -version
56
57 echo "Redirecting karaf console output to karaf_console.log"
58 export KARAF_REDIRECT="${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"
59
60 echo "Starting controller..."
61 ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
62
63 # No need for verbose printing during repeating operations.
64 set +x
65
66 echo "Waiting for controller to come up..."
67 COUNT=0
68 while true; do
69     RESP="$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null || true )"
70     echo ${RESP}
71     if [[ ${RESP} == *"200"* ]]; then
72         echo Controller is UP
73         break
74     elif (( ${COUNT} > 600 )); then
75         echo Timeout Controller DOWN
76         echo "Dumping Karaf log..."
77         cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
78         echo "Listing all open ports on controller system"
79         netstat -pnatu
80         exit 1
81     else
82         COUNT=$(( ${COUNT} + 5 ))
83         sleep 5
84         echo waiting ${COUNT} secs...
85     fi
86 done
87
88 echo "loading many features at once.  Need to allow time for problems to show up in logs.  cool down for 5 min ..."
89 COUNT="300"
90 while true; do
91     if (( "${COUNT}" <= "0" )); then
92         break
93     fi
94     echo "${COUNT} seconds yet to wait..."
95     sleep 10
96     COUNT=$(( ${COUNT} - 10 ))
97 done
98
99 # End of repeating operations, enable verbose printing.
100 set -x
101
102 # echo "Checking OSGi bundles..."
103 # sshpass seems to fail with new karaf version
104 # sshpass -p karaf ${WORKSPACE}/${BUNDLEFOLDER}/bin/client -u karaf 'bundle:list'
105
106 echo "Listing all open ports on controller system"
107 netstat -pnatu
108
109 function exit_on_log_file_message {
110     echo "looking for \"$1\" in karaf.log file"
111     if grep --quiet "$1" ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log; then
112         echo ABORTING: found "$1"
113         echo "Dumping first 500K bytes of karaf log..."
114         head --bytes=500K  ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
115         echo "Dumping last 500K bytes of karaf log..."
116         tail --bytes=500K  ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
117         cp ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log .
118         cp ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log .
119         exit 1
120     fi
121
122     echo "looking for \"$1\" in karaf_console.log file"
123     if grep --quiet "$1" ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log; then
124         echo ABORTING: found "$1"
125         echo "Dumping first 500K bytes of karaf log..."
126         head --bytes=500K  ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log
127         echo "Dumping last 500K bytes of karaf log..."
128         tail --bytes=500K  ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log
129         cp ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log .
130         cp ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log .
131         exit 1
132     fi
133 }
134
135 exit_on_log_file_message 'BindException: Address already in use'
136 exit_on_log_file_message 'server is unhealthy'
137
138 echo "Fetching Karaf logs"
139 # TODO: Move instead of copy? Gzip?
140 cp ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log .
141 cp ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log .
142
143 echo "Kill controller"
144 ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sh
145
146 echo "Detecting misplaced config files"
147 pushd "${WORKSPACE}/${BUNDLEFOLDER}"
148 XMLS_FOUND=`echo *.xml`
149 popd
150 if [ "$XMLS_FOUND" != "*.xml" ]; then
151     echo "Bug 4628 confirmed."
152     ## TODO: Uncomment the following when ODL is fixed, to guard against regression.
153     # exit 1
154 else
155     echo "Bug 4628 not detected."
156 fi
157
158 # vim: ts=4 sw=4 sts=4 et ft=sh :