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