Use computes + control for NUM_OS_SYSTEM
[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 [[ "$PROMOTE" == "True" ]]; then
122     if [[ "$DEPLOY_SCENARIO" =~ "queens" ]]; then
123       CSIT_ENV="csit-queens-environment.yaml"
124     else
125       CSIT_ENV="csit-environment.yaml"
126     fi
127     DEPLOY_CMD="${DEPLOY_CMD} --virtual-computes 2 -e ${CSIT_ENV}"
128   fi
129 else
130   # settings for bare metal deployment
131   NETWORK_SETTINGS_DIR="/root/network"
132   INVENTORY_FILE="/root/inventory/pod_settings.yaml"
133
134   if ! sudo test -e "$INVENTORY_FILE"; then
135     echo "ERROR: Required settings file missing: Inventory settings file ${INVENTORY_FILE}"
136     exit 1
137   fi
138   # include inventory file for bare metal deployment
139   DEPLOY_CMD="${DEPLOY_CMD} -i ${INVENTORY_FILE}"
140 fi
141
142 if [[ "$BRANCH" == "master" ]]; then
143   echo "Upstream deployment detected"
144   DEPLOY_CMD="${DEPLOY_CMD} --upstream"
145 fi
146
147 if [ "$IPV6_FLAG" == "True" ]; then
148   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings_v6.yaml"
149 elif [[ "$PROMOTE" == "True" ]]; then
150   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings_csit.yaml"
151 else
152   NETWORK_FILE="${NETWORK_SETTINGS_DIR}/network_settings.yaml"
153 fi
154
155 # Check that network settings file exists
156 if ! sudo test -e "$NETWORK_FILE"; then
157   echo "ERROR: Required settings file missing: Network Settings file ${NETWORK_FILE}"
158   exit 1
159 fi
160
161 # start deployment
162 sudo ${DEPLOY_CMD} -d ${DEPLOY_FILE} -n ${NETWORK_FILE} --debug
163
164 echo
165 echo "--------------------------------------------------------"
166 echo "Done!"