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