3 ##############################################################################
4 # Copyright (c) 2017 Ericsson AB, Mirantis Inc. 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 ##############################################################################
12 ############################################################################
13 # BEGIN of Exit handlers
20 # End of Exit handlers
21 ############################################################################
23 ############################################################################
24 # BEGIN of usage description
29 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
30 `basename $0`: Deploys the Fuel@OPNFV stack
32 usage: `basename $0` -b base-uri
33 [-B PXE Bridge [-B Mgmt Bridge [-B Internal Bridge [-B Public Bridge]]]]
34 [-f] [-F] [-H] -l lab-name -p pod-name -s deploy-scenario
35 [-S image-dir] [-T timeout] -i iso
36 -s deployment-scenario [-S optional Deploy-scenario path URI]
37 [-R optional local relen repo (containing deployment Scenarios]
40 -b Base-uri for the stack-configuration structure
41 -B Bridge(s): 1st usage = PXE, 2nd = Mgmt, 3rd = Internal, 4th = Public
43 -f Deploy on existing Fuel master
44 -e Do not launch environment deployment
45 -F Do only create a Fuel master
46 -h Print this message and exit
49 -L Deployment log path and file name
51 -s Deploy-scenario short-name/base-file-name
52 -S Storage dir for VM images
53 -T Timeout, in minutes, for the deploy.
57 Deploys the Fuel@OPNFV stack on the indicated lab resource
59 This script provides the Fuel@OPNFV deployment abstraction
60 It depends on the OPNFV official configuration directory/file structure
61 and provides a fairly simple mechanism to execute a deployment.
62 Input parameters to the build script is:
63 -b Base URI to the configuration directory (needs to be provided in a URI
64 style, it can be a local resource: file:// or a remote resource http(s)://)
65 -B Bridges to be used by deploy script. It can be specified several times,
66 or as a comma separated list of bridges, or both: -B br1 -B br2,br3
67 First occurence sets PXE Brige, next Mgmt, then Internal and Public.
68 For an empty value, the deploy script will use virsh to create the default
69 expected network (e.g. -B pxe,,,public will use existing "pxe" and "public"
70 bridges, respectively create "mgmt" and "internal").
72 -d Dry-run - Produces deploy config files (config/dea.yaml and
73 config/dha.yaml), but does not execute deploy
74 -f Deploy on existing Fuel master
75 -e Do not launch environment deployment
76 -F Do only create a Fuel master
77 -h Print this message and exit
78 -H Do not run fuel built in health-check after successfull deployment
79 -l Lab name as defined in the configuration directory, e.g. lf
80 -L Deployment log path and name, eg. -L /home/jenkins/logs/job888.log.tar.gz
81 -p POD name as defined in the configuration directory, e.g. pod-1
82 -s Deployment-scenario, this points to a deployment/test scenario file as
83 defined in the configuration directory:
84 e.g fuel-ocl-heat-ceilometer_scenario_0.0.1.yaml
85 or a deployment short-name as defined by scenario.yaml in the deployment
87 -S Storage dir for VM images, default is fuel/deploy/images
88 -T Timeout, in minutes, for the deploy. It defaults to using the DEPLOY_TIMEOUT
89 environment variable when defined, or to the default in deploy.py otherwise
90 -i .iso image to be deployed (needs to be provided in a URI
91 style, it can be a local resource: file:// or a remote resource http(s)://)
93 NOTE: Root priviledges are needed for this script to run
97 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
102 # END of usage description
103 ############################################################################
105 ############################################################################
106 # BEGIN of deployment clean-up
109 echo "Cleaning up deploy tmp directories"
110 rm -rf ${SCRIPT_PATH}/ISO
113 # END of deployment clean-up
114 ############################################################################
116 ############################################################################
117 # BEGIN of shorthand variables for internal use
119 SCRIPT_PATH=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
120 DEPLOY_DIR=$(cd ${SCRIPT_PATH}/../mcp/scripts; pwd)
121 OPNFV_BRIDGES=('pxe' 'mgmt' 'internal' 'public')
124 FUEL_CREATION_ONLY=''
125 NO_DEPLOY_ENVIRONMENT=''
128 if ! [ -z $DEPLOY_TIMEOUT ]; then
129 DEPLOY_TIMEOUT="-dt $DEPLOY_TIMEOUT"
134 # END of variables to customize
135 ############################################################################
137 ############################################################################
141 while getopts "b:B:dfFHl:L:p:s:S:T:i:he" OPTION
145 BASE_CONFIG_URI=${OPTARG}
146 if [[ ! $BASE_CONFIG_URI == file://* ]] && \
147 [[ ! $BASE_CONFIG_URI == http://* ]] && \
148 [[ ! $BASE_CONFIG_URI == https://* ]] && \
149 [[ ! $BASE_CONFIG_URI == ftp://* ]]; then
150 echo "-b $BASE_CONFIG_URI - Not given in URI style"
158 OPT_BRIDGES=($OPTARG)
159 for bridge in "${OPT_BRIDGES[@]}"; do
160 if [ -n "${bridge}" ]; then
161 OPNFV_BRIDGES[${OPNFV_BRIDGE_IDX}]="${bridge}"
163 OPNFV_BRIDGE_IDX=$[OPNFV_BRIDGE_IDX + 1]
171 USE_EXISTING_FUEL='-nf'
174 FUEL_CREATION_ONLY='-fo'
177 NO_DEPLOY_ENVIRONMENT='-nde'
180 NO_HEALTH_CHECK='-nh'
186 DEPLOY_LOG="-log ${OPTARG}"
192 DEPLOY_SCENARIO=${OPTARG}
195 if [[ ${OPTARG} ]]; then
196 STORAGE_DIR="-s ${OPTARG}"
200 DEPLOY_TIMEOUT="-dt ${OPTARG}"
204 if [[ ! $ISO == file://* ]] && \
205 [[ ! $ISO == http://* ]] && \
206 [[ ! $ISO == https://* ]] && \
207 [[ ! $ISO == ftp://* ]]; then
208 echo "-i $ISO - Not given in URI style"
218 echo "${OPTION} is not a valid argument"
219 echo "Arguments not according to new argument style"
220 echo "Trying old-style compatibility mode"
221 pushd ${DEPLOY_DIR} > /dev/null
222 python deploy.py "$@"
229 if [[ $EUID -ne 0 ]]; then
230 echo "This script must be run as root" 1>&2
234 # Enable the automatic exit trap
235 trap do_exit SIGINT SIGTERM EXIT
237 # Set no restrictive umask so that Jenkins can removeeee any residuals
242 pushd ${DEPLOY_DIR} > /dev/null
243 # Prepare the deploy config files based on lab/pod information, deployment
246 # Install required packages
247 [ -n "$(command -v apt-get)" ] && apt-get install -y mkisofs curl virtinst cpu-checker qemu-kvm
248 [ -n "$(command -v yum)" ] && yum install -y genisoimage curl virt-install qemu-kvm
250 # Check scenario file existence
251 if [[ ! -f ../config/${DEPLOY_SCENARIO}.yaml ]]; then
252 echo "[WARN] ${DEPLOY_SCENARIO}.yaml not found, setting simplest scenario"
253 DEPLOY_SCENARIO='os-nosdn-nofeature-noha'
256 # Get required infra deployment data
258 eval $(parse_yaml ../config/defaults.yaml)
259 eval $(parse_yaml ../config/${DEPLOY_SCENARIO}.yaml)
261 declare -A virtual_nodes_ram virtual_nodes_vcpus
262 for node in "${virtual_nodes[@]}"; do
263 virtual_custom_ram="virtual_${node}_ram"
264 virtual_custom_vcpus="virtual_${node}_vcpus"
265 virtual_nodes_ram[$node]=${!virtual_custom_ram:-$virtual_default_ram}
266 virtual_nodes_vcpus[$node]=${!virtual_custom_vcpus:-$virtual_default_vcpus}
269 export CLUSTER_DOMAIN=$cluster_domain
270 export SSH_KEY=${SSH_KEY:-mcp.rsa}
271 export SALT_MASTER=${SALT_MASTER_IP:-192.168.10.100}
272 export SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${SSH_KEY}"
276 prepare_vms virtual_nodes $base_image
277 create_networks OPNFV_BRIDGES
278 create_vms virtual_nodes virtual_nodes_ram virtual_nodes_vcpus OPNFV_BRIDGES
279 update_pxe_network OPNFV_BRIDGES
280 start_vms virtual_nodes
285 # Openstack cluster setup
286 for state in "${cluster_states[@]}"; do
288 ssh ${SSH_OPTS} ubuntu@${SALT_MASTER} sudo /root/fuel/mcp/config/states/$state
291 ## Disable Fuel deployment engine
293 # 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"
295 # 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
297 # if [ $DRY_RUN -eq 0 ]; then
298 # # Download iso if it doesn't already exists locally
299 # if [[ $ISO == file://* ]]; then
302 # mkdir -p ${SCRIPT_PATH}/ISO
303 # curl -o ${SCRIPT_PATH}/ISO/image.iso $ISO
304 # ISO=${SCRIPT_PATH}/ISO/image.iso
307 # 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 $DEPLOY_TIMEOUT"
308 # 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 $DEPLOY_TIMEOUT
314 ############################################################################