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