Enable all yardstick tasks on baremetal for daisy
[releng.git] / jjb / apex / apex-download-artifact.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 # log info to console
7 echo "Downloading the Apex artifact. This could take some time..."
8 echo "--------------------------------------------------------"
9 echo
10
11 [[ -d $BUILD_DIRECTORY ]] || mkdir -p $BUILD_DIRECTORY
12
13 if [ -z "$DEPLOY_SCENARIO" ]; then
14   echo "Deploy scenario not set!"
15   exit 1
16 elif [[ "$DEPLOY_SCENARIO" == *gate* ]]; then
17   echo "Detecting Gating scenario..."
18   if [ -z "$GERRIT_EVENT_COMMENT_TEXT" ]; then
19     echo "ERROR: Gate job triggered without comment!"
20     exit 1
21   else
22     DEPLOY_SCENARIO=$(echo ${GERRIT_EVENT_COMMENT_TEXT} | grep start-gate-scenario | grep -Eo 'os-.*$')
23     if [ -z "$DEPLOY_SCENARIO" ]; then
24       echo "ERROR: Unable to detect scenario in Gerrit Comment!"
25       echo "Format of comment to trigger gate should be 'start-gate-scenario: <scenario>'"
26       exit 1
27     else
28       echo "Gate scenario detected: ${DEPLOY_SCENARIO}"
29     fi
30   fi
31 fi
32
33 # if upstream we do not need to download anything
34 if [[ "$DEPLOY_SCENARIO" =~ upstream ]]; then
35   echo "Upstream deployment detected, skipping download artifact"
36 elif [[ "$ARTIFACT_VERSION" =~ dev ]]; then
37   # dev build
38   GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_REFSPEC | grep -Eo '[0-9]+$')
39   export OPNFV_ARTIFACT_VERSION="dev${GERRIT_CHANGE_NUMBER}_${GERRIT_PATCHSET_NUMBER}"
40   # get build artifact
41   pushd ${BUILD_DIRECTORY} > /dev/null
42   echo "Downloading packaged dev build: apex-${OPNFV_ARTIFACT_VERSION}.tar.gz"
43   curl --fail -s -o $BUILD_DIRECTORY/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz http://$GS_URL/apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
44   tar -xvf apex-${OPNFV_ARTIFACT_VERSION}.tar.gz
45   popd > /dev/null
46 else
47   echo "Will use RPMs..."
48
49   # Must be RPMs/ISO
50   echo "Downloading latest properties file"
51
52   # get the properties file in order to get info regarding artifacts
53   curl --fail -s -o $BUILD_DIRECTORY/opnfv.properties http://$GS_URL/latest.properties
54
55   # source the file so we get OPNFV vars
56   source $BUILD_DIRECTORY/opnfv.properties
57
58   RPM_INSTALL_PATH=$(echo "http://"$OPNFV_RPM_URL | sed 's/\/'"$(basename $OPNFV_RPM_URL)"'//')
59   RPM_LIST=$(basename $OPNFV_RPM_URL)
60
61   # find version of RPM
62   VERSION_EXTENSION=$(echo $(basename $RPM_LIST) | grep -Eo '[0-9]+\.[0-9]+-([0-9]{8}|[a-z]+-[0-9]\.[0-9]+)')
63   # build RPM List which already includes base Apex RPM
64   RPM_LIST+=" opnfv-apex-undercloud-${VERSION_EXTENSION}.noarch.rpm"
65
66   # add back legacy support for danube
67   if [ "$BRANCH" == 'stable/danube' ]; then
68     RPM_LIST+=" opnfv-apex-common-${VERSION_EXTENSION}.noarch.rpm"
69   else
70     RPM_LIST+=" python34-opnfv-apex-${VERSION_EXTENSION}.noarch.rpm"
71   fi
72
73   # remove old / install new RPMs
74   if rpm -q opnfv-apex > /dev/null; then
75     INSTALLED_RPMS=$(rpm -qa | grep apex)
76     if [ -n "$INSTALLED_RPMS" ]; then
77       sudo yum remove -y ${INSTALLED_RPMS}
78     fi
79   fi
80   # Create an rpms dir on slave
81   mkdir -p ~/apex_rpms
82   pushd ~/apex_rpms
83   # Remove older rpms which do not match this version
84   find . ! -name "*${VERSION_EXTENSION}.noarch.rpm" -type f -exec rm -f {} +
85   # Download RPM only if changed on server
86   for rpm in $RPM_LIST; do
87     wget -N ${RPM_INSTALL_PATH}/${rpm}
88   done
89   if ! sudo yum install -y $RPM_LIST; then
90     echo "Unable to install new RPMs: $RPM_LIST"
91     exit 1
92   fi
93   popd
94 fi
95
96 # TODO: Uncomment these lines to verify SHA512SUMs once the sums are
97 # fixed.
98 # echo "$OPNFV_ARTIFACT_SHA512SUM $BUILD_DIRECTORY/apex.iso" | sha512sum -c
99 # echo "$OPNFV_RPM_SHA512SUM $BUILD_DIRECTORY/$(basename $OPNFV_RPM_URL)" | sha512sum -c
100
101 # list the files
102 ls -al $BUILD_DIRECTORY
103
104 echo
105 echo "--------------------------------------------------------"
106 echo "Done!"