Update cloud image Ubuntu18.04 mininet ovs
[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 if [ "$KARAF_ARTIFACT" = "opendaylight" ]; then
41     FEATURE_TEST_VERSION="$(echo "$BUNDLE_VERSION" | sed -E "s%^([0-9]+)\.([0-9]+)\.0(.*)%0.\1.\2\3%")"
42 fi
43
44 # only replace feature repo in integration/distro, MRI projects need to pull in
45 # the features they need by themselves
46 if [ "$KARAF_PROJECT" = "integration" ]; then
47     sed -ie "s%\(featuresRepositories= \|featuresRepositories = \)%featuresRepositories = mvn:org.opendaylight.integration/${FEATURE_TEST_STRING}/${FEATURE_TEST_VERSION}/xml/features,%g" "${FEATURESCONF}"
48
49     if [ -n "${REPO_URL}" ]; then
50        # sed below will fail if it finds space between feature repos.
51        REPO_URL_NO_SPACE="$(echo "${REPO_URL}" | tr -d '[:space:]')"
52        sed -ie "s%featuresRepositories = %featuresRepositories = ${REPO_URL_NO_SPACE},%g" "${FEATURESCONF}"
53     fi
54
55     # Add actual boot features.
56     # sed below will fail if it finds space between feature repos.
57     FEATURES_NO_SPACE="$(echo "${ACTUALFEATURES}" | tr -d '[:space:]')"
58     sed -ie "s/\(featuresBoot= \|featuresBoot = \)/featuresBoot = ${FEATURES_NO_SPACE},/g" "${FEATURESCONF}"
59     cat "${FEATURESCONF}"
60 fi
61
62 echo "Configuring the log..."
63 LOGCONF="${WORKSPACE}/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg"
64 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=20MB/g' "${LOGCONF}"
65 cat "${LOGCONF}"
66
67 echo "Configure max memory..."
68 MEMCONF="${WORKSPACE}/${BUNDLEFOLDER}/bin/setenv"
69 sed -ie "s/2048m/${CONTROLLERMEM}/g" "${MEMCONF}"
70 cat "${MEMCONF}"
71
72 echo "Listing all open ports on controller system"
73 netstat -pnatu
74
75 echo "Sourcing Java environment variable .."
76 # shellcheck disable=SC1091
77 . /tmp/java.env
78
79 java -version
80 echo JAVA_HOME="${JAVA_HOME}"
81
82 echo "Redirecting karaf console output to karaf_console.log"
83 export KARAF_REDIRECT="${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"
84 mkdir -p "${WORKSPACE}/${BUNDLEFOLDER}/data/log"
85
86 echo "Starting controller..."
87 "${WORKSPACE}/${BUNDLEFOLDER}/bin/start"
88
89 dump_log_and_exit() {
90     echo "Dumping first 500K bytes of karaf log..."
91     head --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
92     echo "Dumping last 500K bytes of karaf log..."
93     tail --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
94     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
95     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
96     exit 1
97 }
98
99 echo "Waiting up to 6 minutes for controller to come up, checking every 5 seconds..."
100 COUNT="0"
101 while true; do
102     COUNT=$(( COUNT + 5 ))
103     sleep 5
104     echo "already waited ${COUNT} seconds..."
105     if grep --quiet 'org.opendaylight.infrautils.*System ready' "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"; then
106         echo "Controller is UP"
107         break
108     elif [ ${COUNT} -ge 360 ]; then
109         echo "Timeout Controller DOWN"
110         dump_log_and_exit
111     fi
112 done
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 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         dump_log_and_exit
126     fi
127
128     echo "looking for \"$1\" in karaf_console.log file"
129     if grep --quiet "$1" "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"; then
130         echo ABORTING: found "$1"
131         dump_log_and_exit
132     fi
133 }
134
135 exit_on_log_file_message 'Error installing boot feature repository'
136 exit_on_log_file_message 'BindException: Address already in use'
137 exit_on_log_file_message 'server is unhealthy'
138
139 echo "Fetching Karaf logs"
140 # TODO: Move instead of copy? Gzip?
141 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
142 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
143
144 echo "Kill controller"
145 # shellcheck disable=SC2009
146 ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sh
147
148 echo "Bug 4628: Detecting misplaced config files"
149 initdir=$(pwd)
150 cd "${WORKSPACE}/${BUNDLEFOLDER}" || exit
151 XMLS_FOUND="$(echo -- *.xml)"
152 cd "$initdir" || exit
153 if [ "$XMLS_FOUND" != "*.xml" ]; then
154     echo "Bug 4628 confirmed."
155     ## TODO: Uncomment the following when ODL is fixed, to guard against regression.
156     # exit 1
157 else
158     echo "Bug 4628 not detected."
159 fi
160
161 # vim: ts=4 sw=4 sts=4 et ft=sh :