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