Apex: Update for master upstream deployments
[releng.git] / jjb / apex / apex-deploy.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 IPV6_FLAG=False
7
8 # log info to console
9 echo "Starting the Apex deployment."
10 echo "--------------------------------------------------------"
11 echo
12
13 if [ -z "$DEPLOY_SCENARIO" ]; then
14   echo "Deploy scenario not set!"
15   exit 1
16 else
17   echo "Deploy scenario: ${DEPLOY_SCENARIO}"
18 fi
19
20 # Dev or RPM/ISO build
21 if [[ "$ARTIFACT_VERSION" =~ dev ]]; then
22   # Settings for deploying from git workspace
23   DEPLOY_SETTINGS_DIR="${WORKSPACE}/config/deploy"
24   NETWORK_SETTINGS_DIR="${WORKSPACE}/config/network"
25   DEPLOY_CMD="opnfv-deploy --image-dir ${WORKSPACE}/.build"
26   CLEAN_CMD="opnfv-clean"
27   # if we are using master, then we are downloading/caching upstream images
28   # we want to use that built in mechanism to avoid re-downloading every job
29   # so we use a dedicated folder to hold the upstream cache
30   UPSTREAM_CACHE=$HOME/upstream_cache
31   if [ "$BRANCH" == 'master' ]; then
32     mkdir -p ${UPSTREAM_CACHE}
33     RESOURCES=$UPSTREAM_CACHE
34   else
35     RESOURCES="${WORKSPACE}/.build/"
36   fi
37   CONFIG="${WORKSPACE}/build"
38   BASE=$CONFIG
39   IMAGES=$RESOURCES
40   LIB="${WORKSPACE}/lib"
41
42   # Ensure artifacts were downloaded and extracted correctly
43   # TODO(trozet) add verification here
44
45   # Install dev build
46   sudo rm -rf /tmp/.build
47   mv -f .build /tmp/
48   sudo pip3 install --upgrade --force-reinstall .
49   mv -f /tmp/.build ${WORKSPACE}/
50 else
51   DEPLOY_SETTINGS_DIR="/etc/opnfv-apex/"
52   NETWORK_SETTINGS_DIR="/etc/opnfv-apex/"
53   DEPLOY_CMD="opnfv-deploy"
54   CLEAN_CMD="opnfv-clean"
55   # set to use different directory here because upon RPM removal this
56   # directory will be wiped in daily
57   UPSTREAM_CACHE=$HOME/upstream_cache
58   if [ "$BRANCH" == 'master' ]; then
59     mkdir -p ${UPSTREAM_CACHE}
60     RESOURCES=$UPSTREAM_CACHE
61   else
62     RESOURCES="/var/opt/opnfv/images"
63   fi
64   CONFIG="/var/opt/opnfv"
65   BASE=$CONFIG
66   IMAGES=$RESOURCES
67   LIB="/var/opt/opnfv/lib"
68   sudo mkdir -p /var/log/apex
69   sudo chmod 777 /var/log/apex
70   cd /var/log/apex
71 fi
72
73 # Install Dependencies
74 # Make sure python34 dependencies are installed
75 dependencies="epel-release python34 python34-devel libvirt-devel python34-pip \
76 ansible python34-PyYAML python34-jinja2 python34-setuptools python-tox ansible"
77
78 for dep_pkg in $dependencies; 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 if [[ "$JOB_NAME" =~ "virtual" ]]; then
88   # Make sure ipxe-roms-qemu package is updated to latest.
89   # This package is needed for multi virtio nic PXE boot in virtual environment.
90   sudo yum update -y ipxe-roms-qemu
91 fi
92
93 if [ "$OPNFV_CLEAN" == 'yes' ]; then
94   if sudo test -e '/root/inventory/pod_settings.yaml'; then
95     clean_opts='-i /root/inventory/pod_settings.yaml'
96   else
97     clean_opts=''
98   fi
99
100   sudo ${CLEAN_CMD} ${clean_opts}
101 fi
102
103 if echo ${DEPLOY_SCENARIO} | grep ipv6; then
104   IPV6_FLAG=True
105   DEPLOY_SCENARIO=$(echo ${DEPLOY_SCENARIO} |  sed 's/-ipv6//')
106   echo "INFO: IPV6 Enabled"
107 fi
108
109 echo "Deploy Scenario set to ${DEPLOY_SCENARIO}"
110 DEPLOY_FILE="${DEPLOY_SETTINGS_DIR}/${DEPLOY_SCENARIO}.yaml"
111
112 if [ ! -e "$DEPLOY_FILE" ]; then
113   echo "ERROR: Required settings file missing: Deploy settings file ${DEPLOY_FILE}"
114 fi
115
116 if [[ "$JOB_NAME" =~ "virtual" ]]; then
117   # settings for virtual deployment
118   DEPLOY_CMD="${DEPLOY_CMD} -v"
119   if [[ "${DEPLOY_SCENARIO}" =~ fdio|ovs ]]; then
120     DEPLOY_CMD="${DEPLOY_CMD} --virtual-default-ram 12 --virtual-compute-ram 7"
121   fi
122   if [[ "$JOB_NAME" == *csit* ]]; then
123     DEPLOY_CMD="${DEPLOY_CMD} -e csit-environment.yaml"
124   fi
125   if [[ "$PROMOTE" == "True" ]]; then
126     DEPLOY_CMD="${DEPLOY_CMD} --virtual-computes 1"
127   fi
128 else
129   # settings for bare metal deployment
130   NETWORK_SETTINGS_DIR="/root/network"
131   INVENTORY_FILE="/root/inventory/pod_settings.yaml"
132
133   if ! sudo test -e "$INVENTORY_FILE"; then
134     echo "ERROR: Required settings file missing: Inventory settings file ${INVENTORY_FILE}"
135     exit 1
136   fi
137   # include inventory file for bare metal deployment
138   DEPLOY_CMD="${DEPLOY_CMD} -i ${INVENTORY_FILE}"
139 fi
140
141 if [[ "$BRANCH" == "master" ]]; then
142   echo "Upstream deployment detected"
143   DEPLOY_CMD="${DEPLOY_CMD} --upstream"
144 fi
145
146 if [ "$IPV6_FLAG" == "True" ]; then
147   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings_v6.yaml"
148 else
149   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings.yaml"
150 fi
151
152 # Check that network settings file exists
153 if ! sudo test -e "$NETWORK_FILE"; then
154   echo "ERROR: Required settings file missing: Network Settings file ${NETWORK_FILE}"
155   exit 1
156 fi
157
158 # start deployment
159 sudo ${DEPLOY_CMD} -d ${DEPLOY_FILE} -n ${NETWORK_FILE} --debug
160
161 if [[ "$JOB_NAME" == *csit* ]]; then
162   echo "CSIT job: setting host route for floating ip routing"
163   # csit route to allow docker container to reach floating ips
164   UNDERCLOUD=$(sudo virsh domifaddr undercloud | grep -Eo "[0-9\.]+{3}[0-9]+")
165   if sudo route | grep 192.168.37.128 > /dev/null; then
166     sudo route del -net 192.168.37.128 netmask 255.255.255.128
167   fi
168   sudo route add -net 192.168.37.128 netmask 255.255.255.128 gw ${UNDERCLOUD}
169 fi
170
171 echo
172 echo "--------------------------------------------------------"
173 echo "Done!"