criteria field must be 'PASS/FAIL'
[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 BRIDGE=${BRIDGE:-pxebr}
42 # shellcheck disable=SC2153
43 LAB_NAME=${NODE_NAME/-*}
44 # shellcheck disable=SC2153
45 POD_NAME=${NODE_NAME/*-}
46 # Armband might override LAB_CONFIG_URL, all others use the default
47 LAB_CONFIG_URL=${LAB_CONFIG_URL:-'ssh://jenkins-ericsson@gerrit.opnfv.org:29418/securedlab'}
48
49 # Fuel requires deploy script to be ran with sudo, Armband does not
50 SUDO='sudo -E'
51 if [ "${PROJECT}" = 'fuel' ]; then
52     # Fuel does not use any POD-specific configuration for virtual deploys
53     if [[ "${NODE_NAME}" =~ "virtual" ]]; then
54         POD_NAME="virtual_kvm"
55     fi
56     # Fuel currently supports ericsson, intel, lf and zte labs
57     if [[ ! "${LAB_NAME}" =~ (ericsson|intel|lf|zte) ]]; then
58         echo "Unsupported/unidentified lab ${LAB_NAME}. Cannot continue!"
59         exit 1
60     fi
61 else
62     SUDO=
63     # Armband currently supports arm, enea labs
64     if [[ ! "${LAB_NAME}" =~ (arm|enea) ]]; then
65         echo "Unsupported/unidentified lab ${LAB_NAME}. Cannot continue!"
66         exit 1
67     fi
68 fi
69
70 echo "Using configuration for ${LAB_NAME}"
71
72 # create TMPDIR if it doesn't exist, change permissions
73 mkdir -p "${TMPDIR}"
74 chmod a+x "${HOME}" "${TMPDIR}"
75
76 cd "${WORKSPACE}" || exit 1
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_URL="file://${LOCAL_CFG}"
83 fi
84
85 # log file name
86 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
87
88 # construct the command
89 DEPLOY_COMMAND="${SUDO} ${WORKSPACE}/ci/deploy.sh -b ${LAB_CONFIG_URL} \
90     -l ${LAB_NAME} -p ${POD_NAME} -s ${DEPLOY_SCENARIO} ${ISO_FILE_ARG:-} \
91     -B ${DEFAULT_BRIDGE:-${BRIDGE}} -S ${TMPDIR} \
92     -L ${WORKSPACE}/${FUEL_LOG_FILENAME}"
93
94 # log info to console
95 echo "Deployment parameters"
96 echo "--------------------------------------------------------"
97 echo "Scenario: ${DEPLOY_SCENARIO}"
98 echo "Lab: ${LAB_NAME}"
99 echo "POD: ${POD_NAME}"
100 [[ "${BRANCH}" =~ 'danube' ]] && echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
101 echo
102 echo "Starting the deployment using ${INSTALLER_TYPE}. This could take some time..."
103 echo "--------------------------------------------------------"
104 echo
105
106 # start the deployment
107 echo "Issuing command"
108 echo "${DEPLOY_COMMAND}"
109 echo
110
111 ${DEPLOY_COMMAND}
112 exit_code=$?
113
114 echo
115 echo "--------------------------------------------------------"
116 echo "Deployment is done!"
117
118 # upload logs for baremetal deployments
119 # work with virtual deployments is still going on, so skip that for now
120 if [[ "${JOB_NAME}" =~ (baremetal-daily|baremetal-weekly) ]]; then
121     echo "Uploading deployment logs"
122     gsutil cp "${WORKSPACE}/${FUEL_LOG_FILENAME}" \
123         "gs://${GS_URL}/logs/${FUEL_LOG_FILENAME}" > /dev/null 2>&1
124     echo "Logs are available at http://${GS_URL}/logs/${FUEL_LOG_FILENAME}"
125 fi
126
127 if [[ "${exit_code}" -ne 0 ]]; then
128     echo "Deployment failed!"
129     exit "${exit_code}"
130 fi
131
132 echo "Deployment is successful!"
133 exit 0