2 # shellcheck disable=SC2034,SC2154,SC1090,SC1091
3 ##############################################################################
4 # Copyright (c) 2017 Ericsson AB, Mirantis Inc., Enea 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 ##############################################################################
12 ##############################################################################
13 # BEGIN of Exit handlers
17 cleanup_mounts > /dev/null 2>&1
18 if [ ${RC} -eq 0 ]; then
19 notify_n "[OK] MCP: Openstack installation finished succesfully!" 2
21 notify_n "[ERROR] MCP: Openstack installation threw a fatal error!"
25 # End of Exit handlers
26 ##############################################################################
28 ##############################################################################
29 # BEGIN of usage description
34 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
35 $(notify "$(basename "$0"): Deploy the Fuel@OPNFV MCP stack" 3)
38 $(basename "$0") -l lab-name -p pod-name -s deploy-scenario \\
39 [-b Lab Config Base URI] \\
40 [-S storage-dir] [-L /path/to/log/file.tar.gz] \\
41 [-f[f]] [-F] [-e | -E[E]] [-d] [-D]
43 $(notify "OPTIONS:" 2)
44 -b Base-uri for the stack-configuration structure
47 -e Do not launch environment deployment
48 -E Remove existing VCP VMs (use twice to redeploy baremetal nodes)
49 -f Deploy on existing Salt master (use twice to also skip config sync)
50 -F Do only create a Salt master
51 -h Print this message and exit
54 -P Skip installation of package dependencies
55 -s Deploy-scenario short-name
56 -S Storage dir for VM images
57 -L Deployment log path and file name
59 $(notify_i "Description:" 2)
60 Deploys the Fuel@OPNFV stack on the indicated lab resource.
62 This script provides the Fuel@OPNFV deployment abstraction.
63 It depends on the OPNFV official configuration directory/file structure
64 and provides a fairly simple mechanism to execute a deployment.
66 $(notify_i "Input parameters to the build script are:" 2)
67 -b Base URI to the configuration directory (needs to be provided in URI style,
68 it can be a local resource: file:// or a remote resource http(s)://).
69 A POD Descriptor File (PDF) and its Installer Descriptor File (IDF)
70 companion should be available at:
71 <base-uri>/labs/<lab-name>/<pod-name>.yaml
72 <base-uri>/labs/<lab-name>/idf-<pod-name>.yaml
73 The default is using the git submodule tracking 'OPNFV Pharos' in
74 <./mcp/scripts/pharos>.
75 An example config is provided inside current repo in
76 <./mcp/config>, automatically linked as <./mcp/scripts/pharos/labs/local>.
77 -d Dry-run - Produce deploy config files, but do not execute deploy
78 -D Debug logging - Enable extra logging in sh deploy scripts (set -x)
79 -e Do not launch environment deployment
80 -E Remove existing VCP VMs. It will destroy and undefine all VCP VMs
81 currently defined on cluster KVM nodes. If specified twice (e.g. -E -E),
82 baremetal nodes (VCP too, implicitly) will be removed, then reprovisioned.
83 Only applicable for baremetal deploys.
84 -f Deploy on existing Salt master. It will skip infrastructure VM creation,
85 but it will still sync reclass configuration from current repo to Salt
86 Master node. If specified twice (e.g. -f -f), config sync will also be
88 -F Do only create a Salt master
89 -h Print this message and exit
90 -L Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
91 -l Lab name as defined in the configuration directory, e.g. lf
92 -p POD name as defined in the configuration directory, e.g. pod2
93 -P Skip installing dependency distro packages on current host
94 This flag should only be used if you have kept back older packages that
95 would be upgraded and that is undesirable on the current system.
96 Note that without the required packages, deploy will fail.
97 -s Deployment-scenario, this points to a short deployment scenario name, which
98 has to be defined in config directory (e.g. os-odl-nofeature-ha).
99 -S Storage dir for VM images, default is mcp/deploy/images
101 $(notify_i "[NOTE] sudo & virsh priviledges are needed for this script to run" 3)
105 $(notify_i "sudo $(basename "$0") \\
106 -b file:///home/jenkins/securedlab \\
108 -s os-odl-nofeature-ha" 2)
113 # END of usage description
114 ##############################################################################
116 ##############################################################################
117 # BEGIN of variables to customize
119 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
120 REPO_ROOT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")
121 DEPLOY_DIR=$(cd "${REPO_ROOT_PATH}/mcp/scripts"; pwd)
122 STORAGE_DIR=$(cd "${REPO_ROOT_PATH}/mcp/deploy/images"; pwd)
123 RECLASS_CLUSTER_DIR=$(cd "${REPO_ROOT_PATH}/mcp/reclass/classes/cluster"; pwd)
124 DEPLOY_TYPE='baremetal'
125 BR_NAMES=('admin' 'mgmt' 'private' 'public')
126 OPNFV_BRIDGES=('pxebr' 'mgmt' 'internal' 'public')
127 URI_REGEXP='(file|https?|ftp)://.*'
128 BASE_CONFIG_URI="file://${REPO_ROOT_PATH}/mcp/scripts/pharos"
130 # Customize deploy workflow
131 DRY_RUN=${DRY_RUN:-0}
132 USE_EXISTING_PKGS=${USE_EXISTING_PKGS:-0}
133 USE_EXISTING_INFRA=${USE_EXISTING_INFRA:-0}
134 INFRA_CREATION_ONLY=${INFRA_CREATION_ONLY:-0}
135 NO_DEPLOY_ENVIRONMENT=${NO_DEPLOY_ENVIRONMENT:-0}
136 ERASE_ENV=${ERASE_ENV:-0}
138 source "${DEPLOY_DIR}/globals.sh"
139 source "${DEPLOY_DIR}/lib.sh"
142 # END of variables to customize
143 ##############################################################################
145 ##############################################################################
149 while getopts "b:dDfEFl:L:p:Ps:S:he" OPTION
153 BASE_CONFIG_URI=${OPTARG}
154 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
155 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI"
167 ((USE_EXISTING_INFRA+=1))
170 INFRA_CREATION_ONLY=1
173 NO_DEPLOY_ENVIRONMENT=1
182 DEPLOY_LOG="${OPTARG}"
186 if [[ "${TARGET_POD}" =~ virtual ]]; then
187 DEPLOY_TYPE='virtual'
188 # All vPODs will use 'local-virtual1' PDF/IDF for now
190 TARGET_POD='virtual1'
197 DEPLOY_SCENARIO=${OPTARG}
200 if [[ ${OPTARG} ]]; then
201 STORAGE_DIR="${OPTARG}"
209 notify_e "[ERROR] Unsupported arg, see -h for help"
214 if [[ "$(sudo whoami)" != 'root' ]]; then
215 notify_e "[ERROR] This script requires sudo rights"
218 # Validate mandatory arguments are set
219 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
220 [ -z "${DEPLOY_SCENARIO}" ]; then
222 notify_e "[ERROR] At least one of the mandatory args is missing!"
225 [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
227 # Enable the automatic exit trap
228 trap do_exit SIGINT SIGTERM EXIT
230 # Set no restrictive umask so that Jenkins can remove any residuals
233 pushd "${DEPLOY_DIR}" > /dev/null
234 # Prepare the deploy config files based on lab/pod information, deployment
237 # Install required packages on jump server
238 if [ ${USE_EXISTING_PKGS} -eq 1 ]; then
239 notify "[NOTE] Skipping distro pkg installation" 2
241 notify "[NOTE] Installing required distro pkgs" 2
242 if [ -n "$(command -v apt-get)" ]; then
243 pkg_type='deb'; pkg_cmd='sudo apt-get install -y'
245 pkg_type='rpm'; pkg_cmd='sudo yum install -y --skip-broken'
247 eval "$(parse_yaml "./requirements_${pkg_type}.yaml")"
248 for section in 'common' "${DEPLOY_TYPE}" "$(uname -m)"; do
249 section_var="requirements_pkg_${section}[*]"
250 pkg_list+=" ${!section_var}"
252 # shellcheck disable=SC2086
253 ${pkg_cmd} ${pkg_list}
256 if ! virsh list >/dev/null 2>&1; then
257 notify_e "[ERROR] This script requires hypervisor access"
260 # Collect jump server system information for deploy debugging
263 # Clone git submodules and apply our patches
264 make -C "${REPO_ROOT_PATH}/mcp/patches" deepclean patches-import
266 # Convert Pharos-compatible POD Descriptor File (PDF) to reclass model input
267 PHAROS_GEN_CONFIG_SCRIPT="./pharos/config/utils/generate_config.py"
268 PHAROS_INSTALLER_ADAPTER="./pharos/config/installers/fuel/pod_config.yml.j2"
269 BASE_CONFIG_PDF="${BASE_CONFIG_URI}/labs/${TARGET_LAB}/${TARGET_POD}.yaml"
270 BASE_CONFIG_IDF="${BASE_CONFIG_URI}/labs/${TARGET_LAB}/idf-${TARGET_POD}.yaml"
271 LOCAL_PDF="${STORAGE_DIR}/$(basename "${BASE_CONFIG_PDF}")"
272 LOCAL_IDF="${STORAGE_DIR}/$(basename "${BASE_CONFIG_IDF}")"
273 LOCAL_PDF_RECLASS="${STORAGE_DIR}/pod_config.yml"
274 rm -f "${LOCAL_PDF_RECLASS}"
275 ln -sf "$(readlink -f "../config/labs/local")" "./pharos/labs/"
276 if ! curl --create-dirs -o "${LOCAL_PDF}" "${BASE_CONFIG_PDF}"; then
277 notify_e "[ERROR] Could not retrieve PDF (Pod Descriptor File)!"
278 elif ! curl -o "${LOCAL_IDF}" "${BASE_CONFIG_IDF}"; then
279 notify_e "[ERROR] Could not retrieve IDF (Installer Descriptor File)!"
280 elif ! "${PHAROS_GEN_CONFIG_SCRIPT}" -y "${LOCAL_PDF}" \
281 -j "${PHAROS_INSTALLER_ADAPTER}" > "${LOCAL_PDF_RECLASS}"; then
282 notify_e "[ERROR] Could not convert PDF+IDF to reclass model input!"
285 # Check scenario file existence
286 SCENARIO_DIR="../config/scenario"
287 if [ ! -f "${SCENARIO_DIR}/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml" ]; then
288 notify_e "[ERROR] Scenario definition file is missing!"
291 # Check defaults file existence
292 if [ ! -f "${SCENARIO_DIR}/defaults-$(uname -i).yaml" ]; then
293 notify_e "[ERROR] Scenario defaults file is missing!"
296 # Get required infra deployment data
298 eval "$(parse_yaml "${SCENARIO_DIR}/defaults-$(uname -i).yaml")"
299 eval "$(parse_yaml "${SCENARIO_DIR}/${DEPLOY_TYPE}/${DEPLOY_SCENARIO}.yaml")"
300 eval "$(parse_yaml "${LOCAL_PDF_RECLASS}")"
301 [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
303 export CLUSTER_DOMAIN=${cluster_domain}
305 # Serialize vnode data as '<name0>,<ram0>,<vcpu0>|<name1>,<ram1>,<vcpu1>[...]'
306 for node in "${virtual_nodes[@]}"; do
307 virtual_custom_ram="virtual_${node}_ram"
308 virtual_custom_vcpus="virtual_${node}_vcpus"
309 virtual_nodes_data+="${node},"
310 virtual_nodes_data+="${!virtual_custom_ram:-$virtual_default_ram},"
311 virtual_nodes_data+="${!virtual_custom_vcpus:-$virtual_default_vcpus}|"
313 virtual_nodes_data=${virtual_nodes_data%|}
315 # Serialize repos, packages to (pre-)install/remove for:
316 # - foundation node VM base image (virtual: all VMs, baremetal: cfg01|mas01)
317 # - virtualized control plane VM base image (only when VCP is used)
318 base_image_flavors=common
319 if [[ "${cluster_states[*]}" =~ virtual_control ]]; then
320 base_image_flavors+=" control"
322 for sc in ${base_image_flavors}; do
323 for va in apt_keys apt_repos pkg_install pkg_remove; do
324 key=virtual_${sc}_${va}
325 eval "${key}=\${${key}[@]// /|}"
326 eval "${key}=\${${key}// /,}"
327 virtual_repos_pkgs+="${!key}^"
330 virtual_repos_pkgs=${virtual_repos_pkgs%^}
332 # Expand reclass and virsh network templates
333 for tp in "${RECLASS_CLUSTER_DIR}/all-mcp-arch-common/opnfv/"*.template \
337 EOF" 2> /dev/null > "${tp%.template}"
340 # Convert Pharos-compatible PDF to reclass network definitions
341 find "${RECLASS_CLUSTER_DIR}" -name '*.j2' | while read -r tp
343 if ! "${PHAROS_GEN_CONFIG_SCRIPT}" -y "${LOCAL_PDF}" \
344 -j "${tp}" > "${tp%.j2}"; then
345 notify_e "[ERROR] Could not convert PDF to reclass network defs!"
349 # Determine 'admin', 'mgmt', 'private' and 'public' bridge names based on IDF
350 for ((i = 0; i < ${#BR_NAMES[@]}; i++)); do
351 br_jump=$(eval echo "\$parameters__param_opnfv_jump_bridge_${BR_NAMES[i]}")
352 if [ -n "${br_jump}" ] && [ "${br_jump}" != 'None' ]; then
353 OPNFV_BRIDGES[${i}]="${br_jump}"
356 notify "[NOTE] Using bridges: ${OPNFV_BRIDGES[*]}" 2
359 if [ ${DRY_RUN} -eq 1 ]; then
360 notify "[NOTE] Dry run, skipping all deployment tasks" 2
362 elif [ ${USE_EXISTING_INFRA} -gt 0 ]; then
363 notify "[NOTE] Use existing infra" 2
367 prepare_vms "${base_image}" "${STORAGE_DIR}" "${virtual_repos_pkgs}" \
368 "${virtual_nodes[@]}"
369 create_networks "${OPNFV_BRIDGES[@]}"
371 create_vms "${STORAGE_DIR}" "${virtual_nodes_data}" "${OPNFV_BRIDGES[@]}"
372 update_mcpcontrol_network
373 start_vms "${virtual_nodes[@]}"
376 if [ ${USE_EXISTING_INFRA} -lt 2 ]; then
377 wait_for 5 "./salt.sh ${LOCAL_PDF_RECLASS}"
380 # Openstack cluster setup
382 if [ ${INFRA_CREATION_ONLY} -eq 1 ] || [ ${NO_DEPLOY_ENVIRONMENT} -eq 1 ]; then
383 notify "[NOTE] Skip openstack cluster setup" 2
385 for state in "${cluster_states[@]}"; do
386 notify "[STATE] Applying state: ${state}" 2
387 # shellcheck disable=SC2086,2029
388 wait_for 5 "ssh ${SSH_OPTS} ${SSH_SALT} sudo \
389 CI_DEBUG=$CI_DEBUG ERASE_ENV=$ERASE_ENV \
390 /root/fuel/mcp/config/states/${state}"
394 ./log.sh "${DEPLOY_LOG}"
400 ##############################################################################