blob: 4778102464392d1d03045f1e53cc6dba1785477d [file] [log] [blame]
Andy Bavierc4a40512017-08-10 07:06:25 -07001#!/usr/bin/env bash
2#
Matteo Scandolo60b640f2017-08-08 13:05:22 -07003# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Zack Williamsa1f55082017-02-28 22:41:36 -070017# cord-in-a-box.sh
Andy Bavier99c11d32016-09-14 17:21:20 -040018
Sapan Bhatia01ddea62017-02-10 11:28:48 -080019set -e -x
Andy Bavier99c11d32016-09-14 17:21:20 -040020
Zack Williamsa1f55082017-02-28 22:41:36 -070021# start time, used to name logfiles
22START_T=$(date -u "+%Y%m%d_%H%M%SZ")
23
24# Paths
Zack Williams0620c932017-01-25 14:36:31 -070025CORDDIR=~/cord
Andy Bavierf55e7f92017-06-22 10:16:44 -040026VMDIR=/opt/cord/build/
Andy Bavier99c11d32016-09-14 17:21:20 -040027CONFIG=config/cord_in_a_box.yml
Andy Baviera69ee722016-11-17 07:26:01 -080028SSHCONFIG=~/.ssh/config
Zack Williams1bffc162017-04-12 16:31:15 -070029VAGRANT_CWD=${CORDDIR}/build/
Zack Williams03a20ec2017-04-12 17:39:36 -070030VAGRANT_VM_PREFIX=build
Andy Bavier99c11d32016-09-14 17:21:20 -040031
Zack Williamsa1f55082017-02-28 22:41:36 -070032# CORD versioning
Sapan Bhatia7d17b9e2017-09-05 15:34:26 -040033REPO_BRANCH="cord-4.0"
34VERSION_STRING="CiaB 4.0"
Andy Bavierd1165102017-01-13 16:38:57 -050035
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010036function finish {
Sapan Bhatia95692092017-03-01 06:48:19 +010037 EXIT=$?
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010038 python $CORDDIR/build/elk-logger/mixpanel --event FINISH --corddir $CORDDIR --finish --status $EXIT
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010039}
40
Andy Bavier0f07bb32017-01-17 10:20:26 -050041function add_box() {
42 vagrant box list | grep $1 | grep virtualbox || vagrant box add $1
43 vagrant box list | grep $1 | grep libvirt || vagrant mutate $1 libvirt --input-provider virtualbox
44}
45
Sapan Bhatia01ddea62017-02-10 11:28:48 -080046function run_stage {
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010047 cd $CORDDIR
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010048 python build/elk-logger/mixpanel --event $1-start --corddir $CORDDIR
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010049
Sapan Bhatia01ddea62017-02-10 11:28:48 -080050 echo "==> "$1": Starting"
51 $1
52 echo "==> "$1": Complete"
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010053
54 cd $CORDDIR
Sapan Bhatiaeb7819c2017-03-01 15:26:17 +010055 python build/elk-logger/mixpanel --event $1-end --corddir $CORDDIR
Sapan Bhatia01ddea62017-02-10 11:28:48 -080056}
57
Andy Bavier99c11d32016-09-14 17:21:20 -040058function cleanup_from_previous_test() {
Andy Bavier99c11d32016-09-14 17:21:20 -040059 echo "## Cleanup ##"
60
Andy Baviera4883ba2016-12-21 15:46:58 -050061 if [ -d $CORDDIR/build ]
62 then
63 echo "Destroying all Vagrant VMs"
64 cd $CORDDIR/build
Zack Williamsa1f55082017-02-28 22:41:36 -070065 for i in `seq 12`; do
Zack Williams9e7249a2017-03-28 13:07:41 -070066 sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant destroy" && break
Zack Williamsa1f55082017-02-28 22:41:36 -070067 done
Andy Baviera4883ba2016-12-21 15:46:58 -050068 fi
Andy Bavier99c11d32016-09-14 17:21:20 -040069
Andy Bavier2505f592016-11-11 15:58:55 -050070 echo "Removing $CORDDIR"
71 cd ~
Andy Bavier99c11d32016-09-14 17:21:20 -040072 rm -rf $CORDDIR
Andy Bavier99c11d32016-09-14 17:21:20 -040073}
74
75function bootstrap() {
Zack Williamsa1f55082017-02-28 22:41:36 -070076
Sapan Bhatia95692092017-03-01 06:48:19 +010077 echo "Generating build id"
Sapan Bhatia77f26672017-03-13 18:30:25 +010078 rm -f /tmp/cord-build-version
Sapan Bhatia95692092017-03-01 06:48:19 +010079 dd bs=18 count=1 if=/dev/urandom | base64 | tr +/ _. > /tmp/cord-build
Andy Bavier99c11d32016-09-14 17:21:20 -040080
Zack Williamsa1f55082017-02-28 22:41:36 -070081 if [ ! -x "/usr/local/bin/repo" ]
82 then
83 echo "Installing repo..."
Luca Prete5a97ca52017-11-30 14:31:21 -080084 REPO_SHA256SUM="394d93ac7261d59db58afa49bb5f88386fea8518792491ee3db8baab49c3ecda"
85 curl -o /tmp/repo 'https://gerrit.opencord.org/gitweb?p=repo.git;a=blob_plain;f=repo;hb=refs/heads/stable'
Zack Williamsa1f55082017-02-28 22:41:36 -070086 echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c -
87 sudo mv /tmp/repo /usr/local/bin/repo
88 sudo chmod a+x /usr/local/bin/repo
89 fi
90
91 if [ ! -x "/usr/bin/vagrant" ]
92 then
93 echo "Installing vagrant and associated tools..."
94 VAGRANT_SHA256SUM="faff6befacc7eed3978b4b71f0dbb9c135c01d8a4d13236bda2f9ed53482d2c4" # version 1.9.3
95 curl -o /tmp/vagrant.deb https://releases.hashicorp.com/vagrant/1.9.3/vagrant_1.9.3_x86_64.deb
96 echo "$VAGRANT_SHA256SUM /tmp/vagrant.deb" | sha256sum -c -
97 sudo apt-get update
98 sudo dpkg -i /tmp/vagrant.deb
Andy Bavier1e6cf6e2017-09-07 08:25:20 -070099 sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential python-pip
Zack Williamsa1f55082017-02-28 22:41:36 -0700100 sudo adduser $USER libvirtd
101 sudo pip install pyparsing python-logstash mixpanel
102 fi
103
104 echo "Installing vagrant plugins..."
Andy Bavier1e6cf6e2017-09-07 08:25:20 -0700105 vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
Zack Williamsa1f55082017-02-28 22:41:36 -0700106 vagrant plugin list | grep vagrant-mutate || vagrant plugin install vagrant-mutate
107
108 add_box ubuntu/trusty64
109
110 echo "Creating SSH key..."
Andy Bavier99c11d32016-09-14 17:21:20 -0400111 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
Andy Bavier99c11d32016-09-14 17:21:20 -0400112
Andy Bavier99c11d32016-09-14 17:21:20 -0400113 if [ ! -d "$CORDDIR" ]
114 then
Zack Williamsa1f55082017-02-28 22:41:36 -0700115 echo "Downloading CORD/XOS..."
116
117 if [ ! -e "~/.gitconfig" ]
118 then
119 echo "No ~/.gitconfig, setting testing defaults"
120 git config --global user.name 'Test User'
121 git config --global user.email 'test@null.com'
122 git config --global color.ui false
123 fi
124
125 # make sure we can find gerrit.opencord.org as DNS failures will fail the build
126 dig +short gerrit.opencord.org || (echo "ERROR: gerrit.opencord.org can't be looked up in DNS" && exit 1)
127
Andy Bavier99c11d32016-09-14 17:21:20 -0400128 mkdir $CORDDIR && cd $CORDDIR
Matteo Scandolo4d7d1662017-05-30 11:20:57 -0700129 repo init -u https://gerrit.opencord.org/manifest -b $REPO_BRANCH
Andy Bavier99c11d32016-09-14 17:21:20 -0400130 repo sync
131
Zack Williamsdae7ff62016-11-14 15:20:06 -0700132 # check out gerrit branches using repo
133 for gerrit_branch in ${GERRIT_BRANCHES[@]}; do
Zack Williamsa1f55082017-02-28 22:41:36 -0700134 echo "Checking out opencord gerrit branch: $gerrit_branch"
Zack Williamsdae7ff62016-11-14 15:20:06 -0700135 repo download ${gerrit_branch/:/ }
136 done
Andy Bavier99c11d32016-09-14 17:21:20 -0400137 fi
138
Sapan Bhatia868e0012017-02-15 22:14:11 -0800139 exec > >(tee -i $CORDDIR/install.out)
140 exec 2>&1
141
Sapan Bhatia95692092017-03-01 06:48:19 +0100142 # Start tracking failures from this point
143 trap finish EXIT
144
Andy Bavier99c11d32016-09-14 17:21:20 -0400145}
146
147function cloudlab_setup() {
Andy Bavier8b4ed1f2017-02-13 17:06:58 -0800148
Andy Bavier46dfda62017-03-02 05:40:08 -0500149 # Don't do anything if not a CloudLab node
150 [ ! -d /usr/local/etc/emulab ] && return
151
Andy Bavier8b4ed1f2017-02-13 17:06:58 -0800152 # The watchdog will sometimes reset groups, turn it off
153 if [ -e /usr/local/etc/emulab/watchdog ]
154 then
155 sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop
156 sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled
157 fi
158
Zack Williamsf4e65222017-03-01 14:22:37 -0700159 # Mount extra space, if haven't already
160 if [ ! -d /mnt/extra ]
Andy Bavier99c11d32016-09-14 17:21:20 -0400161 then
Zack Williamsf4e65222017-03-01 14:22:37 -0700162 # for NVME SSD on Utah Cloudlab, not supported by mkextrafs
163 if $(df | grep -q nvme0n1p1) && [ -e /usr/testbed/bin/mkextrafs ]
Andy Bavier2505f592016-11-11 15:58:55 -0500164 then
Zack Williamsf4e65222017-03-01 14:22:37 -0700165 sudo mkdir -p /mnt/extra
166
167 # set partition type of 4th partition to Linux, ignore errors
168 echo -e "t\n4\n82\np\nw\nq" | sudo fdisk /dev/nvme0n1 || true
169
170 sudo mkfs.ext4 /dev/nvme0n1p4
171 echo "/dev/nvme0n1p4 /mnt/extra/ ext4 defaults 0 0" | sudo tee -a /etc/fstab
172 sudo mount /mnt/extra
173 mount | grep nvme0n1p4 || (echo "ERROR: NVME mkfs/mount failed, exiting!" && exit 1)
174
175 elif [ -e /usr/testbed/bin/mkextrafs ] # if on Clemson/Wisconsin Cloudlab
176 then
177 sudo mkdir -p /mnt/extra
178
179 # Sometimes this command fails on the first try
180 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/"
181
182 # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted)
183 mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1)
Andy Bavier2505f592016-11-11 15:58:55 -0500184 fi
Andy Bavier99c11d32016-09-14 17:21:20 -0400185 fi
Zack Williamsf4e65222017-03-01 14:22:37 -0700186
187 # replace /var/lib/libvirt/images with a symlink
188 [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images
189 sudo mkdir -p /mnt/extra/libvirt_images
190
191 if [ ! -e /var/lib/libvirt/images ]
192 then
193 sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images
194 fi
Andy Bavier99c11d32016-09-14 17:21:20 -0400195}
196
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800197function elk_up() {
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800198
199 cd $CORDDIR
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800200 sudo chmod +x build/elk-logger/logstash_tail
Zack Williams49af5e62017-03-24 18:02:56 -0700201
202 build/elk-logger/logstash_tail --file install.out --hostport 10.100.198.201:5617 &
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800203}
204
Andy Bavier2505f592016-11-11 15:58:55 -0500205function vagrant_vms_up() {
Zack Williamsa1f55082017-02-28 22:41:36 -0700206
207 echo "Bringing up CORD-in-a-Box Vagrant VM's..."
Andy Bavier99c11d32016-09-14 17:21:20 -0400208 cd $CORDDIR/build
209
Zack Williams9e7249a2017-03-28 13:07:41 -0700210 sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant up corddev prod --provider libvirt"
Andy Baviera69ee722016-11-17 07:26:01 -0800211
212 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
213 # It allows SSH'ing to the machine via 'ssh corddev'
Zack Williams9e7249a2017-03-28 13:07:41 -0700214 sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant ssh-config corddev prod > $SSHCONFIG"
Andy Bavier2505f592016-11-11 15:58:55 -0500215
Andy Baviera2acd2a2017-06-19 09:57:32 -0400216 # copy host SSH keypair to corddev
Andy Bavier2505f592016-11-11 15:58:55 -0500217 scp ~/.ssh/id_rsa* corddev:.ssh
218 ssh corddev "chmod go-r ~/.ssh/id_rsa"
Andy Bavier99c11d32016-09-14 17:21:20 -0400219}
220
221function install_head_node() {
222 cd $CORDDIR/build
223
Andy Baviera69ee722016-11-17 07:26:01 -0800224 # SSH config saved earlier allows us to connect to VM without running 'vagrant'
Andy Bavierf55e7f92017-06-22 10:16:44 -0400225 ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch"
226 ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages"
227 ssh corddev "cd $VMDIR; ping -c 3 prod; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish"
228 ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy"
Andy Bavier99c11d32016-09-14 17:21:20 -0400229}
230
231function set_up_maas_user() {
Andy Bavier2505f592016-11-11 15:58:55 -0500232 # Set up MAAS user on server to restart nodes via libvirt
233 grep maas /etc/passwd || sudo useradd -m maas
Andy Bavier99c11d32016-09-14 17:21:20 -0400234 sudo adduser maas libvirtd
235
Andy Bavier2505f592016-11-11 15:58:55 -0500236 # Copy generated public key to maas user's authorized_keys
237 sudo su maas -c "mkdir -p ~/.ssh"
238 sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys
239 sudo chown maas:maas ~maas/.ssh/authorized_keys
Andy Bavier99c11d32016-09-14 17:21:20 -0400240
Andy Bavier2505f592016-11-11 15:58:55 -0500241 # Copy generated private key to maas user's home dir in prod VM
242 scp $HOME/.ssh/id_rsa prod:/tmp
243 ssh prod "sudo mkdir -p ~maas/.ssh"
244 ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa"
245 ssh prod "sudo chown -R maas:maas ~maas/.ssh"
246}
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600247
Andy Bavier0f07bb32017-01-17 10:20:26 -0500248function turn_off_learning () {
249 NET=$1
250 BRIDGE=`sudo virsh net-info $NET|grep "Bridge:"|awk '{print $2}'`
251 sudo brctl setageing $BRIDGE 0
252 sudo brctl stp $BRIDGE off
253}
254
255function leaf_spine_up() {
256 cd $CORDDIR/build
257
258 if [[ $FABRIC -ne 0 ]]
259 then
Zack Williams9e7249a2017-03-28 13:07:41 -0700260 sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 spine-2 --provider libvirt"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500261 else
262 # Linux bridging seems to be having issues with two spine switches
Zack Williams9e7249a2017-03-28 13:07:41 -0700263 sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 --provider libvirt"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500264 fi
265
266 # Turn off MAC learning on "links" -- i.e., bridges created by libvirt.
267 # Without this, sometimes packets are dropped because the bridges
268 # think they are not local -- this needs further investigation.
269 # A better solution might be to replace the bridges with UDP tunnels, but this
270 # is not supported with the version of libvirt available on Ubuntu 14.04.
271 turn_off_learning head-node-leaf-1
272 turn_off_learning compute-node-1-leaf-1
273 turn_off_learning compute-node-2-leaf-2
274 turn_off_learning compute-node-3-leaf-2
275 turn_off_learning leaf-1-spine-1
276 turn_off_learning leaf-1-spine-2
277 turn_off_learning leaf-2-spine-1
278 turn_off_learning leaf-2-spine-2
279}
280
Andy Bavier99c11d32016-09-14 17:21:20 -0400281function add_compute_node() {
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600282 echo add_compute_node: $1 $2
Andy Bavier2505f592016-11-11 15:58:55 -0500283
Andy Bavier99c11d32016-09-14 17:21:20 -0400284 cd $CORDDIR/build
Zack Williams9e7249a2017-03-28 13:07:41 -0700285 sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant up $1 --provider libvirt"
Andy Bavier99c11d32016-09-14 17:21:20 -0400286
Andy Bavier2505f592016-11-11 15:58:55 -0500287 # Set up power cycling for the compute node and wait for it to be provisioned
Andy Bavierf55e7f92017-06-22 10:16:44 -0400288 ssh prod "cd $VMDIR/ansible; ansible-playbook maas-provision.yml --extra-vars \"maas_user=maas vagrant_name=$2\""
Andy Bavier99c11d32016-09-14 17:21:20 -0400289
290 echo ""
Andy Bavier0f07bb32017-01-17 10:20:26 -0500291 echo "$1 is fully provisioned!"
292}
293
294function initialize_fabric() {
295 echo "Initializing fabric"
Andy Bavierf55e7f92017-06-22 10:16:44 -0400296 ssh prod "cd $VMDIR/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-refresh-fabric.yml"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500297
298 echo "Fabric ping test"
Andy Bavierf55e7f92017-06-22 10:16:44 -0400299 ssh prod "cd $VMDIR/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-fabric-pingtest.yml"
Andy Bavier99c11d32016-09-14 17:21:20 -0400300}
301
302function run_e2e_test () {
303 cd $CORDDIR/build
304
Andy Bavier2505f592016-11-11 15:58:55 -0500305 # User has been added to the lbvirtd group, but su $USER to be safe
Andy Bavierf55e7f92017-06-22 10:16:44 -0400306 ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests"
Andy Bavier99c11d32016-09-14 17:21:20 -0400307}
308
309function run_diagnostics() {
Andy Bavierf55e7f92017-06-22 10:16:44 -0400310 ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG PIrunDiag"
Andy Bavier99c11d32016-09-14 17:21:20 -0400311}
312
313# Parse options
Zack Williamsdae7ff62016-11-14 15:20:06 -0700314GERRIT_BRANCHES=
Andy Bavier99c11d32016-09-14 17:21:20 -0400315RUN_TEST=0
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400316SETUP_ONLY=0
Andy Bavier99c11d32016-09-14 17:21:20 -0400317DIAGNOSTICS=0
318CLEANUP=0
Andy Bavier0f07bb32017-01-17 10:20:26 -0500319FABRIC=0
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600320#By default, cord-in-a-box creates 1 compute node. If more than one compute is
321#needed, use -n option
322NUM_COMPUTE_NODES=1
Andy Bavier99c11d32016-09-14 17:21:20 -0400323
Andy Bavier0f07bb32017-01-17 10:20:26 -0500324while getopts "b:cdfhn:stv" opt; do
Andy Bavier99c11d32016-09-14 17:21:20 -0400325 case ${opt} in
Zack Williamsdae7ff62016-11-14 15:20:06 -0700326 b ) GERRIT_BRANCHES+=("$OPTARG")
Andy Bavier99c11d32016-09-14 17:21:20 -0400327 ;;
328 c ) CLEANUP=1
329 ;;
330 d ) DIAGNOSTICS=1
331 ;;
Andy Bavier0f07bb32017-01-17 10:20:26 -0500332 f ) FABRIC=1
333 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400334 h ) echo "Usage:"
335 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsdae7ff62016-11-14 15:20:06 -0700336 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
337 echo " be used multiple times."
Andy Bavier99c11d32016-09-14 17:21:20 -0400338 echo " $0 -c cleanup from previous test"
339 echo " $0 -d run diagnostic collector"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500340 echo " $0 -f use ONOS fabric (EXPERIMENTAL)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400341 echo " $0 -h display this help message"
Zack Williamsa9e76ec2017-01-20 16:17:35 -0700342 echo " $0 -n # number of compute nodes to setup. Currently max 2 nodes can be supported"
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400343 echo " $0 -s run initial setup phase only (don't start building CORD)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400344 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Bavierd1165102017-01-13 16:38:57 -0500345 echo " $0 -v print CiaB version and exit"
Andy Bavier99c11d32016-09-14 17:21:20 -0400346 exit 0
347 ;;
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600348 n ) NUM_COMPUTE_NODES=$OPTARG
349 ;;
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400350 s ) SETUP_ONLY=1
351 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400352 t ) RUN_TEST=1
353 ;;
Andy Bavierd1165102017-01-13 16:38:57 -0500354 v ) echo "$VERSION_STRING ($REPO_BRANCH branch)"
355 exit 0
356 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400357 \? ) echo "Invalid option: -$OPTARG"
358 exit 1
359 ;;
360 esac
361done
362
363# What to do
364if [[ $CLEANUP -eq 1 ]]
365then
Sapan Bhatia3f454b32017-03-01 05:24:19 +0100366 cleanup_from_previous_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400367fi
368
Andy Bavierd1165102017-01-13 16:38:57 -0500369echo ""
370echo "Preparing to install $VERSION_STRING ($REPO_BRANCH branch)"
371echo ""
372
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +0100373bootstrap
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800374run_stage cloudlab_setup
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800375run_stage vagrant_vms_up
Zack Williams49af5e62017-03-24 18:02:56 -0700376run_stage elk_up
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400377
378if [[ $SETUP_ONLY -ne 0 ]]
379then
380 echo "Finished build environment setup, exiting..."
381 exit 0
382fi
383
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800384run_stage install_head_node
385run_stage set_up_maas_user
386run_stage leaf_spine_up
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600387
Andy Bavier0f07bb32017-01-17 10:20:26 -0500388if [[ $NUM_COMPUTE_NODES -gt 3 ]]
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600389then
Andy Bavier0f07bb32017-01-17 10:20:26 -0500390 echo "currently max only three compute nodes can be supported..."
391 NUM_COMPUTE_NODES=3
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600392fi
393
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800394echo "==> Adding compute nodes: Starting"
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600395for i in `seq 1 $NUM_COMPUTE_NODES`;
396do
397 echo adding the compute node: compute-node-$i
Zack Williams03a20ec2017-04-12 17:39:36 -0700398 add_compute_node compute-node-$i ${VAGRANT_VM_PREFIX}_compute-node-$i
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600399done
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800400echo "==> Adding compute nodes: Complete"
Andy Bavier99c11d32016-09-14 17:21:20 -0400401
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700402# run diagnostics both before/after the fabric/e2e tests
403if [[ $DIAGNOSTICS -eq 1 ]]
404then
405 run_diagnostics
406fi
407
408
Andy Bavier0f07bb32017-01-17 10:20:26 -0500409if [[ $FABRIC -ne 0 ]]
410then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800411 run_stage initialize_fabric
Andy Bavier0f07bb32017-01-17 10:20:26 -0500412fi
413
Andy Bavier99c11d32016-09-14 17:21:20 -0400414if [[ $RUN_TEST -eq 1 ]]
415then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800416 run_stage run_e2e_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400417fi
418
419if [[ $DIAGNOSTICS -eq 1 ]]
420then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800421 run_stage run_diagnostics
Andy Bavier99c11d32016-09-14 17:21:20 -0400422fi
423
424exit 0