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