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