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