blob: 0d59ff20311ef99b5c6f8faf34b29d2782bbb530 [file] [log] [blame]
Andy Bavier99c11d32016-09-14 17:21:20 -04001#!/usr/bin/env bash
2
Sapan Bhatia01ddea62017-02-10 11:28:48 -08003set -e -x
Andy Bavier99c11d32016-09-14 17:21:20 -04004
Zack Williams0620c932017-01-25 14:36:31 -07005CORDDIR=~/cord
Andy Bavier99c11d32016-09-14 17:21:20 -04006VMDIR=/cord/build/
7CONFIG=config/cord_in_a_box.yml
Andy Baviera69ee722016-11-17 07:26:01 -08008SSHCONFIG=~/.ssh/config
Andy Bavier99c11d32016-09-14 17:21:20 -04009
Andy Bavierd1165102017-01-13 16:38:57 -050010# For CORD version
11REPO_BRANCH="master"
12VERSION_STRING="CiaB development version"
13
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010014function finish {
Sapan Bhatia95692092017-03-01 06:48:19 +010015 EXIT=$?
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010016 set +x
Sapan Bhatia95692092017-03-01 06:48:19 +010017 python $CORDDIR/build/elk-logger/mixpanel FINISH-$EXIT --finish
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010018}
19
Andy Bavier0f07bb32017-01-17 10:20:26 -050020function add_box() {
21 vagrant box list | grep $1 | grep virtualbox || vagrant box add $1
22 vagrant box list | grep $1 | grep libvirt || vagrant mutate $1 libvirt --input-provider virtualbox
23}
24
Sapan Bhatia01ddea62017-02-10 11:28:48 -080025function run_stage {
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010026 cd $CORDDIR
27 python build/elk-logger/mixpanel $1-start
28
Sapan Bhatia01ddea62017-02-10 11:28:48 -080029 echo "==> "$1": Starting"
30 $1
31 echo "==> "$1": Complete"
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010032
33 cd $CORDDIR
34 python build/elk-logger/mixpanel $1-end
Sapan Bhatia01ddea62017-02-10 11:28:48 -080035}
36
Andy Bavier99c11d32016-09-14 17:21:20 -040037function cleanup_from_previous_test() {
Andy Bavier99c11d32016-09-14 17:21:20 -040038 echo "## Cleanup ##"
39
Andy Baviera4883ba2016-12-21 15:46:58 -050040 if [ -d $CORDDIR/build ]
41 then
42 echo "Destroying all Vagrant VMs"
43 cd $CORDDIR/build
44 sudo su $USER -c 'vagrant destroy'
45 fi
Andy Bavier99c11d32016-09-14 17:21:20 -040046
Andy Bavier2505f592016-11-11 15:58:55 -050047 echo "Removing $CORDDIR"
48 cd ~
Andy Bavier99c11d32016-09-14 17:21:20 -040049 rm -rf $CORDDIR
Andy Bavier99c11d32016-09-14 17:21:20 -040050}
51
52function bootstrap() {
Sapan Bhatia95692092017-03-01 06:48:19 +010053 echo "Generating build id"
54 dd bs=18 count=1 if=/dev/urandom | base64 | tr +/ _. > /tmp/cord-build
Andy Bavier99c11d32016-09-14 17:21:20 -040055 cd ~
56 sudo apt-get update
57 [ -e vagrant_1.8.5_x86_64.deb ] || wget https://releases.hashicorp.com/vagrant/1.8.5/vagrant_1.8.5_x86_64.deb
Andy Bavierad3ea842016-12-21 16:19:07 -050058 dpkg -l vagrant || sudo dpkg -i vagrant_1.8.5_x86_64.deb
Sapan Bhatia01ddea62017-02-10 11:28:48 -080059 sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential python-pip
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010060 sudo pip install pyparsing python-logstash mixpanel
Andy Bavier99c11d32016-09-14 17:21:20 -040061
62 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
Andy Bavier99c11d32016-09-14 17:21:20 -040063
Andy Bavier99c11d32016-09-14 17:21:20 -040064 sudo adduser $USER libvirtd
65
66 sudo curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo
67 sudo chmod a+x /usr/local/bin/repo
68
69 if [ ! -d "$CORDDIR" ]
70 then
71 mkdir $CORDDIR && cd $CORDDIR
Sapan Bhatia868e0012017-02-15 22:14:11 -080072
73
Andy Bavier99c11d32016-09-14 17:21:20 -040074 git config --global user.name 'Test User'
75 git config --global user.email 'test@null.com'
76 git config --global color.ui false
77
Scott Baker0ab86822017-02-01 14:33:40 -080078 repo init -u https://gerrit.opencord.org/manifest -b $REPO_BRANCH -g build,onos,orchestration,voltha
Andy Bavier99c11d32016-09-14 17:21:20 -040079 repo sync
80
Zack Williamsdae7ff62016-11-14 15:20:06 -070081 # check out gerrit branches using repo
82 for gerrit_branch in ${GERRIT_BRANCHES[@]}; do
83 echo "checking out opencord gerrit branch: $gerrit_branch"
84 repo download ${gerrit_branch/:/ }
85 done
Andy Bavier99c11d32016-09-14 17:21:20 -040086 fi
87
Sapan Bhatia868e0012017-02-15 22:14:11 -080088 exec > >(tee -i $CORDDIR/install.out)
89 exec 2>&1
90
Andy Bavier99c11d32016-09-14 17:21:20 -040091 cd $CORDDIR/build
Andy Bavierad3ea842016-12-21 16:19:07 -050092 vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
93 vagrant plugin list | grep vagrant-mutate || vagrant plugin install vagrant-mutate
Andy Bavier0f07bb32017-01-17 10:20:26 -050094 add_box ubuntu/trusty64
Sapan Bhatia95692092017-03-01 06:48:19 +010095
96 # Start tracking failures from this point
97 trap finish EXIT
98
Andy Bavier99c11d32016-09-14 17:21:20 -040099}
100
101function cloudlab_setup() {
Andy Bavier8b4ed1f2017-02-13 17:06:58 -0800102
103 # The watchdog will sometimes reset groups, turn it off
104 if [ -e /usr/local/etc/emulab/watchdog ]
105 then
106 sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop
107 sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled
108 fi
109
Andy Bavier99c11d32016-09-14 17:21:20 -0400110 if [ -e /usr/testbed/bin/mkextrafs ]
111 then
Andy Bavier9c0835e2016-11-11 15:56:47 -0500112 sudo mkdir -p /mnt/extra
Scott Baker8b9182d2016-10-27 17:53:52 -0700113
Andy Bavier8ce395f2016-10-14 12:51:30 -0400114 # Sometimes this command fails on the first try
Andy Bavier9c0835e2016-11-11 15:56:47 -0500115 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/"
116
117 # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted)
Andy Baviera69ee722016-11-17 07:26:01 -0800118 mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1)
Scott Baker8b9182d2016-10-27 17:53:52 -0700119
120 # we'll replace /var/lib/libvirt/images with a symlink below
121 [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images
122
Andy Bavier9c0835e2016-11-11 15:56:47 -0500123 sudo mkdir -p /mnt/extra/libvirt_images
Andy Bavier2505f592016-11-11 15:58:55 -0500124 if [ ! -e /var/lib/libvirt/images ]
125 then
126 sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images
127 fi
Andy Bavier99c11d32016-09-14 17:21:20 -0400128 fi
129}
130
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800131function elk_up() {
132 cd $CORDDIR/build
133
134 sudo su $USER -c 'vagrant up elastic --provider libvirt'
135
136 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
137 # It allows SSH'ing to the machine via 'ssh corddev'
138 sudo su $USER -c "vagrant ssh-config elastic > $SSHCONFIG"
139
140 cd $CORDDIR
141 if [ ! -f /tmp/elk-patch-applied ]; then
142 touch /tmp/elk-patch-applied
143 sh build/scripts/repo-apply.sh build/elk-logger/elk-ciab.diff
144 fi
145
146 sudo chmod +x build/elk-logger/logstash_tail
147 build/elk-logger/logstash_tail --file install.out --hostport 10.100.198.222:5617 &
148}
149
Andy Bavier2505f592016-11-11 15:58:55 -0500150function vagrant_vms_up() {
Andy Bavier99c11d32016-09-14 17:21:20 -0400151 cd $CORDDIR/build
152
Andy Bavier65c8e152016-12-22 16:01:27 -0500153 sudo su $USER -c 'vagrant up corddev prod --provider libvirt'
Andy Baviera69ee722016-11-17 07:26:01 -0800154
155 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
156 # It allows SSH'ing to the machine via 'ssh corddev'
Andy Bavier2505f592016-11-11 15:58:55 -0500157 sudo su $USER -c "vagrant ssh-config corddev prod > $SSHCONFIG"
158
159 scp ~/.ssh/id_rsa* corddev:.ssh
160 ssh corddev "chmod go-r ~/.ssh/id_rsa"
Andy Bavier99c11d32016-09-14 17:21:20 -0400161}
162
163function install_head_node() {
164 cd $CORDDIR/build
165
Andy Baviera69ee722016-11-17 07:26:01 -0800166 # SSH config saved earlier allows us to connect to VM without running 'vagrant'
Zack Williams0620c932017-01-25 14:36:31 -0700167 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch"
168 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages"
Andy Bavier2505f592016-11-11 15:58:55 -0500169 ssh corddev "cd /cord/build; ping -c 3 prod; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish"
Andy Baviera69ee722016-11-17 07:26:01 -0800170 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy"
Andy Bavier99c11d32016-09-14 17:21:20 -0400171}
172
173function set_up_maas_user() {
Andy Bavier2505f592016-11-11 15:58:55 -0500174 # Set up MAAS user on server to restart nodes via libvirt
175 grep maas /etc/passwd || sudo useradd -m maas
Andy Bavier99c11d32016-09-14 17:21:20 -0400176 sudo adduser maas libvirtd
177
Andy Bavier2505f592016-11-11 15:58:55 -0500178 # Copy generated public key to maas user's authorized_keys
179 sudo su maas -c "mkdir -p ~/.ssh"
180 sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys
181 sudo chown maas:maas ~maas/.ssh/authorized_keys
Andy Bavier99c11d32016-09-14 17:21:20 -0400182
Andy Bavier2505f592016-11-11 15:58:55 -0500183 # Copy generated private key to maas user's home dir in prod VM
184 scp $HOME/.ssh/id_rsa prod:/tmp
185 ssh prod "sudo mkdir -p ~maas/.ssh"
186 ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa"
187 ssh prod "sudo chown -R maas:maas ~maas/.ssh"
188}
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600189
Andy Bavier0f07bb32017-01-17 10:20:26 -0500190function turn_off_learning () {
191 NET=$1
192 BRIDGE=`sudo virsh net-info $NET|grep "Bridge:"|awk '{print $2}'`
193 sudo brctl setageing $BRIDGE 0
194 sudo brctl stp $BRIDGE off
195}
196
197function leaf_spine_up() {
198 cd $CORDDIR/build
199
200 if [[ $FABRIC -ne 0 ]]
201 then
202 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 spine-2 --provider libvirt"
203 else
204 # Linux bridging seems to be having issues with two spine switches
205 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 --provider libvirt"
206 fi
207
208 # Turn off MAC learning on "links" -- i.e., bridges created by libvirt.
209 # Without this, sometimes packets are dropped because the bridges
210 # think they are not local -- this needs further investigation.
211 # A better solution might be to replace the bridges with UDP tunnels, but this
212 # is not supported with the version of libvirt available on Ubuntu 14.04.
213 turn_off_learning head-node-leaf-1
214 turn_off_learning compute-node-1-leaf-1
215 turn_off_learning compute-node-2-leaf-2
216 turn_off_learning compute-node-3-leaf-2
217 turn_off_learning leaf-1-spine-1
218 turn_off_learning leaf-1-spine-2
219 turn_off_learning leaf-2-spine-1
220 turn_off_learning leaf-2-spine-2
221}
222
Andy Bavier99c11d32016-09-14 17:21:20 -0400223function add_compute_node() {
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600224 echo add_compute_node: $1 $2
Andy Bavier2505f592016-11-11 15:58:55 -0500225
Andy Bavier99c11d32016-09-14 17:21:20 -0400226 cd $CORDDIR/build
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600227 sudo su $USER -c "vagrant up $1 --provider libvirt"
Andy Bavier99c11d32016-09-14 17:21:20 -0400228
Andy Bavier2505f592016-11-11 15:58:55 -0500229 # Set up power cycling for the compute node and wait for it to be provisioned
230 ssh prod "cd /cord/build/ansible; ansible-playbook maas-provision.yml --extra-vars \"maas_user=maas vagrant_name=$2\""
Andy Bavier99c11d32016-09-14 17:21:20 -0400231
232 echo ""
Andy Bavier0f07bb32017-01-17 10:20:26 -0500233 echo "$1 is fully provisioned!"
234}
235
236function initialize_fabric() {
237 echo "Initializing fabric"
238 ssh prod "cd /cord/build/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-refresh-fabric.yml"
239
240 echo "Fabric ping test"
241 ssh prod "cd /cord/build/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-fabric-pingtest.yml"
Andy Bavier99c11d32016-09-14 17:21:20 -0400242}
243
244function run_e2e_test () {
245 cd $CORDDIR/build
246
Andy Bavier2505f592016-11-11 15:58:55 -0500247 # User has been added to the lbvirtd group, but su $USER to be safe
Andy Baviera69ee722016-11-17 07:26:01 -0800248 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests"
Andy Bavier99c11d32016-09-14 17:21:20 -0400249}
250
251function run_diagnostics() {
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700252 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG PIrunDiag"
Andy Bavier99c11d32016-09-14 17:21:20 -0400253}
254
255# Parse options
Zack Williamsdae7ff62016-11-14 15:20:06 -0700256GERRIT_BRANCHES=
Andy Bavier99c11d32016-09-14 17:21:20 -0400257RUN_TEST=0
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400258SETUP_ONLY=0
Andy Bavier99c11d32016-09-14 17:21:20 -0400259DIAGNOSTICS=0
260CLEANUP=0
Andy Bavier0f07bb32017-01-17 10:20:26 -0500261FABRIC=0
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600262#By default, cord-in-a-box creates 1 compute node. If more than one compute is
263#needed, use -n option
264NUM_COMPUTE_NODES=1
Andy Bavier99c11d32016-09-14 17:21:20 -0400265
Andy Bavier0f07bb32017-01-17 10:20:26 -0500266while getopts "b:cdfhn:stv" opt; do
Andy Bavier99c11d32016-09-14 17:21:20 -0400267 case ${opt} in
Zack Williamsdae7ff62016-11-14 15:20:06 -0700268 b ) GERRIT_BRANCHES+=("$OPTARG")
Andy Bavier99c11d32016-09-14 17:21:20 -0400269 ;;
270 c ) CLEANUP=1
271 ;;
272 d ) DIAGNOSTICS=1
273 ;;
Andy Bavier0f07bb32017-01-17 10:20:26 -0500274 f ) FABRIC=1
275 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400276 h ) echo "Usage:"
277 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsdae7ff62016-11-14 15:20:06 -0700278 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
279 echo " be used multiple times."
Andy Bavier99c11d32016-09-14 17:21:20 -0400280 echo " $0 -c cleanup from previous test"
281 echo " $0 -d run diagnostic collector"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500282 echo " $0 -f use ONOS fabric (EXPERIMENTAL)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400283 echo " $0 -h display this help message"
Zack Williamsa9e76ec2017-01-20 16:17:35 -0700284 echo " $0 -n # number of compute nodes to setup. Currently max 2 nodes can be supported"
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400285 echo " $0 -s run initial setup phase only (don't start building CORD)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400286 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Bavierd1165102017-01-13 16:38:57 -0500287 echo " $0 -v print CiaB version and exit"
Andy Bavier99c11d32016-09-14 17:21:20 -0400288 exit 0
289 ;;
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600290 n ) NUM_COMPUTE_NODES=$OPTARG
291 ;;
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400292 s ) SETUP_ONLY=1
293 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400294 t ) RUN_TEST=1
295 ;;
Andy Bavierd1165102017-01-13 16:38:57 -0500296 v ) echo "$VERSION_STRING ($REPO_BRANCH branch)"
297 exit 0
298 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400299 \? ) echo "Invalid option: -$OPTARG"
300 exit 1
301 ;;
302 esac
303done
304
305# What to do
306if [[ $CLEANUP -eq 1 ]]
307then
Sapan Bhatia3f454b32017-03-01 05:24:19 +0100308 cleanup_from_previous_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400309fi
310
Andy Bavierd1165102017-01-13 16:38:57 -0500311echo ""
312echo "Preparing to install $VERSION_STRING ($REPO_BRANCH branch)"
313echo ""
314
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +0100315bootstrap
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800316run_stage cloudlab_setup
317run_stage elk_up
318run_stage vagrant_vms_up
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400319
320if [[ $SETUP_ONLY -ne 0 ]]
321then
322 echo "Finished build environment setup, exiting..."
323 exit 0
324fi
325
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800326run_stage install_head_node
327run_stage set_up_maas_user
328run_stage leaf_spine_up
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600329
Andy Bavier0f07bb32017-01-17 10:20:26 -0500330if [[ $NUM_COMPUTE_NODES -gt 3 ]]
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600331then
Andy Bavier0f07bb32017-01-17 10:20:26 -0500332 echo "currently max only three compute nodes can be supported..."
333 NUM_COMPUTE_NODES=3
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600334fi
335
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800336echo "==> Adding compute nodes: Starting"
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600337for i in `seq 1 $NUM_COMPUTE_NODES`;
338do
339 echo adding the compute node: compute-node-$i
Andy Bavier0f07bb32017-01-17 10:20:26 -0500340 add_compute_node compute-node-$i build_compute-node-$i
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600341done
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800342echo "==> Adding compute nodes: Complete"
Andy Bavier99c11d32016-09-14 17:21:20 -0400343
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700344# run diagnostics both before/after the fabric/e2e tests
345if [[ $DIAGNOSTICS -eq 1 ]]
346then
347 run_diagnostics
348fi
349
350
Andy Bavier0f07bb32017-01-17 10:20:26 -0500351if [[ $FABRIC -ne 0 ]]
352then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800353 run_stage initialize_fabric
Andy Bavier0f07bb32017-01-17 10:20:26 -0500354fi
355
Andy Bavier99c11d32016-09-14 17:21:20 -0400356if [[ $RUN_TEST -eq 1 ]]
357then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800358 run_stage run_e2e_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400359fi
360
361if [[ $DIAGNOSTICS -eq 1 ]]
362then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800363 run_stage run_diagnostics
Andy Bavier99c11d32016-09-14 17:21:20 -0400364fi
365
366exit 0