Merge "Set pass-if to 100% in every csit-related job"
[releng/builder.git] / jjb / integration / include-raw-integration-start-cluster-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 echo "#################################################"
8 echo "##         Verify Cluster is UP                ##"
9 echo "#################################################"
10
11 cat > ${WORKSPACE}/verify-cluster-is-up.sh <<EOF
12
13 CONTROLLERID="member-\$1"
14 ODL_SYSTEM_IP_PATH=\$2
15
16 echo "Waiting for controller to come up..."
17 COUNT="0"
18 while true; do
19     RESP="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null )"
20     echo \$RESP
21     SHARD="\$( curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/jolokia/read/org.opendaylight.controller:Category=Shards,name=\$CONTROLLERID-shard-inventory-config,type=DistributedConfigDatastore)"
22     echo \$SHARD
23     if ([[ \$RESP == *"200"* ]] && [[ \$SHARD  == *'"status":200'* ]]); then
24         echo Controller is UP
25         break
26     elif (( "\$COUNT" > "600" )); then
27         echo Timeout Controller DOWN
28         echo "Dumping Karaf log..."
29         head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
30         echo "Listing all open ports on controller system"
31         netstat -natu
32         exit 1
33     else
34         COUNT=\$(( \${COUNT} + 5 ))
35         sleep 5
36         echo waiting \$COUNT secs...
37     fi
38 done
39
40 echo "Checking OSGi bundles..."
41 sshpass -p karaf /tmp/${BUNDLEFOLDER}/bin/client -u karaf 'bundle:list'
42
43 echo "Listing all open ports on controller system.."
44 netstat -natu
45
46 function exit_on_log_file_message {
47     echo "looking for \"\$1\" in log file"
48     if grep --quiet "\$1" "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"; then
49         echo ABORTING: found "\$1"
50         echo "Dumping Karaf log..."
51         head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
52         exit 1
53     fi
54 }
55
56 exit_on_log_file_message 'BindException: Address already in use'
57 exit_on_log_file_message 'server is unhealthy'
58
59 EOF
60
61 for i in `seq 1 ${NUM_ODL_SYSTEM}`
62 do
63     CONTROLLERIP=ODL_SYSTEM_${i}_IP
64     echo "Verifying member-${i} with IP address ${!CONTROLLERIP} is UP"
65     scp ${WORKSPACE}/verify-cluster-is-up.sh ${!CONTROLLERIP}:/tmp
66     ssh ${!CONTROLLERIP} "bash /tmp/verify-cluster-is-up.sh ${i} ${!CONTROLLERIP}"
67 done
68
69 echo "Cool down for 1 min :)..."
70 sleep 60
71
72 echo "Changing the testplan path..."
73 cat ${WORKSPACE}/test/csit/testplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > testplan.txt
74 cat testplan.txt
75
76 SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
77
78 echo "Generating controller variables..."
79 for i in `seq 1 ${NUM_ODL_SYSTEM}`
80 do
81     CONTROLLERIP=ODL_SYSTEM_${i}_IP
82     odl_variables=${odl_variables}" -v ${CONTROLLERIP}:${!CONTROLLERIP}"
83 done
84
85 echo "Generating mininet variables..."
86 for i in `seq 1 ${NUM_TOOLS_SYSTEM}`
87 do
88     MININETIP=TOOLS_SYSTEM_${i}_IP
89     tools_variables=${tools_variables}" -v ${MININETIP}:${!MININETIP}"
90 done
91
92 echo "Starting Robot test suites ${SUITES} ..."
93 pybot -N ${TESTPLAN} -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
94 -v CONTROLLER:${ODL_SYSTEM_IP} -v CONTROLLER1:${ODL_SYSTEM_2_IP} -v CONTROLLER2:${ODL_SYSTEM_3_IP} -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} \
95 ${odl_variables} -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} -v CONTROLLER_USER:${USER} -v ODL_SYSTEM_USER:${USER} -v \
96 TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_IP} ${tools_variables} -v NUM_TOOLS_SYSTEM:${NUM_TOOLS_SYSTEM} -v TOOLS_SYSTEM_USER:${USER} \
97 -v MININET:${TOOLS_SYSTEM_IP} -v MININET1:${TOOLS_SYSTEM_2_IP} -v MININET2:${TOOLS_SYSTEM_3_IP} -v MININET_USER:${USER} \
98 -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
99
100 echo "Killing ODL and fetching Karaf log..."
101 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
102 for i in `seq 1 ${NUM_ODL_SYSTEM}`
103 do
104     CONTROLLERIP=ODL_SYSTEM_${i}_IP
105     ssh "${!CONTROLLERIP}" head --bytes=1M "/tmp/${BUNDLEFOLDER}/data/log/karaf.log" > "odl${i}_karaf.log"
106     ssh "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
107 done
108 sleep 5
109 for i in `seq 1 ${NUM_ODL_SYSTEM}`
110 do
111     CONTROLLERIP=ODL_SYSTEM_${i}_IP
112     ssh "${!CONTROLLERIP}" xz -9ekvv "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
113     scp "${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/data/log/karaf.log.xz" "odl${i}_karaf.log.xz"
114 done
115 true  # perhaps Jenkins is testing last exit code
116
117 # vim: ts=4 sw=4 sts=4 et ft=sh :
118