adabfcaeb87b8255a90145648030f64010e2f7c1
[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 nounset
12 set -o pipefail
13
14 export TERM="vt220"
15
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
22 if [[ "$JOB_NAME" =~ "merge" ]]; then
23     # set simplest scenario for virtual deploys to run for merges
24     DEPLOY_SCENARIO="os-nosdn-nofeature-ha"
25 else
26     # for none-merge deployments
27     # checkout the commit that was used for building the downloaded artifact
28     # to make sure the ISO and deployment mechanism uses same versions
29     echo "Checking out $OPNFV_GIT_SHA1"
30     git checkout $OPNFV_GIT_SHA1 --quiet
31 fi
32
33 # set deployment parameters
34 export TMPDIR=${WORKSPACE}/tmpdir
35 LAB_NAME=${NODE_NAME/-*}
36 POD_NAME=${NODE_NAME/*-}
37
38 # we currently support enea
39 if [[ ! $LAB_NAME =~ (arm|enea) ]]; then
40     echo "Unsupported/unidentified lab $LAB_NAME. Cannot continue!"
41     exit 1
42 fi
43
44 echo "Using configuration for $LAB_NAME"
45
46 # create TMPDIR if it doesn't exist
47 mkdir -p $TMPDIR
48
49 cd $WORKSPACE
50 if [[ $LAB_CONFIG_URL =~ ^(git|ssh):// ]]; then
51     echo "Cloning securedlab repo $BRANCH"
52     git clone --quiet --branch $BRANCH $LAB_CONFIG_URL lab-config
53     LAB_CONFIG_URL=file://${WORKSPACE}/lab-config
54
55     # Source local_env if present, which contains POD-specific config
56     local_env="${WORKSPACE}/lab-config/labs/$LAB_NAME/$POD_NAME/fuel/config/local_env"
57     if [ -e $local_env ]; then
58         echo "-- Sourcing local environment file"
59         source $local_env
60     fi
61 fi
62
63 if [[ "$NODE_NAME" =~ "virtual" ]]; then
64     POD_NAME="virtual_kvm"
65 fi
66
67 # releng wants us to use nothing else but opnfv.iso for now. We comply.
68 ISO_FILE=$WORKSPACE/opnfv.iso
69
70 # log file name
71 FUEL_LOG_FILENAME="${JOB_NAME}_${BUILD_NUMBER}.log.tar.gz"
72
73 # Deploy Cache (to enable just create the deploy-cache subdir)
74 # NOTE: Only available when ISO files are cached using ISOSTORE mechanism
75 DEPLOY_CACHE=${ISOSTORE:-/iso_mount/opnfv_ci}/${BRANCH##*/}/deploy-cache
76 if [[ -d "${DEPLOY_CACHE}" ]]; then
77     echo "Deploy cache dir present."
78     echo "--------------------------------------------------------"
79     echo "Fuel@OPNFV deploy cache: ${DEPLOY_CACHE}"
80     DEPLOY_CACHE="-C ${DEPLOY_CACHE}"
81 else
82     DEPLOY_CACHE=""
83 fi
84
85 # construct the command
86 DEPLOY_COMMAND="$WORKSPACE/ci/deploy.sh -b ${LAB_CONFIG_URL} \
87     -l $LAB_NAME -p $POD_NAME -s $DEPLOY_SCENARIO -i file://${ISO_FILE} \
88     -H -B ${DEFAULT_BRIDGE:-pxebr} -S $TMPDIR -L $WORKSPACE/$FUEL_LOG_FILENAME \
89     ${DEPLOY_CACHE}"
90
91 # log info to console
92 echo "Deployment parameters"
93 echo "--------------------------------------------------------"
94 echo "Scenario: $DEPLOY_SCENARIO"
95 echo "Lab: $LAB_NAME"
96 echo "POD: $POD_NAME"
97 echo "ISO: ${OPNFV_ARTIFACT_URL/*\/}"
98 echo
99 echo "Starting the deployment using $INSTALLER_TYPE. This could take some time..."
100 echo "--------------------------------------------------------"
101 echo
102
103 # start the deployment
104 echo "Issuing command"
105 echo "$DEPLOY_COMMAND"
106 echo
107
108 $DEPLOY_COMMAND
109 exit_code=$?
110
111 echo
112 echo "--------------------------------------------------------"
113 echo "Deployment is done!"
114
115 # upload logs for baremetal deployments
116 # work with virtual deployments is still going on so we skip that for the timebeing
117 if [[ "$JOB_NAME" =~ "baremetal-daily" ]]; then
118     echo "Uploading deployment logs"
119     gsutil cp $WORKSPACE/$FUEL_LOG_FILENAME gs://$GS_URL/logs/$FUEL_LOG_FILENAME > /dev/null 2>&1
120     echo "Logs are available as 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 else
127     echo "Deployment is successful!"
128 fi