armband: deploy: upload logs to GS
[releng.git] / jjb / armband / armband-deploy.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
5 #           (c) 2016 Enea Software AB
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 ##############################################################################
11 set -o errexit
12 set -o nounset
13 set -o pipefail
14
15 # source the file so we get OPNFV vars
16 source latest.properties
17
18 # echo the info about artifact that is used during the deployment
19 echo "Using ${OPNFV_ARTIFACT_URL/*\/} for deployment"
20
21 if [[ "$JOB_NAME" =~ "merge" ]]; then
22     # set simplest scenario for virtual deploys to run for merges
23     DEPLOY_SCENARIO="os-nosdn-nofeature-ha"
24 else
25     # for none-merge deployments
26     # checkout the commit that was used for building the downloaded artifact
27     # to make sure the ISO and deployment mechanism uses same versions
28     echo "Checking out $OPNFV_GIT_SHA1"
29     git checkout $OPNFV_GIT_SHA1 --quiet
30 fi
31
32 # set deployment parameters
33 export TMPDIR=${WORKSPACE}/tmpdir
34 LAB_NAME=${NODE_NAME/-*}
35 POD_NAME=${NODE_NAME/*-}
36
37 # we currently support enea
38 if [[ ! $LAB_NAME =~ (arm|enea) ]]; then
39     echo "Unsupported/unidentified lab $LAB_NAME. Cannot continue!"
40     exit 1
41 fi
42
43 echo "Using configuration for $LAB_NAME"
44
45 # create TMPDIR if it doesn't exist
46 mkdir -p $TMPDIR
47
48 cd $WORKSPACE
49 if [[ $LAB_CONFIG_URL =~ ^(git|ssh):// ]]; then
50     echo "cloning $LAB_CONFIG_URL"
51     git clone --quiet --branch ${GIT_BRANCH##origin/} $LAB_CONFIG_URL lab-config
52     LAB_CONFIG_URL=file://${WORKSPACE}/lab-config
53
54     # Source local_env if present, which contains POD-specific config
55     local_env="${WORKSPACE}/lab-config/labs/$LAB_NAME/$POD_NAME/fuel/config/local_env"
56     if [ -e $local_env ]; then
57         echo "-- Sourcing local environment file"
58         source $local_env
59     fi
60 fi
61
62 # releng wants us to use nothing else but opnfv.iso for now. We comply.
63 ISO_FILE=$WORKSPACE/opnfv.iso
64
65 # log file name
66 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
67
68 # construct the command
69 DEPLOY_COMMAND="$WORKSPACE/ci/deploy.sh -b ${LAB_CONFIG_URL} \
70     -l $LAB_NAME -p $POD_NAME -s $DEPLOY_SCENARIO -i file://${ISO_FILE} \
71     -H -B ${DEFAULT_BRIDGE:-pxebr} -S $TMPDIR -L $WORKSPACE/$FUEL_LOG_FILENAME"
72
73 # log info to console
74 echo "Deployment parameters"
75 echo "--------------------------------------------------------"
76 echo "Scenario: $DEPLOY_SCENARIO"
77 echo "Lab: $LAB_NAME"
78 echo "POD: $POD_NAME"
79 echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
80 echo
81 echo "Starting the deployment using $INSTALLER_TYPE. This could take some time..."
82 echo "--------------------------------------------------------"
83 echo
84
85 # start the deployment
86 echo "Issuing command"
87 echo "$DEPLOY_COMMAND"
88 echo
89
90 $DEPLOY_COMMAND
91 exit_code=$?
92
93 echo
94 echo "--------------------------------------------------------"
95 echo "Deployment is done!"
96
97 # upload logs for baremetal deployments
98 # work with virtual deployments is still going on so we skip that for the timebeing
99 if [[ "$JOB_NAME" =~ "baremetal-daily" ]]; then
100     echo "Uploading deployment logs"
101     gsutil cp $WORKSPACE/$FUEL_LOG_FILENAME gs://$GS_URL/logs/$FUEL_LOG_FILENAME > /dev/null 2>&1
102     echo "Logs are available as http://$GS_URL/logs/$FUEL_LOG_FILENAME"
103 fi
104
105 if [[ $exit_code -ne 0 ]]; then
106     echo "Deployment failed!"
107     exit $exit_code
108 else
109     echo "Deployment is successful!"
110 fi