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