Merge "Use ${SUITES} for pybot SUITES var"
[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}" == 'openjdk8' ]; then
59     echo "Setting the JRE Version to 8"
60     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
61     # 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
62     export JAVA_HOME='/usr/lib/jvm/java-1.8.0'
63 elif [ "${JDKVERSION}" == 'openjdk7' ]; then
64     echo "Setting the JRE Version to 7"
65     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
66     # 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
67     export JAVA_HOME='/usr/lib/jvm/java-1.7.0'
68 fi
69 readlink -e "${JAVA_HOME}/bin/java"
70 echo "JDK Version should be overriden by JAVA_HOME"
71 java -version
72
73 echo "Redirecting karaf console output to karaf_console.log"
74 export KARAF_REDIRECT="${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"
75 mkdir -p ${WORKSPACE}/${BUNDLEFOLDER}/data/log
76
77 echo "Starting controller..."
78 ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
79
80 function dump_log_and_exit {
81     echo "Dumping first 500K bytes of karaf log..."
82     head --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
83     echo "Dumping last 500K bytes of karaf log..."
84     tail --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
85     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
86     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
87     exit 1
88 }
89
90 echo "Waiting up to 6 minutes for controller to come up, checking every 5 seconds..."
91 COUNT="0"
92 while true; do
93     COUNT=$(( ${COUNT} + 5 ))
94     sleep 5
95     echo "already waited ${COUNT} seconds..."
96     if grep --quiet 'org.opendaylight.infrautils.ready-impl.*System ready' "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"; then
97         echo "Controller is UP"
98         break
99     elif (( "${COUNT}" > "360" )); then
100         echo "Timeout Controller DOWN"
101         dump_log_and_exit
102     fi
103 done
104
105 # echo "Checking OSGi bundles..."
106 # sshpass seems to fail with new karaf version
107 # sshpass -p karaf ${WORKSPACE}/${BUNDLEFOLDER}/bin/client -u karaf 'bundle:list'
108
109 echo "Listing all open ports on controller system"
110 netstat -pnatu
111
112 function exit_on_log_file_message {
113     echo "looking for \"$1\" in karaf.log file"
114     if grep --quiet "$1" "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"; then
115         echo ABORTING: found "$1"
116         dump_log_and_exit
117     fi
118
119     echo "looking for \"$1\" in karaf_console.log file"
120     if grep --quiet "$1" "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"; then
121         echo ABORTING: found "$1"
122         dump_log_and_exit
123     fi
124 }
125
126 exit_on_log_file_message 'Error installing boot feature repository'
127 exit_on_log_file_message 'BindException: Address already in use'
128 exit_on_log_file_message 'server is unhealthy'
129
130 echo "Fetching Karaf logs"
131 # TODO: Move instead of copy? Gzip?
132 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
133 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
134
135 echo "Kill controller"
136 ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sh
137
138 echo "Bug 4628: Detecting misplaced config files"
139 pushd "${WORKSPACE}/${BUNDLEFOLDER}" || exit
140 XMLS_FOUND="$(echo *.xml)"
141 popd || exit
142 if [ "$XMLS_FOUND" != "*.xml" ]; then
143     echo "Bug 4628 confirmed."
144     ## TODO: Uncomment the following when ODL is fixed, to guard against regression.
145     # exit 1
146 else
147     echo "Bug 4628 not detected."
148 fi
149
150 # vim: ts=4 sw=4 sts=4 et ft=sh :