blob: b018f22a8055cb2a0365d9e31e3cbd75532ae9a1 [file] [log] [blame]
Andy Bavier99c11d32016-09-14 17:21:20 -04001#!/usr/bin/env bash
2
3set -e
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
Andy Bavier0f07bb32017-01-17 10:20:26 -050014function add_box() {
15 vagrant box list | grep $1 | grep virtualbox || vagrant box add $1
16 vagrant box list | grep $1 | grep libvirt || vagrant mutate $1 libvirt --input-provider virtualbox
17}
18
Andy Bavier99c11d32016-09-14 17:21:20 -040019function cleanup_from_previous_test() {
Andy Bavier99c11d32016-09-14 17:21:20 -040020 echo "## Cleanup ##"
21
Andy Baviera4883ba2016-12-21 15:46:58 -050022 if [ -d $CORDDIR/build ]
23 then
24 echo "Destroying all Vagrant VMs"
25 cd $CORDDIR/build
26 sudo su $USER -c 'vagrant destroy'
27 fi
Andy Bavier99c11d32016-09-14 17:21:20 -040028
Andy Bavier2505f592016-11-11 15:58:55 -050029 echo "Removing $CORDDIR"
30 cd ~
Andy Bavier99c11d32016-09-14 17:21:20 -040031 rm -rf $CORDDIR
Andy Bavier99c11d32016-09-14 17:21:20 -040032}
33
34function bootstrap() {
35 cd ~
36 sudo apt-get update
37 [ -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 -050038 dpkg -l vagrant || sudo dpkg -i vagrant_1.8.5_x86_64.deb
Andy Bavier1a35ae62016-11-15 19:58:13 -080039 sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential
Andy Bavier99c11d32016-09-14 17:21:20 -040040
41 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
Andy Bavier99c11d32016-09-14 17:21:20 -040042
Andy Bavier99c11d32016-09-14 17:21:20 -040043 sudo adduser $USER libvirtd
44
45 sudo curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo
46 sudo chmod a+x /usr/local/bin/repo
47
48 if [ ! -d "$CORDDIR" ]
49 then
50 mkdir $CORDDIR && cd $CORDDIR
51 git config --global user.name 'Test User'
52 git config --global user.email 'test@null.com'
53 git config --global color.ui false
54
Scott Baker0ab86822017-02-01 14:33:40 -080055 repo init -u https://gerrit.opencord.org/manifest -b $REPO_BRANCH -g build,onos,orchestration,voltha
Andy Bavier99c11d32016-09-14 17:21:20 -040056 repo sync
57
Zack Williamsdae7ff62016-11-14 15:20:06 -070058 # check out gerrit branches using repo
59 for gerrit_branch in ${GERRIT_BRANCHES[@]}; do
60 echo "checking out opencord gerrit branch: $gerrit_branch"
61 repo download ${gerrit_branch/:/ }
62 done
Andy Bavier99c11d32016-09-14 17:21:20 -040063 fi
64
65 cd $CORDDIR/build
Andy Bavierad3ea842016-12-21 16:19:07 -050066 vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
67 vagrant plugin list | grep vagrant-mutate || vagrant plugin install vagrant-mutate
Andy Bavier0f07bb32017-01-17 10:20:26 -050068 add_box ubuntu/trusty64
Andy Bavier99c11d32016-09-14 17:21:20 -040069}
70
71function cloudlab_setup() {
Andy Bavier8b4ed1f2017-02-13 17:06:58 -080072
73 # The watchdog will sometimes reset groups, turn it off
74 if [ -e /usr/local/etc/emulab/watchdog ]
75 then
76 sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop
77 sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled
78 fi
79
Andy Bavier99c11d32016-09-14 17:21:20 -040080 if [ -e /usr/testbed/bin/mkextrafs ]
81 then
Andy Bavier9c0835e2016-11-11 15:56:47 -050082 sudo mkdir -p /mnt/extra
Scott Baker8b9182d2016-10-27 17:53:52 -070083
Andy Bavier8ce395f2016-10-14 12:51:30 -040084 # Sometimes this command fails on the first try
Andy Bavier9c0835e2016-11-11 15:56:47 -050085 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/"
86
87 # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted)
Andy Baviera69ee722016-11-17 07:26:01 -080088 mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1)
Scott Baker8b9182d2016-10-27 17:53:52 -070089
90 # we'll replace /var/lib/libvirt/images with a symlink below
91 [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images
92
Andy Bavier9c0835e2016-11-11 15:56:47 -050093 sudo mkdir -p /mnt/extra/libvirt_images
Andy Bavier2505f592016-11-11 15:58:55 -050094 if [ ! -e /var/lib/libvirt/images ]
95 then
96 sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images
97 fi
Andy Bavier99c11d32016-09-14 17:21:20 -040098 fi
99}
100
Andy Bavier2505f592016-11-11 15:58:55 -0500101function vagrant_vms_up() {
Andy Bavier99c11d32016-09-14 17:21:20 -0400102 cd $CORDDIR/build
103
Andy Bavier65c8e152016-12-22 16:01:27 -0500104 sudo su $USER -c 'vagrant up corddev prod --provider libvirt'
Andy Baviera69ee722016-11-17 07:26:01 -0800105
106 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
107 # It allows SSH'ing to the machine via 'ssh corddev'
Andy Bavier2505f592016-11-11 15:58:55 -0500108 sudo su $USER -c "vagrant ssh-config corddev prod > $SSHCONFIG"
109
110 scp ~/.ssh/id_rsa* corddev:.ssh
111 ssh corddev "chmod go-r ~/.ssh/id_rsa"
Andy Bavier99c11d32016-09-14 17:21:20 -0400112}
113
114function install_head_node() {
115 cd $CORDDIR/build
116
Andy Baviera69ee722016-11-17 07:26:01 -0800117 # SSH config saved earlier allows us to connect to VM without running 'vagrant'
Zack Williams0620c932017-01-25 14:36:31 -0700118 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch"
119 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages"
Andy Bavier2505f592016-11-11 15:58:55 -0500120 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 -0800121 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy"
Andy Bavier99c11d32016-09-14 17:21:20 -0400122}
123
124function set_up_maas_user() {
Andy Bavier2505f592016-11-11 15:58:55 -0500125 # Set up MAAS user on server to restart nodes via libvirt
126 grep maas /etc/passwd || sudo useradd -m maas
Andy Bavier99c11d32016-09-14 17:21:20 -0400127 sudo adduser maas libvirtd
128
Andy Bavier2505f592016-11-11 15:58:55 -0500129 # Copy generated public key to maas user's authorized_keys
130 sudo su maas -c "mkdir -p ~/.ssh"
131 sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys
132 sudo chown maas:maas ~maas/.ssh/authorized_keys
Andy Bavier99c11d32016-09-14 17:21:20 -0400133
Andy Bavier2505f592016-11-11 15:58:55 -0500134 # Copy generated private key to maas user's home dir in prod VM
135 scp $HOME/.ssh/id_rsa prod:/tmp
136 ssh prod "sudo mkdir -p ~maas/.ssh"
137 ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa"
138 ssh prod "sudo chown -R maas:maas ~maas/.ssh"
139}
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600140
Andy Bavier0f07bb32017-01-17 10:20:26 -0500141function turn_off_learning () {
142 NET=$1
143 BRIDGE=`sudo virsh net-info $NET|grep "Bridge:"|awk '{print $2}'`
144 sudo brctl setageing $BRIDGE 0
145 sudo brctl stp $BRIDGE off
146}
147
148function leaf_spine_up() {
149 cd $CORDDIR/build
150
151 if [[ $FABRIC -ne 0 ]]
152 then
153 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 spine-2 --provider libvirt"
154 else
155 # Linux bridging seems to be having issues with two spine switches
156 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 --provider libvirt"
157 fi
158
159 # Turn off MAC learning on "links" -- i.e., bridges created by libvirt.
160 # Without this, sometimes packets are dropped because the bridges
161 # think they are not local -- this needs further investigation.
162 # A better solution might be to replace the bridges with UDP tunnels, but this
163 # is not supported with the version of libvirt available on Ubuntu 14.04.
164 turn_off_learning head-node-leaf-1
165 turn_off_learning compute-node-1-leaf-1
166 turn_off_learning compute-node-2-leaf-2
167 turn_off_learning compute-node-3-leaf-2
168 turn_off_learning leaf-1-spine-1
169 turn_off_learning leaf-1-spine-2
170 turn_off_learning leaf-2-spine-1
171 turn_off_learning leaf-2-spine-2
172}
173
Andy Bavier99c11d32016-09-14 17:21:20 -0400174function add_compute_node() {
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600175 echo add_compute_node: $1 $2
Andy Bavier2505f592016-11-11 15:58:55 -0500176
Andy Bavier99c11d32016-09-14 17:21:20 -0400177 cd $CORDDIR/build
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600178 sudo su $USER -c "vagrant up $1 --provider libvirt"
Andy Bavier99c11d32016-09-14 17:21:20 -0400179
Andy Bavier2505f592016-11-11 15:58:55 -0500180 # Set up power cycling for the compute node and wait for it to be provisioned
181 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 -0400182
183 echo ""
Andy Bavier0f07bb32017-01-17 10:20:26 -0500184 echo "$1 is fully provisioned!"
185}
186
187function initialize_fabric() {
188 echo "Initializing fabric"
189 ssh prod "cd /cord/build/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-refresh-fabric.yml"
190
191 echo "Fabric ping test"
192 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 -0400193}
194
195function run_e2e_test () {
196 cd $CORDDIR/build
197
Andy Bavier2505f592016-11-11 15:58:55 -0500198 # User has been added to the lbvirtd group, but su $USER to be safe
Andy Baviera69ee722016-11-17 07:26:01 -0800199 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests"
Andy Bavier99c11d32016-09-14 17:21:20 -0400200}
201
202function run_diagnostics() {
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700203 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG PIrunDiag"
Andy Bavier99c11d32016-09-14 17:21:20 -0400204}
205
206# Parse options
Zack Williamsdae7ff62016-11-14 15:20:06 -0700207GERRIT_BRANCHES=
Andy Bavier99c11d32016-09-14 17:21:20 -0400208RUN_TEST=0
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400209SETUP_ONLY=0
Andy Bavier99c11d32016-09-14 17:21:20 -0400210DIAGNOSTICS=0
211CLEANUP=0
Andy Bavier0f07bb32017-01-17 10:20:26 -0500212FABRIC=0
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600213#By default, cord-in-a-box creates 1 compute node. If more than one compute is
214#needed, use -n option
215NUM_COMPUTE_NODES=1
Andy Bavier99c11d32016-09-14 17:21:20 -0400216
Andy Bavier0f07bb32017-01-17 10:20:26 -0500217while getopts "b:cdfhn:stv" opt; do
Andy Bavier99c11d32016-09-14 17:21:20 -0400218 case ${opt} in
Zack Williamsdae7ff62016-11-14 15:20:06 -0700219 b ) GERRIT_BRANCHES+=("$OPTARG")
Andy Bavier99c11d32016-09-14 17:21:20 -0400220 ;;
221 c ) CLEANUP=1
222 ;;
223 d ) DIAGNOSTICS=1
224 ;;
Andy Bavier0f07bb32017-01-17 10:20:26 -0500225 f ) FABRIC=1
226 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400227 h ) echo "Usage:"
228 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsdae7ff62016-11-14 15:20:06 -0700229 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
230 echo " be used multiple times."
Andy Bavier99c11d32016-09-14 17:21:20 -0400231 echo " $0 -c cleanup from previous test"
232 echo " $0 -d run diagnostic collector"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500233 echo " $0 -f use ONOS fabric (EXPERIMENTAL)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400234 echo " $0 -h display this help message"
Zack Williamsa9e76ec2017-01-20 16:17:35 -0700235 echo " $0 -n # number of compute nodes to setup. Currently max 2 nodes can be supported"
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400236 echo " $0 -s run initial setup phase only (don't start building CORD)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400237 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Bavierd1165102017-01-13 16:38:57 -0500238 echo " $0 -v print CiaB version and exit"
Andy Bavier99c11d32016-09-14 17:21:20 -0400239 exit 0
240 ;;
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600241 n ) NUM_COMPUTE_NODES=$OPTARG
242 ;;
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400243 s ) SETUP_ONLY=1
244 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400245 t ) RUN_TEST=1
246 ;;
Andy Bavierd1165102017-01-13 16:38:57 -0500247 v ) echo "$VERSION_STRING ($REPO_BRANCH branch)"
248 exit 0
249 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400250 \? ) echo "Invalid option: -$OPTARG"
251 exit 1
252 ;;
253 esac
254done
255
256# What to do
257if [[ $CLEANUP -eq 1 ]]
258then
259 cleanup_from_previous_test
260fi
261
Andy Bavierd1165102017-01-13 16:38:57 -0500262echo ""
263echo "Preparing to install $VERSION_STRING ($REPO_BRANCH branch)"
264echo ""
265
Andy Bavier99c11d32016-09-14 17:21:20 -0400266bootstrap
267cloudlab_setup
Andy Bavier2505f592016-11-11 15:58:55 -0500268vagrant_vms_up
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400269
270if [[ $SETUP_ONLY -ne 0 ]]
271then
272 echo "Finished build environment setup, exiting..."
273 exit 0
274fi
275
Andy Bavier99c11d32016-09-14 17:21:20 -0400276install_head_node
277set_up_maas_user
Andy Bavier0f07bb32017-01-17 10:20:26 -0500278leaf_spine_up
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600279
Andy Bavier0f07bb32017-01-17 10:20:26 -0500280if [[ $NUM_COMPUTE_NODES -gt 3 ]]
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600281then
Andy Bavier0f07bb32017-01-17 10:20:26 -0500282 echo "currently max only three compute nodes can be supported..."
283 NUM_COMPUTE_NODES=3
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600284fi
285
286for i in `seq 1 $NUM_COMPUTE_NODES`;
287do
288 echo adding the compute node: compute-node-$i
Andy Bavier0f07bb32017-01-17 10:20:26 -0500289 add_compute_node compute-node-$i build_compute-node-$i
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600290done
Andy Bavier99c11d32016-09-14 17:21:20 -0400291
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700292# run diagnostics both before/after the fabric/e2e tests
293if [[ $DIAGNOSTICS -eq 1 ]]
294then
295 run_diagnostics
296fi
297
298
Andy Bavier0f07bb32017-01-17 10:20:26 -0500299if [[ $FABRIC -ne 0 ]]
300then
301 initialize_fabric
302fi
303
Andy Bavier99c11d32016-09-14 17:21:20 -0400304if [[ $RUN_TEST -eq 1 ]]
305then
306 run_e2e_test
307fi
308
309if [[ $DIAGNOSTICS -eq 1 ]]
310then
311 run_diagnostics
312fi
313
314exit 0