Merge "Functest: Sets max concurrent jobs to 10"
[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 ALLINONE_FLAG=False
8 CSIT_ENV_FLAG=False
9
10 # log info to console
11 echo "Starting the Apex deployment."
12 echo "--------------------------------------------------------"
13 echo
14
15 if [ -z "$DEPLOY_SCENARIO" ]; then
16   echo "Deploy scenario not set!"
17   exit 1
18 else
19   echo "Deploy scenario: ${DEPLOY_SCENARIO}"
20 fi
21
22 # Dev or RPM/ISO build
23 if [[ "$ARTIFACT_VERSION" =~ dev ]]; then
24   # Settings for deploying from git workspace
25   DEPLOY_SETTINGS_DIR="${WORKSPACE}/config/deploy"
26   NETWORK_SETTINGS_DIR="${WORKSPACE}/config/network"
27   CLEAN_CMD="opnfv-clean"
28   # if we are using master, then we are downloading/caching upstream images
29   # we want to use that built in mechanism to avoid re-downloading every job
30   # so we use a dedicated folder to hold the upstream cache
31   UPSTREAM_CACHE=$HOME/upstream_cache
32   if [[ "$BRANCH" != 'stable/fraser' ]]; then
33     mkdir -p ${UPSTREAM_CACHE}
34     RESOURCES=$UPSTREAM_CACHE
35   else
36     RESOURCES="${WORKSPACE}/.build/"
37   fi
38   CONFIG="${WORKSPACE}/build"
39   BASE=$CONFIG
40   IMAGES=$RESOURCES
41   LIB="${WORKSPACE}/lib"
42   DEPLOY_CMD="opnfv-deploy --image-dir ${RESOURCES}"
43   # Ensure artifacts were downloaded and extracted correctly
44   # TODO(trozet) add verification here
45
46   # Install dev build
47   sudo rm -rf /tmp/.build
48   mv -f .build /tmp/
49   sudo pip3 install --upgrade --force-reinstall .
50   mv -f /tmp/.build ${WORKSPACE}/
51 else
52   DEPLOY_SETTINGS_DIR="/etc/opnfv-apex/"
53   NETWORK_SETTINGS_DIR="/etc/opnfv-apex/"
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" != 'stable/fraser' ]]; then
59     mkdir -p ${UPSTREAM_CACHE}
60     RESOURCES=$UPSTREAM_CACHE
61   else
62     RESOURCES="/var/opt/opnfv/images"
63   fi
64   DEPLOY_CMD="opnfv-deploy --image-dir ${RESOURCES}"
65   CONFIG="/var/opt/opnfv"
66   BASE=$CONFIG
67   IMAGES=$RESOURCES
68   LIB="/var/opt/opnfv/lib"
69   sudo mkdir -p /var/log/apex
70   sudo chmod 777 /var/log/apex
71   cd /var/log/apex
72 fi
73
74 # Install Dependencies
75 # Make sure python34 dependencies are installed
76 dependencies="epel-release python34 python34-devel libvirt-devel python34-pip \
77 ansible python34-PyYAML python34-jinja2 python34-setuptools python-tox ansible"
78
79 for dep_pkg in $dependencies; do
80   if ! rpm -q ${dep_pkg} > /dev/null; then
81     if ! sudo yum install -y ${dep_pkg}; then
82       echo "Failed to install ${dep_pkg}"
83       exit 1
84     fi
85   fi
86 done
87
88 if [[ "$JOB_NAME" =~ "virtual" ]]; then
89   # Make sure ipxe-roms-qemu package is updated to latest.
90   # This package is needed for multi virtio nic PXE boot in virtual environment.
91   sudo yum update -y ipxe-roms-qemu
92 fi
93
94 if [ "$OPNFV_CLEAN" == 'yes' ]; then
95   if sudo test -e '/root/inventory/pod_settings.yaml'; then
96     clean_opts='-i /root/inventory/pod_settings.yaml'
97   else
98     clean_opts=''
99   fi
100
101   sudo ${CLEAN_CMD} ${clean_opts}
102 fi
103
104 # These are add-ons to regular scenarios where you can do like
105 # os-nosdn-nofeature-noha-ipv6, or os-nosdn-nofeature-noha-allinone
106 if echo ${DEPLOY_SCENARIO} | grep ipv6; then
107   IPV6_FLAG=True
108   DEPLOY_SCENARIO=$(echo ${DEPLOY_SCENARIO} |  sed 's/-ipv6//')
109   echo "INFO: IPV6 Enabled"
110 fi
111
112 if echo ${DEPLOY_SCENARIO} | grep allinone; then
113   ALLINONE_FLAG=True
114   DEPLOY_SCENARIO=$(echo ${DEPLOY_SCENARIO} |  sed 's/-allinone//')
115   echo "INFO: All in one deployment detected"
116 fi
117
118 if echo ${DEPLOY_SCENARIO} | grep csit; then
119   CSIT_ENV_FLAG=True
120   DEPLOY_SCENARIO=$(echo ${DEPLOY_SCENARIO} |  sed 's/-csit//')
121   echo "INFO: CSIT env requested in deploy scenario"
122 fi
123
124 echo "Deploy Scenario set to ${DEPLOY_SCENARIO}"
125 DEPLOY_FILE="${DEPLOY_SETTINGS_DIR}/${DEPLOY_SCENARIO}.yaml"
126
127 if [ ! -e "$DEPLOY_FILE" ]; then
128   echo "ERROR: Required settings file missing: Deploy settings file ${DEPLOY_FILE}"
129 fi
130
131 if [[ "$JOB_NAME" =~ "virtual" ]]; then
132   # settings for virtual deployment
133   DEPLOY_CMD="${DEPLOY_CMD} -v"
134   if [[ "${DEPLOY_SCENARIO}" =~ fdio|ovs ]]; then
135     DEPLOY_CMD="${DEPLOY_CMD} --virtual-default-ram 12 --virtual-compute-ram 7"
136   fi
137   if [[ "$ALLINONE_FLAG" == "True" ]]; then
138     DEPLOY_CMD="${DEPLOY_CMD} --virtual-computes 0"
139   elif [[ "$PROMOTE" == "True" ]]; then
140     DEPLOY_CMD="${DEPLOY_CMD} --virtual-computes 2"
141   fi
142
143   if [[ "$PROMOTE" == "True"  || "$CSIT_ENV_FLAG" == "True" ]]; then
144     if [[ "$OS_VERSION" != "master" ]]; then
145       CSIT_ENV="csit-${OS_VERSION}-environment.yaml"
146     else
147       CSIT_ENV="csit-environment.yaml"
148     fi
149     DEPLOY_CMD="${DEPLOY_CMD} -e ${CSIT_ENV}"
150   fi
151 else
152   # settings for bare metal deployment
153   NETWORK_SETTINGS_DIR="/root/network"
154   INVENTORY_FILE="/root/inventory/pod_settings.yaml"
155
156   if ! sudo test -e "$INVENTORY_FILE"; then
157     echo "ERROR: Required settings file missing: Inventory settings file ${INVENTORY_FILE}"
158     exit 1
159   fi
160   # include inventory file for bare metal deployment
161   DEPLOY_CMD="${DEPLOY_CMD} -i ${INVENTORY_FILE}"
162 fi
163
164 if [ "$IPV6_FLAG" == "True" ]; then
165   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings_v6.yaml"
166 elif [[ "$PROMOTE" == "True" ]]; then
167   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings_csit.yaml"
168 else
169   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings.yaml"
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!"