8bc5fa2683551922c0bdc85481772f6246e2aa7a
[releng.git] / jjb / fuel / fuel-deploy.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 Ericsson AB, Mirantis Inc., Enea Software AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -o nounset
11 set -o pipefail
12
13 export TERM="vt220"
14
15 # set deployment parameters
16 export TMPDIR=${HOME}/tmpdir
17 # shellcheck disable=SC2153
18 LAB_NAME=${NODE_NAME/-*}
19 # shellcheck disable=SC2153
20 POD_NAME=${NODE_NAME/*-}
21
22 # define Docker tag for stable branches
23 [[ "${BRANCH}" != master ]] && export MCP_DOCKER_TAG=${BRANCH##*/}
24
25 # Fuel currently supports arm, enea, ericsson, intel, lf, unh and zte labs
26 if [[ ! "${LAB_NAME}" =~ (arm|enea|ericsson|intel|lf|unh|zte) ]]; then
27     echo "Unsupported/unidentified lab ${LAB_NAME}. Cannot continue!"
28     exit 1
29 fi
30
31 echo "Using configuration for ${LAB_NAME}"
32
33 # create TMPDIR if it doesn't exist, change permissions
34 mkdir -p "${TMPDIR}"
35 sudo chmod a+x "${HOME}" "${TMPDIR}"
36
37 cd "${WORKSPACE}" || exit 1
38
39 # log file name
40 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
41
42 # Limited scope for vPOD verify jobs running on armband-virtual
43 [[ ! "${JOB_NAME}" =~ verify-deploy-virtual-arm64 ]] || EXTRA_ARGS='-e'
44
45 # turn on DEBUG mode
46 [[ ${CI_DEBUG,,} == true ]] && EXTRA_ARGS="-D ${EXTRA_ARGS:-}"
47
48 # construct the command
49 DEPLOY_COMMAND="${WORKSPACE}/ci/deploy.sh \
50     -l ${LAB_NAME} -p ${POD_NAME} -s ${DEPLOY_SCENARIO} \
51     -S ${TMPDIR} ${EXTRA_ARGS:-} \
52     -L ${WORKSPACE}/${FUEL_LOG_FILENAME}"
53
54 # log info to console
55 echo "Deployment parameters"
56 echo "--------------------------------------------------------"
57 echo "Scenario: ${DEPLOY_SCENARIO}"
58 echo "Lab: ${LAB_NAME}"
59 echo "POD: ${POD_NAME}"
60 echo
61 echo "Starting the deployment using ${INSTALLER_TYPE}. This could take some time..."
62 echo "--------------------------------------------------------"
63 echo
64
65 # start the deployment
66 echo "Issuing command"
67 echo "${DEPLOY_COMMAND}"
68 echo
69
70 ${DEPLOY_COMMAND}
71 exit_code=$?
72
73 echo
74 echo "--------------------------------------------------------"
75 echo "Deployment is done!"
76
77 # upload logs for baremetal deployments
78 # work with virtual deployments is still going on, so skip that for now
79 if [[ "${JOB_NAME}" =~ baremetal-daily ]]; then
80     echo "Uploading deployment logs"
81     gsutil cp "${WORKSPACE}/${FUEL_LOG_FILENAME}" \
82         "gs://${GS_URL}/logs/${FUEL_LOG_FILENAME}" > /dev/null 2>&1
83     echo "Logs are available at http://${GS_URL}/logs/${FUEL_LOG_FILENAME}"
84 fi
85
86 if [[ "${exit_code}" -ne 0 ]]; then
87     echo "Deployment failed!"
88     exit "${exit_code}"
89 fi
90
91 echo "Deployment is successful!"
92 exit 0