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