efb6561d7bdc3ebb27b60b6a0110c2f04e8d422c
[releng.git] / jjb / apex / apex-deploy-baremetal.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 # log info to console
7 echo "Starting the Apex baremetal deployment."
8 echo "--------------------------------------------------------"
9 echo
10
11 if [[ ! "$ARTIFACT_NAME" == "latest" ]]; then
12     # if artifact name is passed the pull a
13     # specific artifact from artifacts.opnfv.org
14     RPM_INSTALL_PATH=$GS_URL/$ARTIFACT_NAME
15 else
16     if [[ $BUILD_DIRECTORY == *apex-build* ]]; then
17       BUILD_DIRECTORY=$WORKSPACE/../$BUILD_DIRECTORY
18       echo "BUILD DIRECTORY modified to $BUILD_DIRECTORY"
19     fi
20     if [[ -f ${BUILD_DIRECTORY}/../opnfv.properties ]]; then
21         # if opnfv.properties exists then use the
22         # local build. Source the file so we get local OPNFV vars
23         source ${BUILD_DIRECTORY}/../opnfv.properties
24         RPM_INSTALL_PATH=${BUILD_DIRECTORY}/$(basename $OPNFV_RPM_URL)
25     else
26         # no opnfv.properties means use the latest from artifacts.opnfv.org
27         # get the latest.properties to get the link to the latest artifact
28         curl -s -o $WORKSPACE/opnfv.properties http://$GS_URL/latest.properties
29         [[ -f opnfv.properties ]] || exit 1
30         # source the file so we get OPNFV vars
31         source opnfv.properties
32         RPM_INSTALL_PATH=$OPNFV_RPM_URL
33     fi
34 fi
35
36 if [ ! -e "$RPM_INSTALL_PATH" ]; then
37    RPM_INSTALL_PATH=http://${OPNFV_RPM_URL}
38 fi
39
40 RPM_LIST=$RPM_INSTALL_PATH
41 for pkg in common undercloud; do
42     RPM_LIST+=" ${RPM_INSTALL_PATH/opnfv-apex/opnfv-apex-${pkg}}"
43 done
44
45 # update / install the new rpm
46 if rpm -q opnfv-apex > /dev/null; then
47    if [ $(basename $OPNFV_RPM_URL) == $(rpm -q opnfv-apex).rpm ]; then
48      echo "RPM is already installed"
49    elif sudo yum update -y $RPM_LIST | grep "does not update installed package"; then
50        if ! sudo yum downgrade -y $RPM_LIST; then
51          sudo yum remove -y opnfv-undercloud opnfv-common
52          sudo yum downgrade -y $RPM_INSTALL_PATH
53        fi
54    fi
55 else
56    sudo yum install -y $RPM_LIST;
57 fi
58
59 # cleanup environment before we start
60 sudo opnfv-clean
61 # initiate baremetal deployment
62 if [ -e /etc/opnfv-apex/network_settings.yaml ]; then
63   if [ -n "$DEPLOY_SCENARIO" ]; then
64     echo "Deploy Scenario set to ${DEPLOY_SCENARIO}"
65     if [ -e /etc/opnfv-apex/${DEPLOY_SCENARIO}.yaml ]; then
66       sudo opnfv-deploy -i  /root/inventory/pod_settings.yaml \
67       -d /etc/opnfv-apex/${DEPLOY_SCENARIO}.yaml \
68       -n /root/network/network_settings.yaml --debug
69     else
70       echo "File does not exist /etc/opnfv-apex/${DEPLOY_SCENARIO}.yaml"
71       exit 1
72     fi
73   else
74     echo "Deploy scenario not set!"
75     exit 1
76   fi
77 else
78   echo "File /etc/opnfv-apex/network_settings.yaml does not exist!"
79   exit 1
80 fi
81
82 echo
83 echo "--------------------------------------------------------"
84 echo "Done!"