JJB integration: Return code from pybot shall be ignored
[releng/builder.git] / jjb / integration / include-raw-integration-deploy-controller-run-test.sh
1 # Create a script to run controller inside a dynamic jenkins slave
2 CONTROLLERMEM="2048m"
3 DISTRIBUTION="karaf"
4
5 if [ ${CONTROLLERSCOPE} == 'all' ]; then
6     CONTROLLERFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
7     CONTROLLERMEM="3072m"
8 fi
9
10 NEXUSURL_PREFIX=${ODLNEXUSPROXY:-https://nexus.opendaylight.org}
11
12 if [ ${BUNDLEURL} == 'last' ]; then
13     NEXUSPATH="${NEXUSURL_PREFIX}/content/repositories/opendaylight.snapshot/org/opendaylight/integration/distribution-${DISTRIBUTION}"
14     # Extract the BUNDLEVERSION from the pom.xml
15     BUNDLEVERSION=`xpath pom.xml '/project/version/text()' 2> /dev/null`
16     echo "Bundle version is ${BUNDLEVERSION}"
17     # Acquire the timestamp information from maven-metadata.xml
18     wget ${NEXUSPATH}/${BUNDLEVERSION}/maven-metadata.xml
19     TIMESTAMP=`xpath maven-metadata.xml "//snapshotVersion[extension='zip'][1]/value/text()" 2>/dev/null`
20     echo "Nexus timestamp is ${TIMESTAMP}"
21     BUNDLEFOLDER="distribution-${DISTRIBUTION}-${BUNDLEVERSION}"
22     BUNDLE="distribution-${DISTRIBUTION}-${TIMESTAMP}.zip"
23     BUNDLEURL="${NEXUSPATH}/${BUNDLEVERSION}/${BUNDLE}"
24 else
25     BUNDLE="${BUNDLEURL##*/}"
26     BUNDLEVERSION="$(basename $(dirname $BUNDLEURL))"
27     BUNDLEFOLDER="distribution-${DISTRIBUTION}-${BUNDLEVERSION}"
28 fi
29
30 echo "Distribution bundle URL is ${BUNDLEURL}"
31 echo "Distribution bundle is ${BUNDLE}"
32 echo "Distribution folder is ${BUNDLEFOLDER}"
33
34 cat > ${WORKSPACE}/controller-script.sh <<EOF
35 echo "Downloading the distribution..."
36 cd /tmp
37 wget --no-verbose '${BUNDLEURL}'
38
39 echo "Extracting the new controller..."
40 unzip -q ${BUNDLE}
41
42 echo "Configuring the startup features..."
43 cd ${BUNDLEFOLDER}/etc
44 CFG=org.apache.karaf.features.cfg
45 cp \${CFG} \${CFG}.bak
46 cat \${CFG}.bak | sed "s/^featuresBoot=.*/featuresBoot=config,standard,region,package,kar,ssh,management,${CONTROLLERFEATURES}/" > \${CFG}.1
47 cat \${CFG}.1 | sed "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%" > \${CFG}
48 cat \${CFG}
49
50 echo "Configuring the log..."
51 LOG=org.ops4j.pax.logging.cfg
52 cp \${LOG} \${LOG}.bak
53 cat \${LOG}.bak | sed 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=20MB/' > \${LOG}
54 cat \${LOG}
55
56 echo "Configure max memory..."
57 MEM=setenv
58 cd ../bin
59 cp \${MEM} \${MEM}.bak
60 cat \${MEM}.bak | sed 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/' > \${MEM}
61 cat \${MEM}
62
63 echo "Starting controller..."
64 ./start &
65
66 echo "Waiting for controller to come up..."
67 COUNT="0"
68 while true; do
69     RESP="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null )"
70     echo \$RESP
71     if [[ \$RESP == *"200"* ]]; then
72         echo Controller is UP
73         break
74     elif (( "\$COUNT" > "600" )); then
75         echo Timeout Controller DOWN
76         echo "Dumping Karaf log..."
77         cd ../data/log
78         cat karaf.log
79         exit 1
80     else
81         COUNT=\$(( \${COUNT} + 5 ))
82         sleep 5
83         echo waiting \$COUNT secs...
84     fi
85 done
86
87 echo "Cool down for 1 min :)..."
88 sleep 60
89
90 echo "Checking OSGi bundles..."
91 sshpass -p karaf ./client -u karaf 'bundle:list'
92
93 EOF
94
95 scp ${WORKSPACE}/controller-script.sh ${CONTROLLER0}:/tmp
96 ssh ${CONTROLLER0} 'bash /tmp/controller-script.sh'
97
98 echo "Changing the testplan path..."
99 cat ${WORKSPACE}/test/csit/testplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > testplan.txt
100 cat testplan.txt
101
102 SUITES=$( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' ' )
103
104 echo "Starting Robot test suites ${SUITES} ..."
105 pybot -N ${TESTPLAN} -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp \
106 -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} -v CONTROLLER:${CONTROLLER0} \
107 -v MININET:${MININET0} -v MININET_USER:${USER} -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
108 # the "|| true" is there to swallow a non-zero error code, as we do not want a failed critical test case to stop this script (run with -xe by Jenkins) from gathering karaf.log
109
110 echo "Fetching Karaf log"
111 scp ${CONTROLLER0}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log .
112
113 # vim: ts=4 sw=4 sts=4 et ft=sh :
114