2 # shellcheck disable=SC2034,SC2154,SC1091
4 ##############################################################################
5 # Copyright (c) 2017 Ericsson AB, Mirantis Inc., Enea AB and others.
6 # jonas.bjurel@ericsson.com
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Apache License, Version 2.0
9 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
11 ##############################################################################
13 ##############################################################################
14 # BEGIN of Exit handlers
21 # End of Exit handlers
22 ##############################################################################
24 ##############################################################################
25 # BEGIN of usage description
30 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
31 $(notify "$(basename "$0"): Deploy the Fuel@OPNFV MCP stack" 3)
34 $(basename "$0") -b base-uri -l lab-name -p pod-name -s deploy-scenario \\
35 [-B PXE Bridge [-B Mgmt Bridge [-B Internal Bridge [-B Public Bridge]]]]
37 $(notify "OPTIONS:" 2)
38 -b Base-uri for the stack-configuration structure
39 -B Bridge(s): 1st usage = PXE, 2nd = Mgmt, 3rd = Internal, 4th = Public
40 -h Print this message and exit
43 -s Deploy-scenario short-name
45 $(notify "DISABLED OPTIONS (not yet supported with MCP):" 3)
47 -e (disabled) Do not launch environment deployment
48 -f (disabled) Deploy on existing Salt master
49 -F (disabled) Do only create a Salt master
51 -L (disabled) Deployment log path and file name
52 -S (disabled) Storage dir for VM images
53 -T (disabled) Timeout, in minutes, for the deploy.
55 $(notify "Description:" 2)
56 Deploys the Fuel@OPNFV stack on the indicated lab resource.
58 This script provides the Fuel@OPNFV deployment abstraction.
59 It depends on the OPNFV official configuration directory/file structure
60 and provides a fairly simple mechanism to execute a deployment.
62 $(notify "Input parameters to the build script are:" 2)
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 -h Print this message and exit
73 -l Lab name as defined in the configuration directory, e.g. lf
74 -p POD name as defined in the configuration directory, e.g. pod-1
75 -s Deployment-scenario, this points to a short deployment scenario name, which
76 has to be defined in config directory (e.g. os-odl_l2-nofeature-noha).
78 $(notify "Disabled input parameters (not yet supported with MCP):" 3)
79 -d (disabled) Dry-run - Produce deploy config files, but do not execute deploy
80 -f (disabled) Deploy on existing Salt master
81 -e (disabled) Do not launch environment deployment
82 -F (disabled) Do only create a Salt master
83 -L (disabled) Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
84 -S (disabled) Storage dir for VM images, default is fuel/deploy/images
85 -T (disabled) Timeout, in minutes, for the deploy.
86 It defaults to using the DEPLOY_TIMEOUT environment variable when defined.
87 -i (disabled) .iso image to be deployed (needs to be provided in a URI
88 style, it can be a local resource: file:// or a remote resource http(s)://)
90 $(notify "[NOTE] Root priviledges are needed for this script to run" 3)
94 $(notify "sudo $(basename "$0") \\
95 -b file:///home/jenkins/lab-config \\
97 -s os-odl_l2-nofeature-noha" 2)
102 # END of usage description
103 ##############################################################################
105 ##############################################################################
106 # BEGIN of colored notification wrapper
109 tput setaf "${2:-1}" || true
110 echo -en "${1:-"[WARN] Unsupported opt arg: $3\\n"}"
114 # END of colored notification wrapper
115 ##############################################################################
117 ##############################################################################
118 # BEGIN of deployment clean-up
121 echo "Cleaning up deploy tmp directories"
124 # END of deployment clean-up
125 ##############################################################################
127 ##############################################################################
128 # BEGIN of variables to customize
130 SCRIPT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
131 DEPLOY_DIR=$(cd "${SCRIPT_PATH}/../mcp/scripts"; pwd)
132 DEPLOY_TYPE='baremetal'
133 OPNFV_BRIDGES=('pxe' 'mgmt' 'internal' 'public')
134 URI_REGEXP='(file|https?|ftp)://.*'
136 export SSH_KEY=${SSH_KEY:-mcp.rsa}
137 export SALT_MASTER=${SALT_MASTER_IP:-192.168.10.100}
138 export SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${SSH_KEY}"
140 # Variables below are disabled for now, to be re-introduced or removed later
143 FUEL_CREATION_ONLY=''
144 NO_DEPLOY_ENVIRONMENT=''
147 if ! [ -z "${DEPLOY_TIMEOUT}" ]; then
148 DEPLOY_TIMEOUT="-dt ${DEPLOY_TIMEOUT}"
154 # END of variables to customize
155 ##############################################################################
157 ##############################################################################
162 while getopts "b:B:dfFl:L:p:s:S:T:i:he" OPTION
166 BASE_CONFIG_URI=${OPTARG}
167 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
168 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI\n"
176 OPT_BRIDGES=($OPTARG)
177 for bridge in "${OPT_BRIDGES[@]}"; do
178 if [ -n "${bridge}" ]; then
179 OPNFV_BRIDGES[${OPNFV_BRIDGE_IDX}]="${bridge}"
181 OPNFV_BRIDGE_IDX=$[OPNFV_BRIDGE_IDX + 1]
186 notify '' 3 "${OPTION}"; continue
190 notify '' 3 "${OPTION}"; continue
191 USE_EXISTING_FUEL='-nf'
194 notify '' 3 "${OPTION}"; continue
195 FUEL_CREATION_ONLY='-fo'
198 notify '' 3 "${OPTION}"; continue
199 NO_DEPLOY_ENVIRONMENT='-nde'
205 notify '' 3 "${OPTION}"; continue
206 DEPLOY_LOG="-log ${OPTARG}"
210 if [[ "${TARGET_POD}" =~ "virtual" ]]; then
211 DEPLOY_TYPE='virtual'
215 DEPLOY_SCENARIO=${OPTARG}
218 notify '' 3 "${OPTION}"; continue
219 if [[ ${OPTARG} ]]; then
220 STORAGE_DIR="-s ${OPTARG}"
224 notify '' 3 "${OPTION}"; continue
225 DEPLOY_TIMEOUT="-dt ${OPTARG}"
228 notify '' 3 "${OPTION}"; continue
230 if [[ ! $ISO =~ ${URI_REGEXP} ]]; then
231 notify "[ERROR] -i $ISO - invalid URI\n"
241 notify "[ERROR] Arguments not according to new argument style\n"
247 if [[ $EUID -ne 0 ]]; then
248 notify "[ERROR] This script must be run as root\n" 1>&2
252 # Validate mandatory arguments are set
253 # FIXME(armband): Bring back support for BASE_CONFIG_URI
254 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
255 [ -z "${DEPLOY_SCENARIO}" ]; then
256 notify "[ERROR] At least one of the mandatory args is missing!\n" 1>&2
263 # Enable the automatic exit trap
264 trap do_exit SIGINT SIGTERM EXIT
266 # Set no restrictive umask so that Jenkins can removeeee any residuals
271 pushd "${DEPLOY_DIR}" > /dev/null
272 # Prepare the deploy config files based on lab/pod information, deployment
275 # Install required packages
276 [ -n "$(command -v apt-get)" ] && apt-get install -y \
277 git make rsync mkisofs curl virtinst cpu-checker qemu-kvm
278 [ -n "$(command -v yum)" ] && yum install -y \
279 git make rsync genisoimage curl virt-install qemu-kvm
281 # Check scenario file existence
282 if [[ ! -f ../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml ]]; then
283 notify "[WARN] ${DEPLOY_SCENARIO}.yaml not found! \
284 Setting simplest scenario (os-nosdn-nofeature-noha)\n" 3
285 DEPLOY_SCENARIO='os-nosdn-nofeature-noha'
288 # Get required infra deployment data
290 eval "$(parse_yaml "../config/scenario/${DEPLOY_TYPE}/defaults.yaml")"
291 eval "$(parse_yaml "../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml")"
293 export CLUSTER_DOMAIN=${cluster_domain}
295 declare -A virtual_nodes_ram virtual_nodes_vcpus
296 for node in "${virtual_nodes[@]}"; do
297 virtual_custom_ram="virtual_${node}_ram"
298 virtual_custom_vcpus="virtual_${node}_vcpus"
299 virtual_nodes_ram[$node]=${!virtual_custom_ram:-$virtual_default_ram}
300 virtual_nodes_vcpus[$node]=${!virtual_custom_vcpus:-$virtual_default_vcpus}
305 prepare_vms virtual_nodes "${base_image}"
306 create_networks OPNFV_BRIDGES
307 create_vms virtual_nodes virtual_nodes_ram virtual_nodes_vcpus OPNFV_BRIDGES
308 update_pxe_network OPNFV_BRIDGES
309 start_vms virtual_nodes
314 # Openstack cluster setup
315 for state in "${cluster_states[@]}"; do
316 notify "STATE: ${state}\n" 2
317 # shellcheck disable=SC2086,2029
318 ssh ${SSH_OPTS} "ubuntu@${SALT_MASTER}" \
319 sudo "/root/fuel/mcp/config/states/${state}"
326 ##############################################################################