6ab50cfb389161cf82ca817635beb5ce7ae02033
[releng/builder.git] / jjb / integration / distribution / distribution-check-bootup.sh
1 CONTROLLERMEM="3072m"
2 ACTUALFEATURES="odl-integration-all"
3
4 if [[ ! -z "${CONTROLLERFEATURES}" ]]; then
5     ACTUALFEATURES="odl-integration-all,${CONTROLLERFEATURES}"
6 fi
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 Existing distribution"
12 rm -rf ${BUNDLEFOLDER}
13
14 echo "Fetch the distribution..."
15 if  [[ -z "${BUNDLE_PATH}" ]]; then
16     wget --progress=dot:mega  "${ACTUAL_BUNDLE_URL}"
17 else
18     cp "${BUNDLE_PATH}" .
19 fi
20
21 echo "Extracting the new controller..."
22 unzip -q "${BUNDLE}"
23
24 echo "Configuring the startup features..."
25 FEATURESCONF="${WORKSPACE}/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg"
26 FEATURE_TEST_STRING="features-test"
27 if [[ "$KARAF_VERSION" == "karaf3" ]]; then
28     FEATURE_TEST_STRING="features-integration-test"
29 fi
30
31 sed -ie "s%\(featuresRepositories= \|featuresRepositories = \)%featuresRepositories = mvn:org.opendaylight.integration/${FEATURE_TEST_STRING}/${BUNDLE_VERSION}/xml/features,%g" ${FEATURESCONF}
32
33 if [[ ! -z "${REPO_URL}" ]]; then
34    # sed below will fail if it finds space between feature repos.
35    REPO_URL_NO_SPACE="$(echo -e "${REPO_URL}" | tr -d '[:space:]')"
36    sed -ie "s%featuresRepositories = %featuresRepositories = ${REPO_URL_NO_SPACE},%g" ${FEATURESCONF}
37 fi
38
39 # Add actual boot features.
40 # sed below will fail if it finds space between feature repos.
41 FEATURES_NO_SPACE="$(echo -e "${ACTUALFEATURES}" | tr -d '[:space:]')"
42 sed -ie "s/\(featuresBoot= \|featuresBoot = \)/featuresBoot = ${FEATURES_NO_SPACE},/g" "${FEATURESCONF}"
43 cat "${FEATURESCONF}"
44
45 echo "Configuring the log..."
46 LOGCONF="${WORKSPACE}/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg"
47 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=20MB/g' "${LOGCONF}"
48 cat "${LOGCONF}"
49
50 echo "Configure max memory..."
51 MEMCONF="${WORKSPACE}/${BUNDLEFOLDER}/bin/setenv"
52 sed -ie "s/2048m/${CONTROLLERMEM}/g" "${MEMCONF}"
53 cat "${MEMCONF}"
54
55 echo "Listing all open ports on controller system"
56 netstat -pnatu
57
58 if [ "$JDKVERSION" == 'openjdk11' ]; then
59     echo "Preparing for JRE Version 11"
60     JAVA_HOME="/opt/jdk-11"
61 elif [ "${JDKVERSION}" == 'openjdk8' ]; then
62     echo "Setting the JRE Version to 8"
63     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
64     # 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
65     export JAVA_HOME='/usr/lib/jvm/java-1.8.0'
66 elif [ "${JDKVERSION}" == 'openjdk7' ]; then
67     echo "Setting the JRE Version to 7"
68     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
69     # 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
70     export JAVA_HOME='/usr/lib/jvm/java-1.7.0'
71 fi
72 readlink -e "${JAVA_HOME}/bin/java"
73 echo "JDK Version should be overriden by JAVA_HOME"
74 java -version
75
76 echo "Redirecting karaf console output to karaf_console.log"
77 export KARAF_REDIRECT="${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"
78 mkdir -p ${WORKSPACE}/${BUNDLEFOLDER}/data/log
79
80 echo "Starting controller..."
81 ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
82
83 function dump_log_and_exit {
84     echo "Dumping first 500K bytes of karaf log..."
85     head --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
86     echo "Dumping last 500K bytes of karaf log..."
87     tail --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
88     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
89     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
90     exit 1
91 }
92
93 echo "Waiting up to 6 minutes for controller to come up, checking every 5 seconds..."
94 COUNT="0"
95 while true; do
96     COUNT=$(( ${COUNT} + 5 ))
97     sleep 5
98     echo "already waited ${COUNT} seconds..."
99     if grep --quiet 'org.opendaylight.infrautils.*System ready' "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"; then
100         echo "Controller is UP"
101         break
102     elif (( "${COUNT}" >= "360" )); then
103         echo "Timeout Controller DOWN"
104         dump_log_and_exit
105     fi
106 done
107
108 # echo "Checking OSGi bundles..."
109 # sshpass seems to fail with new karaf version
110 # sshpass -p karaf ${WORKSPACE}/${BUNDLEFOLDER}/bin/client -u karaf 'bundle:list'
111
112 echo "Listing all open ports on controller system"
113 netstat -pnatu
114
115 function exit_on_log_file_message {
116     echo "looking for \"$1\" in karaf.log file"
117     if grep --quiet "$1" "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"; then
118         echo ABORTING: found "$1"
119         dump_log_and_exit
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         dump_log_and_exit
126     fi
127 }
128
129 exit_on_log_file_message 'Error installing boot feature repository'
130 exit_on_log_file_message 'BindException: Address already in use'
131 exit_on_log_file_message 'server is unhealthy'
132
133 echo "Fetching Karaf logs"
134 # TODO: Move instead of copy? Gzip?
135 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
136 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
137
138 echo "Kill controller"
139 ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sh
140
141 echo "Bug 4628: Detecting misplaced config files"
142 pushd "${WORKSPACE}/${BUNDLEFOLDER}" || exit
143 XMLS_FOUND="$(echo *.xml)"
144 popd || exit
145 if [ "$XMLS_FOUND" != "*.xml" ]; then
146     echo "Bug 4628 confirmed."
147     ## TODO: Uncomment the following when ODL is fixed, to guard against regression.
148     # exit 1
149 else
150     echo "Bug 4628 not detected."
151 fi
152
153 # vim: ts=4 sw=4 sts=4 et ft=sh :