summaryrefslogtreecommitdiffstats
path: root/jjb/apex/apex-deploy-virtual.sh
blob: 4d9b03088bb376265bdc0258d2d0a646e514671e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail

# log info to console
echo "Starting the Apex virtual deployment."
echo "--------------------------------------------------------"
echo

if [[ $BUILD_DIRECTORY == *verify-master* ]]; then
    cd $WORKSPACE/../${BUILD_DIRECTORY/build_output/}
    WORKSPACE=$(pwd)
    echo "WORKSPACE modified to $WORKSPACE"
    cd $WORKSPACE/ci
elif [[ ! "$ARTIFACT_NAME" == "latest" ]]; then
    # if artifact name is passed the pull a
    # specific artifact from artifacts.opnfv.org
    RPM_INSTALL_PATH=$GS_URL
    RPM_LIST=$RPM_INSTALL_PATH/$ARTIFACT_NAME
else
    if [[ $BUILD_DIRECTORY == *verify* ]]; then
      BUILD_DIRECTORY=$WORKSPACE/../$BUILD_DIRECTORY
      echo "BUILD DIRECTORY modified to $BUILD_DIRECTORY"
    elif [[ $BUILD_DIRECTORY == *apex-build* ]]; then
      BUILD_DIRECTORY=$WORKSPACE/../$BUILD_DIRECTORY
      echo "BUILD DIRECTORY modified to $BUILD_DIRECTORY"
    fi

    if [[ -f ${BUILD_DIRECTORY}/../opnfv.properties ]]; then
        # if opnfv.properties exists then use the
        # local build. Source the file so we get local OPNFV vars
        source ${BUILD_DIRECTORY}/../opnfv.properties
        RPM_INSTALL_PATH=${BUILD_DIRECTORY}/noarch
        RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
    else
        if [[ $BUILD_DIRECTORY == *verify* ]]; then
          echo "BUILD_DIRECTORY is from a verify job, so will not use latest from URL"
          echo "Check that the slave has opnfv.properties in $BUILD_DIRECTORY"
          exit 1
        elif [[ $BUILD_DIRECTORY == *apex-build* ]]; then
          echo "BUILD_DIRECTORY is from a daily job, so will not use latest from URL"
          echo "Check that the slave has opnfv.properties in $BUILD_DIRECTORY"
          exit 1
        fi
        # no opnfv.properties means use the latest from artifacts.opnfv.org
        # get the latest.properties to get the link to the latest artifact
        curl -s -o $WORKSPACE/opnfv.properties http://$GS_URL/latest.properties
        [[ -f opnfv.properties ]] || exit 1
        # source the file so we get OPNFV vars
        source opnfv.properties
        RPM_INSTALL_PATH=$(echo $OPNFV_RPM_URL | sed 's/'"$(basename $OPNFV_RPM_URL)"'//')
        RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
    fi
fi

if [ -z "$DEPLOY_SCENARIO" ]; then
  echo "Deploy scenario not set!"
  exit 1
fi

# use local build for verify
if [[ $BUILD_DIRECTORY == *verify-master* ]]; then
    if [ ! -e "${WORKSPACE}/build/lib" ]; then ln -s ${WORKSPACE}/lib ${WORKSPACE}/build/lib; fi
    DEPLOY_CMD="CONFIG=${WORKSPACE}/build RESOURCES=${WORKSPACE}/build/images/ ./deploy.sh -c ${WORKSPACE}/build -r ${WORKSPACE}/build/images/"
    DEPLOY_FILE="${WORKSPACE}/config/deploy/${DEPLOY_SCENARIO}.yaml"
    NETWORK_FILE="${WORKSPACE}/config/network/network_settings.yaml"
    # Make sure python34 is installed
    if ! rpm -q python34 > /dev/null; then
        sudo yum install -y epel-release
        if ! sudo yum install -y python34; then
            echo "Failed to install python34"
            exit 1
        fi
    fi
    if ! rpm -q python34-PyYAML > /dev/null; then
        sudo yum install -y epel-release
        if ! sudo yum install -y python34-PyYAML; then
            echo "Failed to install python34-PyYAML"
            exit 1
        fi
    fi
    if ! rpm -q python34-setuptools > /dev/null; then
        if ! sudo yum install -y python34-setuptools; then
            echo "Failed to install python34-setuptools"
            exit 1
        fi
    fi
    if [ -z ${PYTHONPATH:-} ]; then
        export PYTHONPATH=${WORKSPACE}/lib/python
    else
        export PYTHONPATH=$PYTHONPATH:${WORKSPACE}/lib/python
    fi
else
    VERSION_EXTENSION=$(echo $(basename $RPM_LIST) | grep -Eo '[0-9]+\.[0-9]+-[0-9]{8}')
    for pkg in common undercloud opendaylight-sfc onos; do
        RPM_LIST+=" ${RPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}.noarch.rpm"
    done

    # update / install the new rpm
    if rpm -q opnfv-apex > /dev/null; then
       INSTALLED_RPMS=$(rpm -qa | grep apex)
       for x in $INSTALLED_RPMS; do
         INSTALLED_RPM_VER=$(echo $x | grep -Eo '[0-9]+\.[0-9]+-[0-9]{8}')
         # Does each RPM's version match the version required for deployment
         if [ "$INSTALLED_RPM_VER" == "$VERSION_EXTENSION" ]; then
           echo "RPM $x is already installed"
         else
           echo "RPM $x does not match version $VERSION_EXTENSION"
           echo "Will upgrade/downgrade RPMs..."
           # Try to upgrade/downgrade RPMS
           if sudo yum update -y $RPM_LIST | grep "does not update installed package"; then
             if ! sudo yum downgrade -y $RPM_LIST; then
               sudo yum remove -y opnfv-apex-undercloud opnfv-apex-common opnfv-apex-opendaylight-sfc opnfv-apex-onos
               if ! sudo yum downgrade -y $RPM_LIST; then
                 echo "Unable to downgrade RPMs: $RPM_LIST"
                 exit 1
               fi
             fi
           fi
           break
         fi
       done
    else
       sudo yum install -y $RPM_LIST;
    fi
    DEPLOY_CMD=opnfv-deploy
    DEPLOY_FILE="/etc/opnfv-apex/${DEPLOY_SCENARIO}.yaml"
    NETWORK_FILE="/etc/opnfv-apex/network_settings.yaml"
    export RESOURCES="/var/opt/opnfv/images"
    export CONFIG="/var/opt/opnfv"
fi

if [ "$OPNFV_CLEAN" == 'yes' ]; then
    if [[ $BUILD_DIRECTORY == *verify-master* ]]; then
        sudo CONFIG=${WORKSPACE}/build ./clean.sh
    else
        sudo opnfv-clean
    fi
fi
# initiate virtual deployment
echo "Deploy Scenario set to ${DEPLOY_SCENARIO}"
if [ -e $DEPLOY_FILE ]; then
  sudo $DEPLOY_CMD -v -d ${DEPLOY_FILE} -n $NETWORK_FILE --debug
else
  echo "File does not exist /etc/opnfv-apex/${DEPLOY_SCENARIO}.yaml"
  exit 1
fi
echo
echo "--------------------------------------------------------"
echo "Done!"