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