To enable odl_l3 and l2gw feature work together
[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 # TODO: remove this work to run changes.py if/when it's moved higher up to be visible at the Robot level
8 echo "showing recent changes that made it in to the distribution used by this job"
9 pip install --upgrade urllib3
10 python ${WORKSPACE}/test/tools/distchanges/changes.py -d /tmp/distribution_folder \
11                   -u ${ACTUALBUNDLEURL} -b ${DISTROBRANCH} \
12                   -r ssh://jenkins-${SILO}@git.opendaylight.org:29418 || true
13
14 echo "#################################################"
15 echo "##         Deploy Openstack 3-node             ##"
16 echo "#################################################"
17
18
19 SSH="ssh -t -t"
20
21 function create_control_node_local_conf {
22 HOSTIP=$1
23 MGRIP=$2
24 ODL_OVS_MANAGERS="$3"
25 #Needs to be removed
26 if [ "${ODL_ML2_BRANCH}" != "stable/ocata" ]; then
27    RECLONE=no
28 else
29    RECLONE=yes
30 fi
31 local_conf_file_name=${WORKSPACE}/local.conf_control_${HOSTIP}
32 cat > ${local_conf_file_name} << EOF
33 [[local|localrc]]
34 LOGFILE=stack.sh.log
35 SCREEN_LOGDIR=/opt/stack/data/log
36 LOG_COLOR=False
37 RECLONE=${RECLONE}
38 EOF
39
40 IFS=,
41 for service_name in ${DISABLE_OS_SERVICES}
42 do
43 cat >> ${local_conf_file_name} << EOF
44 disable_service ${service_name}
45 EOF
46 done
47 for service_name in ${ENABLE_OS_SERVICES}
48 do
49 cat >> ${local_conf_file_name} << EOF
50 enable_service ${service_name}
51 EOF
52 done
53 for plugin_name in ${ENABLE_OS_PLUGINS}
54 do
55 if [ "$plugin_name" == "networking-odl" ]; then
56     ENABLE_PLUGIN_ARGS="${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}"
57 elif [ "$plugin_name" == "kuryr-kubernetes" ]; then
58     ENABLE_PLUGIN_ARGS="${DEVSTACK_KUBERNETES_PLUGIN_REPO} master" # note: kuryr-kubernetes only exists in master at the moment
59 elif [ "$plugin_name" == "neutron-lbaas" ]; then
60     ENABLE_PLUGIN_ARGS="${DEVSTACK_LBAAS_PLUGIN_REPO} ${OPENSTACK_BRANCH}"
61 else
62     echo "Error: Invalid plugin $plugin_name, unsupported"
63     continue
64 fi
65 cat >> ${local_conf_file_name} << EOF
66 enable_plugin ${plugin_name} ${ENABLE_PLUGIN_ARGS}
67 EOF
68 done
69 unset IFS
70 if [ "${OPENSTACK_BRANCH}" == "master" ] || [ "${OPENSTACK_BRANCH}" == "stable/ocata" ]; then # Ocata+
71     # placement is mandatory for nova since Ocata, note that this requires computes to enable placement-client
72     # this should be moved into enabled_services for each job (but only for Ocata)
73     echo "enable_service placement-api" >> ${local_conf_file_name}
74 fi
75 cat >> ${local_conf_file_name} << EOF
76 HOST_IP=${HOSTIP}
77 SERVICE_HOST=\$HOST_IP
78
79 NEUTRON_CREATE_INITIAL_NETWORKS=${CREATE_INITIAL_NETWORKS}
80 Q_PLUGIN=ml2
81 Q_ML2_TENANT_NETWORK_TYPE=${TENANT_NETWORK_TYPE}
82 Q_OVS_USE_VETH=True
83
84 ENABLE_TENANT_TUNNELS=True
85
86 MYSQL_HOST=\$SERVICE_HOST
87 RABBIT_HOST=\$SERVICE_HOST
88 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
89 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
90 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
91
92 MYSQL_PASSWORD=mysql
93 RABBIT_PASSWORD=rabbit
94 SERVICE_TOKEN=service
95 SERVICE_PASSWORD=admin
96 ADMIN_PASSWORD=admin
97
98 ODL_PORT=8080
99 ODL_MODE=externalodl
100 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
101
102 LIBVIRT_TYPE=qemu
103 ODL_MGR_IP=${MGRIP}
104
105 NEUTRON_LBAAS_SERVICE_PROVIDERV2=${LBAAS_SERVICE_PROVIDER} # Only relevant if neutron-lbaas plugin is enabled
106 EOF
107
108 if [ "${ENABLE_NETWORKING_L2GW}" == "yes" ]; then
109 cat >> ${local_conf_file_name} << EOF
110
111 enable_plugin networking-l2gw ${NETWORKING_L2GW_DRIVER} ${ODL_ML2_BRANCH}
112 NETWORKING_L2GW_SERVICE_DRIVER=L2GW:OpenDaylight:networking_odl.l2gateway.driver.OpenDaylightL2gwDriver:default
113 ENABLED_SERVICES+=,neutron,q-svc,nova,q-meta
114
115 EOF
116 fi
117
118 if [ "${ODL_ML2_DRIVER_VERSION}" == "v2" ]; then
119     echo "ODL_V2DRIVER=True" >> ${local_conf_file_name}
120 fi
121
122 echo "ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}" >> ${local_conf_file_name}
123
124 # if we are using the old netvirt impl, as determined by the feature name
125 # odl-ovsdb-openstack (note: new impl is odl-netvirt-openstack) then we
126 # want ODL_L3 to be True.  New impl wants it False
127 if [[ ${CONTROLLERFEATURES} == *"odl-ovsdb-openstack"* ]]; then
128     ODL_L3=True
129 else
130     ODL_L3=False
131 fi
132
133 # if we are using the new netvirt impl, as determined by the feature name
134 # odl-netvirt-openstack (note: old impl is odl-ovsdb-openstack) then we
135 # want PROVIDER_MAPPINGS to be used -- this should be fixed if we want to support
136 # external networks in legacy netvirt
137 if [[ ${CONTROLLERFEATURES} == *"odl-netvirt-openstack"* ]]; then
138   ODL_PROVIDER_MAPPINGS="\${PUBLIC_PHYSICAL_NETWORK}:${PUBLIC_BRIDGE}"
139 else
140   ODL_PROVIDER_MAPPINGS=
141 fi
142
143 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
144 cat >> ${local_conf_file_name} << EOF
145 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
146 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
147 ML2_VLAN_RANGES=${PUBLIC_PHYSICAL_NETWORK}
148 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
149
150 disable_service q-l3
151 PUBLIC_INTERFACE=br100
152 EOF
153
154 if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
155 cat >> ${local_conf_file_name} << EOF
156 Q_L3_ENABLED=True
157 ODL_L3=${ODL_L3}
158
159 EOF
160 if [ "${ENABLE_NETWORKING_L2GW}" == "yes" ]; then
161 cat >> ${local_conf_file_name} << EOF
162 [[post-config|\$NEUTRON_CONF]]
163 [DEFAULT]
164 service_plugins = networking_odl.l3.l3_odl.OpenDaylightL3RouterPlugin, networking_l2gw.services.l2gateway.plugin.L2GatewayPlugin
165
166 EOF
167 else
168 cat >> ${local_conf_file_name} << EOF
169 [[post-config|\$NEUTRON_CONF]]
170 [DEFAULT]
171 service_plugins = networking_odl.l3.l3_odl.OpenDaylightL3RouterPlugin
172 EOF
173 fi #check for ENABLE_NETWORKING_L2GW
174
175 fi #check for ODL_ML2_BRANCH
176
177 fi #ODL_ENABLE_L3_FWD check
178
179 cat >> ${local_conf_file_name} << EOF
180 [[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]
181 [agent]
182 minimize_polling=True
183
184 [ml2]
185 # Needed for VLAN provider tests - because our provider networks are always encapsulated in VXLAN (br-phys1)
186 # MTU(1440) + VXLAN(50) + VLAN(4) = 1494 < MTU eth0/br-phys1(1500)
187 physical_network_mtus = ${PUBLIC_PHYSICAL_NETWORK}:1440
188 path_mtu = 1490
189
190 [[post-config|/etc/neutron/dhcp_agent.ini]]
191 [DEFAULT]
192 force_metadata = True
193 enable_isolated_metadata = True
194
195 [[post-config|/etc/nova/nova.conf]]
196 [DEFAULT]
197 force_config_drive = False
198
199 EOF
200
201 echo "local.conf Created...."
202 cat ${local_conf_file_name}
203 }
204
205 function create_compute_node_local_conf {
206 HOSTIP=$1
207 SERVICEHOST=$2
208 MGRIP=$3
209 ODL_OVS_MANAGERS="$4"
210 #Needs to be removed
211 if [ "${ODL_ML2_BRANCH}" != "stable/ocata" ]; then
212    RECLONE=no
213 else
214    RECLONE=yes
215 fi
216 if [ "${OPENSTACK_BRANCH}" == "master" ] || [ "${OPENSTACK_BRANCH}" == "stable/ocata" ]; then # Ocata+
217     # placement is mandatory for nova since Ocata, note that this requires controller to enable placement-api
218     ENABLED_SERVICES="n-cpu,placement-client"
219 else
220     ENABLED_SERVICES="n-cpu"
221 fi
222
223 local_conf_file_name=${WORKSPACE}/local.conf_compute_${HOSTIP}
224 cat > ${local_conf_file_name} << EOF
225 [[local|localrc]]
226 LOGFILE=stack.sh.log
227 LOG_COLOR=False
228 SCREEN_LOGDIR=/opt/stack/data/log
229 RECLONE=${RECLONE}
230
231 NOVA_VNC_ENABLED=True
232 MULTI_HOST=1
233 ENABLED_SERVICES=${ENABLED_SERVICES}
234 HOST_IP=${HOSTIP}
235 SERVICE_HOST=${SERVICEHOST}
236
237 Q_PLUGIN=ml2
238 ENABLE_TENANT_TUNNELS=True
239 Q_ML2_TENANT_NETWORK_TYPE=vxlan
240
241 Q_HOST=\$SERVICE_HOST
242 MYSQL_HOST=\$SERVICE_HOST
243 RABBIT_HOST=\$SERVICE_HOST
244 GLANCE_HOSTPORT=\$SERVICE_HOST:9292
245 KEYSTONE_AUTH_HOST=\$SERVICE_HOST
246 KEYSTONE_SERVICE_HOST=\$SERVICE_HOST
247
248 MYSQL_PASSWORD=mysql
249 RABBIT_PASSWORD=rabbit
250 SERVICE_TOKEN=service
251 SERVICE_PASSWORD=admin
252 ADMIN_PASSWORD=admin
253
254 ODL_MODE=compute
255 ODL_PORT_BINDING_CONTROLLER=${ODL_ML2_PORT_BINDING}
256 LIBVIRT_TYPE=qemu
257 ODL_MGR_IP=${MGRIP}
258 EOF
259
260 if [[ "${ENABLE_OS_PLUGINS}" =~ networking-odl ]]; then
261 cat >> ${local_conf_file_name} << EOF
262 enable_plugin networking-odl ${ODL_ML2_DRIVER_REPO} ${ODL_ML2_BRANCH}
263 EOF
264 fi
265
266 echo "ODL_OVS_MANAGERS=${ODL_OVS_MANAGERS}" >> ${local_conf_file_name}
267
268 # if we are using the new netvirt impl, as determined by the feature name
269 # odl-netvirt-openstack (note: old impl is odl-ovsdb-openstack) then we
270 # want PROVIDER_MAPPINGS to be used -- this should be fixed if we want to support
271 # external networks in legacy netvirt
272 if [[ ${CONTROLLERFEATURES} == *"odl-netvirt-openstack"* ]]; then
273   ODL_PROVIDER_MAPPINGS="\${PUBLIC_PHYSICAL_NETWORK}:${PUBLIC_BRIDGE}"
274 else
275   ODL_PROVIDER_MAPPINGS=
276 fi
277
278 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
279 cat >> ${local_conf_file_name} << EOF
280 # Uncomment lines below if odl-compute is to be used for l3 forwarding
281 Q_L3_ENABLED=True
282 ODL_L3=${ODL_L3}
283 PUBLIC_INTERFACE=br100 # FIXME do we use br100 at all?
284 PUBLIC_BRIDGE=${PUBLIC_BRIDGE}
285 PUBLIC_PHYSICAL_NETWORK=${PUBLIC_PHYSICAL_NETWORK}
286 ODL_PROVIDER_MAPPINGS=${ODL_PROVIDER_MAPPINGS}
287 EOF
288 fi
289 echo "local.conf Created...."
290 cat ${local_conf_file_name}
291 }
292
293 function configure_haproxy_for_neutron_requests () {
294 MGRIP=$1
295 ODL_IPS=(${2//,/ })
296
297 cat > ${WORKSPACE}/install_ha_proxy.sh<< EOF
298 sudo systemctl stop firewalld
299 sudo yum -y install policycoreutils-python haproxy
300 EOF
301
302 cat > ${WORKSPACE}/haproxy.cfg << EOF
303 global
304   daemon
305   group  haproxy
306   log  /dev/log local0
307   maxconn  20480
308   pidfile  /tmp/haproxy.pid
309   user  haproxy
310
311 defaults
312   log  global
313   maxconn  4096
314   mode  tcp
315   retries  3
316   timeout  http-request 10s
317   timeout  queue 1m
318   timeout  connect 10s
319   timeout  client 1m
320   timeout  server 1m
321   timeout  check 10s
322
323 listen opendaylight
324   bind ${MGRIP}:8080
325   balance source
326 EOF
327
328 odlindex=1
329 for odlip in ${ODL_IPS[*]}
330 do
331 cat >> ${WORKSPACE}/haproxy.cfg << EOF
332   server controller-${odlindex} ${odlip}:8080 check fall 5 inter 2000 rise 2
333 EOF
334 odlindex=$((odlindex+1))
335 done
336
337 cat >> ${WORKSPACE}/haproxy.cfg << EOF
338 listen opendaylight_rest
339   bind ${MGRIP}:8181
340   balance source
341 EOF
342
343 odlindex=1
344 for odlip in ${ODL_IPS[*]}
345 do
346 cat >> ${WORKSPACE}/haproxy.cfg << EOF
347   server controller-rest-${odlindex} ${odlip}:8181 check fall 5 inter 2000 rise 2
348 EOF
349 odlindex=$((odlindex+1))
350 done
351
352 echo "Dump haproxy.cfg"
353 cat ${WORKSPACE}/haproxy.cfg
354
355 cat > ${WORKSPACE}/deploy_ha_proxy.sh<< EOF
356 sudo chown haproxy:haproxy /tmp/haproxy.cfg
357 sudo sed -i 's/\\/etc\\/haproxy\\/haproxy.cfg/\\/tmp\\/haproxy.cfg/g' /usr/lib/systemd/system/haproxy.service
358 sudo /usr/sbin/semanage permissive -a haproxy_t
359 sudo systemctl restart haproxy
360 sleep 3
361 sudo netstat -tunpl
362 sudo systemctl status haproxy
363 true
364 EOF
365 scp ${WORKSPACE}/install_ha_proxy.sh ${MGRIP}:/tmp
366 ${SSH} ${MGRIP} "sudo bash /tmp/install_ha_proxy.sh"
367 scp ${WORKSPACE}/haproxy.cfg ${MGRIP}:/tmp
368 scp ${WORKSPACE}/deploy_ha_proxy.sh ${MGRIP}:/tmp
369 ${SSH} ${MGRIP} "sudo bash /tmp/deploy_ha_proxy.sh"
370 }
371
372 function collect_logs_and_exit () {
373 set +e  # We do not want to create red dot just because something went wrong while fetching logs.
374 for i in `seq 1 ${NUM_ODL_SYSTEM}`
375 do
376     CONTROLLERIP=ODL_SYSTEM_${i}_IP
377     echo "killing karaf process..."
378     ${SSH} "${!CONTROLLERIP}" bash -c 'ps axf | grep karaf | grep -v grep | awk '"'"'{print "kill -9 " $1}'"'"' | sh'
379 done
380
381 cat > extra_debug.sh << EOF
382 echo -e "/usr/sbin/lsmod | /usr/bin/grep openvswitch\n"
383 /usr/sbin/lsmod | /usr/bin/grep openvswitch
384 echo -e "\ngrep ct_ /var/log/openvswitch/ovs-vswitchd.log\n"
385 grep ct_ /var/log/openvswitch/ovs-vswitchd.log
386 EOF
387
388 sleep 5
389 # FIXME: Do not create .tar and gzip before copying.
390 for i in `seq 1 ${NUM_ODL_SYSTEM}`
391 do
392     CONTROLLERIP=ODL_SYSTEM_${i}_IP
393     ${SSH} "${!CONTROLLERIP}"  "cp -r /tmp/${BUNDLEFOLDER}/data/log /tmp/odl_log"
394     ${SSH} "${!CONTROLLERIP}"  "tar -cf /tmp/odl${i}_karaf.log.tar /tmp/odl_log/*"
395     scp "${!CONTROLLERIP}:/tmp/odl${i}_karaf.log.tar" "${WORKSPACE}/odl${i}_karaf.log.tar"
396     tar -xvf ${WORKSPACE}/odl${i}_karaf.log.tar -C . --strip-components 2 --transform s/karaf/odl${i}_karaf/g
397     grep "ROBOT MESSAGE\| ERROR " odl${i}_karaf.log > odl${i}_err.log
398     grep "ROBOT MESSAGE\|Exception" odl${i}_karaf.log > odl${i}_exception.log
399     grep "ROBOT MESSAGE\| ERROR \| WARN \|Exception" odl${i}_karaf.log > odl${i}_err_warn_exception.log
400     rm ${WORKSPACE}/odl${i}_karaf.log.tar
401 done
402
403 # Since this log collection work is happening before the archive build macro which also
404 # creates the ${WORKSPACE}/archives dir, we have to do it here first.  The mkdir in the
405 # archives build step will essentially be a noop.
406 mkdir -p ${WORKSPACE}/archives
407
408 # Control Node
409 for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`
410 do
411     OS_CTRL_IP=OPENSTACK_CONTROL_NODE_${i}_IP
412     OS_CTRL_FOLDER="control_${i}"
413     mkdir -p ${OS_CTRL_FOLDER}
414     scp ${!OS_CTRL_IP}:/opt/stack/devstack/nohup.out ${OS_CTRL_FOLDER}/stack.log
415     scp ${!OS_CTRL_IP}:/var/log/openvswitch/ovs-vswitchd.log ${OS_CTRL_FOLDER}/ovs-vswitchd.log
416     scp ${!OS_CTRL_IP}:/etc/neutron/neutron.conf ${OS_CTRL_FOLDER}/neutron.conf
417     scp ${!OS_CTRL_IP}:/etc/nova/nova.conf ${OS_CTRL_FOLDER}/nova.conf
418     rsync -avhe ssh ${!OS_CTRL_IP}:/opt/stack/logs/* ${OS_CTRL_FOLDER} # rsync to prevent copying of symbolic links
419     scp extra_debug.sh ${!OS_CTRL_IP}:/tmp
420     ${SSH} ${!OS_CTRL_IP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
421     scp ${!OS_CTRL_IP}:/tmp/extra_debug.log ${OS_CTRL_FOLDER}/extra_debug.log
422     scp ${!OS_CTRL_IP}:/opt/stack/devstack/local.conf ${OS_CTRL_FOLDER}/local.conf
423     mv ${OS_CTRL_FOLDER} ${WORKSPACE}/archives/
424 done
425
426 # Compute Nodes
427 for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`
428 do
429     OSIP=OPENSTACK_COMPUTE_NODE_${i}_IP
430     OS_COMPUTE_FOLDER="compute_${i}"
431     mkdir -p ${OS_COMPUTE_FOLDER}
432     scp ${!OSIP}:/opt/stack/devstack/nohup.out ${OS_COMPUTE_FOLDER}/stack.log
433     scp ${!OSIP}:/var/log/openvswitch/ovs-vswitchd.log ${OS_COMPUTE_FOLDER}/ovs-vswitchd.log
434     scp ${!OSIP}:/etc/nova/nova.conf ${OS_COMPUTE_FOLDER}/nova.conf
435     rsync -avhe ssh ${!OSIP}:/opt/stack/logs/* ${OS_COMPUTE_FOLDER} # rsync to prevent copying of symbolic links
436     scp extra_debug.sh ${!OSIP}:/tmp
437     ${SSH} ${!OSIP} "bash /tmp/extra_debug.sh > /tmp/extra_debug.log"
438     scp ${!OSIP}:/tmp/extra_debug.log ${OS_COMPUTE_FOLDER}/extra_debug.log
439     mv local.conf_compute_${!OSIP} ${OS_COMPUTE_FOLDER}/local.conf
440     mv ${OS_COMPUTE_FOLDER} ${WORKSPACE}/archives/
441 done
442
443 ls local.conf* | xargs -I % mv % %.log
444
445 # Tempest
446 DEVSTACK_TEMPEST_DIR="/opt/stack/tempest"
447 if $(ssh ${OPENSTACK_CONTROL_NODE_1_IP} "sudo sh -c '[ -f ${DEVSTACK_TEMPEST_DIR}/.testrepository/0 ]'"); then # if Tempest results exist
448     ssh ${OPENSTACK_CONTROL_NODE_1_IP} "for I in \$(sudo ls ${DEVSTACK_TEMPEST_DIR}/.testrepository/ | grep -E '^[0-9]+$'); do sudo sh -c \"${DEVSTACK_TEMPEST_DIR}/.tox/tempest/bin/subunit-1to2 < ${DEVSTACK_TEMPEST_DIR}/.testrepository/\${I} >> ${DEVSTACK_TEMPEST_DIR}/subunit_log.txt\"; done"
449     ssh ${OPENSTACK_CONTROL_NODE_1_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'"
450     TEMPEST_LOGS_DIR=${WORKSPACE}/archives/tempest
451     mkdir -p ${TEMPEST_LOGS_DIR}
452     scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest_results.html ${TEMPEST_LOGS_DIR}
453     scp ${OPENSTACK_CONTROL_NODE_1_IP}:${DEVSTACK_TEMPEST_DIR}/tempest.log ${TEMPEST_LOGS_DIR}
454     mv ${WORKSPACE}/tempest_output* ${TEMPEST_LOGS_DIR}
455 fi
456 }
457
458 cat > ${WORKSPACE}/disable_firewall.sh << EOF
459 sudo systemctl stop firewalld
460 sudo systemctl stop iptables
461 true
462 EOF
463
464 cat > ${WORKSPACE}/get_devstack.sh << EOF
465 sudo systemctl stop firewalld
466 sudo yum install bridge-utils -y
467 sudo systemctl stop  NetworkManager
468 #Disable NetworkManager and kill dhclient and dnsmasq
469 sudo systemctl stop NetworkManager
470 sudo killall dhclient
471 sudo killall dnsmasq
472 #Workaround for mysql failure
473 echo "127.0.0.1    localhost \${HOSTNAME}" > /tmp/hosts
474 echo "::1   localhost  \${HOSTNAME}" >> /tmp/hosts
475 sudo mv /tmp/hosts /etc/hosts
476 sudo /usr/sbin/brctl addbr br100
477 #sudo ifconfig eth0 mtu 2000
478 sudo mkdir /opt/stack
479 sudo chmod 777 /opt/stack
480 cd /opt/stack
481 git clone https://git.openstack.org/openstack-dev/devstack
482 cd devstack
483 git checkout $OPENSTACK_BRANCH
484 EOF
485
486 [ "$NUM_OPENSTACK_SITES" ] || NUM_OPENSTACK_SITES=1
487 compute_index=1
488 odl_index=1
489 os_node_list=()
490 os_interval=$(( ${NUM_OPENSTACK_SYSTEM} / ${NUM_OPENSTACK_SITES} ))
491 ha_proxy_index=${os_interval}
492
493 cat > "${WORKSPACE}/manual_install_package.sh" << EOF
494 cd /opt/stack
495 git clone "\$1"
496 cd "\$2"
497 git checkout "\$3"
498 sudo python setup.py install
499 EOF
500
501 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
502 do
503     if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
504         echo "Configure HAProxy"
505         ODL_HAPROXYIP_PARAM=OPENSTACK_HAPROXY_${i}_IP
506         ha_proxy_index=$(( $ha_proxy_index + $os_interval ))
507         odl_index=$(((i - 1) * 3 + 1))
508         ODL_IP_PARAM1=ODL_SYSTEM_$((odl_index++))_IP
509         ODL_IP_PARAM2=ODL_SYSTEM_$((odl_index++))_IP
510         ODL_IP_PARAM3=ODL_SYSTEM_$((odl_index++))_IP
511         ODLMGRIP[$i]=${!ODL_HAPROXYIP_PARAM} # ODL Northbound uses HAProxy VIP
512         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM1},${!ODL_IP_PARAM2},${!ODL_IP_PARAM3}" # OVSDB connects to all ODL IPs
513
514         configure_haproxy_for_neutron_requests ${!ODL_HAPROXYIP_PARAM} "${ODL_OVS_MGRS[$i]}"
515     else
516         ODL_IP_PARAM=ODL_SYSTEM_${i}_IP
517         ODL_OVS_MGRS[$i]="${!ODL_IP_PARAM}" # ODL Northbound uses ODL IP
518         ODLMGRIP[$i]=${!ODL_IP_PARAM} # OVSDB connects to ODL IP
519     fi
520 done
521
522 for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`
523 do
524     echo "Stack the Control Node"
525     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
526     scp ${WORKSPACE}/get_devstack.sh ${!CONTROLIP}:/tmp
527     ${SSH} ${!CONTROLIP} "bash /tmp/get_devstack.sh"
528     create_control_node_local_conf ${!CONTROLIP} ${ODLMGRIP[$i]} "${ODL_OVS_MGRS[$i]}"
529     scp ${WORKSPACE}/local.conf_control_${!CONTROLIP} ${!CONTROLIP}:/opt/stack/devstack/local.conf
530     if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
531         # Workaround for problems with latest versions/specified versions in requirements of openstack
532         # Openstacksdk,libvirt-python -> the current version does not work with  Mitaka diue to some requirements
533         # conflict and breaks when trying to stack
534         # paramiko -> Problems with tempest tests due to paramiko incompatibility with pycrypto.
535         # the problem has been solved with  version 1.17. If the latest version of paramiko is used, it causes
536         # other timeout problems
537         ssh ${!CONTROLIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/mitaka; sed -i /openstacksdk/d upper-constraints.txt; sed -i /libvirt-python/d upper-constraints.txt; sed -i /paramiko/d upper-constraints.txt"
538         scp "${WORKSPACE}/manual_install_package.sh"  "${!CONTROLIP}:/tmp"
539         ssh ${!CONTROLIP} "sudo pip install deprecation"
540         # Fix for recent requirements update  in the  master branch of the sdk.The section must be replaced with a better fix.
541         ssh "${!CONTROLIP}" "sh /tmp/manual_install_package.sh https://github.com/openstack/python-openstacksdk python-openstacksdk 0.9.14"
542         ssh "${!CONTROLIP}" "sh /tmp/manual_install_package.sh https://github.com/paramiko/paramiko paramiko 1.17"
543     fi
544     ssh ${!CONTROLIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
545     ssh ${!CONTROLIP} "ps -ef | grep stack.sh"
546     ssh ${!CONTROLIP} "ls -lrt /opt/stack/devstack/nohup.out"
547     os_node_list+=(${!CONTROLIP})
548
549     #Workaround for stable/newton jobs
550     if [ "${ODL_ML2_BRANCH}" == "stable/newton" ]; then
551         ssh ${!CONTROLIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/newton; sed -i /appdirs/d upper-constraints.txt"
552     fi
553 done
554
555 for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`
556 do
557     echo "Stack the Compute Node"
558     NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
559     SITE_INDEX=$((((i - 1) / NUM_COMPUTES_PER_SITE) + 1)) # We need the site index to infer the control node IP for this compute
560     COMPUTEIP=OPENSTACK_COMPUTE_NODE_${i}_IP
561     CONTROLIP=OPENSTACK_CONTROL_NODE_${SITE_INDEX}_IP
562     scp ${WORKSPACE}/get_devstack.sh  ${!COMPUTEIP}:/tmp
563     ${SSH} ${!COMPUTEIP} "bash /tmp/get_devstack.sh"
564     create_compute_node_local_conf ${!COMPUTEIP} ${!CONTROLIP} ${ODLMGRIP[$SITE_INDEX]} "${ODL_OVS_MGRS[$SITE_INDEX]}"
565     scp ${WORKSPACE}/local.conf_compute_${!COMPUTEIP} ${!COMPUTEIP}:/opt/stack/devstack/local.conf
566     if [ "${ODL_ML2_BRANCH}" == "stable/mitaka" ]; then
567         ssh ${!COMPUTEIP} "cd /opt/stack; git clone https://git.openstack.org/openstack/requirements; cd requirements; git checkout stable/mitaka; sed -i /libvirt-python/d upper-constraints.txt"
568     fi
569     ssh ${!COMPUTEIP} "cd /opt/stack/devstack; nohup ./stack.sh > /opt/stack/devstack/nohup.out 2>&1 &"
570     ssh ${!COMPUTEIP} "ps -ef | grep stack.sh"
571     os_node_list+=(${!COMPUTEIP})
572 done
573
574 echo ${os_node_list[*]}
575
576 cat > ${WORKSPACE}/check_stacking.sh << EOF
577 > /tmp/stack_progress
578 ps -ef | grep "stack.sh" | grep -v grep
579 ret=\$?
580 if [ \${ret} -eq 1 ]; then
581   grep "This is your host IP address:" /opt/stack/devstack/nohup.out
582   if [ \$? -eq 0 ]; then
583      echo "Stacking Complete" > /tmp/stack_progress
584   else
585      echo "Stacking Failed" > /tmp/stack_progress
586   fi
587 elif [ \${ret} -eq 0 ]; then
588   echo "Still Stacking" > /tmp/stack_progress
589 fi
590 EOF
591
592 #the checking is repeated for an hour
593 iteration=0
594 in_progress=1
595 while [ ${in_progress} -eq 1 ]; do
596 iteration=$(($iteration + 1))
597 for index in ${!os_node_list[@]}
598 do
599 echo "Check the status of stacking in ${os_node_list[index]}"
600 scp ${WORKSPACE}/check_stacking.sh  ${os_node_list[index]}:/tmp
601 ${SSH} ${os_node_list[index]} "bash /tmp/check_stacking.sh"
602 scp ${os_node_list[index]}:/tmp/stack_progress .
603 #debug
604 cat stack_progress
605 stacking_status=`cat stack_progress`
606 if [ "$stacking_status" == "Still Stacking" ]; then
607   continue
608 elif [ "$stacking_status" == "Stacking Failed" ]; then
609   collect_logs_and_exit
610   exit 1
611 elif [ "$stacking_status" == "Stacking Complete" ]; then
612   unset os_node_list[index]
613   if  [ ${#os_node_list[@]} -eq 0 ]; then
614      in_progress=0
615   fi
616 fi
617 done
618  echo "sleep for a minute before the next check"
619  sleep 60
620  if [ ${iteration} -eq 60 ]; then
621   collect_logs_and_exit
622   exit 1
623  fi
624 done
625
626 NUM_COMPUTES_PER_SITE=$((NUM_OPENSTACK_COMPUTE_NODES / NUM_OPENSTACK_SITES))
627 for i in `seq 1 ${NUM_OPENSTACK_SITES}`
628 do
629     echo "Configure the Control Node"
630     CONTROLIP=OPENSTACK_CONTROL_NODE_${i}_IP
631
632     #Need to disable firewalld and iptables in control node
633     echo "Stop Firewall in Control Node for compute nodes to be able to reach the ports and add to hypervisor-list"
634     scp ${WORKSPACE}/disable_firewall.sh ${!CONTROLIP}:/tmp
635     ${SSH} ${!CONTROLIP} "sudo bash /tmp/disable_firewall.sh"
636
637     echo "sleep for 60s and print hypervisor-list"
638     sleep 60
639     ${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; nova hypervisor-list"
640     # in the case that we are doing openstack (control + compute) all in one node, then the number of hypervisors
641     # will be the same as the number of openstack systems. However, if we are doing multinode openstack then the
642     # assumption is we have a single control node and the rest are compute nodes, so the number of expected hypervisors
643     # is one less than the total number of openstack systems
644     if [ $((NUM_OPENSTACK_SYSTEM / NUM_OPENSTACK_SITES - 1)) -eq 1 ]; then
645         expected_num_hypervisors=1
646     else
647         expected_num_hypervisors=${NUM_COMPUTES_PER_SITE}
648     fi
649     num_hypervisors=$(${SSH} ${!CONTROLIP} "cd /opt/stack/devstack; source openrc admin admin; openstack hypervisor list -f value | wc -l" | tail -1 | tr -d "\r")
650     if ! [ "${num_hypervisors}" ] || ! [ ${num_hypervisors} -eq ${expected_num_hypervisors} ]; then
651         echo "Error: Only $num_hypervisors hypervisors detected, expected $expected_num_hypervisors"
652         collect_logs_and_exit
653         exit 1
654     fi
655
656     # upgrading pip, urllib3 and httplib2 so that tempest tests can be run on openstack control node
657     # this needs to happen after devstack runs because it seems devstack is pulling in specific versions
658     # of these libs that are not working for tempest.
659     ${SSH} ${!CONTROLIP} "sudo pip install --upgrade pip"
660     ${SSH} ${!CONTROLIP} "sudo pip install urllib3 --upgrade"
661     ${SSH} ${!CONTROLIP} "sudo pip install httplib2 --upgrade"
662
663     # Gather Compute IPs for the site
664     for j in `seq 1 ${NUM_COMPUTES_PER_SITE}`
665     do
666         COMPUTE_INDEX=$(((i-1) * NUM_COMPUTES_PER_SITE + j))
667         IP_VAR=OPENSTACK_COMPUTE_NODE_${COMPUTE_INDEX}_IP
668         COMPUTE_IPS[$((j-1))]=${!IP_VAR}
669     done
670
671     # Need to disable firewalld and iptables in compute nodes as well
672     for ip in ${COMPUTE_IPS[*]}
673     do
674         scp ${WORKSPACE}/disable_firewall.sh "${ip}:/tmp"
675         ${SSH} "${ip}" "sudo bash /tmp/disable_firewall.sh"
676     done
677
678     # External Network
679     echo "prepare external networks by adding vxlan tunnels between all nodes on a separate bridge..."
680     # FIXME Should there be a unique gateway IP and devstack index for each site?
681     devstack_index=1
682     for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}
683     do
684         # FIXME - Workaround, ODL (new netvirt) currently adds PUBLIC_BRIDGE as a port in br-int since it doesn't see such a bridge existing when we stack
685         ${SSH} $ip "sudo ovs-vsctl --if-exists del-port br-int $PUBLIC_BRIDGE"
686         ${SSH} $ip "sudo ovs-vsctl --may-exist add-br $PUBLIC_BRIDGE -- set bridge $PUBLIC_BRIDGE other-config:disable-in-band=true other_config:hwaddr=f6:00:00:ff:01:0$((devstack_index++))"
687     done
688
689     # ipsec support
690     if [ "${IPSEC_VXLAN_TUNNELS_ENABLED}" == "yes" ]; then
691         ALL_NODES=(${!CONTROLIP} ${COMPUTE_IPS[*]})
692         for ((inx_ip1=0; inx_ip1<$((${#ALL_NODES[@]} - 1)); inx_ip1++))
693         do
694             for ((inx_ip2=$((inx_ip1 + 1)); inx_ip2<${#ALL_NODES[@]}; inx_ip2++))
695             do
696                 KEY1=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
697                 KEY2=0x$(dd if=/dev/urandom count=32 bs=1 2> /dev/null| xxd -p -c 64)
698                 ID=0x$(dd if=/dev/urandom count=4 bs=1 2> /dev/null| xxd -p -c 8)
699                 ip1=${ALL_NODES[$inx_ip1]}
700                 ip2=${ALL_NODES[$inx_ip2]}
701                 ${SSH} $ip1 "sudo ip xfrm state add src $ip1 dst $ip2 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
702                 ${SSH} $ip1 "sudo ip xfrm state add src $ip2 dst $ip1 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
703                 ${SSH} $ip1 "sudo ip xfrm policy add src $ip1 dst $ip2 proto udp dir out tmpl src $ip1 dst $ip2 proto esp reqid $ID mode transport"
704                 ${SSH} $ip1 "sudo ip xfrm policy add src $ip2 dst $ip1 proto udp dir in tmpl src $ip2 dst $ip1 proto esp reqid $ID mode transport"
705
706                 ${SSH} $ip2 "sudo ip xfrm state add src $ip2 dst $ip1 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
707                 ${SSH} $ip2 "sudo ip xfrm state add src $ip1 dst $ip2 proto esp spi $ID reqid $ID mode transport auth sha256 $KEY1 enc aes $KEY2"
708                 ${SSH} $ip2 "sudo ip xfrm policy add src $ip2 dst $ip1 proto udp dir out tmpl src $ip2 dst $ip1 proto esp reqid $ID mode transport"
709                 ${SSH} $ip2 "sudo ip xfrm policy add src $ip1 dst $ip2 proto udp dir in tmpl src $ip1 dst $ip2 proto esp reqid $ID mode transport"
710             done
711         done
712
713         for ip in ${!CONTROLIP} ${COMPUTE_IPS[*]}
714         do
715             echo "ip xfrm configuration for node $ip:"
716             ${SSH} $ip "sudo ip xfrm policy list"
717             ${SSH} $ip "sudo ip xfrm state list"
718         done
719     fi
720
721     # Control Node - PUBLIC_BRIDGE will act as the external router
722     GATEWAY_IP="10.10.10.250" # FIXME this should be a parameter, also shared with integration-test
723     GATEWAY_VLAN_ID=167
724     ${SSH} ${!CONTROLIP} "sudo ip link add link ${PUBLIC_BRIDGE} name ${PUBLIC_BRIDGE}.${GATEWAY_VLAN_ID} type vlan id ${GATEWAY_VLAN_ID}"
725     ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE} up"
726     ${SSH} ${!CONTROLIP} "sudo ifconfig ${PUBLIC_BRIDGE}.${GATEWAY_VLAN_ID} up ${GATEWAY_IP}/24"
727
728     # Computes
729     compute_index=1
730     for compute_ip in ${COMPUTE_IPS[*]}
731     do
732         # Tunnel from controller to compute
733         COMPUTEPORT=compute$(( compute_index++ ))_vxlan
734         ${SSH} ${!CONTROLIP} "sudo ovs-vsctl add-port $PUBLIC_BRIDGE $COMPUTEPORT -- set interface $COMPUTEPORT type=vxlan options:local_ip="${!CONTROLIP}" options:remote_ip="$compute_ip" options:dst_port=9876 options:key=flow"
735         # Tunnel from compute to controller
736         CONTROLPORT="control_vxlan"
737         ${SSH} $compute_ip "sudo ovs-vsctl add-port $PUBLIC_BRIDGE $CONTROLPORT -- set interface $CONTROLPORT type=vxlan options:local_ip="$compute_ip" options:remote_ip="${!CONTROLIP}" options:dst_port=9876 options:key=flow"
738     done
739 done
740
741 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
742     odlmgrip=OPENSTACK_HAPROXY_1_IP
743     HA_PROXY_IP=${!odlmgrip}
744     HA_PROXY_1_IP=${!odlmgrip}
745     odlmgrip2=OPENSTACK_HAPROXY_2_IP
746     HA_PROXY_2_IP=${!odlmgrip2}
747     odlmgrip3=OPENSTACK_HAPROXY_1_IP
748     HA_PROXY_3_IP=${!odlmgrip3}
749 else
750     HA_PROXY_IP=${ODL_SYSTEM_IP}
751     HA_PROXY_1_IP=${ODL_SYSTEM_1_IP}
752     HA_PROXY_2_IP=${ODL_SYSTEM_2_IP}
753     HA_PROXY_3_IP=${ODL_SYSTEM_3_IP}
754 fi
755
756 echo "Locating test plan to use..."
757 testplan_filepath="${WORKSPACE}/test/csit/testplans/${STREAMTESTPLAN}"
758 if [ ! -f "${testplan_filepath}" ]; then
759     testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
760 fi
761
762 echo "Changing the testplan path..."
763 cat "${testplan_filepath}" | sed "s:integration:${WORKSPACE}:" > testplan.txt
764 cat testplan.txt
765
766 SUITES=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
767
768 #FIXME currently support only 1 site
769 echo "Starting Robot test suites ${SUITES} ..."
770 # please add pybot -v arguments on a single line and alphabetized
771 pybot -N ${TESTPLAN} --removekeywords wuks -c critical -e exclude \
772     -v BUNDLEFOLDER:${BUNDLEFOLDER} \
773     -v BUNDLE_URL:${ACTUALBUNDLEURL} \
774     -v CONTROLLER_USER:${USER} \
775     -v DEVSTACK_DEPLOY_PATH:/opt/stack/devstack \
776     -v HA_PROXY_IP:${HA_PROXY_IP} \
777     -v HA_PROXY_1_IP:${HA_PROXY_1_IP} \
778     -v HA_PROXY_2_IP:${HA_PROXY_2_IP} \
779     -v HA_PROXY_3_IP:${HA_PROXY_3_IP} \
780     -v JDKVERSION:${JDKVERSION} \
781     -v NEXUSURL_PREFIX:${NEXUSURL_PREFIX} \
782     -v NUM_ODL_SYSTEM:${NUM_ODL_SYSTEM} \
783     -v NUM_OPENSTACK_SITES:${NUM_OPENSTACK_SITES} \
784     -v NUM_OS_SYSTEM:${NUM_OPENSTACK_SYSTEM} \
785     -v NUM_TOOLS_SYSTEM:${NUM_TOOLS_SYSTEM} \
786     -v ODL_STREAM:${DISTROSTREAM} \
787     -v ODL_SYSTEM_IP:${ODL_SYSTEM_IP} \
788     -v ODL_SYSTEM_1_IP:${ODL_SYSTEM_1_IP} \
789     -v ODL_SYSTEM_2_IP:${ODL_SYSTEM_2_IP} \
790     -v ODL_SYSTEM_3_IP:${ODL_SYSTEM_3_IP} \
791     -v ODL_SYSTEM_4_IP:${ODL_SYSTEM_4_IP} \
792     -v ODL_SYSTEM_5_IP:${ODL_SYSTEM_5_IP} \
793     -v ODL_SYSTEM_6_IP:${ODL_SYSTEM_6_IP} \
794     -v ODL_SYSTEM_7_IP:${ODL_SYSTEM_7_IP} \
795     -v ODL_SYSTEM_8_IP:${ODL_SYSTEM_8_IP} \
796     -v ODL_SYSTEM_9_IP:${ODL_SYSTEM_9_IP} \
797     -v OS_CONTROL_NODE_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
798     -v OS_CONTROL_NODE_1_IP:${OPENSTACK_CONTROL_NODE_1_IP} \
799     -v OS_CONTROL_NODE_2_IP:${OPENSTACK_CONTROL_NODE_2_IP} \
800     -v OS_CONTROL_NODE_3_IP:${OPENSTACK_CONTROL_NODE_3_IP} \
801     -v OPENSTACK_BRANCH:${OPENSTACK_BRANCH} \
802     -v OS_COMPUTE_1_IP:${OPENSTACK_COMPUTE_NODE_1_IP} \
803     -v OS_COMPUTE_2_IP:${OPENSTACK_COMPUTE_NODE_2_IP} \
804     -v OS_COMPUTE_3_IP:${OPENSTACK_COMPUTE_NODE_3_IP} \
805     -v OS_COMPUTE_4_IP:${OPENSTACK_COMPUTE_NODE_4_IP} \
806     -v OS_COMPUTE_5_IP:${OPENSTACK_COMPUTE_NODE_5_IP} \
807     -v OS_COMPUTE_6_IP:${OPENSTACK_COMPUTE_NODE_6_IP} \
808     -v OS_USER:${USER} \
809     -v PUBLIC_PHYSICAL_NETWORK:${PUBLIC_PHYSICAL_NETWORK} \
810     -v SECURITY_GROUP_MODE:${SECURITY_GROUP_MODE} \
811     -v TOOLS_SYSTEM_IP:${TOOLS_SYSTEM_1_IP} \
812     -v TOOLS_SYSTEM_1_IP:${TOOLS_SYSTEM_1_IP} \
813     -v TOOLS_SYSTEM_2_IP:${TOOLS_SYSTEM_2_IP} \
814     -v USER_HOME:${HOME} \
815     -v WORKSPACE:/tmp \
816     ${TESTOPTIONS} ${SUITES} || true
817
818 echo "Examining the files in data/log and checking filesize"
819 ssh ${ODL_SYSTEM_IP} "ls -altr /tmp/${BUNDLEFOLDER}/data/log/"
820 ssh ${ODL_SYSTEM_IP} "du -hs /tmp/${BUNDLEFOLDER}/data/log/*"
821
822 echo "Tests Executed"
823 collect_logs_and_exit
824
825 true  # perhaps Jenkins is testing last exit code
826 # vim: ts=4 sw=4 sts=4 et ft=sh :