Add support for odl-fdio scenario
[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/neutron-opendaylight-honeycomb.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   # Install ovs-dpdk inside the overcloud image if it is enabled.
73   if [[ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' || "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
74     # install dpdk packages before ovs
75     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
76
77     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
78       cat << EOF > vfio_pci.modules
79 #!/bin/bash
80 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
81 EOF
82
83       cat << EOF > uio_pci_generic.modules
84 #!/bin/bash
85 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
86 EOF
87
88       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
89                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
90                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
91                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
92                                                -a overcloud-full.qcow2
93
94       if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
95         LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/dpdk_rpms/*" \
96                                                  --run-command "sed -i '/RuntimeDirectoryMode=.*/d' /usr/lib/systemd/system/openvswitch-nonetwork.service" \
97                                                  --run-command "printf \"%s\\n\" RuntimeDirectoryMode=0775 Group=qemu UMask=0002 >> /usr/lib/systemd/system/openvswitch-nonetwork.service" \
98                                                  --run-command "sed -i 's/\\(^\\s\\+\\)\\(start_daemon "$OVS_VSWITCHD_PRIORITY"\\)/\\1umask 0002 \\&\\& \\2/' /usr/share/openvswitch/scripts/ovs-ctl" \
99                                                  -a overcloud-full.qcow2
100       fi
101
102 EOI
103
104   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
105     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
106     exit 1
107   fi
108
109   if [ "$debug" == 'TRUE' ]; then
110     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex"
111   fi
112
113   # upgrade ovs into ovs 2.5.90 with NSH function if SFC is enabled
114   if [[ "${deploy_options_array['sfc']}" == 'True' && "${deploy_options_array['dataplane']}" == 'ovs' ]]; then
115     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
116          LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum install -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_kmod_rpm_name}" \
117                                                   --run-command "yum upgrade -y /root/ovs/rpm/rpmbuild/RPMS/x86_64/${ovs_rpm_name}" \
118                                                   -a overcloud-full.qcow2
119 EOI
120   fi
121
122   if [ -n "${deploy_options_array['performance']}" ]; then
123     for option in "${performance_options[@]}" ; do
124     arr=($option)
125     # use compute's kernel settings for all nodes for now.
126     if [ "${arr[0]}" == "Compute" ] && [ "${arr[1]}" == "kernel" ]; then
127       kernel_args+=" ${arr[2]}=${arr[3]}"
128     fi
129     done
130
131     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
132        sed -i "/ComputeKernelArgs:/c\  ComputeKernelArgs: '$kernel_args'" ${ENV_FILE}
133        sed -i "$ a\resource_registry:\n  OS::TripleO::NodeUserData: first-boot.yaml" ${ENV_FILE}
134        sed -i "/NovaSchedulerDefaultFilters:/c\  NovaSchedulerDefaultFilters: 'RamFilter,ComputeFilter,AvailabilityZoneFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,NUMATopologyFilter'" ${ENV_FILE}
135 EOI
136   fi
137
138   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['dataplane']}" == 'fdio' ]]; then
139     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
140       sed -i "/neutron::agents::dhcp::interface_driver:/c\    neutron::agents::dhcp::interface_driver: neutron.agent.linux.interface.NSDriver" ${ENV_FILE}
141       sed -i "/neutron::agents::l3::interface_driver:/c\    neutron::agents::l3::interface_driver: neutron.agent.linux.interface.NSDriver" ${ENV_FILE}
142 EOI
143   fi
144
145   # Set ODL version accordingly
146   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && -n "${deploy_options_array['odl_version']}" ]]; then
147     case "${deploy_options_array['odl_version']}" in
148       beryllium) odl_version=''
149               ;;
150       boron)  odl_version='boron'
151               ;;
152       carbon) odl_version='master'
153               ;;
154       *) echo -e "${red}Invalid ODL version ${deploy_options_array['odl_version']}.  Please use 'carbon' or 'boron' values.${reset}"
155          exit 1
156          ;;
157     esac
158
159     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
160       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
161                                                --run-command "yum -y install /root/${odl_version}/*" \
162                                                -a overcloud-full.qcow2
163 EOI
164   fi
165
166
167   # check if ceph should be enabled
168   if [ "${deploy_options_array['ceph']}" == 'True' ]; then
169     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
170   fi
171
172   #DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml"
173   DEPLOY_OPTIONS+=" -e network-environment.yaml"
174
175
176   # get number of nodes available in inventory
177   num_control_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:control /home/stack/instackenv.json")
178   num_compute_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "grep -c profile:compute /home/stack/instackenv.json")
179
180   # check if HA is enabled
181   if [[ "$ha_enabled" == "True" ]]; then
182     if [ "$num_control_nodes" -lt 3 ]; then
183       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}"
184       exit 1
185     else
186      DEPLOY_OPTIONS+=" --control-scale ${num_control_nodes}"
187      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
188      echo -e "${blue}INFO: Number of control nodes set for deployment: ${num_control_nodes}${reset}"
189     fi
190   else
191     if [ "$num_control_nodes" -lt 1 ]; then
192       echo -e "${red}ERROR: Number of control nodes in inventory is less than 1: ${num_control_nodes}. Check your inventory file.${reset}"
193       exit 1
194     fi
195   fi
196
197   if [ "$num_compute_nodes" -le 0 ]; then
198     echo -e "${red}ERROR: Invalid number of compute nodes: ${num_compute_nodes}. Check your inventory file.${reset}"
199     exit 1
200   else
201     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${num_compute_nodes}${reset}"
202     DEPLOY_OPTIONS+=" --compute-scale ${num_compute_nodes}"
203   fi
204
205   DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
206
207   DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
208   if [[ "$virtual" == "TRUE" ]]; then
209      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
210   fi
211
212   DEPLOY_OPTIONS+=" -e ${ENV_FILE}"
213
214   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
215
216   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
217 # Create a key for use by nova for live migration
218 echo "Creating nova SSH key for nova resize support"
219 ssh-keygen -f nova_id_rsa -b 1024 -P ""
220 public_key=\'\$(cat nova_id_rsa.pub | cut -d ' ' -f 2)\'
221 sed -i "s#replace_public_key:#key: \$public_key#g" ${ENV_FILE}
222 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") + "\"")))'
223 mv -f opnfv-environment-new.yaml ${ENV_FILE}
224
225 source stackrc
226 set -o errexit
227 # Workaround for APEX-207 where sometimes swift proxy is down
228 if ! sudo systemctl status openstack-swift-proxy > /dev/null; then
229   sudo systemctl restart openstack-swift-proxy
230 fi
231 echo "Uploading overcloud glance images"
232 openstack overcloud image upload
233
234 echo "Configuring undercloud and discovering nodes"
235 openstack baremetal import --json instackenv.json
236
237 if [[ -z "$virtual" ]]; then
238   openstack baremetal introspection bulk start
239   if [[ -n "$root_disk_list" ]]; then
240     openstack baremetal configure boot --root-device=${root_disk_list}
241   else
242     openstack baremetal configure boot
243   fi
244 else
245   openstack baremetal configure boot
246 fi
247
248 echo "Configuring flavors"
249 for flavor in baremetal control compute; do
250   echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
251   if openstack flavor list | grep \${flavor}; then
252     openstack flavor delete \${flavor}
253   fi
254   openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
255   if ! openstack flavor list | grep \${flavor}; then
256     echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
257   fi
258 done
259 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
260 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
261 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
262 echo "Configuring nameserver on ctlplane network"
263 dns_server_ext=''
264 for dns_server in ${dns_servers}; do
265   dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
266 done
267 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
268 sed -i '/CloudDomain:/c\  CloudDomain: '${domain_name} ${ENV_FILE}
269 echo "Executing overcloud deployment, this should run for an extended period without output."
270 sleep 60 #wait for Hypervisor stats to check-in to nova
271 # save deploy command so it can be used for debugging
272 cat > deploy_command << EOF
273 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
274 EOF
275 EOI
276
277   if [ "$interactive" == "TRUE" ]; then
278     if ! prompt_user "Overcloud Deployment"; then
279       echo -e "${blue}INFO: User requests exit${reset}"
280       exit 0
281     fi
282   fi
283
284   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
285 source stackrc
286 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
287 if ! openstack stack list | grep CREATE_COMPLETE 1>/dev/null; then
288   $(typeset -f debug_stack)
289   debug_stack
290   exit 1
291 fi
292 EOI
293
294   # Configure DPDK
295   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
296     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
297 source stackrc
298 set -o errexit
299 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
300 echo "Running DPDK test app on \$node"
301 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
302 set -o errexit
303 sudo dpdk_helloworld --no-pci
304 sudo dpdk_nic_bind -s
305 EOF
306 done
307 EOI
308   fi
309
310   if [ "$debug" == 'TRUE' ]; then
311       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
312 source overcloudrc
313 echo "Keystone Endpoint List:"
314 openstack endpoint list
315 echo "Keystone Service List"
316 openstack service list
317 EOI
318   fi
319 }