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