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").
71 Note that a virtual network "mcpcontrol" is always created. For virtual
72 deploys, "mcpcontrol" is also used for PXE, leaving the PXE bridge unused.
73 For baremetal deploys, PXE bridge is used for baremetal node provisioning,
74 while "mcpcontrol" is used to provision the infrastructure VMs only.
75 The default is 'pxebr'.
76 -h Print this message and exit
77 -l Lab name as defined in the configuration directory, e.g. lf
78 -p POD name as defined in the configuration directory, e.g. pod-1
79 -s Deployment-scenario, this points to a short deployment scenario name, which
80 has to be defined in config directory (e.g. os-odl_l2-nofeature-noha).
82 $(notify "Disabled input parameters (not yet supported with MCP):" 3)
83 -d (disabled) Dry-run - Produce deploy config files, but do not execute deploy
84 -f (disabled) Deploy on existing Salt master
85 -e (disabled) Do not launch environment deployment
86 -F (disabled) Do only create a Salt master
87 -L (disabled) Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
88 -S (disabled) Storage dir for VM images, default is fuel/deploy/images
89 -T (disabled) Timeout, in minutes, for the deploy.
90 It defaults to using the DEPLOY_TIMEOUT environment variable when defined.
91 -i (disabled) .iso image to be deployed (needs to be provided in a URI
92 style, it can be a local resource: file:// or a remote resource http(s)://)
94 $(notify "[NOTE] sudo & virsh priviledges are needed for this script to run" 3)
98 $(notify "sudo $(basename "$0") \\
99 -b file:///home/jenkins/lab-config \\
101 -s os-odl_l2-nofeature-noha" 2)
106 # END of usage description
107 ##############################################################################
109 ##############################################################################
110 # BEGIN of colored notification wrapper
113 tput setaf "${2:-1}" || true
114 echo -en "${1:-"[WARN] Unsupported opt arg: $3\\n"}"
118 # END of colored notification wrapper
119 ##############################################################################
121 ##############################################################################
122 # BEGIN of deployment clean-up
125 echo "Cleaning up deploy tmp directories"
128 # END of deployment clean-up
129 ##############################################################################
131 ##############################################################################
132 # BEGIN of variables to customize
134 SCRIPT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
135 DEPLOY_DIR=$(cd "${SCRIPT_PATH}/../mcp/scripts"; pwd)
136 DEPLOY_TYPE='baremetal'
137 OPNFV_BRIDGES=('pxebr' 'mgmt' 'internal' 'public')
138 URI_REGEXP='(file|https?|ftp)://.*'
140 export SSH_KEY=${SSH_KEY:-mcp.rsa}
141 export SALT_MASTER=${SALT_MASTER_IP:-192.168.10.100}
142 export MAAS_IP=${MAAS_IP:-192.168.10.3}
143 export SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${SSH_KEY}"
145 # Variables below are disabled for now, to be re-introduced or removed later
148 FUEL_CREATION_ONLY=''
149 NO_DEPLOY_ENVIRONMENT=''
152 if ! [ -z "${DEPLOY_TIMEOUT}" ]; then
153 DEPLOY_TIMEOUT="-dt ${DEPLOY_TIMEOUT}"
159 # END of variables to customize
160 ##############################################################################
162 ##############################################################################
167 while getopts "b:B:dfFl:L:p:s:S:T:i:he" OPTION
171 BASE_CONFIG_URI=${OPTARG}
172 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
173 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI\n"
181 OPT_BRIDGES=($OPTARG)
182 for bridge in "${OPT_BRIDGES[@]}"; do
183 if [ -n "${bridge}" ]; then
184 OPNFV_BRIDGES[${OPNFV_BRIDGE_IDX}]="${bridge}"
186 OPNFV_BRIDGE_IDX=$[OPNFV_BRIDGE_IDX + 1]
191 notify '' 3 "${OPTION}"; continue
195 notify '' 3 "${OPTION}"; continue
196 USE_EXISTING_FUEL='-nf'
199 notify '' 3 "${OPTION}"; continue
200 FUEL_CREATION_ONLY='-fo'
203 notify '' 3 "${OPTION}"; continue
204 NO_DEPLOY_ENVIRONMENT='-nde'
210 notify '' 3 "${OPTION}"; continue
211 DEPLOY_LOG="-log ${OPTARG}"
215 if [[ "${TARGET_POD}" =~ "virtual" ]]; then
216 DEPLOY_TYPE='virtual'
220 DEPLOY_SCENARIO=${OPTARG}
223 notify '' 3 "${OPTION}"; continue
224 if [[ ${OPTARG} ]]; then
225 STORAGE_DIR="-s ${OPTARG}"
229 notify '' 3 "${OPTION}"; continue
230 DEPLOY_TIMEOUT="-dt ${OPTARG}"
233 notify '' 3 "${OPTION}"; continue
235 if [[ ! $ISO =~ ${URI_REGEXP} ]]; then
236 notify "[ERROR] -i $ISO - invalid URI\n"
246 notify "[ERROR] Arguments not according to new argument style\n"
252 if [[ "$(sudo whoami)" != 'root' ]]; then
253 notify "This script requires sudo rights\n" 1>&2
257 if ! virsh list >/dev/null 2>&1; then
258 notify "This script requires hypervisor access\n" 1>&2
262 # Validate mandatory arguments are set
263 # FIXME(armband): Bring back support for BASE_CONFIG_URI
264 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
265 [ -z "${DEPLOY_SCENARIO}" ]; then
266 notify "[ERROR] At least one of the mandatory args is missing!\n" 1>&2
273 # Enable the automatic exit trap
274 trap do_exit SIGINT SIGTERM EXIT
276 # Set no restrictive umask so that Jenkins can removeeee any residuals
281 pushd "${DEPLOY_DIR}" > /dev/null
282 # Prepare the deploy config files based on lab/pod information, deployment
285 # Install required packages
286 [ -n "$(command -v apt-get)" ] && sudo apt-get install -y \
287 git make rsync mkisofs curl virtinst cpu-checker qemu-kvm
288 [ -n "$(command -v yum)" ] && sudo yum install -y \
289 git make rsync genisoimage curl virt-install qemu-kvm
291 if [ "$(uname -i)" = "aarch64" ]; then
292 [ -n "$(command -v apt-get)" ] && sudo apt-get install -y vgabios && \
293 sudo ln -sf /usr/share/vgabios/vgabios.bin /usr/share/qemu/vgabios-stdvga.bin
294 [ -n "$(command -v yum)" ] && sudo yum install -y vgabios
297 # Check scenario file existence
298 if [ ! -f ../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml ]; then
299 notify "[WARN] ${DEPLOY_SCENARIO}.yaml not found! \
300 Setting simplest scenario (os-nosdn-nofeature-noha)\n" 3
301 DEPLOY_SCENARIO='os-nosdn-nofeature-noha'
302 if [ ! -f ../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml ]; then
303 notify "[ERROR] Scenario definition file is missing!\n" 1>&2
308 # Get required infra deployment data
310 eval "$(parse_yaml "../config/scenario/${DEPLOY_TYPE}/defaults.yaml")"
311 eval "$(parse_yaml "../config/scenario/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml")"
313 export CLUSTER_DOMAIN=${cluster_domain}
315 declare -A virtual_nodes_ram virtual_nodes_vcpus
316 for node in "${virtual_nodes[@]}"; do
317 virtual_custom_ram="virtual_${node}_ram"
318 virtual_custom_vcpus="virtual_${node}_vcpus"
319 virtual_nodes_ram[$node]=${!virtual_custom_ram:-$virtual_default_ram}
320 virtual_nodes_vcpus[$node]=${!virtual_custom_vcpus:-$virtual_default_vcpus}
325 prepare_vms virtual_nodes "${base_image}"
326 create_networks OPNFV_BRIDGES
327 create_vms virtual_nodes virtual_nodes_ram virtual_nodes_vcpus OPNFV_BRIDGES
328 update_mcpcontrol_network
329 start_vms virtual_nodes
334 # Openstack cluster setup
335 for state in "${cluster_states[@]}"; do
336 notify "STATE: ${state}\n" 2
337 # shellcheck disable=SC2086,2029
338 ssh ${SSH_OPTS} "ubuntu@${SALT_MASTER}" \
339 sudo "/root/fuel/mcp/config/states/${state}"
346 ##############################################################################