Fixes OVS DPDK scenarios
[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   local dpdk_cores pmd_cores socket_mem ovs_dpdk_perf_flag ovs_option_heat_arr
17   declare -A ovs_option_heat_arr
18
19   ovs_option_heat_arr['dpdk_cores']=OvsDpdkCoreList
20   ovs_option_heat_arr['pmd_cores']=PmdCoreList
21   ovs_option_heat_arr['socket_memory']=OvsDpdkSocketMemory
22
23   # OPNFV Default Environment and Network settings
24   DEPLOY_OPTIONS+=" -e ${ENV_FILE}"
25   DEPLOY_OPTIONS+=" -e network-environment.yaml"
26
27   # Custom Deploy Environment Templates
28   if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
29     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
30       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
31     elif [ "${deploy_options_array['vpn']}" == 'True' ]; then
32       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-bgpvpn.yaml"
33       if [ "${deploy_options_array['gluon']}" == 'True' ]; then
34         DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/services/gluon.yaml"
35       fi
36     elif [ "${deploy_options_array['vpp']}" == 'True' ]; then
37       if [ "${deploy_options_array['sdn_l3']}" == "True" ]; then
38         DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-honeycomb.yaml"
39       else
40         DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-honeycomb-l2.yaml"
41       fi
42     else
43       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-opendaylight-l3.yaml"
44     fi
45     SDN_IMAGE=opendaylight
46   elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
47     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
48     SDN_IMAGE=opendaylight
49   elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
50     echo -e "${red}ERROR: ONOS is unsupported in Danube...exiting${reset}"
51     exit 1
52     #if [ "${deploy_options_array['sfc']}" == 'True' ]; then
53     #  DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos_sfc.yaml"
54     #else
55     #  DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
56     #fi
57     #SDN_IMAGE=onos
58   elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
59     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
60     exit 1
61   elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
62     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
63     if [ "${deploy_options_array['vpp']}" == 'True' ]; then
64       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-ml2-vpp.yaml"
65     elif [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
66       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/neutron-ovs-dpdk.yaml"
67     fi
68     SDN_IMAGE=opendaylight
69   else
70     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
71     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
72     exit 1
73   fi
74
75   # Enable Tacker
76   if [ "${deploy_options_array['tacker']}" == 'True' ]; then
77     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/enable_tacker.yaml"
78   fi
79
80   # Enable Congress
81   if [ "${deploy_options_array['congress']}" == 'True' ]; then
82     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/enable_congress.yaml"
83   fi
84
85   # Enable Real Time Kernel (kvm4nfv)
86   if [ "${deploy_options_array['rt_kvm']}" == 'True' ]; then
87     DEPLOY_OPTIONS+=" -e /home/stack/enable_rt_kvm.yaml"
88   fi
89
90   # Make sure the correct overcloud image is available
91   if [ ! -f $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
92       echo "${red} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
93       echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
94       exit 1
95   fi
96
97   echo "Copying overcloud image to Undercloud"
98   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
99   scp ${SSH_OPTIONS[@]} $IMAGES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
100
101   if [ "${deploy_options_array['vpn']}" == 'True' ]; then
102       echo -e "${blue}INFO: Enabling ZRPC and Quagga${reset}"
103       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
104       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y install /root/quagga/*.rpm" \
105                                                --run-command "systemctl enable zrpcd" \
106                                                -a overcloud-full.qcow2
107 EOI
108   fi
109
110   # Install ovs-dpdk inside the overcloud image if it is enabled.
111   if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' || "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
112     # install dpdk packages before ovs
113     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
114
115     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
116       cat << EOF > vfio_pci.modules
117 #!/bin/bash
118 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
119 EOF
120
121       cat << EOF > uio_pci_generic.modules
122 #!/bin/bash
123 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
124 EOF
125
126       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
127                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
128                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
129                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
130                                                -a overcloud-full.qcow2
131
132       if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
133         sed -i "/OS::TripleO::ComputeExtraConfigPre:/c\  OS::TripleO::ComputeExtraConfigPre: ./ovs-dpdk-preconfig.yaml" network-environment.yaml
134       fi
135
136 EOI
137
138   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
139     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
140     exit 1
141   fi
142
143   if [ "$debug" == 'TRUE' ]; then
144     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex"
145   fi
146
147   # upgrade ovs into ovs 2.5.90 with NSH function if SFC is enabled
148   if [[ "${deploy_options_array['sfc']}" == 'True' && "${deploy_options_array['dataplane']}" == 'ovs' ]]; then
149     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
150          LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_kmod_rpm_name}" \
151                                                   --run-command "yum upgrade -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_rpm_name}" \
152                                                   -a overcloud-full.qcow2
153 EOI
154   fi
155
156   # Patch neutron with using OVS external interface for router and add generic linux NS interface driver
157   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
158     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
159       LIBGUESTFS_BACKEND=direct virt-customize --run-command "cd /usr/lib/python2.7/site-packages/ && patch -p1 < neutron-patch-NSDriver.patch" \
160                                                -a overcloud-full.qcow2
161 EOI
162     # Configure routing node for odl_l3-fdio
163     if [[ "${deploy_options_array['sdn_l3']}" == 'True' ]]; then
164       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
165         sed -i "/opendaylight::vpp_routing_node:/c\    opendaylight::vpp_routing_node: ${deploy_options_array['odl_vpp_routing_node']}.${domain_name}" ${ENV_FILE}
166 EOI
167     fi
168   fi
169
170   if [ -n "${deploy_options_array['performance']}" ]; then
171     ovs_dpdk_perf_flag="False"
172     for option in "${performance_options[@]}" ; do
173       arr=($option)
174       # use compute's kernel settings for all nodes for now.
175       if [ "${arr[0]}" == "Compute" ] && [ "${arr[1]}" == "kernel" ]; then
176         kernel_args+=" ${arr[2]}=${arr[3]}"
177       fi
178       if [ "${arr[0]}" == "Compute" ] && [ "${arr[1]}" == "ovs" ]; then
179          eval "${arr[2]}=${arr[3]}"
180          ovs_dpdk_perf_flag="True"
181       fi
182     done
183
184     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
185       sed -i "/ComputeKernelArgs:/c\  ComputeKernelArgs: '$kernel_args'" ${ENV_FILE}
186       sed -i "$ a\resource_registry:\n  OS::TripleO::NodeUserData: first-boot.yaml" ${ENV_FILE}
187       sed -i "/NovaSchedulerDefaultFilters:/c\  NovaSchedulerDefaultFilters: 'RamFilter,ComputeFilter,AvailabilityZoneFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,NUMATopologyFilter'" ${ENV_FILE}
188 EOI
189
190     if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' && "$ovs_dpdk_perf_flag" == "True" ]]; then
191       for ovs_option in ${!ovs_option_heat_arr[@]}; do
192         if [ -n "${!ovs_option}" ]; then
193           ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
194             sed -i "/${ovs_option_heat_arr[$ovs_option]}:/c\  ${ovs_option_heat_arr[$ovs_option]}: ${!ovs_option}" ${ENV_FILE}
195 EOI
196         fi
197       done
198     fi
199   fi
200
201   if [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
202     if [ "${deploy_options_array['dataplane']}" == "fdio" ]; then
203       if [ "$tenant_nic_mapping_controller_members" == "$tenant_nic_mapping_compute_members" ]; then
204         ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
205           sed -i "/NeutronVPPAgentPhysnets:/c\  NeutronVPPAgentPhysnets: 'datacentre:${tenant_nic_mapping_controller_members}'" ${ENV_FILE}
206 EOI
207       else
208         echo -e "${red}Compute and Controller must use the same tenant nic name, please modify network setting file.${reset}"
209         exit 1
210       fi
211     fi
212   fi
213
214   # Set ODL version accordingly
215   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && -n "${deploy_options_array['odl_version']}" ]]; then
216     case "${deploy_options_array['odl_version']}" in
217       beryllium) odl_version=''
218               ;;
219       boron)  odl_version='boron'
220               ;;
221       carbon) odl_version='master'
222               ;;
223       *) echo -e "${red}Invalid ODL version ${deploy_options_array['odl_version']}.  Please use 'carbon' or 'boron' values.${reset}"
224          exit 1
225          ;;
226     esac
227
228     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
229       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
230                                                --run-command "yum -y install /root/${odl_version}/*" \
231                                                -a overcloud-full.qcow2
232 EOI
233   fi
234
235   # Override any previous packages if FDIO and ODL L2
236   #if [[ "${deploy_options_array['vpp']}" == 'True' && "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['sdn_l3']}" == "False" ]]; then
237   #  ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
238   #       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight vpp vpp-api-python vpp-lib vpp-plugins honeycomb" \
239   #                                                --run-command "yum -y install /root/fdio_l2/*.rpm" \
240   #                                                --run-command "rm -f /etc/sysctl.d/80-vpp.conf" \
241   #                                                -a overcloud-full.qcow2
242 #EOI
243   #fi
244
245   # check if ceph should be enabled
246   if [ "${deploy_options_array['ceph']}" == 'True' ]; then
247     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
248   fi
249
250   # get number of nodes available in inventory
251   num_control_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:control /home/stack/instackenv.json")
252   num_compute_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:compute /home/stack/instackenv.json")
253
254   # check if HA is enabled
255   if [[ "$ha_enabled" == "True" ]]; then
256     if [ "$num_control_nodes" -lt 3 ]; then
257       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}"
258       exit 1
259     else
260      DEPLOY_OPTIONS+=" --control-scale ${num_control_nodes}"
261      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
262      echo -e "${blue}INFO: Number of control nodes set for deployment: ${num_control_nodes}${reset}"
263     fi
264   else
265     if [ "$num_control_nodes" -lt 1 ]; then
266       echo -e "${red}ERROR: Number of control nodes in inventory is less than 1: ${num_control_nodes}. Check your inventory file.${reset}"
267       exit 1
268     fi
269   fi
270
271   if [ "$num_compute_nodes" -le 0 ]; then
272     echo -e "${red}ERROR: Invalid number of compute nodes: ${num_compute_nodes}. Check your inventory file.${reset}"
273     exit 1
274   else
275     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${num_compute_nodes}${reset}"
276     DEPLOY_OPTIONS+=" --compute-scale ${num_compute_nodes}"
277   fi
278
279   DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
280
281   DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
282   if [[ "$virtual" == "TRUE" ]]; then
283      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
284   fi
285
286   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
287
288   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
289 # Create a key for use by nova for live migration
290 echo "Creating nova SSH key for nova resize support"
291 ssh-keygen -f nova_id_rsa -b 1024 -P ""
292 public_key=\'\$(cat nova_id_rsa.pub | cut -d ' ' -f 2)\'
293 sed -i "s#replace_public_key:#key: \$public_key#g" ${ENV_FILE}
294 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") + "\"")))'
295 mv -f opnfv-environment-new.yaml ${ENV_FILE}
296
297 source stackrc
298 set -o errexit
299 # Workaround for APEX-207 where sometimes swift proxy is down
300 if ! sudo systemctl status openstack-swift-proxy > /dev/null; then
301   sudo systemctl restart openstack-swift-proxy
302 fi
303 echo "Uploading overcloud glance images"
304 openstack overcloud image upload
305
306 echo "Configuring undercloud and discovering nodes"
307 openstack baremetal import --json instackenv.json
308
309 if [[ -z "$virtual" ]]; then
310   openstack baremetal introspection bulk start
311   if [[ -n "$root_disk_list" ]]; then
312     openstack baremetal configure boot --root-device=${root_disk_list}
313   else
314     openstack baremetal configure boot
315   fi
316 else
317   openstack baremetal configure boot
318 fi
319
320 echo "Configuring flavors"
321 for flavor in baremetal control compute; do
322   echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
323   if openstack flavor list | grep \${flavor}; then
324     openstack flavor delete \${flavor}
325   fi
326   openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
327   if ! openstack flavor list | grep \${flavor}; then
328     echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
329   fi
330 done
331 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
332 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
333 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
334 echo "Configuring nameserver on ctlplane network"
335 dns_server_ext=''
336 for dns_server in ${dns_servers}; do
337   dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
338 done
339 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
340 sed -i '/CloudDomain:/c\  CloudDomain: '${domain_name} ${ENV_FILE}
341 echo "Executing overcloud deployment, this should run for an extended period without output."
342 sleep 60 #wait for Hypervisor stats to check-in to nova
343 # save deploy command so it can be used for debugging
344 cat > deploy_command << EOF
345 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
346 EOF
347 EOI
348
349   if [ "$interactive" == "TRUE" ]; then
350     if ! prompt_user "Overcloud Deployment"; then
351       echo -e "${blue}INFO: User requests exit${reset}"
352       exit 0
353     fi
354   fi
355
356   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
357 source stackrc
358 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
359 if ! openstack stack list | grep CREATE_COMPLETE 1>/dev/null; then
360   $(typeset -f debug_stack)
361   debug_stack
362   exit 1
363 fi
364 EOI
365
366   # Configure DPDK and restart ovs agent after bringing up br-phy
367   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
368     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
369 source stackrc
370 set -o errexit
371 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
372 echo "Checking DPDK status and bringing up br-phy on \$node"
373 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
374 set -o errexit
375 sudo dpdk-devbind -s
376 sudo ifup br-phy
377 if [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
378   echo "Restarting openvswitch agent to pick up VXLAN tunneling"
379   sudo systemctl restart neutron-openvswitch-agent
380 fi
381 EOF
382 done
383 EOI
384   fi
385
386   if [ "$debug" == 'TRUE' ]; then
387       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
388 source overcloudrc
389 echo "Keystone Endpoint List:"
390 openstack endpoint list
391 echo "Keystone Service List"
392 openstack service list
393 EOI
394   fi
395 }