blob: afee8ec62ef9784416a4b76f726a94b18935ce19 [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 {
15 set +x
16 python $CORDDIR/build/elk-logger/mixpanel FINISH --finish
17}
18
19trap finish EXIT
Sapan Bhatia01ddea62017-02-10 11:28:48 -080020
Andy Bavier0f07bb32017-01-17 10:20:26 -050021function add_box() {
22 vagrant box list | grep $1 | grep virtualbox || vagrant box add $1
23 vagrant box list | grep $1 | grep libvirt || vagrant mutate $1 libvirt --input-provider virtualbox
24}
25
Sapan Bhatia01ddea62017-02-10 11:28:48 -080026function run_stage {
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010027 cd $CORDDIR
28 python build/elk-logger/mixpanel $1-start
29
Sapan Bhatia01ddea62017-02-10 11:28:48 -080030 echo "==> "$1": Starting"
31 $1
32 echo "==> "$1": Complete"
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010033
34 cd $CORDDIR
35 python build/elk-logger/mixpanel $1-end
Sapan Bhatia01ddea62017-02-10 11:28:48 -080036}
37
Andy Bavier99c11d32016-09-14 17:21:20 -040038function cleanup_from_previous_test() {
Andy Bavier99c11d32016-09-14 17:21:20 -040039 echo "## Cleanup ##"
40
Andy Baviera4883ba2016-12-21 15:46:58 -050041 if [ -d $CORDDIR/build ]
42 then
43 echo "Destroying all Vagrant VMs"
44 cd $CORDDIR/build
45 sudo su $USER -c 'vagrant destroy'
46 fi
Andy Bavier99c11d32016-09-14 17:21:20 -040047
Andy Bavier2505f592016-11-11 15:58:55 -050048 echo "Removing $CORDDIR"
49 cd ~
Andy Bavier99c11d32016-09-14 17:21:20 -040050 rm -rf $CORDDIR
Andy Bavier99c11d32016-09-14 17:21:20 -040051}
52
53function bootstrap() {
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +010054 cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 > /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
Andy Bavier99c11d32016-09-14 17:21:20 -040095}
96
97function cloudlab_setup() {
Andy Bavier8b4ed1f2017-02-13 17:06:58 -080098
99 # The watchdog will sometimes reset groups, turn it off
100 if [ -e /usr/local/etc/emulab/watchdog ]
101 then
102 sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop
103 sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled
104 fi
105
Andy Bavier99c11d32016-09-14 17:21:20 -0400106 if [ -e /usr/testbed/bin/mkextrafs ]
107 then
Andy Bavier9c0835e2016-11-11 15:56:47 -0500108 sudo mkdir -p /mnt/extra
Scott Baker8b9182d2016-10-27 17:53:52 -0700109
Andy Bavier8ce395f2016-10-14 12:51:30 -0400110 # Sometimes this command fails on the first try
Andy Bavier9c0835e2016-11-11 15:56:47 -0500111 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/"
112
113 # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted)
Andy Baviera69ee722016-11-17 07:26:01 -0800114 mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1)
Scott Baker8b9182d2016-10-27 17:53:52 -0700115
116 # we'll replace /var/lib/libvirt/images with a symlink below
117 [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images
118
Andy Bavier9c0835e2016-11-11 15:56:47 -0500119 sudo mkdir -p /mnt/extra/libvirt_images
Andy Bavier2505f592016-11-11 15:58:55 -0500120 if [ ! -e /var/lib/libvirt/images ]
121 then
122 sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images
123 fi
Andy Bavier99c11d32016-09-14 17:21:20 -0400124 fi
125}
126
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800127function elk_up() {
128 cd $CORDDIR/build
129
130 sudo su $USER -c 'vagrant up elastic --provider libvirt'
131
132 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
133 # It allows SSH'ing to the machine via 'ssh corddev'
134 sudo su $USER -c "vagrant ssh-config elastic > $SSHCONFIG"
135
136 cd $CORDDIR
137 if [ ! -f /tmp/elk-patch-applied ]; then
138 touch /tmp/elk-patch-applied
139 sh build/scripts/repo-apply.sh build/elk-logger/elk-ciab.diff
140 fi
141
142 sudo chmod +x build/elk-logger/logstash_tail
143 build/elk-logger/logstash_tail --file install.out --hostport 10.100.198.222:5617 &
144}
145
Andy Bavier2505f592016-11-11 15:58:55 -0500146function vagrant_vms_up() {
Andy Bavier99c11d32016-09-14 17:21:20 -0400147 cd $CORDDIR/build
148
Andy Bavier65c8e152016-12-22 16:01:27 -0500149 sudo su $USER -c 'vagrant up corddev prod --provider libvirt'
Andy Baviera69ee722016-11-17 07:26:01 -0800150
151 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
152 # It allows SSH'ing to the machine via 'ssh corddev'
Andy Bavier2505f592016-11-11 15:58:55 -0500153 sudo su $USER -c "vagrant ssh-config corddev prod > $SSHCONFIG"
154
155 scp ~/.ssh/id_rsa* corddev:.ssh
156 ssh corddev "chmod go-r ~/.ssh/id_rsa"
Andy Bavier99c11d32016-09-14 17:21:20 -0400157}
158
159function install_head_node() {
160 cd $CORDDIR/build
161
Andy Baviera69ee722016-11-17 07:26:01 -0800162 # SSH config saved earlier allows us to connect to VM without running 'vagrant'
Zack Williams0620c932017-01-25 14:36:31 -0700163 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch"
164 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages"
Andy Bavier2505f592016-11-11 15:58:55 -0500165 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 -0800166 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy"
Andy Bavier99c11d32016-09-14 17:21:20 -0400167}
168
169function set_up_maas_user() {
Andy Bavier2505f592016-11-11 15:58:55 -0500170 # Set up MAAS user on server to restart nodes via libvirt
171 grep maas /etc/passwd || sudo useradd -m maas
Andy Bavier99c11d32016-09-14 17:21:20 -0400172 sudo adduser maas libvirtd
173
Andy Bavier2505f592016-11-11 15:58:55 -0500174 # Copy generated public key to maas user's authorized_keys
175 sudo su maas -c "mkdir -p ~/.ssh"
176 sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys
177 sudo chown maas:maas ~maas/.ssh/authorized_keys
Andy Bavier99c11d32016-09-14 17:21:20 -0400178
Andy Bavier2505f592016-11-11 15:58:55 -0500179 # Copy generated private key to maas user's home dir in prod VM
180 scp $HOME/.ssh/id_rsa prod:/tmp
181 ssh prod "sudo mkdir -p ~maas/.ssh"
182 ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa"
183 ssh prod "sudo chown -R maas:maas ~maas/.ssh"
184}
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600185
Andy Bavier0f07bb32017-01-17 10:20:26 -0500186function turn_off_learning () {
187 NET=$1
188 BRIDGE=`sudo virsh net-info $NET|grep "Bridge:"|awk '{print $2}'`
189 sudo brctl setageing $BRIDGE 0
190 sudo brctl stp $BRIDGE off
191}
192
193function leaf_spine_up() {
194 cd $CORDDIR/build
195
196 if [[ $FABRIC -ne 0 ]]
197 then
198 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 spine-2 --provider libvirt"
199 else
200 # Linux bridging seems to be having issues with two spine switches
201 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 --provider libvirt"
202 fi
203
204 # Turn off MAC learning on "links" -- i.e., bridges created by libvirt.
205 # Without this, sometimes packets are dropped because the bridges
206 # think they are not local -- this needs further investigation.
207 # A better solution might be to replace the bridges with UDP tunnels, but this
208 # is not supported with the version of libvirt available on Ubuntu 14.04.
209 turn_off_learning head-node-leaf-1
210 turn_off_learning compute-node-1-leaf-1
211 turn_off_learning compute-node-2-leaf-2
212 turn_off_learning compute-node-3-leaf-2
213 turn_off_learning leaf-1-spine-1
214 turn_off_learning leaf-1-spine-2
215 turn_off_learning leaf-2-spine-1
216 turn_off_learning leaf-2-spine-2
217}
218
Andy Bavier99c11d32016-09-14 17:21:20 -0400219function add_compute_node() {
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600220 echo add_compute_node: $1 $2
Andy Bavier2505f592016-11-11 15:58:55 -0500221
Andy Bavier99c11d32016-09-14 17:21:20 -0400222 cd $CORDDIR/build
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600223 sudo su $USER -c "vagrant up $1 --provider libvirt"
Andy Bavier99c11d32016-09-14 17:21:20 -0400224
Andy Bavier2505f592016-11-11 15:58:55 -0500225 # Set up power cycling for the compute node and wait for it to be provisioned
226 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 -0400227
228 echo ""
Andy Bavier0f07bb32017-01-17 10:20:26 -0500229 echo "$1 is fully provisioned!"
230}
231
232function initialize_fabric() {
233 echo "Initializing fabric"
234 ssh prod "cd /cord/build/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-refresh-fabric.yml"
235
236 echo "Fabric ping test"
237 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 -0400238}
239
240function run_e2e_test () {
241 cd $CORDDIR/build
242
Andy Bavier2505f592016-11-11 15:58:55 -0500243 # User has been added to the lbvirtd group, but su $USER to be safe
Andy Baviera69ee722016-11-17 07:26:01 -0800244 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests"
Andy Bavier99c11d32016-09-14 17:21:20 -0400245}
246
247function run_diagnostics() {
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700248 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG PIrunDiag"
Andy Bavier99c11d32016-09-14 17:21:20 -0400249}
250
251# Parse options
Zack Williamsdae7ff62016-11-14 15:20:06 -0700252GERRIT_BRANCHES=
Andy Bavier99c11d32016-09-14 17:21:20 -0400253RUN_TEST=0
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400254SETUP_ONLY=0
Andy Bavier99c11d32016-09-14 17:21:20 -0400255DIAGNOSTICS=0
256CLEANUP=0
Andy Bavier0f07bb32017-01-17 10:20:26 -0500257FABRIC=0
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600258#By default, cord-in-a-box creates 1 compute node. If more than one compute is
259#needed, use -n option
260NUM_COMPUTE_NODES=1
Andy Bavier99c11d32016-09-14 17:21:20 -0400261
Andy Bavier0f07bb32017-01-17 10:20:26 -0500262while getopts "b:cdfhn:stv" opt; do
Andy Bavier99c11d32016-09-14 17:21:20 -0400263 case ${opt} in
Zack Williamsdae7ff62016-11-14 15:20:06 -0700264 b ) GERRIT_BRANCHES+=("$OPTARG")
Andy Bavier99c11d32016-09-14 17:21:20 -0400265 ;;
266 c ) CLEANUP=1
267 ;;
268 d ) DIAGNOSTICS=1
269 ;;
Andy Bavier0f07bb32017-01-17 10:20:26 -0500270 f ) FABRIC=1
271 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400272 h ) echo "Usage:"
273 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsdae7ff62016-11-14 15:20:06 -0700274 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
275 echo " be used multiple times."
Andy Bavier99c11d32016-09-14 17:21:20 -0400276 echo " $0 -c cleanup from previous test"
277 echo " $0 -d run diagnostic collector"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500278 echo " $0 -f use ONOS fabric (EXPERIMENTAL)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400279 echo " $0 -h display this help message"
Zack Williamsa9e76ec2017-01-20 16:17:35 -0700280 echo " $0 -n # number of compute nodes to setup. Currently max 2 nodes can be supported"
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400281 echo " $0 -s run initial setup phase only (don't start building CORD)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400282 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Bavierd1165102017-01-13 16:38:57 -0500283 echo " $0 -v print CiaB version and exit"
Andy Bavier99c11d32016-09-14 17:21:20 -0400284 exit 0
285 ;;
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600286 n ) NUM_COMPUTE_NODES=$OPTARG
287 ;;
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400288 s ) SETUP_ONLY=1
289 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400290 t ) RUN_TEST=1
291 ;;
Andy Bavierd1165102017-01-13 16:38:57 -0500292 v ) echo "$VERSION_STRING ($REPO_BRANCH branch)"
293 exit 0
294 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400295 \? ) echo "Invalid option: -$OPTARG"
296 exit 1
297 ;;
298 esac
299done
300
301# What to do
302if [[ $CLEANUP -eq 1 ]]
303then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800304 run_stage cleanup_from_previous_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400305fi
306
Andy Bavierd1165102017-01-13 16:38:57 -0500307echo ""
308echo "Preparing to install $VERSION_STRING ($REPO_BRANCH branch)"
309echo ""
310
Sapan Bhatiaa94c2db2017-02-27 20:18:24 +0100311bootstrap
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800312run_stage cloudlab_setup
313run_stage elk_up
314run_stage vagrant_vms_up
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400315
316if [[ $SETUP_ONLY -ne 0 ]]
317then
318 echo "Finished build environment setup, exiting..."
319 exit 0
320fi
321
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800322run_stage install_head_node
323run_stage set_up_maas_user
324run_stage leaf_spine_up
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600325
Andy Bavier0f07bb32017-01-17 10:20:26 -0500326if [[ $NUM_COMPUTE_NODES -gt 3 ]]
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600327then
Andy Bavier0f07bb32017-01-17 10:20:26 -0500328 echo "currently max only three compute nodes can be supported..."
329 NUM_COMPUTE_NODES=3
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600330fi
331
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800332echo "==> Adding compute nodes: Starting"
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600333for i in `seq 1 $NUM_COMPUTE_NODES`;
334do
335 echo adding the compute node: compute-node-$i
Andy Bavier0f07bb32017-01-17 10:20:26 -0500336 add_compute_node compute-node-$i build_compute-node-$i
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600337done
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800338echo "==> Adding compute nodes: Complete"
Andy Bavier99c11d32016-09-14 17:21:20 -0400339
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700340# run diagnostics both before/after the fabric/e2e tests
341if [[ $DIAGNOSTICS -eq 1 ]]
342then
343 run_diagnostics
344fi
345
346
Andy Bavier0f07bb32017-01-17 10:20:26 -0500347if [[ $FABRIC -ne 0 ]]
348then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800349 run_stage initialize_fabric
Andy Bavier0f07bb32017-01-17 10:20:26 -0500350fi
351
Andy Bavier99c11d32016-09-14 17:21:20 -0400352if [[ $RUN_TEST -eq 1 ]]
353then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800354 run_stage run_e2e_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400355fi
356
357if [[ $DIAGNOSTICS -eq 1 ]]
358then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800359 run_stage run_diagnostics
Andy Bavier99c11d32016-09-14 17:21:20 -0400360fi
361
362exit 0