2 # shellcheck disable=SC2034,SC2154,SC1090,SC1091,SC2155
3 ##############################################################################
4 # Copyright (c) 2018 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: Installation of $DEPLOY_SCENARIO finished succesfully!" 2
21 notify_n "[ERROR] MCP: Installation of $DEPLOY_SCENARIO threw a fatal error!"
25 # End of Exit handlers
26 ##############################################################################
28 ##############################################################################
29 # BEGIN of usage description
34 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
35 $(notify "$(basename "$0"): Deploy the OPNFV Fuel 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[E]] [-d] [-D] [-N] [-m]
43 $(notify "OPTIONS:" 2)
44 -b Base-uri for the stack-configuration structure
47 -e Do not launch environment deployment (use twice to skip cloud setup)
48 -E Remove existing VCP VMs (use twice to redeploy baremetal nodes)
49 -f Deploy on existing Salt master (use twice or more to skip states)
50 -F Same as -e, do not launch environment deployment (legacy option)
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 and other deploy artifacts
57 -L Deployment log path and file name
58 -m Use single socket CPU compute nodes (only affects virtual computes)
59 -N Experimental: Do not virtualize control plane (novcp)
61 $(notify_i "Description:" 2)
62 Deploys the OPNFV Fuel stack on the indicated lab resource.
64 This script provides the OPNFV Fuel deployment abstraction.
65 It depends on the OPNFV official configuration directory/file structure
66 and provides a fairly simple mechanism to execute a deployment.
68 $(notify_i "Input parameters to the build script are:" 2)
69 -b Base URI to the configuration directory (needs to be provided in URI style,
70 it can be a local resource: file:// or a remote resource http(s)://).
71 A POD Descriptor File (PDF) and its Installer Descriptor File (IDF)
72 companion should be available at:
73 <base-uri>/labs/<lab-name>/<pod-name>.yaml
74 <base-uri>/labs/<lab-name>/idf-<pod-name>.yaml
75 The default is using the git submodule tracking 'OPNFV Pharos' in
76 <./mcp/scripts/pharos>.
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 If specified twice (e.g. -e -e), only the operating system and networks
81 will be provisioned, skipping cloud installation.
82 -E Remove existing VCP VMs. It will destroy and undefine all VCP VMs
83 currently defined on cluster KVM nodes. If specified twice (e.g. -E -E),
84 baremetal nodes (VCP too, implicitly) will be removed, then reprovisioned.
85 Only applicable for baremetal deploys.
86 If specified 3 times, a complete uninstallation (cleanup) will be performed
87 on the jumpserver (even for virtual deploys): VMs, virsh networks,
88 containers, networks, services etc.
89 -f Deploy on existing Salt master. It will skip infrastructure VM creation,
90 but it will still sync reclass configuration from current repo to Salt
92 Each additional use skips one more state file. For example, -fff would
93 skip the first 3 state files (e.g. virtual_init, maas, baremetal_init).
94 -F Same as -e, do not launch environment deployment (legacy option)
95 -h Print this message and exit
96 -L Deployment log path and name, eg. -L /home/jenkins/job.log.tar.gz
97 -l Lab name as defined in the configuration directory, e.g. lf
98 -p POD name as defined in the configuration directory, e.g. pod2
99 -m Use single socket compute nodes. Instead of using default NUMA-enabled
100 topology for virtual compute nodes created via libvirt, configure a
101 single guest CPU socket.
102 -N Experimental: Instead of virtualizing the control plane (VCP), deploy
103 control plane directly on baremetal nodes
104 -P Skip installing dependency distro packages on current host
105 This flag should only be used if you have kept back older packages that
106 would be upgraded and that is undesirable on the current system.
107 Note that without the required packages, deploy will fail.
108 -s Deployment-scenario, this points to a short deployment scenario name, which
109 has to be defined in config directory (e.g. os-odl-nofeature-ha).
110 -S Storage dir for VM images, default is /var/lib/opnfv/tmpdir
111 It is recommended to store the deploy artifacts on a fast disk, outside of
112 the current git repository (so clean operations won't erase it).
114 $(notify_i "[NOTE] sudo & virsh priviledges are needed for this script to run" 3)
118 $(notify_i "sudo $(basename "$0") \\
119 -b file:///home/jenkins/securedlab \\
121 -s os-odl-nofeature-ha \\
122 -S /home/jenkins/tmpdir" 2)
127 # END of usage description
128 ##############################################################################
130 ##############################################################################
131 # BEGIN of variables to customize
133 CI_DEBUG=${CI_DEBUG:-0}; [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
134 MCP_REPO_ROOT_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")
135 DEPLOY_DIR=$(cd "${MCP_REPO_ROOT_PATH}/mcp/scripts"; pwd)
136 MCP_STORAGE_DIR='/var/lib/opnfv/tmpdir'
137 URI_REGEXP='(file|https?|ftp)://.*'
138 BASE_CONFIG_URI="file://${MCP_REPO_ROOT_PATH}/mcp/scripts/pharos"
139 OPNFV_BRANCH=$(sed -ne 's/defaultbranch=//p' "${MCP_REPO_ROOT_PATH}/.gitreview")
140 DEF_DOCKER_TAG=$(basename "${OPNFV_BRANCH/master/latest}")
142 # Customize deploy workflow
143 DRY_RUN=${DRY_RUN:-0}
144 USE_EXISTING_PKGS=${USE_EXISTING_PKGS:-0}
145 USE_EXISTING_INFRA=${USE_EXISTING_INFRA:-0}
146 MCP_NO_DEPLOY_ENVIRONMENT=${MCP_NO_DEPLOY_ENVIRONMENT:-0}
147 ERASE_ENV=${ERASE_ENV:-0}
148 MCP_VCP=${MCP_VCP:-1}
149 MCP_DOCKER_TAG=${MCP_DOCKER_TAG:-${DEF_DOCKER_TAG}}
150 MCP_CMP_SS=${MCP_CMP_SS:-0}
152 source "${DEPLOY_DIR}/globals.sh"
153 source "${DEPLOY_DIR}/lib.sh"
154 source "${DEPLOY_DIR}/lib_template.sh"
155 source "${DEPLOY_DIR}/lib_jump_common.sh"
156 source "${DEPLOY_DIR}/lib_jump_deploy.sh"
159 # END of variables to customize
160 ##############################################################################
162 ##############################################################################
166 while getopts "b:dDfEFl:L:Np:Ps:S:he" OPTION
170 BASE_CONFIG_URI=${OPTARG}
171 if [[ ! $BASE_CONFIG_URI =~ ${URI_REGEXP} ]]; then
172 notify "[ERROR] -b $BASE_CONFIG_URI - invalid URI"
184 ((USE_EXISTING_INFRA+=1))
187 ((MCP_NO_DEPLOY_ENVIRONMENT+=1))
196 DEPLOY_LOG="${OPTARG}"
211 DEPLOY_SCENARIO=${OPTARG}
214 if [[ ${OPTARG} ]]; then
215 MCP_STORAGE_DIR="${OPTARG}"
223 notify_e "[ERROR] Unsupported arg, see -h for help"
228 if [[ "$(sudo whoami)" != 'root' ]]; then
229 notify_e "[ERROR] This script requires sudo rights"
232 # Validate mandatory arguments are set
233 if [ -z "${TARGET_LAB}" ] || [ -z "${TARGET_POD}" ] || \
234 [ -z "${DEPLOY_SCENARIO}" ]; then
236 notify_e "[ERROR] At least one of the mandatory args is missing!"
239 [[ "${CI_DEBUG}" =~ (false|0) ]] || set -x
241 # Enable the automatic exit trap
242 trap do_exit SIGINT SIGTERM EXIT
244 # Set no restrictive umask so that Jenkins can remove any residuals
247 pushd "${DEPLOY_DIR}" > /dev/null
248 # Prepare the deploy config files based on lab/pod information, deployment
251 # Install required packages on jump server
252 sudo mkdir -p "${MCP_STORAGE_DIR}"
253 sudo chown -R "${USER}:${USER}" "${MCP_STORAGE_DIR}"
254 if [ ${USE_EXISTING_PKGS} -eq 1 ]; then
255 notify "[NOTE] Skipping distro pkg installation" 2
257 notify "[NOTE] Installing required distro pkgs" 2
258 jumpserver_pkg_install 'deploy'
259 docker_install "${MCP_STORAGE_DIR}"
260 virtinst_install "${MCP_STORAGE_DIR}"
263 if ! ${VIRSH} list >/dev/null 2>&1; then
264 notify_e "[ERROR] This script requires hypervisor access"
267 # Collect jump server system information for deploy debugging
270 # Clone git submodules and apply our patches
271 make -C "${MCP_REPO_ROOT_PATH}/mcp/patches" deepclean patches-import
273 # Check scenario file existence
274 SCENARIO_DIR="$(readlink -f "../config/scenario")"
275 if [ ! -f "${SCENARIO_DIR}/${DEPLOY_SCENARIO}.yaml" ] && \
276 [ ! -f "${SCENARIO_DIR}/${DEPLOY_SCENARIO}.yaml.j2" ]; then
277 notify_e "[ERROR] Scenario definition file is missing!"
280 # key might not exist yet ...
282 export MAAS_SSH_KEY="$(cat "$(basename "${SSH_KEY}").pub")"
284 # Expand jinja2 templates based on PDF data and env vars
285 [[ "${DEPLOY_SCENARIO}" =~ -ha$ ]] || MCP_VCP=0
286 export MCP_REPO_ROOT_PATH MCP_VCP MCP_STORAGE_DIR MCP_DOCKER_TAG MCP_CMP_SS \
287 MCP_JUMP_ARCH=$(uname -i) MCP_DEPLOY_SCENARIO="${DEPLOY_SCENARIO}" \
288 MCP_NO_DEPLOY_ENVIRONMENT
289 do_templates_scenario "${MCP_STORAGE_DIR}" "${TARGET_LAB}" "${TARGET_POD}" \
290 "${BASE_CONFIG_URI}" "${SCENARIO_DIR}" \
291 "${SCENARIO_DIR}/${DEPLOY_SCENARIO}.yaml"
292 do_templates_cluster "${MCP_STORAGE_DIR}" "${TARGET_LAB}" "${TARGET_POD}" \
293 "${MCP_REPO_ROOT_PATH}" \
294 "${SCENARIO_DIR}/defaults.yaml"
296 # Determine additional data (e.g. jump bridge names) based on XDF
297 source "${DEPLOY_DIR}/xdf_data.sh"
299 # Jumpserver prerequisites check
300 notify "[NOTE] Using bridges: ${OPNFV_BRIDGES[*]}" 2
301 jumpserver_check_requirements "${cluster_states[*]}" "${virtual_nodes[*]}" \
302 "${OPNFV_BRIDGES[@]}"
305 if [ ${DRY_RUN} -eq 1 ]; then
306 notify "[NOTE] Dry run, skipping all deployment tasks" 2
308 elif [ ${ERASE_ENV} -gt 2 ]; then
309 notify "[NOTE] Uninstall / cleanup all jumpserver Fuel resources" 2
310 cleanup_all "${MCP_STORAGE_DIR}" "${OPNFV_BRIDGES[@]}"
312 elif [ ${USE_EXISTING_INFRA} -gt 0 ]; then
313 notify "[NOTE] Use existing infra: skip first ${USE_EXISTING_INFRA} states" 2
314 notify "[STATE] Skipping: ${cluster_states[*]::${USE_EXISTING_INFRA}}" 2
316 prepare_vms "${base_image}" "${MCP_STORAGE_DIR}" "${virtual_repos_pkgs}"
317 create_networks "${OPNFV_BRIDGES[@]}"
320 create_vms "${MCP_STORAGE_DIR}" "${virtual_nodes_data}" "${OPNFV_BRIDGES[@]}"
321 start_vms "${virtual_nodes[@]}"
323 # https://github.com/docker/libnetwork/issues/1743
324 # rm -f /var/lib/docker/network/files/local-kv.db
325 sudo systemctl restart docker
326 prepare_containers "${MCP_STORAGE_DIR}"
329 start_containers "${MCP_STORAGE_DIR}"
332 # Openstack cluster setup
334 if [ ${MCP_NO_DEPLOY_ENVIRONMENT} -eq 1 ]; then
335 notify "[NOTE] Skip openstack cluster setup" 2
337 for state in "${cluster_states[@]:${USE_EXISTING_INFRA}}"; do
338 notify "[STATE] Applying state: ${state}" 2
339 # shellcheck disable=SC2086,2029
340 wait_for 5 "ssh ${SSH_OPTS} ${SSH_SALT} sudo \
341 CI_DEBUG=$CI_DEBUG ERASE_ENV=$ERASE_ENV \
342 /root/fuel/mcp/config/states/${state}"
343 if [ "${state}" = 'maas' ]; then
344 # For hybrid PODs (virtual + baremetal nodes), the virtual nodes
345 # should be reset to force a DHCP request from MaaS DHCP
346 reset_vms "${virtual_nodes[@]}"
350 ./log.sh "${DEPLOY_LOG}"
357 ##############################################################################