fuel, armband: Sync deploy scripts, cleanup
[releng.git] / jjb / fuel / fuel-deploy.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2017 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 if [[ "$BRANCH" != 'master' ]]; then
16     # source the file so we get OPNFV vars
17     source latest.properties
18
19     # echo the info about artifact that is used during the deployment
20     echo "Using ${OPNFV_ARTIFACT_URL/*\/} for deployment"
21 fi
22
23 # shellcheck disable=SC2153
24 if [[ "${JOB_NAME}" =~ "merge" ]]; then
25     # set simplest scenario for virtual deploys to run for merges
26     DEPLOY_SCENARIO="os-nosdn-nofeature-ha"
27 elif [[ "${BRANCH}" != 'master' ]]; then
28     # for none-merge deployments
29     # checkout the commit that was used for building the downloaded artifact
30     # to make sure the ISO and deployment mechanism uses same versions
31     echo "Checking out ${OPNFV_GIT_SHA1}"
32     git checkout "${OPNFV_GIT_SHA1}" --quiet
33 fi
34
35 # set deployment parameters
36 export TMPDIR=${HOME}/tmpdir
37 BRIDGE=${BRIDGE:-pxebr}
38 # shellcheck disable=SC2153
39 LAB_NAME=${NODE_NAME/-*}
40 # shellcheck disable=SC2153
41 POD_NAME=${NODE_NAME/*-}
42 # Fuel requires deploy script to be ran with sudo
43 SUDO=sudo
44
45 if [[ "${NODE_NAME}" =~ "virtual" ]]; then
46     POD_NAME="virtual_kvm"
47 fi
48
49 # we currently support ericsson, intel, lf and zte labs
50 if [[ ! "${LAB_NAME}" =~ (ericsson|intel|lf|zte) ]]; then
51     echo "Unsupported/unidentified lab ${LAB_NAME}. Cannot continue!"
52     exit 1
53 fi
54
55 echo "Using configuration for ${LAB_NAME}"
56
57 # create TMPDIR if it doesn't exist, change permissions
58 mkdir -p "${TMPDIR}"
59 chmod a+x "${HOME}" "${TMPDIR}"
60
61 # TODO: move lab-config URL to Jenkins param
62 LAB_CONFIG_URL='ssh://jenkins-ericsson@gerrit.opnfv.org:29418/securedlab'
63
64 cd "${WORKSPACE}" || exit 1
65 if [[ "${LAB_CONFIG_URL}" =~ ^(git|ssh):// ]]; then
66     echo "Cloning securedlab repo ${BRANCH}"
67     git clone --quiet --branch "${BRANCH}" "${LAB_CONFIG_URL}" lab-config
68     LAB_CONFIG_URL=file://${WORKSPACE}/lab-config
69
70     # Source local_env if present, which contains POD-specific config
71     local_env="${WORKSPACE}/lab-config/labs/${LAB_NAME}/${POD_NAME}/fuel/config/local_env"
72     if [ -e "${local_env}" ]; then
73         echo "-- Sourcing local environment file"
74         source "${local_env}"
75     fi
76 fi
77
78 # releng wants us to use nothing else but opnfv.iso for now. We comply.
79 ISO_FILE=file://${WORKSPACE}/opnfv.iso
80
81 # log file name
82 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
83
84 # construct the command
85 DEPLOY_COMMAND="${SUDO} ${WORKSPACE}/ci/deploy.sh -b ${LAB_CONFIG_URL} \
86     -l ${LAB_NAME} -p ${POD_NAME} -s ${DEPLOY_SCENARIO} -i ${ISO_FILE} \
87     -B ${DEFAULT_BRIDGE:-${BRIDGE}} -S ${TMPDIR} \
88     -L ${WORKSPACE}/${FUEL_LOG_FILENAME}"
89
90 # log info to console
91 echo "Deployment parameters"
92 echo "--------------------------------------------------------"
93 echo "Scenario: ${DEPLOY_SCENARIO}"
94 echo "Lab: ${LAB_NAME}"
95 echo "POD: ${POD_NAME}"
96 [[ "${BRANCH}" != 'master' ]] && echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
97 echo
98 echo "Starting the deployment using ${INSTALLER_TYPE}. This could take some time..."
99 echo "--------------------------------------------------------"
100 echo
101
102 # start the deployment
103 echo "Issuing command"
104 echo "${DEPLOY_COMMAND}"
105 echo
106
107 ${DEPLOY_COMMAND}
108 exit_code=$?
109
110 echo
111 echo "--------------------------------------------------------"
112 echo "Deployment is done!"
113
114 # upload logs for baremetal deployments
115 # work with virtual deployments is still going on, so skip that for now
116 if [[ "${JOB_NAME}" =~ (baremetal-daily|baremetal-weekly) ]]; then
117     echo "Uploading deployment logs"
118     gsutil cp "${WORKSPACE}/${FUEL_LOG_FILENAME}" \
119         "gs://${GS_URL}/logs/${FUEL_LOG_FILENAME}" > /dev/null 2>&1
120     echo "Logs are available at http://${GS_URL}/logs/${FUEL_LOG_FILENAME}"
121 fi
122
123 if [[ "${exit_code}" -ne 0 ]]; then
124     echo "Deployment failed!"
125     exit "${exit_code}"
126 fi
127
128 echo "Deployment is successful!"
129 exit 0