APEX: update ipxe-rom-qemu package for multiple virtio nic pxe boot
[releng.git] / jjb / apex / apex-deploy.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 APEX_PKGS="common undercloud opendaylight-sfc onos"
7
8 # log info to console
9 echo "Starting the Apex virtual deployment."
10 echo "--------------------------------------------------------"
11 echo
12
13 if ! rpm -q wget > /dev/null; then
14   sudo yum -y install wget
15 fi
16
17 if [[ $BUILD_DIRECTORY == *verify* ]]; then
18     # Build is from a verify, use local build artifacts (not RPMs)
19     cd $WORKSPACE/../${BUILD_DIRECTORY}
20     WORKSPACE=$(pwd)
21     echo "WORKSPACE modified to $WORKSPACE"
22     cd $WORKSPACE/ci
23 elif [[ ! "$ARTIFACT_NAME" == "latest" ]]; then
24     # if artifact name is passed the pull a
25     # specific artifact from artifacts.opnfv.org
26     # artifact specified should be opnfv-apex-<version>.noarch.rpm
27     RPM_INSTALL_PATH=$GS_URL
28     RPM_LIST=$RPM_INSTALL_PATH/$ARTIFACT_NAME
29 else
30     # Use latest RPMS
31     if [[ $BUILD_DIRECTORY == *apex-build* ]]; then
32       # Triggered from a daily so RPMS should be in local directory
33       BUILD_DIRECTORY=$WORKSPACE/../$BUILD_DIRECTORY
34       echo "BUILD DIRECTORY modified to $BUILD_DIRECTORY"
35
36       if [[ -f ${BUILD_DIRECTORY}/../opnfv.properties ]]; then
37         # if opnfv.properties exists then use the
38         # local build. Source the file so we get local OPNFV vars
39         source ${BUILD_DIRECTORY}/../opnfv.properties
40         RPM_INSTALL_PATH=${BUILD_DIRECTORY}/noarch
41         RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
42       else
43         echo "BUILD_DIRECTORY is from a daily job, so will not use latest from URL"
44         echo "Check that the slave has opnfv.properties in $BUILD_DIRECTORY"
45         exit 1
46       fi
47     else
48       # use the latest from artifacts.opnfv.org
49       # get the latest.properties to get the link to the latest artifact
50       if ! wget -O $WORKSPACE/opnfv.properties http://$GS_URL/latest.properties; then
51         echo "ERROR: Unable to find latest.properties at ${GS_URL}...exiting"
52         exit 1
53       fi
54       # source the file so we get OPNFV vars
55       source opnfv.properties
56       RPM_INSTALL_PATH=$(echo $OPNFV_RPM_URL | sed 's/'"$(basename $OPNFV_RPM_URL)"'//')
57       RPM_LIST=$RPM_INSTALL_PATH/$(basename $OPNFV_RPM_URL)
58     fi
59 fi
60
61 if [ -z "$DEPLOY_SCENARIO" ]; then
62   echo "Deploy scenario not set!"
63   exit 1
64 fi
65
66 # use local build for verify
67 if [[ "$BUILD_DIRECTORY" == *verify* ]]; then
68     if [ ! -e "${WORKSPACE}/build/lib" ]; then
69       ln -s ${WORKSPACE}/lib ${WORKSPACE}/build/lib
70     fi
71     DEPLOY_SETTINGS_DIR="${WORKSPACE}/config/deploy"
72     NETWORK_SETTINGS_DIR="${WORKSPACE}/config/network"
73     DEPLOY_CMD="$(pwd)/deploy.sh"
74     RESOURCES="${WORKSPACE}/build/images/"
75     CONFIG="${WORKSPACE}/build"
76     LIB="${WORKSPACE}/lib"
77     # Make sure python34 deps are installed
78     for dep_pkg in epel-release python34 python34-PyYAML python34-setuptools; do
79       if ! rpm -q ${dep_pkg} > /dev/null; then
80         if ! sudo yum install -y ${dep_pkg}; then
81           echo "Failed to install ${dep_pkg}"
82           exit 1
83         fi
84       fi
85     done
86
87     # Make sure jinja2 is installed
88     for python_pkg in jinja2; do
89       if ! python3.4 -c "import $python_pkg"; then
90         echo "$python_pkg package not found for python3.4, attempting to install..."
91         if ! sudo easy_install-3.4 $python_pkg; then
92           echo -e "Failed to install $python_pkg package for python3.4"
93           exit 1
94         fi
95       fi
96     done
97
98     # Make sure ipxe-roms-qemu package is updated to latest.
99     # This package is needed for multi virtio nic PXE boot in virtual environment.
100     sudo yum update -y ipxe-roms-qemu
101
102     if [ -z ${PYTHONPATH:-} ]; then
103         export PYTHONPATH=${WORKSPACE}/lib/python
104     else
105         export PYTHONPATH=$PYTHONPATH:${WORKSPACE}/lib/python
106     fi
107 # use RPMs
108 else
109     # find version of RPM
110     VERSION_EXTENSION=$(echo $(basename $RPM_LIST) | grep -Eo '[0-9]+\.[0-9]+-[0-9]{8}')
111     # build RPM List which already includes base Apex RPM
112     for pkg in ${APEX_PKGS}; do
113         RPM_LIST+=" ${RPM_INSTALL_PATH}/opnfv-apex-${pkg}-${VERSION_EXTENSION}.noarch.rpm"
114     done
115
116     # remove old / install new RPMs
117     if rpm -q opnfv-apex > /dev/null; then
118       INSTALLED_RPMS=$(rpm -qa | grep apex)
119       if [ -n "$INSTALLED_RPMS" ]; then
120         sudo yum remove -y ${INSTALLED_RPMS}
121       fi
122     fi
123
124     if ! sudo yum install -y $RPM_LIST; then
125       echo "Unable to install new RPMs: $RPM_LIST"
126       exit 1
127     fi
128
129     DEPLOY_CMD=opnfv-deploy
130     DEPLOY_SETTINGS_DIR="/etc/opnfv-apex/"
131     NETWORK_SETTINGS_DIR="/etc/opnfv-apex/"
132     RESOURCES="/var/opt/opnfv/images"
133     CONFIG="/var/opt/opnfv"
134     LIB="/var/opt/opnfv/lib"
135 fi
136
137 # set env vars to deploy cmd
138 DEPLOY_CMD="CONFIG=${CONFIG} RESOURCES=${RESOURCES} LIB=${LIB} ${DEPLOY_CMD}"
139
140 if [ "$OPNFV_CLEAN" == 'yes' ]; then
141   if [[ "$BUILD_DIRECTORY" == *verify* ]]; then
142     sudo CONFIG=${CONFIG} LIB=${LIB} ./clean.sh
143   else
144     sudo CONFIG=${CONFIG} LIB=${LIB} opnfv-clean
145   fi
146 fi
147
148 echo "Deploy Scenario set to ${DEPLOY_SCENARIO}"
149 DEPLOY_FILE="${DEPLOY_SETTINGS_DIR}/${DEPLOY_SCENARIO}.yaml"
150
151 if [ ! -e "$DEPLOY_FILE" ]; then
152   echo "ERROR: Required settings file missing: Deploy settings file ${DEPLOY_FILE}"
153 fi
154
155 if [[ "$JOB_NAME" == *virtual* ]]; then
156   # settings for virtual deployment
157   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings.yaml"
158   DEPLOY_CMD="${DEPLOY_CMD} -v"
159 else
160   # settings for bare metal deployment
161   NETWORK_FILE="/root/network/network_settings.yaml"
162   INVENTORY_FILE="/root/inventory/pod_settings.yaml"
163
164   if ! sudo test -e "$INVENTORY_FILE"; then
165     echo "ERROR: Required settings file missing: Inventory settings file ${INVENTORY_FILE}"
166     exit 1
167   fi
168   # include inventory file for bare metal deployment
169   DEPLOY_CMD="${DEPLOY_CMD} -i ${INVENTORY_FILE}"
170 fi
171
172 # Check that network settings file exists
173 if ! sudo test -e "$NETWORK_FILE"; then
174   echo "ERROR: Required settings file missing: Network Settings file ${NETWORK_FILE}"
175   exit 1
176 fi
177
178 # start deployment
179 sudo ${DEPLOY_CMD} -d ${DEPLOY_FILE} -n ${NETWORK_FILE} --debug
180
181 echo
182 echo "--------------------------------------------------------"
183 echo "Done!"