Merge "Build odl plugin with openjdk-8"
[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   -F  Do only create a Fuel master
42   -H  No health check
43   -l  Lab-name
44   -p  Pod-name
45   -s  Deploy-scenario short-name/base-file-name
46   -S  Storage dir for VM images
47   -i  iso url
48
49 Description:
50 Deploys the Fuel@OPNFV stack on the indicated lab resource
51
52 This script provides the Fuel@OPNFV deployment abstraction
53 It depends on the OPNFV official configuration directory/file structure
54 and provides a fairly simple mechanism to execute a deployment.
55 Input parameters to the build script is:
56 -b Base URI to the configuration directory (needs to be provided in a URI
57    style, it can be a local resource: file:// or a remote resource http(s)://)
58 -B PXE Bridge for booting of Fuel master, default is pxebr
59 -d Dry-run - Produces deploy config files (config/dea.yaml and
60    config/dha.yaml), but does not execute deploy
61 -f Deploy on existing Fuel master
62 -F Do only create a Fuel master
63 -H Do not run fuel built in health-check after successfull deployment
64 -l Lab name as defined in the configuration directory, e.g. lf
65 -p POD name as defined in the configuration directory, e.g. pod-1
66 -s Deployment-scenario, this points to a deployment/test scenario file as
67    defined in the configuration directory:
68    e.g fuel-ocl-heat-ceilometer_scenario_0.0.1.yaml
69    or a deployment short-name as defined by scenario.yaml in the deployment
70    scenario path.
71 -S Storage dir for VM images, default is fuel/deploy/images
72 -i .iso image to be deployed (needs to be provided in a URI
73    style, it can be a local resource: file:// or a remote resource http(s)://)
74
75 NOTE: Root priviledges are needed for this script to run
76
77
78 Examples:
79 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
80 EOF
81 }
82
83 #
84 # END of usage description
85 ############################################################################
86
87 ############################################################################
88 # BEGIN of deployment clean-up
89 #
90 clean() {
91     echo "Cleaning up deploy tmp directories"
92     rm -rf ${SCRIPT_PATH}/ISO
93 }
94 #
95 # END of deployment clean-up
96 ############################################################################
97
98 ############################################################################
99 # BEGIN of shorthand variables for internal use
100 #
101 SCRIPT_PATH=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
102 DEPLOY_DIR=$(cd ${SCRIPT_PATH}/../deploy; pwd)
103 PXE_BRIDGE=''
104 NO_HEALTH_CHECK=''
105 USE_EXISTING_FUEL=''
106 FUEL_CREATION_ONLY=''
107 STORAGE_DIR=''
108 DRY_RUN=0
109 #
110 # END of variables to customize
111 ############################################################################
112
113 ############################################################################
114 # BEGIN of main
115 #
116 while getopts "b:B:dfFHl:p:s:S:i:h" OPTION
117 do
118     case $OPTION in
119         b)
120             BASE_CONFIG_URI=${OPTARG}
121             if [[ ! $BASE_CONFIG_URI == file://* ]] && \
122                [[ ! $BASE_CONFIG_URI == http://* ]] && \
123                [[ ! $BASE_CONFIG_URI == https://* ]] && \
124                [[ ! $BASE_CONFIG_URI == ftp://* ]]; then
125                 echo "-b $BASE_CONFIG_URI - Not given in URI style"
126                 usage
127                 exit 1
128             fi
129             ;;
130         B)
131             PXE_BRIDGE="-b ${OPTARG}"
132             ;;
133         d)
134             DRY_RUN=1
135             ;;
136         f)
137             USE_EXISTING_FUEL='-nf'
138             ;;
139         F)
140             FUEL_CREATION_ONLY='-fo'
141             ;;
142         H)
143             NO_HEALTH_CHECK='-nh'
144             ;;
145         l)
146             TARGET_LAB=${OPTARG}
147             ;;
148         p)
149             TARGET_POD=${OPTARG}
150             ;;
151         s)
152             DEPLOY_SCENARIO=${OPTARG}
153             ;;
154         S)
155             STORAGE_DIR="-s ${OPTARG}"
156             ;;
157         i)
158             ISO=${OPTARG}
159             if [[ ! $ISO == file://* ]] && \
160                [[ ! $ISO == http://* ]] && \
161                [[ ! $ISO == https://* ]] && \
162                [[ ! $ISO == ftp://* ]]; then
163                 echo "-i $ISO - Not given in URI style"
164                 usage
165                 exit 1
166             fi
167
168             ;;
169         h)
170             usage
171             exit 0
172             ;;
173         *)
174             echo "${OPTION} is not a valid argument"
175             echo "Arguments not according to new argument style"
176             echo "Trying old-style compatibility mode"
177             pushd ${DEPLOY_DIR} > /dev/null
178             python deploy.py "$@"
179             popd > /dev/null
180             exit 0
181             ;;
182     esac
183 done
184
185 if [[ $EUID -ne 0 ]]; then
186    echo "This script must be run as root" 1>&2
187    exit 1
188 fi
189
190 if [ -z $BASE_CONFIG_URI ] || [ -z $TARGET_LAB ] || \
191    [ -z $TARGET_POD ] || [ -z $DEPLOY_SCENARIO ] || \
192    [ -z $ISO ]; then
193     echo "Arguments not according to new argument style"
194     echo "Trying old-style compatibility mode"
195     pushd ${DEPLOY_DIR} > /dev/null
196     python deploy.py "$@"
197     popd > /dev/null
198     exit 0
199 fi
200
201 # Enable the automatic exit trap
202 trap do_exit SIGINT SIGTERM EXIT
203
204 # Set no restrictive umask so that Jenkins can removeeee any residuals
205 umask 0000
206
207 clean
208
209 pushd ${DEPLOY_DIR} > /dev/null
210 # Prepare the deploy config files based on lab/pod information, deployment
211 # scenario, etc.
212
213 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"
214
215 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
216
217 if [ $DRY_RUN -eq 0 ]; then
218     # Download iso if it doesn't already exists locally
219     if [[ $ISO == file://* ]]; then
220         ISO=${ISO#file://}
221     else
222         mkdir -p ${SCRIPT_PATH}/ISO
223         curl -o ${SCRIPT_PATH}/ISO/image.iso $ISO
224         ISO=${SCRIPT_PATH}/ISO/image.iso
225     fi
226     # Start deployment
227     echo "python deploy.py -s $STORAGE_DIR -b $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO"
228     python deploy.py $STORAGE_DIR $PXE_BRIDGE $USE_EXISTING_FUEL $FUEL_CREATION_ONLY $NO_HEALTH_CHECK -dea ${SCRIPT_PATH}/config/dea.yaml -dha ${SCRIPT_PATH}/config/dha.yaml -iso $ISO
229 fi
230 popd > /dev/null
231
232 #
233 # END of main
234 ############################################################################