Merge "Allow to use Intel NICs for DPDK on Ericsson POD2"
[fuel.git] / ci / deploy.sh
1 #!/bin/bash
2 set -e
3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 ############################################################################
13 # BEGIN of Exit handlers
14 #
15 do_exit () {
16     clean
17     echo "Exiting ..."
18 }
19 #
20 # End of Exit handlers
21 ############################################################################
22
23 ############################################################################
24 # BEGIN of usage description
25 #
26 usage ()
27 {
28 cat << EOF
29 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
30 `basename $0`: Deploys the Fuel@OPNFV stack
31
32 usage: `basename $0` -b base-uri [-B PXE Bridge] [-f] [-F] [-H] -l lab-name -p pod-name -s deploy-scenario [-S image-dir] -i iso
33        -s deployment-scenario [-S optional Deploy-scenario path URI]
34        [-R optional local relen repo (containing deployment Scenarios]
35
36 OPTIONS:
37   -b  Base-uri for the stack-configuration structure
38   -B  PXE Bridge for booting of Fuel master
39   -d  Dry-run
40   -f  Deploy on existing Fuel master
41   -e  Do not launch environment deployment
42   -F  Do only create a Fuel master
43   -h  Print this message and exit
44   -H  No health check
45   -l  Lab-name
46   -L  Deployment log path and file name
47   -p  Pod-name
48   -s  Deploy-scenario short-name/base-file-name
49   -S  Storage dir for VM images
50   -i  iso url
51
52 Description:
53 Deploys the Fuel@OPNFV stack on the indicated lab resource
54
55 This script provides the Fuel@OPNFV deployment abstraction
56 It depends on the OPNFV official configuration directory/file structure
57 and provides a fairly simple mechanism to execute a deployment.
58 Input parameters to the build script is:
59 -b Base URI to the configuration directory (needs to be provided in a URI
60    style, it can be a local resource: file:// or a remote resource http(s)://)
61 -B PXE Bridge for booting of Fuel master. It can be specified several times,
62    or as a comma separated list of bridges, or both: -B br1 -B br2,br3
63    One NIC connected to each specified bridge will be created in the Fuel VM,
64    in the same order as provided in the command line. The default is pxebr.
65 -d Dry-run - Produces deploy config files (config/dea.yaml and
66    config/dha.yaml), but does not execute deploy
67 -f Deploy on existing Fuel master
68 -e Do not launch environment deployment
69 -F Do only create a Fuel master
70 -h Print this message and exit
71 -H Do not run fuel built in health-check after successfull deployment
72 -l Lab name as defined in the configuration directory, e.g. lf
73 -L Deployment log path and name, eg. -L /home/jenkins/logs/job888.log.tar.gz
74 -p POD name as defined in the configuration directory, e.g. pod-1
75 -s Deployment-scenario, this points to a deployment/test scenario file as
76    defined in the configuration directory:
77    e.g fuel-ocl-heat-ceilometer_scenario_0.0.1.yaml
78    or a deployment short-name as defined by scenario.yaml in the deployment
79    scenario path.
80 -S Storage dir for VM images, default is fuel/deploy/images
81 -i .iso image to be deployed (needs to be provided in a URI
82    style, it can be a local resource: file:// or a remote resource http(s)://)
83
84 NOTE: Root priviledges are needed for this script to run
85
86
87 Examples:
88 sudo `basename $0` -b file:///home/jenkins/lab-config -l lf -p pod1 -s ha_odl-l3_heat_ceilometer -i file:///home/jenkins/myiso.iso
89 EOF
90 }
91
92 #
93 # END of usage description
94 ############################################################################
95
96 ############################################################################
97 # BEGIN of deployment clean-up
98 #
99 clean() {
100     echo "Cleaning up deploy tmp directories"
101     rm -rf ${SCRIPT_PATH}/ISO
102 }
103 #
104 # END of deployment clean-up
105 ############################################################################
106
107 ############################################################################
108 # BEGIN of shorthand variables for internal use
109 #
110 SCRIPT_PATH=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
111 DEPLOY_DIR=$(cd ${SCRIPT_PATH}/../deploy; pwd)
112 PXE_BRIDGE=''
113 NO_HEALTH_CHECK=''
114 USE_EXISTING_FUEL=''
115 FUEL_CREATION_ONLY=''
116 NO_DEPLOY_ENVIRONMENT=''
117 STORAGE_DIR=''
118 DRY_RUN=0
119 #
120 # END of variables to customize
121 ############################################################################
122
123 ############################################################################
124 # BEGIN of main
125 #
126 while getopts "b:B:dfFHl:L:p:s:S:i:he" OPTION
127 do
128     case $OPTION in
129         b)
130             BASE_CONFIG_URI=${OPTARG}
131             if [[ ! $BASE_CONFIG_URI == file://* ]] && \
132                [[ ! $BASE_CONFIG_URI == http://* ]] && \
133                [[ ! $BASE_CONFIG_URI == https://* ]] && \
134                [[ ! $BASE_CONFIG_URI == ftp://* ]]; then
135                 echo "-b $BASE_CONFIG_URI - Not given in URI style"
136                 usage
137                 exit 1
138             fi
139             ;;
140         B)
141             for bridge in ${OPTARG//,/ }; do
142                 PXE_BRIDGE+=" -b $bridge"
143             done
144             ;;
145         d)
146             DRY_RUN=1
147             ;;
148         f)
149             USE_EXISTING_FUEL='-nf'
150             ;;
151         F)
152             FUEL_CREATION_ONLY='-fo'
153             ;;
154         e)
155             NO_DEPLOY_ENVIRONMENT='-nde'
156             ;;
157         H)
158             NO_HEALTH_CHECK='-nh'
159             ;;
160         l)
161             TARGET_LAB=${OPTARG}
162             ;;
163         L)
164             DEPLOY_LOG="-log ${OPTARG}"
165             ;;
166         p)
167             TARGET_POD=${OPTARG}
168             ;;
169         s)
170             DEPLOY_SCENARIO=${OPTARG}
171             ;;
172         S)
173             if [[ ${OPTARG} ]]; then
174                 STORAGE_DIR="-s ${OPTARG}"
175             fi
176             ;;
177         i)
178             ISO=${OPTARG}
179             if [[ ! $ISO == file://* ]] && \
180                [[ ! $ISO == http://* ]] && \
181                [[ ! $ISO == https://* ]] && \
182                [[ ! $ISO == ftp://* ]]; then
183                 echo "-i $ISO - Not given in URI style"
184                 usage
185                 exit 1
186             fi
187             ;;
188         h)
189             usage
190             exit 0
191             ;;
192         *)
193             echo "${OPTION} is not a valid argument"
194             echo "Arguments not according to new argument style"
195             echo "Trying old-style compatibility mode"
196             pushd ${DEPLOY_DIR} > /dev/null
197             python deploy.py "$@"
198             popd > /dev/null
199             exit 0
200             ;;
201     esac
202 done
203
204 if [[ $EUID -ne 0 ]]; then
205     echo "This script must be run as root" 1>&2
206     exit 1
207 fi
208
209 if [ -z $BASE_CONFIG_URI ] || [ -z $TARGET_LAB ] || \
210    [ -z $TARGET_POD ] || [ -z $DEPLOY_SCENARIO ] || \
211    [ -z $ISO ]; then
212     echo "Arguments not according to new argument style"
213     echo "Trying old-style compatibility mode"
214     pushd ${DEPLOY_DIR} > /dev/null
215     python deploy.py "$@"
216     popd > /dev/null
217     exit 0
218 fi
219
220 # Enable the automatic exit trap
221 trap do_exit SIGINT SIGTERM EXIT
222
223 # Set no restrictive umask so that Jenkins can removeeee any residuals
224 umask 0000
225
226 clean
227
228 pushd ${DEPLOY_DIR} > /dev/null
229 # Prepare the deploy config files based on lab/pod information, deployment
230 # scenario, etc.
231
232 echo "python deploy-config.py -dha ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dha.yaml -deab file://${DEPLOY_DIR}/config/dea_base.yaml -deao ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dea-pod-override.yaml -scenario-base-uri file://${DEPLOY_DIR}/scenario -scenario ${DEPLOY_SCENARIO} -plugins file://${DEPLOY_DIR}/config/plugins -output ${SCRIPT_PATH}/config"
233
234 python deploy-config.py -dha ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dha.yaml -deab file://${DEPLOY_DIR}/config/dea_base.yaml -deao ${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}/fuel/config/dea-pod-override.yaml -scenario-base-uri file://${DEPLOY_DIR}/scenario -scenario ${DEPLOY_SCENARIO} -plugins file://${DEPLOY_DIR}/config/plugins -output ${SCRIPT_PATH}/config
235
236 if [ $DRY_RUN -eq 0 ]; then
237     # Download iso if it doesn't already exists locally
238     if [[ $ISO == file://* ]]; then
239         ISO=${ISO#file://}
240     else
241         mkdir -p ${SCRIPT_PATH}/ISO
242         curl -o ${SCRIPT_PATH}/ISO/image.iso $ISO
243         ISO=${SCRIPT_PATH}/ISO/image.iso
244     fi
245     # Start deployment
246     echo "python deploy.py $DEPLOY_LOG $STORAGE_DIR $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK $NO_DEPLOY_ENVIRONMENT -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO"
247     python deploy.py $DEPLOY_LOG $STORAGE_DIR $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK $NO_DEPLOY_ENVIRONMENT -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO
248 fi
249 popd > /dev/null
250
251 #
252 # END of main
253 ############################################################################