Merge "Generally refactor JJB docs"
[releng/builder.git] / jjb / integration / include-raw-integration-deploy-controller-run-test.sh
1 #@IgnoreInspection BashAddShebang
2 # Activate robotframework virtualenv
3 # ${ROBOT_VENV} comes from the include-raw-integration-install-robotframework.sh
4 # script.
5 source ${ROBOT_VENV}/bin/activate
6
7 CONTROLLERMEM="2048m"
8
9 if [ ${CONTROLLERSCOPE} == 'all' ]; then
10     ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
11     CONTROLLERMEM="3072m"
12 else
13     ACTUALFEATURES="${CONTROLLERFEATURES}"
14 fi
15
16 if [ -f ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} ]; then
17     echo "scriptplan exists!!!"
18     echo "Changing the scriptplan path..."
19     cat ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > scriptplan.txt
20     cat scriptplan.txt
21     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' scriptplan.txt ); do
22         echo "Executing ${line}..."
23         source ${line}
24     done
25 fi
26
27 cat > ${WORKSPACE}/controller-script.sh <<EOF
28
29 echo "Changing to /tmp"
30 cd /tmp
31
32 echo "Downloading the distribution..."
33 wget --no-verbose '${ACTUALBUNDLEURL}'
34
35 echo "Extracting the new controller..."
36 unzip -q ${BUNDLE}
37
38 echo "Configuring the startup features..."
39 FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg
40 sed -ie "s/featuresBoot=.*/featuresBoot=config,standard,region,package,kar,ssh,management,${ACTUALFEATURES}/g" \${FEATURESCONF}
41 sed -ie "s%mvn:org.opendaylight.integration/features-integration-index/${BUNDLEVERSION}/xml/features%mvn:org.opendaylight.integration/features-integration-index/${BUNDLEVERSION}/xml/features,mvn:org.opendaylight.integration/features-integration-test/${BUNDLEVERSION}/xml/features%g" \${FEATURESCONF}
42 cat \${FEATURESCONF}
43
44 echo "Configuring the log..."
45 LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
46 sed -ie 's/log4j.appender.out.maxBackupIndex=10/log4j.appender.out.maxBackupIndex=1/g' \${LOGCONF}
47 # FIXME: Make log size limit configurable from build parameter.
48 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=100GB/g' \${LOGCONF}
49 cat \${LOGCONF}
50
51 echo "Configure max memory..."
52 MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv
53 sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' \${MEMCONF}
54 cat \${MEMCONF}
55
56 echo "Listing all open ports on controller system..."
57 netstat -natu
58
59 echo "Starting controller..."
60 /tmp/${BUNDLEFOLDER}/bin/start
61
62 echo "Waiting for controller to come up..."
63 COUNT="0"
64 while true; do
65     RESP="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null )"
66     echo \$RESP
67     if [[ \$RESP == *"200"* ]]; then
68         echo Controller is UP
69         break
70     elif (( "\$COUNT" > "600" )); then
71         echo Timeout Controller DOWN
72         echo "Dumping Karaf log..."
73         head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
74         echo "Listing all open ports on controller system"
75         netstat -natu
76         exit 1
77     else
78         COUNT=\$(( \${COUNT} + 5 ))
79         sleep 5
80         echo waiting \$COUNT secs...
81     fi
82 done
83
84 echo "Cool down for 1 min :)..."
85 sleep 60
86
87 echo "Checking OSGi bundles..."
88 sshpass -p karaf /tmp/${BUNDLEFOLDER}/bin/client -u karaf 'bundle:list'
89
90 echo "Listing all open ports on controller system..."
91 netstat -natu
92
93 function exit_on_log_file_message {
94     echo "looking for \"\$1\" in log file"
95     if grep --quiet "\$1" /tmp/${BUNDLEFOLDER}/data/log/karaf.log; then
96         echo ABORTING: found "\$1"
97         echo "Dumping Karaf log..."
98         head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
99         exit 1
100     fi
101 }
102
103 exit_on_log_file_message 'BindException: Address already in use'
104 exit_on_log_file_message 'server is unhealthy'
105
106 EOF
107
108 scp ${WORKSPACE}/controller-script.sh ${ODL_SYSTEM_IP}:/tmp
109 ssh ${ODL_SYSTEM_IP} 'bash /tmp/controller-script.sh'
110
111 echo "Changing the testplan path..."
112 cat ${WORKSPACE}/test/csit/testplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > testplan.txt
113 cat testplan.txt
114
115 SUITES=$( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' ' )
116
117 echo "Starting Robot test suites ${SUITES} ..."
118 pybot -N ${TESTPLAN} -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp \
119 -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
120 -v CONTROLLER:${ODL_SYSTEM_IP} -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} -v CONTROLLER_USER:${USER} -v ODL_SYSTEM_USER:${USER} \
121 -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_IP} -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} -v TOOLS_SYSTEM_3_IP:${TOOLS_SYSTEM_3_IP} \
122 -v TOOLS_SYSTEM_4_IP:${TOOLS_SYSTEM_4_IP} -v TOOLS_SYSTEM_5_IP:${TOOLS_SYSTEM_5_IP} -v TOOLS_SYSTEM_6_IP:${TOOLS_SYSTEM_6_IP} \
123 -v TOOLS_SYSTEM_USER:${USER} \
124 -v MININET:${TOOLS_SYSTEM_IP} -v MININET1:${TOOLS_SYSTEM_2_IP} -v MININET2:${TOOLS_SYSTEM_3_IP} \
125 -v MININET3:${TOOLS_SYSTEM_4_IP} -v MININET4:${TOOLS_SYSTEM_5_IP} -v MININET5:${TOOLS_SYSTEM_6_IP} \
126 -v MININET_USER:${USER} -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
127
128 echo "Killing ODL and fetching Karaf log..."
129 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
130 ssh "${ODL_SYSTEM_IP}" head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log" > "karaf.log"
131 ssh "${ODL_SYSTEM_IP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
132 sleep 5
133 ssh "${ODL_SYSTEM_IP}" xz -9ekvv "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
134 scp "${ODL_SYSTEM_IP}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log.xz" .
135 true  # perhaps Jenkins is testing last exit code
136
137 # vim: ts=4 sw=4 sts=4 et ft=sh :
138