Set distro-check job time limit to 60 minutes
[releng/builder.git] / jjb / integration / include-raw-integration-deploy-openstack-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 "##         Deploy Openstack 3-node             ##"
9 echo "#################################################"
10
11
12 SSH="ssh -t -t"
13 function create_control_node_local_conf {
14 local_conf_file_name=${WORKSPACE}/local.conf_control
15 cat > ${local_conf_file_name} << EOF
16 [[local|localrc]]
17 LOGFILE=stack.sh.log
18 SCREEN_LOGDIR=/opt/stack/data/log
19 LOG_COLOR=False
20 RECLONE=yes
21 EOF
22
23 IFS=,
24 for service_name in ${DISABLE_OS_SERVICES}
25 do
26 cat >> ${local_conf_file_name} << EOF
27 disable_service ${service_name}
28 EOF
29 done
30 for service_name in ${ENABLE_OS_SERVICES}
31 do
32 cat >> ${local_conf_file_name} << EOF
33 enable_service ${service_name}
34 EOF
35 done
36 unset IFS
37
38 cat >> ${local_conf_file_name} << EOF
39 HOST_IP=$OPENSTACK_CONTROL_NODE_IP
40 SERVICE_HOST=\$HOST_IP
41
42 NEUTRON_CREATE_INITIAL_NETWORKS=False
43 Q_PLUGIN=ml2
44 Q_ML2_TENANT_NETWORK_TYPE=${TENANT_NETWORK_TYPE}
45 Q_OVS_USE_VETH=True
46
47 ENABLE_TENANT_TUNNELS=True
48
49 MYSQL_HOST=\$SERVICE_HOST
50 RABBIT_HOST=\$SERVICE_HOST
51 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
52 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
53 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
54
55 MYSQL_PASSWORD=mysql
56 RABBIT_PASSWORD=rabbit
57 SERVICE_TOKEN=service
58 SERVICE_PASSWORD=admin
59 ADMIN_PASSWORD=admin
60
61 enable_plugin networking-odl ${ODL_ML2_DRIVER_REPO} ${ODL_ML2_VERSION}
62
63 ODL_PORT=8080
64 ODL_MODE=externalodl
65 LIBVIRT_TYPE=qemu
66
67 EOF
68
69 if [ "${NUM_ODL_SYSTEM}" -gt 1 ]; then
70 odl_list=${ODL_SYSTEM_1_IP}
71 for i in `seq 2 ${NUM_ODL_SYSTEM}`
72 do
73 odlip=ODL_SYSTEM_${i}_IP
74 odl_list=${odl_list},${!odlip}
75 done
76 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
77 HA_PROXY_INDEX=${NUM_OPENSTACK_SYSTEM}
78 odlmgrip=OPENSTACK_COMPUTE_NODE_${HA_PROXY_INDEX}_IP
79 odl_mgr_ip=${!odlmgrip}
80 else
81 odl_mgr_ip=${ODL_SYSTEM_1_IP}
82 fi
83 cat >> ${local_conf_file_name} << EOF
84 ODL_OVS_MANAGERS=${odl_list}
85 ODL_MGR_IP=${odl_mgr_ip}
86 EOF
87 else
88 cat >> ${local_conf_file_name} << EOF
89 ODL_MGR_IP=${ODL_SYSTEM_1_IP}
90 EOF
91 fi
92
93 # if we are using the old netvirt impl, as determined by the feature name
94 # odl-ovsdb-openstack (note: new impl is odl-netvirt-openstack) then we
95 # want ODL_L3 to be True.  New impl wants it False
96 if [[ ${CONTROLLERFEATURES} == *"odl-ovsdb-openstack"* ]]; then
97   ODL_L3=True
98 else
99   ODL_L3=False
100 fi
101
102 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
103 cat >> ${local_conf_file_name} << EOF
104
105 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
106 ODL_PROVIDER_MAPPINGS=${PUBLIC_BRIDGE}:br100
107
108 disable_service q-l3
109 Q_L3_ENABLED=True
110 ODL_L3=${ODL_L3}
111 PUBLIC_INTERFACE=br100
112 [[post-config|\$NEUTRON_CONF]]
113 [DEFAULT]
114 service_plugins = networking_odl.l3.l3_odl.OpenDaylightL3RouterPlugin
115
116 EOF
117 fi
118 cat >> ${local_conf_file_name} << EOF
119 [[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]
120 [agent]
121 minimize_polling=True
122
123 [[post-config|/etc/neutron/dhcp_agent.ini]]
124 [DEFAULT]
125 force_metadata = True
126 enable_isolated_metadata = True
127
128 [[post-config|/etc/nova/nova.conf]]
129 [DEFAULT]
130 force_config_drive = False
131
132 EOF
133
134 echo "local.conf Created...."
135 cat ${local_conf_file_name}
136 }
137
138 function create_compute_node_local_conf {
139 HOSTIP=$1
140 local_conf_file_name=${WORKSPACE}/local.conf_compute_${HOSTIP}
141 cat > ${local_conf_file_name} << EOF
142 [[local|localrc]]
143 LOGFILE=stack.sh.log
144 LOG_COLOR=False
145 SCREEN_LOGDIR=/opt/stack/data/log
146 RECLONE=yes
147
148 NOVA_VNC_ENABLED=True
149 MULTI_HOST=1
150 ENABLED_SERVICES=n-cpu
151
152 HOST_IP=${HOSTIP}
153 SERVICE_HOST=${OPENSTACK_CONTROL_NODE_IP}
154
155 Q_PLUGIN=ml2
156 ENABLE_TENANT_TUNNELS=True
157 Q_ML2_TENANT_NETWORK_TYPE=vxlan
158
159 Q_HOST=\$SERVICE_HOST
160 MYSQL_HOST=\$SERVICE_HOST
161 RABBIT_HOST=\$SERVICE_HOST
162 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
163 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
164 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
165
166 MYSQL_PASSWORD=mysql
167 RABBIT_PASSWORD=rabbit
168 SERVICE_TOKEN=service
169 SERVICE_PASSWORD=admin
170 ADMIN_PASSWORD=admin
171
172 enable_plugin networking-odl ${ODL_ML2_DRIVER_REPO} ${ODL_ML2_VERSION}
173 ODL_MODE=compute
174 LIBVIRT_TYPE=qemu
175
176 EOF
177
178 if [ "${NUM_ODL_SYSTEM}" -gt 1 ]; then
179 odl_list=${ODL_SYSTEM_1_IP}
180 for i in `seq 2 ${NUM_ODL_SYSTEM}`
181 do
182 odlip=ODL_SYSTEM_${i}_IP
183 odl_list=${odl_list},${!odlip}
184 done
185 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
186 HA_PROXY_INDEX=${NUM_OPENSTACK_SYSTEM}
187 odlmgrip=OPENSTACK_COMPUTE_NODE_${HA_PROXY_INDEX}_IP
188 odl_mgr_ip=${!odlmgrip}
189 else
190 odl_mgr_ip=${ODL_SYSTEM_1_IP}
191 fi
192 cat >> ${local_conf_file_name} << EOF
193 ODL_OVS_MANAGERS=${odl_list}
194 ODL_MGR_IP=${odl_mgr_ip}
195 EOF
196 else
197 cat >> ${local_conf_file_name} << EOF
198 ODL_MGR_IP=${ODL_SYSTEM_1_IP}
199 EOF
200 fi
201
202 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
203 cat >> ${local_conf_file_name} << EOF
204 # Uncomment lines below if odl-compute is to be used for l3 forwarding
205 Q_L3_ENABLED=True
206 ODL_L3=${ODL_L3}
207 PUBLIC_INTERFACE=br100
208 EOF
209 fi
210 echo "local.conf Created...."
211 cat ${local_conf_file_name}
212 }
213
214 function configure_haproxy_for_neutron_requests () {
215 HA_PROXY_INDEX=${NUM_OPENSTACK_SYSTEM}
216 odlmgrip=OPENSTACK_COMPUTE_NODE_${HA_PROXY_INDEX}_IP
217 ha_proxy_ip=${!odlmgrip}
218
219 cat > ${WORKSPACE}/install_ha_proxy.sh<< EOF
220 sudo systemctl stop firewalld
221 sudo yum -y install policycoreutils-python haproxy
222 EOF
223
224 cat > ${WORKSPACE}/haproxy.cfg << EOF
225 global
226   daemon
227   group  haproxy
228   log  /dev/log local0
229   maxconn  20480
230   pidfile  /tmp/haproxy.pid
231   user  haproxy
232
233 defaults
234   log  global
235   maxconn  4096
236   mode  tcp
237   retries  3
238   timeout  http-request 10s
239   timeout  queue 1m
240   timeout  connect 10s
241   timeout  client 1m
242   timeout  server 1m
243   timeout  check 10s
244
245 listen opendaylight
246   bind ${ha_proxy_ip}:8080
247   balance source
248 EOF
249
250 for i in `seq 1 ${NUM_ODL_SYSTEM}`
251 do
252 odlip=ODL_SYSTEM_${i}_IP
253 cat >> ${WORKSPACE}/haproxy.cfg << EOF
254   server controller-$i ${!odlip}:8080 check fall 5 inter 2000 rise 2
255 EOF
256 done
257
258 cat > ${WORKSPACE}/deploy_ha_proxy.sh<< EOF
259 sudo chown haproxy:haproxy /tmp/haproxy.cfg
260 sudo sed -i 's/\\/etc\\/haproxy\\/haproxy.cfg/\\/tmp\\/haproxy.cfg/g' /usr/lib/systemd/system/haproxy.service
261 sudo /usr/sbin/semanage permissive -a haproxy_t
262 sudo systemctl restart haproxy
263 sleep 3
264 sudo netstat -tunpl
265 sudo systemctl status haproxy
266 true
267 EOF
268 scp ${WORKSPACE}/install_ha_proxy.sh ${ha_proxy_ip}:/tmp
269 ${SSH} ${ha_proxy_ip} "sudo bash /tmp/install_ha_proxy.sh"
270 scp ${WORKSPACE}/haproxy.cfg ${ha_proxy_ip}:/tmp
271 scp ${WORKSPACE}/deploy_ha_proxy.sh ${ha_proxy_ip}:/tmp
272 ${SSH} ${ha_proxy_ip} "sudo bash /tmp/deploy_ha_proxy.sh"
273 }
274
275 function collect_logs_and_exit (){
276 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
277 for i in `seq 1 ${NUM_ODL_SYSTEM}`
278 do
279     CONTROLLERIP=ODL_SYSTEM_${i}_IP
280     echo "killing karaf process..."
281     ${SSH} "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
282 done
283
284 sleep 5
285 # FIXME: Do not create .tar and gzip before copying.
286 for i in `seq 1 ${NUM_ODL_SYSTEM}`
287 do
288     CONTROLLERIP=ODL_SYSTEM_${i}_IP
289     ${SSH} "${!CONTROLLERIP}"  "cp -r /tmp/${BUNDLEFOLDER}/data/log /tmp/odl_log"
290     ${SSH} "${!CONTROLLERIP}"  "tar -cf /tmp/odl${i}_karaf.log.tar /tmp/odl_log/*"
291     scp "${!CONTROLLERIP}:/tmp/odl${i}_karaf.log.tar" "${WORKSPACE}/odl${i}_karaf.log.tar"
292     tar -xvf ${WORKSPACE}/odl${i}_karaf.log.tar -C . --strip-components 2 --transform s/karaf/odl${i}_karaf/g
293     rm ${WORKSPACE}/odl${i}_karaf.log.tar
294 done
295
296 scp ${OPENSTACK_CONTROL_NODE_IP}:/opt/stack/devstack/nohup.out "openstack_control_stack.log"
297 ${SSH} ${OPENSTACK_CONTROL_NODE_IP} "tar -cf /tmp/control_node_openstack_logs.tgz  /opt/stack/logs/*"
298 scp "${OPENSTACK_CONTROL_NODE_IP}:/tmp/control_node_openstack_logs.tgz" control_node_openstack_logs.tgz
299 for i in `seq 1 $((NUM_OPENSTACK_SYSTEM - 1))`
300 do
301     OSIP=OPENSTACK_COMPUTE_NODE_${i}_IP
302     scp "${!OSIP}:/opt/stack/devstack/nohup.out" "openstack_compute_stack_${i}.log"
303     ${SSH} "${!OSIP}" "tar -cf /tmp/compute_node_${i}_openstack_logs.tgz  /opt/stack/logs/*"
304     scp "${!OSIP}:/tmp/compute_node_${i}_openstack_logs.tgz"  "compute_node_${i}_openstack_logs.tgz"
305 done
306 }
307
308 cat > ${WORKSPACE}/disable_firewall.sh << EOF
309 sudo systemctl stop firewalld
310 sudo systemctl stop iptables
311 true
312 EOF
313
314 cat > ${WORKSPACE}/get_devstack.sh << EOF
315 sudo systemctl stop firewalld
316 sudo yum install bridge-utils -y
317 sudo systemctl stop  NetworkManager
318 #Disable NetworkManager and kill dhclient and dnsmasq
319 sudo systemctl stop NetworkManager
320 sudo killall dhclient
321 sudo killall dnsmasq
322 #Workaround for mysql failure
323 echo "127.0.0.1    localhost \${HOSTNAME}" > /tmp/hosts
324 echo "::1   localhost  \${HOSTNAME}" >> /tmp/hosts
325 sudo mv /tmp/hosts /etc/hosts
326 sudo /usr/sbin/brctl addbr br100
327 #sudo ifconfig eth0 mtu 2000 
328 sudo mkdir /opt/stack
329 sudo chmod 777 /opt/stack
330 cd /opt/stack
331 git clone https://git.openstack.org/openstack-dev/devstack
332 cd devstack
333 git checkout $OPENSTACK_BRANCH
334 EOF
335
336 echo "Create HAProxy if needed"
337 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
338  echo "Need to configure HAProxy"
339  configure_haproxy_for_neutron_requests
340 fi
341
342 os_node_list=()
343 echo "Stack the Control Node"
344 scp ${WORKSPACE}/get_devstack.sh ${OPENSTACK_CONTROL_NODE_IP}:/tmp
345 ${SSH} ${OPENSTACK_CONTROL_NODE_IP} "bash /tmp/get_devstack.sh"
346 create_control_node_local_conf
347 scp ${WORKSPACE}/local.conf_control ${OPENSTACK_CONTROL_NODE_IP}:/opt/stack/devstack/local.conf
348 ssh ${OPENSTACK_CONTROL_NODE_IP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
349 ssh ${OPENSTACK_CONTROL_NODE_IP} "ps -ef | grep stack.sh"
350 ssh ${OPENSTACK_CONTROL_NODE_IP} "ls -lrt /opt/stack/devstack/nohup.out"
351 os_node_list+=(${OPENSTACK_CONTROL_NODE_IP})
352
353
354 for i in `seq 1 $((NUM_OPENSTACK_SYSTEM - 1))`
355 do
356     COMPUTEIP=OPENSTACK_COMPUTE_NODE_${i}_IP
357     scp ${WORKSPACE}/get_devstack.sh  ${!COMPUTEIP}:/tmp
358     ${SSH} ${!COMPUTEIP} "bash /tmp/get_devstack.sh"
359     create_compute_node_local_conf ${!COMPUTEIP}
360     scp ${WORKSPACE}/local.conf_compute_${!COMPUTEIP} ${!COMPUTEIP}:/opt/stack/devstack/local.conf
361     ssh ${!COMPUTEIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
362     ssh ${!COMPUTEIP} "ps -ef | grep stack.sh"
363     os_node_list+=(${!COMPUTEIP})
364 done
365
366 cat > ${WORKSPACE}/check_stacking.sh << EOF
367 > /tmp/stack_progress
368 ps -ef | grep "stack.sh" | grep -v grep
369 ret=\$?
370 if [ \${ret} -eq 1 ]; then
371   grep "This is your host IP address:" /opt/stack/devstack/nohup.out
372   if [ \$? -eq 0 ]; then
373      echo "Stacking Complete" > /tmp/stack_progress
374   else
375      echo "Stacking Failed" > /tmp/stack_progress
376   fi
377 elif [ \${ret} -eq 0 ]; then
378   echo "Still Stacking" > /tmp/stack_progress
379 fi
380 EOF
381
382 #the checking is repeated for an hour
383 iteration=0
384 in_progress=1
385 while [ ${in_progress} -eq 1 ]; do
386 iteration=$(($iteration + 1))
387 for index in ${!os_node_list[@]}
388 do
389 echo "Check the status of stacking in ${os_node_list[index]}"
390 scp ${WORKSPACE}/check_stacking.sh  ${os_node_list[index]}:/tmp
391 ${SSH} ${os_node_list[index]} "bash /tmp/check_stacking.sh"
392 scp ${os_node_list[index]}:/tmp/stack_progress .
393 #debug
394 cat stack_progress
395 stacking_status=`cat stack_progress`
396 if [ "$stacking_status" == "Still Stacking" ]; then
397   continue
398 elif [ "$stacking_status" == "Stacking Failed" ]; then
399   collect_logs_and_exit
400   exit 1
401 elif [ "$stacking_status" == "Stacking Complete" ]; then
402   unset os_node_list[index]
403   if  [ ${#os_node_list[@]} -eq 0 ]; then
404      in_progress=0
405   fi
406 fi
407 done
408  echo "sleep for a minute before the next check"
409  sleep 60
410  if [ ${iteration} -eq 60 ]; then
411   collect_logs_and_exit
412   exit 1
413  fi
414 done
415
416 #Need to disable firewalld and iptables in control node
417 echo "Stop Firewall in Control Node for compute nodes to be able to reach the ports and add to hypervisor-list"
418 scp ${WORKSPACE}/disable_firewall.sh ${OPENSTACK_CONTROL_NODE_IP}:/tmp
419 ${SSH} ${OPENSTACK_CONTROL_NODE_IP} "sudo bash /tmp/disable_firewall.sh"
420 echo "sleep for a minute and print hypervisor-list"
421 sleep 60
422 ${SSH} ${OPENSTACK_CONTROL_NODE_IP} "cd /opt/stack/devstack; source openrc admin admin; nova hypervisor-list"
423
424 #Need to disable firewalld and iptables in compute nodes as well
425 for i in `seq 1 $((NUM_OPENSTACK_SYSTEM - 1))`
426 do
427     OSIP=OPENSTACK_COMPUTE_NODE_${i}_IP
428     scp ${WORKSPACE}/disable_firewall.sh "${!OSIP}:/tmp"
429     ${SSH} "${!OSIP}" "sudo bash /tmp/disable_firewall.sh"
430 done
431
432 # upgrading pip, urllib3 and httplib2 so that tempest tests can be run on ${OPENSTACK_CONTROL_NODE_IP}
433 # this needs to happen after devstack runs because it seems devstack is pulling in specific versions
434 # of these libs that are not working for tempest.
435 ${SSH} ${OPENSTACK_CONTROL_NODE_IP} "sudo pip install --upgrade pip"
436 ${SSH} ${OPENSTACK_CONTROL_NODE_IP} "sudo pip install urllib3 --upgrade"
437 ${SSH} ${OPENSTACK_CONTROL_NODE_IP} "sudo pip install httplib2 --upgrade"
438
439 echo "Locating test plan to use..."
440 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
441 if [ ! -f "${testplan_filepath}" ]; then
442     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
443 fi
444
445 echo "Changing the testplan path..."
446 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
447 cat testplan.txt
448
449 SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
450
451 echo "Starting Robot test suites ${SUITES} ..."
452 pybot -N ${TESTPLAN} -c critical -e exclude -v BUNDLEFOLDER:${BUNDLEFOLDER} -v WORKSPACE:/tmp -v BUNDLE_URL:${ACTUALBUNDLEURL} \
453 -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} -v JDKVERSION:${JDKVERSION} -v ODL_STREAM:${DISTROSTREAM} \
454 -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_1_IP} -v ODL_SYSTEM_2_IP:${ODL_SYSTEM_2_IP} \
455 -v ODL_SYSTEM_3_IP:${ODL_SYSTEM_3_IP} -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} -v CONTROLLER_USER:${USER} -v OS_USER:${USER} \
456 -v NUM_OS_SYSTEM:${NUM_OPENSTACK_SYSTEM} -v OS_CONTROL_NODE_IP:${OPENSTACK_CONTROL_NODE_IP} \
457 -v OS_COMPUTE_1_IP:${OPENSTACK_COMPUTE_NODE_1_IP} -v OS_COMPUTE_2_IP:${OPENSTACK_COMPUTE_NODE_2_IP} \
458 -v DEVSTACK_DEPLOY_PATH:/opt/stack/devstack -v USER_HOME:${HOME} ${TESTOPTIONS} ${SUITES} || true
459
460 echo "Tests Executed"
461 DEVSTACK_TEMPEST_DIR="/opt/stack/tempest"
462 if $(ssh ${OPENSTACK_CONTROL_NODE_IP} "sudo sh -c '[ -f ${DEVSTACK_TEMPEST_DIR}/.testrepository/0 ]'"); then # if Tempest results exist
463     ssh ${OPENSTACK_CONTROL_NODE_IP} "sudo sh -c '${DEVSTACK_TEMPEST_DIR}/.tox/tempest/bin/subunit-1to2 < ${DEVSTACK_TEMPEST_DIR}/.testrepository/0 > ${DEVSTACK_TEMPEST_DIR}/subunit_log.txt'"
464     ssh ${OPENSTACK_CONTROL_NODE_IP} "sudo sh -c '${DEVSTACK_TEMPEST_DIR}/.tox/tempest/bin/python ${DEVSTACK_TEMPEST_DIR}/.tox/tempest/lib/python2.7/site-packages/os_testr/subunit2html.py ${DEVSTACK_TEMPEST_DIR}/subunit_log.txt ${DEVSTACK_TEMPEST_DIR}/tempest_results.html'"
465     scp ${OPENSTACK_CONTROL_NODE_IP}:${DEVSTACK_TEMPEST_DIR}/tempest_results.html ${WORKSPACE}/
466 fi
467 collect_logs_and_exit
468
469 true  # perhaps Jenkins is testing last exit code
470 # vim: ts=4 sw=4 sts=4 et ft=sh :