blob: e984f47154b72ea97a6fb3599c4ce4e9e3ce025b [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 Bhatia01ddea62017-02-10 11:28:48 -080014exec > >(tee -i $CORDDIR/install.out)
15exec 2>&1
16
Andy Bavier0f07bb32017-01-17 10:20:26 -050017function add_box() {
18 vagrant box list | grep $1 | grep virtualbox || vagrant box add $1
19 vagrant box list | grep $1 | grep libvirt || vagrant mutate $1 libvirt --input-provider virtualbox
20}
21
Sapan Bhatia01ddea62017-02-10 11:28:48 -080022function run_stage {
23 echo "==> "$1": Starting"
24 $1
25 echo "==> "$1": Complete"
26}
27
Andy Bavier99c11d32016-09-14 17:21:20 -040028function cleanup_from_previous_test() {
Andy Bavier99c11d32016-09-14 17:21:20 -040029 echo "## Cleanup ##"
30
Andy Baviera4883ba2016-12-21 15:46:58 -050031 if [ -d $CORDDIR/build ]
32 then
33 echo "Destroying all Vagrant VMs"
34 cd $CORDDIR/build
35 sudo su $USER -c 'vagrant destroy'
36 fi
Andy Bavier99c11d32016-09-14 17:21:20 -040037
Andy Bavier2505f592016-11-11 15:58:55 -050038 echo "Removing $CORDDIR"
39 cd ~
Andy Bavier99c11d32016-09-14 17:21:20 -040040 rm -rf $CORDDIR
Andy Bavier99c11d32016-09-14 17:21:20 -040041}
42
43function bootstrap() {
44 cd ~
45 sudo apt-get update
46 [ -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 -050047 dpkg -l vagrant || sudo dpkg -i vagrant_1.8.5_x86_64.deb
Sapan Bhatia01ddea62017-02-10 11:28:48 -080048 sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential python-pip
49 sudo pip install pyparsing python-logstash
Andy Bavier99c11d32016-09-14 17:21:20 -040050
51 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
Andy Bavier99c11d32016-09-14 17:21:20 -040052
Andy Bavier99c11d32016-09-14 17:21:20 -040053 sudo adduser $USER libvirtd
54
55 sudo curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo
56 sudo chmod a+x /usr/local/bin/repo
57
58 if [ ! -d "$CORDDIR" ]
59 then
60 mkdir $CORDDIR && cd $CORDDIR
61 git config --global user.name 'Test User'
62 git config --global user.email 'test@null.com'
63 git config --global color.ui false
64
Scott Baker0ab86822017-02-01 14:33:40 -080065 repo init -u https://gerrit.opencord.org/manifest -b $REPO_BRANCH -g build,onos,orchestration,voltha
Andy Bavier99c11d32016-09-14 17:21:20 -040066 repo sync
67
Zack Williamsdae7ff62016-11-14 15:20:06 -070068 # check out gerrit branches using repo
69 for gerrit_branch in ${GERRIT_BRANCHES[@]}; do
70 echo "checking out opencord gerrit branch: $gerrit_branch"
71 repo download ${gerrit_branch/:/ }
72 done
Andy Bavier99c11d32016-09-14 17:21:20 -040073 fi
74
75 cd $CORDDIR/build
Andy Bavierad3ea842016-12-21 16:19:07 -050076 vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
77 vagrant plugin list | grep vagrant-mutate || vagrant plugin install vagrant-mutate
Andy Bavier0f07bb32017-01-17 10:20:26 -050078 add_box ubuntu/trusty64
Andy Bavier99c11d32016-09-14 17:21:20 -040079}
80
81function cloudlab_setup() {
Andy Bavier8b4ed1f2017-02-13 17:06:58 -080082
83 # The watchdog will sometimes reset groups, turn it off
84 if [ -e /usr/local/etc/emulab/watchdog ]
85 then
86 sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop
87 sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled
88 fi
89
Andy Bavier99c11d32016-09-14 17:21:20 -040090 if [ -e /usr/testbed/bin/mkextrafs ]
91 then
Andy Bavier9c0835e2016-11-11 15:56:47 -050092 sudo mkdir -p /mnt/extra
Scott Baker8b9182d2016-10-27 17:53:52 -070093
Andy Bavier8ce395f2016-10-14 12:51:30 -040094 # Sometimes this command fails on the first try
Andy Bavier9c0835e2016-11-11 15:56:47 -050095 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/"
96
97 # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted)
Andy Baviera69ee722016-11-17 07:26:01 -080098 mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1)
Scott Baker8b9182d2016-10-27 17:53:52 -070099
100 # we'll replace /var/lib/libvirt/images with a symlink below
101 [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images
102
Andy Bavier9c0835e2016-11-11 15:56:47 -0500103 sudo mkdir -p /mnt/extra/libvirt_images
Andy Bavier2505f592016-11-11 15:58:55 -0500104 if [ ! -e /var/lib/libvirt/images ]
105 then
106 sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images
107 fi
Andy Bavier99c11d32016-09-14 17:21:20 -0400108 fi
109}
110
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800111function elk_up() {
112 cd $CORDDIR/build
113
114 sudo su $USER -c 'vagrant up elastic --provider libvirt'
115
116 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
117 # It allows SSH'ing to the machine via 'ssh corddev'
118 sudo su $USER -c "vagrant ssh-config elastic > $SSHCONFIG"
119
120 cd $CORDDIR
121 if [ ! -f /tmp/elk-patch-applied ]; then
122 touch /tmp/elk-patch-applied
123 sh build/scripts/repo-apply.sh build/elk-logger/elk-ciab.diff
124 fi
125
126 sudo chmod +x build/elk-logger/logstash_tail
127 build/elk-logger/logstash_tail --file install.out --hostport 10.100.198.222:5617 &
128}
129
Andy Bavier2505f592016-11-11 15:58:55 -0500130function vagrant_vms_up() {
Andy Bavier99c11d32016-09-14 17:21:20 -0400131 cd $CORDDIR/build
132
Andy Bavier65c8e152016-12-22 16:01:27 -0500133 sudo su $USER -c 'vagrant up corddev prod --provider libvirt'
Andy Baviera69ee722016-11-17 07:26:01 -0800134
135 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
136 # It allows SSH'ing to the machine via 'ssh corddev'
Andy Bavier2505f592016-11-11 15:58:55 -0500137 sudo su $USER -c "vagrant ssh-config corddev prod > $SSHCONFIG"
138
139 scp ~/.ssh/id_rsa* corddev:.ssh
140 ssh corddev "chmod go-r ~/.ssh/id_rsa"
Andy Bavier99c11d32016-09-14 17:21:20 -0400141}
142
143function install_head_node() {
144 cd $CORDDIR/build
145
Andy Baviera69ee722016-11-17 07:26:01 -0800146 # SSH config saved earlier allows us to connect to VM without running 'vagrant'
Zack Williams0620c932017-01-25 14:36:31 -0700147 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch"
148 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages"
Andy Bavier2505f592016-11-11 15:58:55 -0500149 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 -0800150 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy"
Andy Bavier99c11d32016-09-14 17:21:20 -0400151}
152
153function set_up_maas_user() {
Andy Bavier2505f592016-11-11 15:58:55 -0500154 # Set up MAAS user on server to restart nodes via libvirt
155 grep maas /etc/passwd || sudo useradd -m maas
Andy Bavier99c11d32016-09-14 17:21:20 -0400156 sudo adduser maas libvirtd
157
Andy Bavier2505f592016-11-11 15:58:55 -0500158 # Copy generated public key to maas user's authorized_keys
159 sudo su maas -c "mkdir -p ~/.ssh"
160 sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys
161 sudo chown maas:maas ~maas/.ssh/authorized_keys
Andy Bavier99c11d32016-09-14 17:21:20 -0400162
Andy Bavier2505f592016-11-11 15:58:55 -0500163 # Copy generated private key to maas user's home dir in prod VM
164 scp $HOME/.ssh/id_rsa prod:/tmp
165 ssh prod "sudo mkdir -p ~maas/.ssh"
166 ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa"
167 ssh prod "sudo chown -R maas:maas ~maas/.ssh"
168}
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600169
Andy Bavier0f07bb32017-01-17 10:20:26 -0500170function turn_off_learning () {
171 NET=$1
172 BRIDGE=`sudo virsh net-info $NET|grep "Bridge:"|awk '{print $2}'`
173 sudo brctl setageing $BRIDGE 0
174 sudo brctl stp $BRIDGE off
175}
176
177function leaf_spine_up() {
178 cd $CORDDIR/build
179
180 if [[ $FABRIC -ne 0 ]]
181 then
182 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 spine-2 --provider libvirt"
183 else
184 # Linux bridging seems to be having issues with two spine switches
185 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 --provider libvirt"
186 fi
187
188 # Turn off MAC learning on "links" -- i.e., bridges created by libvirt.
189 # Without this, sometimes packets are dropped because the bridges
190 # think they are not local -- this needs further investigation.
191 # A better solution might be to replace the bridges with UDP tunnels, but this
192 # is not supported with the version of libvirt available on Ubuntu 14.04.
193 turn_off_learning head-node-leaf-1
194 turn_off_learning compute-node-1-leaf-1
195 turn_off_learning compute-node-2-leaf-2
196 turn_off_learning compute-node-3-leaf-2
197 turn_off_learning leaf-1-spine-1
198 turn_off_learning leaf-1-spine-2
199 turn_off_learning leaf-2-spine-1
200 turn_off_learning leaf-2-spine-2
201}
202
Andy Bavier99c11d32016-09-14 17:21:20 -0400203function add_compute_node() {
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600204 echo add_compute_node: $1 $2
Andy Bavier2505f592016-11-11 15:58:55 -0500205
Andy Bavier99c11d32016-09-14 17:21:20 -0400206 cd $CORDDIR/build
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600207 sudo su $USER -c "vagrant up $1 --provider libvirt"
Andy Bavier99c11d32016-09-14 17:21:20 -0400208
Andy Bavier2505f592016-11-11 15:58:55 -0500209 # Set up power cycling for the compute node and wait for it to be provisioned
210 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 -0400211
212 echo ""
Andy Bavier0f07bb32017-01-17 10:20:26 -0500213 echo "$1 is fully provisioned!"
214}
215
216function initialize_fabric() {
217 echo "Initializing fabric"
218 ssh prod "cd /cord/build/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-refresh-fabric.yml"
219
220 echo "Fabric ping test"
221 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 -0400222}
223
224function run_e2e_test () {
225 cd $CORDDIR/build
226
Andy Bavier2505f592016-11-11 15:58:55 -0500227 # User has been added to the lbvirtd group, but su $USER to be safe
Andy Baviera69ee722016-11-17 07:26:01 -0800228 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests"
Andy Bavier99c11d32016-09-14 17:21:20 -0400229}
230
231function run_diagnostics() {
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700232 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG PIrunDiag"
Andy Bavier99c11d32016-09-14 17:21:20 -0400233}
234
235# Parse options
Zack Williamsdae7ff62016-11-14 15:20:06 -0700236GERRIT_BRANCHES=
Andy Bavier99c11d32016-09-14 17:21:20 -0400237RUN_TEST=0
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400238SETUP_ONLY=0
Andy Bavier99c11d32016-09-14 17:21:20 -0400239DIAGNOSTICS=0
240CLEANUP=0
Andy Bavier0f07bb32017-01-17 10:20:26 -0500241FABRIC=0
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600242#By default, cord-in-a-box creates 1 compute node. If more than one compute is
243#needed, use -n option
244NUM_COMPUTE_NODES=1
Andy Bavier99c11d32016-09-14 17:21:20 -0400245
Andy Bavier0f07bb32017-01-17 10:20:26 -0500246while getopts "b:cdfhn:stv" opt; do
Andy Bavier99c11d32016-09-14 17:21:20 -0400247 case ${opt} in
Zack Williamsdae7ff62016-11-14 15:20:06 -0700248 b ) GERRIT_BRANCHES+=("$OPTARG")
Andy Bavier99c11d32016-09-14 17:21:20 -0400249 ;;
250 c ) CLEANUP=1
251 ;;
252 d ) DIAGNOSTICS=1
253 ;;
Andy Bavier0f07bb32017-01-17 10:20:26 -0500254 f ) FABRIC=1
255 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400256 h ) echo "Usage:"
257 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsdae7ff62016-11-14 15:20:06 -0700258 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
259 echo " be used multiple times."
Andy Bavier99c11d32016-09-14 17:21:20 -0400260 echo " $0 -c cleanup from previous test"
261 echo " $0 -d run diagnostic collector"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500262 echo " $0 -f use ONOS fabric (EXPERIMENTAL)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400263 echo " $0 -h display this help message"
Zack Williamsa9e76ec2017-01-20 16:17:35 -0700264 echo " $0 -n # number of compute nodes to setup. Currently max 2 nodes can be supported"
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400265 echo " $0 -s run initial setup phase only (don't start building CORD)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400266 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Bavierd1165102017-01-13 16:38:57 -0500267 echo " $0 -v print CiaB version and exit"
Andy Bavier99c11d32016-09-14 17:21:20 -0400268 exit 0
269 ;;
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600270 n ) NUM_COMPUTE_NODES=$OPTARG
271 ;;
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400272 s ) SETUP_ONLY=1
273 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400274 t ) RUN_TEST=1
275 ;;
Andy Bavierd1165102017-01-13 16:38:57 -0500276 v ) echo "$VERSION_STRING ($REPO_BRANCH branch)"
277 exit 0
278 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400279 \? ) echo "Invalid option: -$OPTARG"
280 exit 1
281 ;;
282 esac
283done
284
285# What to do
286if [[ $CLEANUP -eq 1 ]]
287then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800288 run_stage cleanup_from_previous_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400289fi
290
Andy Bavierd1165102017-01-13 16:38:57 -0500291echo ""
292echo "Preparing to install $VERSION_STRING ($REPO_BRANCH branch)"
293echo ""
294
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800295run_stage bootstrap
296run_stage cloudlab_setup
297run_stage elk_up
298run_stage vagrant_vms_up
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400299
300if [[ $SETUP_ONLY -ne 0 ]]
301then
302 echo "Finished build environment setup, exiting..."
303 exit 0
304fi
305
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800306run_stage install_head_node
307run_stage set_up_maas_user
308run_stage leaf_spine_up
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600309
Andy Bavier0f07bb32017-01-17 10:20:26 -0500310if [[ $NUM_COMPUTE_NODES -gt 3 ]]
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600311then
Andy Bavier0f07bb32017-01-17 10:20:26 -0500312 echo "currently max only three compute nodes can be supported..."
313 NUM_COMPUTE_NODES=3
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600314fi
315
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800316echo "==> Adding compute nodes: Starting"
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600317for i in `seq 1 $NUM_COMPUTE_NODES`;
318do
319 echo adding the compute node: compute-node-$i
Andy Bavier0f07bb32017-01-17 10:20:26 -0500320 add_compute_node compute-node-$i build_compute-node-$i
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600321done
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800322echo "==> Adding compute nodes: Complete"
Andy Bavier99c11d32016-09-14 17:21:20 -0400323
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700324# run diagnostics both before/after the fabric/e2e tests
325if [[ $DIAGNOSTICS -eq 1 ]]
326then
327 run_diagnostics
328fi
329
330
Andy Bavier0f07bb32017-01-17 10:20:26 -0500331if [[ $FABRIC -ne 0 ]]
332then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800333 run_stage initialize_fabric
Andy Bavier0f07bb32017-01-17 10:20:26 -0500334fi
335
Andy Bavier99c11d32016-09-14 17:21:20 -0400336if [[ $RUN_TEST -eq 1 ]]
337then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800338 run_stage run_e2e_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400339fi
340
341if [[ $DIAGNOSTICS -eq 1 ]]
342then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800343 run_stage run_diagnostics
Andy Bavier99c11d32016-09-14 17:21:20 -0400344fi
345
346exit 0