Adding Quagga to build
[apex.git] / lib / overcloud-deploy-functions.sh
1 #!/usr/bin/env bash
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 ##preping it for deployment and launch the deploy
12 ##params: none
13 function overcloud_deploy {
14   local num_compute_nodes
15   local num_control_nodes
16
17   if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
18     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
19       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
20     elif [ "${deploy_options_array['vpn']}" == 'True' ]; then
21       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-bgpvpn.yaml"
22       if [ "${deploy_options_array['gluon']}" == 'True' ]; then
23         DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/services/gluon.yaml"
24       fi
25     elif [ "${deploy_options_array['vpp']}" == 'True' ]; then
26       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_fdio.yaml"
27     else
28       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-l3.yaml"
29     fi
30     SDN_IMAGE=opendaylight
31   elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
32     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
33     SDN_IMAGE=opendaylight
34   elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
35     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
36       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos_sfc.yaml"
37     else
38       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
39     fi
40     SDN_IMAGE=onos
41   elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
42     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
43     exit 1
44   elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
45     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
46     if [ "${deploy_options_array['vpp']}" == 'True' ]; then
47       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-ml2-networking-vpp.yaml"
48     fi
49     SDN_IMAGE=opendaylight
50   else
51     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
52     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
53     exit 1
54   fi
55
56   # Enable Tacker
57   if [ "${deploy_options_array['tacker']}" == 'True' ]; then
58     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/enable_tacker.yaml"
59   fi
60
61   # Make sure the correct overcloud image is available
62   if [ ! -f $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
63       echo "${red} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
64       echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
65       exit 1
66   fi
67
68   echo "Copying overcloud image to Undercloud"
69   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
70   scp ${SSH_OPTIONS[@]} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
71
72   if [ "${deploy_options_array['vpn']}" == 'True' ]; then
73       echo -e "${blue}INFO: Enabling ZRPC and Quagga${reset}"
74       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
75       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y install /root/quagga/*.rpm" \
76                                                --run-command "systemctl enable zrpcd" \
77                                                -a overcloud-full.qcow2
78 EOI
79   fi
80
81   # Install ovs-dpdk inside the overcloud image if it is enabled.
82   if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' || "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
83     # install dpdk packages before ovs
84     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
85
86     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
87       cat << EOF > vfio_pci.modules
88 #!/bin/bash
89 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
90 EOF
91
92       cat << EOF > uio_pci_generic.modules
93 #!/bin/bash
94 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
95 EOF
96
97       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
98                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
99                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
100                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
101                                                -a overcloud-full.qcow2
102
103       if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
104         sudo sed -i '/NeutronOVSDataPathType:/c\  NeutronOVSDataPathType: netdev' /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml
105         LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/dpdk_rpms/*" \
106                                                  --run-command "sed -i '/RuntimeDirectoryMode=.*/d' /usr/lib/systemd/system/openvswitch-nonetwork.service" \
107                                                  --run-command "printf \"%s\\n\" RuntimeDirectoryMode=0775 Group=qemu UMask=0002 >> /usr/lib/systemd/system/openvswitch-nonetwork.service" \
108                                                  --run-command "sed -i 's/\\(^\\s\\+\\)\\(start_daemon "$OVS_VSWITCHD_PRIORITY"\\)/\\1umask 0002 \\&\\& \\2/' /usr/share/openvswitch/scripts/ovs-ctl" \
109                                                  -a overcloud-full.qcow2
110       fi
111
112 EOI
113
114   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
115     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
116     exit 1
117   fi
118
119   if [ "$debug" == 'TRUE' ]; then
120     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex"
121   fi
122
123   # upgrade ovs into ovs 2.5.90 with NSH function if SFC is enabled
124   if [[ "${deploy_options_array['sfc']}" == 'True' && "${deploy_options_array['dataplane']}" == 'ovs' ]]; then
125     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
126          LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_kmod_rpm_name}" \
127                                                   --run-command "yum upgrade -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_rpm_name}" \
128                                                   -a overcloud-full.qcow2
129 EOI
130   fi
131
132   # Set ODL version accordingly
133   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && -n "${deploy_options_array['odl_version']}" ]]; then
134     case "${deploy_options_array['odl_version']}" in
135       beryllium) odl_version=''
136               ;;
137       boron)  odl_version='boron'
138               ;;
139       carbon) odl_version='master'
140               ;;
141       *) echo -e "${red}Invalid ODL version ${deploy_options_array['odl_version']}.  Please use 'carbon' or 'boron' values.${reset}"
142          exit 1
143          ;;
144     esac
145
146     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
147       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
148                                                --run-command "yum -y install /root/${odl_version}/*" \
149                                                -a overcloud-full.qcow2
150 EOI
151   fi
152
153   # Add performance deploy options if they have been set
154   if [ ! -z "${deploy_options_array['performance']}" ]; then
155
156     # Remove previous kernel args files per role
157     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Compute-kernel_params.txt"
158     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Controller-kernel_params.txt"
159
160     # Push performance options to subscript to modify per-role images as needed
161     for option in "${performance_options[@]}" ; do
162       echo -e "${blue}Setting performance option $option${reset}"
163       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "dataplane=${deploy_options_array['dataplane']} bash build_perf_image.sh $option"
164     done
165
166     # Build IPA kernel option ramdisks
167     ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
168 /bin/cp -f /home/stack/ironic-python-agent.initramfs /root/
169 mkdir -p ipa/
170 pushd ipa
171 gunzip -c ../ironic-python-agent.initramfs | cpio -i
172 if [ ! -f /home/stack/Compute-kernel_params.txt ]; then
173   touch /home/stack/Compute-kernel_params.txt
174   chown stack /home/stack/Compute-kernel_params.txt
175 fi
176 /bin/cp -f /home/stack/Compute-kernel_params.txt tmp/kernel_params.txt
177 echo "Compute params set: "
178 cat tmp/kernel_params.txt
179 /bin/cp -f /root/image.py usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.py
180 /bin/cp -f /root/image.pyc usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.pyc
181 find . | cpio -o -H newc | gzip > /home/stack/Compute-ironic-python-agent.initramfs
182 chown stack /home/stack/Compute-ironic-python-agent.initramfs
183 if [ ! -f /home/stack/Controller-kernel_params.txt ]; then
184   touch /home/stack/Controller-kernel_params.txt
185   chown stack /home/stack/Controller-kernel_params.txt
186 fi
187 /bin/cp -f /home/stack/Controller-kernel_params.txt tmp/kernel_params.txt
188 echo "Controller params set: "
189 cat tmp/kernel_params.txt
190 find . | cpio -o -H newc | gzip > /home/stack/Controller-ironic-python-agent.initramfs
191 chown stack /home/stack/Controller-ironic-python-agent.initramfs
192 popd
193 /bin/rm -rf ipa/
194 EOI
195
196     # set NIC heat params and resource registry
197     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
198 if [ -n "${private_network_compute_interface}" ]; then
199   sudo sed -i '/ComputeTenantNIC:/c\  ComputeTenantNIC: '${private_network_compute_interface} /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml
200 fi
201 if [ -n "${private_network_controller_interface}" ]; then
202   sudo sed -i '/ControllerTenantNIC:/c\  ControllerTenantNIC: '${private_network_controller_interface} /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml
203 fi
204 # TODO: PublicNIC is not used today, however, in the future, we'll bind public nic to DPDK as well for certain scenarios. At that time,
205 # we'll need to make sure public network is enabled.
206 if [ -n "${public_network_compute_interface}" ]; then
207   sudo sed -i '/ComputePublicNIC:/c\  ComputePublicNIC: '${public_network_compute_interface} /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml
208 fi
209 if [ -n "${public_network_controller_interface}" ]; then
210   sudo sed -i '/ControllerPublicNIC:/c\  ControllerPublicNIC: '${public_network_controller_interface} /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml
211 fi
212 EOI
213
214     echo -e "${blue}INFO: Including /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml ${reset}"
215     if [ "$debug" == 'TRUE' ]; then
216       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "cat /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml"
217     fi
218     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml"
219   fi
220
221   # check if ceph should be enabled
222   if [ "${deploy_options_array['ceph']}" == 'True' ]; then
223     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
224   fi
225
226   #DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml"
227   DEPLOY_OPTIONS+=" -e network-environment.yaml"
228
229
230   # get number of nodes available in inventory
231   num_control_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:control /home/stack/instackenv.json")
232   num_compute_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:compute /home/stack/instackenv.json")
233
234   # check if HA is enabled
235   if [[ "$ha_enabled" == "True" ]]; then
236     if [ "$num_control_nodes" -lt 3 ]; then
237       echo -e "${red}ERROR: Number of control nodes in inventory is less than 3 and HA is enabled: ${num_control_nodes}. Check your inventory file.${reset}"
238       exit 1
239     else
240      DEPLOY_OPTIONS+=" --control-scale ${num_control_nodes}"
241      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
242      echo -e "${blue}INFO: Number of control nodes set for deployment: ${num_control_nodes}${reset}"
243     fi
244   else
245     if [ "$num_control_nodes" -lt 1 ]; then
246       echo -e "${red}ERROR: Number of control nodes in inventory is less than 1: ${num_control_nodes}. Check your inventory file.${reset}"
247       exit 1
248     fi
249   fi
250
251   if [ "$num_compute_nodes" -le 0 ]; then
252     echo -e "${red}ERROR: Invalid number of compute nodes: ${num_compute_nodes}. Check your inventory file.${reset}"
253     exit 1
254   else
255     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${num_compute_nodes}${reset}"
256     DEPLOY_OPTIONS+=" --compute-scale ${num_compute_nodes}"
257   fi
258
259   DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
260
261   DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
262   if [[ "$virtual" == "TRUE" ]]; then
263      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
264   fi
265
266   DEPLOY_OPTIONS+=" -e ${ENV_FILE}"
267
268   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
269
270   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
271 # Create a key for use by nova for live migration
272 echo "Creating nova SSH key for nova resize support"
273 ssh-keygen -f nova_id_rsa -b 1024 -P ""
274 public_key=\'\$(cat nova_id_rsa.pub | cut -d ' ' -f 2)\'
275 sed -i "s#replace_public_key:#key: \$public_key#g" ${ENV_FILE}
276 python -c 'open("opnfv-environment-new.yaml", "w").write((open("${ENV_FILE}").read().replace("replace_private_key:", "key: \"" + "".join(open("nova_id_rsa").readlines()).replace("\\n","\\\n") + "\"")))'
277 mv -f opnfv-environment-new.yaml ${ENV_FILE}
278
279 source stackrc
280 set -o errexit
281 # Workaround for APEX-207 where sometimes swift proxy is down
282 if ! sudo systemctl status openstack-swift-proxy > /dev/null; then
283   sudo systemctl restart openstack-swift-proxy
284 fi
285 echo "Uploading overcloud glance images"
286 openstack overcloud image upload
287
288 echo "Configuring undercloud and discovering nodes"
289 openstack baremetal import --json instackenv.json
290
291 bash -x set_perf_images.sh ${performance_roles[@]}
292 if [[ -z "$virtual" ]]; then
293   openstack baremetal introspection bulk start
294   if [[ -n "$root_disk_list" ]]; then
295     openstack baremetal configure boot --root-device=${root_disk_list}
296   else
297     openstack baremetal configure boot
298   fi
299 else
300   openstack baremetal configure boot
301 fi
302
303 echo "Configuring flavors"
304 for flavor in baremetal control compute; do
305   echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
306   if openstack flavor list | grep \${flavor}; then
307     openstack flavor delete \${flavor}
308   fi
309   openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
310   if ! openstack flavor list | grep \${flavor}; then
311     echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
312   fi
313 done
314 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
315 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
316 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
317 echo "Configuring nameserver on ctlplane network"
318 dns_server_ext=''
319 for dns_server in ${dns_servers}; do
320   dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
321 done
322 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
323 sed -i '/CloudDomain:/c\  CloudDomain: '${domain_name} ${ENV_FILE}
324 echo "Executing overcloud deployment, this should run for an extended period without output."
325 sleep 60 #wait for Hypervisor stats to check-in to nova
326 # save deploy command so it can be used for debugging
327 cat > deploy_command << EOF
328 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
329 EOF
330 EOI
331
332   if [ "$interactive" == "TRUE" ]; then
333     if ! prompt_user "Overcloud Deployment"; then
334       echo -e "${blue}INFO: User requests exit${reset}"
335       exit 0
336     fi
337   fi
338
339   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
340 source stackrc
341 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
342 if ! openstack stack list | grep CREATE_COMPLETE 1>/dev/null; then
343   $(typeset -f debug_stack)
344   debug_stack
345   exit 1
346 fi
347 EOI
348
349   # Configure DPDK
350   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
351     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
352 source stackrc
353 set -o errexit
354 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
355 echo "Running DPDK test app on \$node"
356 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
357 set -o errexit
358 sudo dpdk_helloworld --no-pci
359 sudo dpdk_nic_bind -s
360 EOF
361 done
362 EOI
363   fi
364
365   if [ "$debug" == 'TRUE' ]; then
366       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
367 source overcloudrc
368 echo "Keystone Endpoint List:"
369 openstack endpoint list
370 echo "Keystone Service List"
371 openstack service list
372 EOI
373   fi
374 }