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