Merge "Pins ODL L3 VPP/HC packages"
[apex.git] / ci / deploy.sh
1 #!/bin/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 # Deploy script to install provisioning server for OPNFV Apex
12 # author: Dan Radez (dradez@redhat.com)
13 # author: Tim Rozet (trozet@redhat.com)
14 #
15 # Based on RDO Manager http://www.rdoproject.org
16
17 set -e
18
19 ##VARIABLES
20 reset=$(tput sgr0 || echo "")
21 blue=$(tput setaf 4 || echo "")
22 red=$(tput setaf 1 || echo "")
23 green=$(tput setaf 2 || echo "")
24
25 interactive="FALSE"
26 ping_site="8.8.8.8"
27 dnslookup_site="www.google.com"
28 post_config="TRUE"
29 debug="FALSE"
30
31 ovs_rpm_name=openvswitch-2.5.90-1.el7.centos.x86_64.rpm
32 ovs_kmod_rpm_name=openvswitch-kmod-2.5.90-1.el7.centos.x86_64.rpm
33
34 declare -i CNT
35 declare UNDERCLOUD
36 declare -A deploy_options_array
37 declare -a performance_options
38 declare -A NET_MAP
39
40 # Backwards compat for old ENV Vars
41 # Remove in E Release
42 if [ -n "$CONFIG" ]; then
43     echo -e "${red}WARNING: ENV var CONFIG is Deprecated, please unset CONFIG and export BASE in its place${reset}"
44     echo -e "${red}WARNING: CONFIG will be removed in E${reset}"
45     BASE=$CONFIG
46 fi
47 if [ -n "$RESOURCES" ]; then
48     echo -e "${red}WARNING: ENV var RESOURCES is Deprecated, please unset RESOURCES and export IMAGES in its place${reset}"
49     echo -e "${red}WARNING: RESOURCES will be removed in E${reset}"
50     IMAGES=$RESOURCES
51 fi
52
53 APEX_TMP_DIR=$(python3 -c "import tempfile; print(tempfile.mkdtemp())")
54 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
55 DEPLOY_OPTIONS=""
56 BASE=${BASE:-'/var/opt/opnfv'}
57 IMAGES=${IMAGES:-"$BASE/images"}
58 LIB=${LIB:-"$BASE/lib"}
59 OPNFV_NETWORK_TYPES="admin tenant external storage api"
60 ENV_FILE="opnfv-environment.yaml"
61
62 VM_CPUS=4
63 VM_RAM=8
64 VM_COMPUTES=1
65
66 # Netmap used to map networks to OVS bridge names
67 NET_MAP['admin']="br-admin"
68 NET_MAP['tenant']="br-tenant"
69 NET_MAP['external']="br-external"
70 NET_MAP['storage']="br-storage"
71 NET_MAP['api']="br-api"
72 ext_net_type="interface"
73 ip_address_family=4
74
75 # Libraries
76 lib_files=(
77 $LIB/common-functions.sh
78 $LIB/configure-deps-functions.sh
79 $LIB/parse-functions.sh
80 $LIB/virtual-setup-functions.sh
81 $LIB/undercloud-functions.sh
82 $LIB/overcloud-deploy-functions.sh
83 $LIB/post-install-functions.sh
84 $LIB/utility-functions.sh
85 $LIB/installer/onos/onos_gw_mac_update.sh
86 )
87 for lib_file in ${lib_files[@]}; do
88   if ! source $lib_file; then
89     echo -e "${red}ERROR: Failed to source $lib_file${reset}"
90     exit 1
91   fi
92 done
93
94 display_usage() {
95   echo -e "Usage:\n$0 [arguments] \n"
96   echo -e "   --deploy-settings | -d : Full path to deploy settings yaml file. Optional.  Defaults to null"
97   echo -e "   --inventory | -i : Full path to inventory yaml file. Required only for baremetal"
98   echo -e "   --net-settings | -n : Full path to network settings file. Optional."
99   echo -e "   --ping-site | -p : site to use to verify IP connectivity. Optional. Defaults to 8.8.8.8"
100   echo -e "   --dnslookup-site : site to use to verify DNS resolution. Optional. Defaults to www.google.com"
101   echo -e "   --virtual | -v : Virtualize overcloud nodes instead of using baremetal."
102   echo -e "   --no-post-config : disable Post Install configuration."
103   echo -e "   --debug : enable debug output."
104   echo -e "   --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
105   echo -e "   --virtual-cpus : Number of CPUs to use per Overcloud VM in a virtual deployment (defaults to 4)."
106   echo -e "   --virtual-computes : Number of Virtual Compute nodes to create and use during deployment (defaults to 1 for noha and 2 for ha)."
107   echo -e "   --virtual-default-ram : Amount of default RAM to use per Overcloud VM in GB (defaults to 8)."
108   echo -e "   --virtual-compute-ram : Amount of RAM to use per Overcloud Compute VM in GB (defaults to 8). Overrides --virtual-default-ram arg for computes"
109 }
110
111 ##translates the command line parameters into variables
112 ##params: $@ the entire command line is passed
113 ##usage: parse_cmd_line() "$@"
114 parse_cmdline() {
115   echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
116   echo "Use -h to display help"
117
118   while [ "${1:0:1}" = "-" ]
119   do
120     case "$1" in
121         -h|--help)
122                 display_usage
123                 exit 0
124             ;;
125         -d|--deploy-settings)
126                 DEPLOY_SETTINGS_FILE=$2
127                 echo "Deployment Configuration file: $2"
128                 shift 2
129             ;;
130         -i|--inventory)
131                 INVENTORY_FILE=$2
132                 shift 2
133             ;;
134         -n|--net-settings)
135                 NETSETS=$2
136                 echo "Network Settings Configuration file: $2"
137                 shift 2
138             ;;
139         -e|--environment-file)
140                 ENV_FILE=$2
141                 echo "Base OOO Environment file: $2"
142                 shift 2
143             ;;
144         -p|--ping-site)
145                 ping_site=$2
146                 echo "Using $2 as the ping site"
147                 shift 2
148             ;;
149         --dnslookup-site)
150                 dnslookup_site=$2
151                 echo "Using $2 as the dnslookup site"
152                 shift 2
153             ;;
154         -v|--virtual)
155                 virtual="TRUE"
156                 echo "Executing a Virtual Deployment"
157                 shift 1
158             ;;
159         --no-post-config )
160                 post_config="FALSE"
161                 echo "Post install configuration disabled"
162                 shift 1
163             ;;
164         --debug )
165                 debug="TRUE"
166                 echo "Enable debug output"
167                 shift 1
168             ;;
169         --interactive )
170                 interactive="TRUE"
171                 echo "Interactive mode enabled"
172                 shift 1
173             ;;
174         --virtual-cpus )
175                 VM_CPUS=$2
176                 echo "Number of CPUs per VM set to $VM_CPUS"
177                 shift 2
178             ;;
179         --virtual-default-ram )
180                 VM_RAM=$2
181                 echo "Amount of Default RAM per VM set to $VM_RAM"
182                 shift 2
183             ;;
184         --virtual-computes )
185                 VM_COMPUTES=$2
186                 echo "Virtual Compute nodes set to $VM_COMPUTES"
187                 shift 2
188             ;;
189         --virtual-compute-ram )
190                 VM_COMPUTE_RAM=$2
191                 echo "Virtual Compute RAM set to $VM_COMPUTE_RAM"
192                 shift 2
193             ;;
194         *)
195                 display_usage
196                 exit 1
197             ;;
198     esac
199   done
200   sleep 2
201
202   if [[ -z "$NETSETS" ]]; then
203     echo -e "${red}ERROR: You must provide a network_settings file with -n.${reset}"
204     exit 1
205   fi
206
207   # inventory file usage validation
208   if [[ -n "$virtual" ]]; then
209       if [[ -n "$INVENTORY_FILE" ]]; then
210           echo -e "${red}ERROR: You should not specify an inventory file with virtual deployments${reset}"
211           exit 1
212       else
213           INVENTORY_FILE="$APEX_TMP_DIR/inventory-virt.yaml"
214       fi
215   elif [[ -z "$INVENTORY_FILE" ]]; then
216     echo -e "${red}ERROR: You must specify an inventory file for baremetal deployments! Exiting...${reset}"
217     exit 1
218   elif [[ ! -f "$INVENTORY_FILE" ]]; then
219     echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
220     exit 1
221   fi
222
223   if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
224     echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
225     exit 1
226   fi
227
228   if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
229     echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
230     exit 1
231   fi
232
233 }
234
235 main() {
236   parse_cmdline "$@"
237   if [ -n "$DEPLOY_SETTINGS_FILE" ]; then
238     echo -e "${blue}INFO: Parsing deploy settings file...${reset}"
239     parse_deploy_settings
240   fi
241   echo -e "${blue}INFO: Parsing network settings file...${reset}"
242   parse_network_settings
243   if ! configure_deps; then
244     echo -e "${red}Dependency Validation Failed, Exiting.${reset}"
245     exit 1
246   fi
247   #Correct the time on the server prior to launching any VMs
248   if ntpdate $ntp_server; then
249     hwclock --systohc
250   else
251     echo "${blue}WARNING: ntpdate failed to update the time on the server. ${reset}"
252   fi
253   setup_undercloud_vm
254   if [ "$virtual" == "TRUE" ]; then
255     setup_virtual_baremetal $VM_CPUS $VM_RAM
256   fi
257   parse_inventory_file
258   configure_undercloud
259   overcloud_deploy
260   if [ "$post_config" == "TRUE" ]; then
261     if ! configure_post_install; then
262       echo -e "${red}ERROR:Post Install Configuration Failed, Exiting.${reset}"
263       exit 1
264     else
265       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
266     fi
267   fi
268   if [[ "${deploy_options_array['sdn_controller']}" == 'onos' ]]; then
269     if ! onos_update_gw_mac ${external_cidr} ${external_gateway}; then
270       echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
271       exit 1
272     else
273       echo -e "${blue}INFO: ONOS Post Install Configuration Complete${reset}"
274     fi
275   fi
276 }
277
278 main "$@"