blob: df48a127ab512725f253916bd9e04dcf46db2d92 [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 -080014
Andy Bavier0f07bb32017-01-17 10:20:26 -050015function add_box() {
16 vagrant box list | grep $1 | grep virtualbox || vagrant box add $1
17 vagrant box list | grep $1 | grep libvirt || vagrant mutate $1 libvirt --input-provider virtualbox
18}
19
Sapan Bhatia01ddea62017-02-10 11:28:48 -080020function run_stage {
21 echo "==> "$1": Starting"
22 $1
23 echo "==> "$1": Complete"
24}
25
Andy Bavier99c11d32016-09-14 17:21:20 -040026function cleanup_from_previous_test() {
Andy Bavier99c11d32016-09-14 17:21:20 -040027 echo "## Cleanup ##"
28
Andy Baviera4883ba2016-12-21 15:46:58 -050029 if [ -d $CORDDIR/build ]
30 then
31 echo "Destroying all Vagrant VMs"
32 cd $CORDDIR/build
33 sudo su $USER -c 'vagrant destroy'
34 fi
Andy Bavier99c11d32016-09-14 17:21:20 -040035
Andy Bavier2505f592016-11-11 15:58:55 -050036 echo "Removing $CORDDIR"
37 cd ~
Andy Bavier99c11d32016-09-14 17:21:20 -040038 rm -rf $CORDDIR
Andy Bavier99c11d32016-09-14 17:21:20 -040039}
40
41function bootstrap() {
42 cd ~
43 sudo apt-get update
44 [ -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 -050045 dpkg -l vagrant || sudo dpkg -i vagrant_1.8.5_x86_64.deb
Sapan Bhatia01ddea62017-02-10 11:28:48 -080046 sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential python-pip
47 sudo pip install pyparsing python-logstash
Andy Bavier99c11d32016-09-14 17:21:20 -040048
49 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
Andy Bavier99c11d32016-09-14 17:21:20 -040050
Andy Bavier99c11d32016-09-14 17:21:20 -040051 sudo adduser $USER libvirtd
52
53 sudo curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo
54 sudo chmod a+x /usr/local/bin/repo
55
56 if [ ! -d "$CORDDIR" ]
57 then
58 mkdir $CORDDIR && cd $CORDDIR
Sapan Bhatia868e0012017-02-15 22:14:11 -080059
60
Andy Bavier99c11d32016-09-14 17:21:20 -040061 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
Sapan Bhatia868e0012017-02-15 22:14:11 -080075 exec > >(tee -i $CORDDIR/install.out)
76 exec 2>&1
77
Andy Bavier99c11d32016-09-14 17:21:20 -040078 cd $CORDDIR/build
Andy Bavierad3ea842016-12-21 16:19:07 -050079 vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
80 vagrant plugin list | grep vagrant-mutate || vagrant plugin install vagrant-mutate
Andy Bavier0f07bb32017-01-17 10:20:26 -050081 add_box ubuntu/trusty64
Andy Bavier99c11d32016-09-14 17:21:20 -040082}
83
84function cloudlab_setup() {
Andy Bavier8b4ed1f2017-02-13 17:06:58 -080085
86 # The watchdog will sometimes reset groups, turn it off
87 if [ -e /usr/local/etc/emulab/watchdog ]
88 then
89 sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop
90 sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled
91 fi
92
Andy Bavier99c11d32016-09-14 17:21:20 -040093 if [ -e /usr/testbed/bin/mkextrafs ]
94 then
Andy Bavier9c0835e2016-11-11 15:56:47 -050095 sudo mkdir -p /mnt/extra
Scott Baker8b9182d2016-10-27 17:53:52 -070096
Andy Bavier8ce395f2016-10-14 12:51:30 -040097 # Sometimes this command fails on the first try
Andy Bavier9c0835e2016-11-11 15:56:47 -050098 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/"
99
100 # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted)
Andy Baviera69ee722016-11-17 07:26:01 -0800101 mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1)
Scott Baker8b9182d2016-10-27 17:53:52 -0700102
103 # we'll replace /var/lib/libvirt/images with a symlink below
104 [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images
105
Andy Bavier9c0835e2016-11-11 15:56:47 -0500106 sudo mkdir -p /mnt/extra/libvirt_images
Andy Bavier2505f592016-11-11 15:58:55 -0500107 if [ ! -e /var/lib/libvirt/images ]
108 then
109 sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images
110 fi
Andy Bavier99c11d32016-09-14 17:21:20 -0400111 fi
112}
113
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800114function elk_up() {
115 cd $CORDDIR/build
116
117 sudo su $USER -c 'vagrant up elastic --provider libvirt'
118
119 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
120 # It allows SSH'ing to the machine via 'ssh corddev'
121 sudo su $USER -c "vagrant ssh-config elastic > $SSHCONFIG"
122
123 cd $CORDDIR
124 if [ ! -f /tmp/elk-patch-applied ]; then
125 touch /tmp/elk-patch-applied
126 sh build/scripts/repo-apply.sh build/elk-logger/elk-ciab.diff
127 fi
128
129 sudo chmod +x build/elk-logger/logstash_tail
130 build/elk-logger/logstash_tail --file install.out --hostport 10.100.198.222:5617 &
131}
132
Andy Bavier2505f592016-11-11 15:58:55 -0500133function vagrant_vms_up() {
Andy Bavier99c11d32016-09-14 17:21:20 -0400134 cd $CORDDIR/build
135
Andy Bavier65c8e152016-12-22 16:01:27 -0500136 sudo su $USER -c 'vagrant up corddev prod --provider libvirt'
Andy Baviera69ee722016-11-17 07:26:01 -0800137
138 # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh'
139 # It allows SSH'ing to the machine via 'ssh corddev'
Andy Bavier2505f592016-11-11 15:58:55 -0500140 sudo su $USER -c "vagrant ssh-config corddev prod > $SSHCONFIG"
141
142 scp ~/.ssh/id_rsa* corddev:.ssh
143 ssh corddev "chmod go-r ~/.ssh/id_rsa"
Andy Bavier99c11d32016-09-14 17:21:20 -0400144}
145
146function install_head_node() {
147 cd $CORDDIR/build
148
Andy Baviera69ee722016-11-17 07:26:01 -0800149 # SSH config saved earlier allows us to connect to VM without running 'vagrant'
Zack Williams0620c932017-01-25 14:36:31 -0700150 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch"
151 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages"
Andy Bavier2505f592016-11-11 15:58:55 -0500152 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 -0800153 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy"
Andy Bavier99c11d32016-09-14 17:21:20 -0400154}
155
156function set_up_maas_user() {
Andy Bavier2505f592016-11-11 15:58:55 -0500157 # Set up MAAS user on server to restart nodes via libvirt
158 grep maas /etc/passwd || sudo useradd -m maas
Andy Bavier99c11d32016-09-14 17:21:20 -0400159 sudo adduser maas libvirtd
160
Andy Bavier2505f592016-11-11 15:58:55 -0500161 # Copy generated public key to maas user's authorized_keys
162 sudo su maas -c "mkdir -p ~/.ssh"
163 sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys
164 sudo chown maas:maas ~maas/.ssh/authorized_keys
Andy Bavier99c11d32016-09-14 17:21:20 -0400165
Andy Bavier2505f592016-11-11 15:58:55 -0500166 # Copy generated private key to maas user's home dir in prod VM
167 scp $HOME/.ssh/id_rsa prod:/tmp
168 ssh prod "sudo mkdir -p ~maas/.ssh"
169 ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa"
170 ssh prod "sudo chown -R maas:maas ~maas/.ssh"
171}
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600172
Andy Bavier0f07bb32017-01-17 10:20:26 -0500173function turn_off_learning () {
174 NET=$1
175 BRIDGE=`sudo virsh net-info $NET|grep "Bridge:"|awk '{print $2}'`
176 sudo brctl setageing $BRIDGE 0
177 sudo brctl stp $BRIDGE off
178}
179
180function leaf_spine_up() {
181 cd $CORDDIR/build
182
183 if [[ $FABRIC -ne 0 ]]
184 then
185 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 spine-2 --provider libvirt"
186 else
187 # Linux bridging seems to be having issues with two spine switches
188 sudo su $USER -c "FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 --provider libvirt"
189 fi
190
191 # Turn off MAC learning on "links" -- i.e., bridges created by libvirt.
192 # Without this, sometimes packets are dropped because the bridges
193 # think they are not local -- this needs further investigation.
194 # A better solution might be to replace the bridges with UDP tunnels, but this
195 # is not supported with the version of libvirt available on Ubuntu 14.04.
196 turn_off_learning head-node-leaf-1
197 turn_off_learning compute-node-1-leaf-1
198 turn_off_learning compute-node-2-leaf-2
199 turn_off_learning compute-node-3-leaf-2
200 turn_off_learning leaf-1-spine-1
201 turn_off_learning leaf-1-spine-2
202 turn_off_learning leaf-2-spine-1
203 turn_off_learning leaf-2-spine-2
204}
205
Andy Bavier99c11d32016-09-14 17:21:20 -0400206function add_compute_node() {
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600207 echo add_compute_node: $1 $2
Andy Bavier2505f592016-11-11 15:58:55 -0500208
Andy Bavier99c11d32016-09-14 17:21:20 -0400209 cd $CORDDIR/build
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600210 sudo su $USER -c "vagrant up $1 --provider libvirt"
Andy Bavier99c11d32016-09-14 17:21:20 -0400211
Andy Bavier2505f592016-11-11 15:58:55 -0500212 # Set up power cycling for the compute node and wait for it to be provisioned
213 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 -0400214
215 echo ""
Andy Bavier0f07bb32017-01-17 10:20:26 -0500216 echo "$1 is fully provisioned!"
217}
218
219function initialize_fabric() {
220 echo "Initializing fabric"
221 ssh prod "cd /cord/build/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-refresh-fabric.yml"
222
223 echo "Fabric ping test"
224 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 -0400225}
226
227function run_e2e_test () {
228 cd $CORDDIR/build
229
Andy Bavier2505f592016-11-11 15:58:55 -0500230 # User has been added to the lbvirtd group, but su $USER to be safe
Andy Baviera69ee722016-11-17 07:26:01 -0800231 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests"
Andy Bavier99c11d32016-09-14 17:21:20 -0400232}
233
234function run_diagnostics() {
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700235 ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG PIrunDiag"
Andy Bavier99c11d32016-09-14 17:21:20 -0400236}
237
238# Parse options
Zack Williamsdae7ff62016-11-14 15:20:06 -0700239GERRIT_BRANCHES=
Andy Bavier99c11d32016-09-14 17:21:20 -0400240RUN_TEST=0
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400241SETUP_ONLY=0
Andy Bavier99c11d32016-09-14 17:21:20 -0400242DIAGNOSTICS=0
243CLEANUP=0
Andy Bavier0f07bb32017-01-17 10:20:26 -0500244FABRIC=0
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600245#By default, cord-in-a-box creates 1 compute node. If more than one compute is
246#needed, use -n option
247NUM_COMPUTE_NODES=1
Andy Bavier99c11d32016-09-14 17:21:20 -0400248
Andy Bavier0f07bb32017-01-17 10:20:26 -0500249while getopts "b:cdfhn:stv" opt; do
Andy Bavier99c11d32016-09-14 17:21:20 -0400250 case ${opt} in
Zack Williamsdae7ff62016-11-14 15:20:06 -0700251 b ) GERRIT_BRANCHES+=("$OPTARG")
Andy Bavier99c11d32016-09-14 17:21:20 -0400252 ;;
253 c ) CLEANUP=1
254 ;;
255 d ) DIAGNOSTICS=1
256 ;;
Andy Bavier0f07bb32017-01-17 10:20:26 -0500257 f ) FABRIC=1
258 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400259 h ) echo "Usage:"
260 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsdae7ff62016-11-14 15:20:06 -0700261 echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can"
262 echo " be used multiple times."
Andy Bavier99c11d32016-09-14 17:21:20 -0400263 echo " $0 -c cleanup from previous test"
264 echo " $0 -d run diagnostic collector"
Andy Bavier0f07bb32017-01-17 10:20:26 -0500265 echo " $0 -f use ONOS fabric (EXPERIMENTAL)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400266 echo " $0 -h display this help message"
Zack Williamsa9e76ec2017-01-20 16:17:35 -0700267 echo " $0 -n # number of compute nodes to setup. Currently max 2 nodes can be supported"
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400268 echo " $0 -s run initial setup phase only (don't start building CORD)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400269 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Bavierd1165102017-01-13 16:38:57 -0500270 echo " $0 -v print CiaB version and exit"
Andy Bavier99c11d32016-09-14 17:21:20 -0400271 exit 0
272 ;;
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600273 n ) NUM_COMPUTE_NODES=$OPTARG
274 ;;
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400275 s ) SETUP_ONLY=1
276 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400277 t ) RUN_TEST=1
278 ;;
Andy Bavierd1165102017-01-13 16:38:57 -0500279 v ) echo "$VERSION_STRING ($REPO_BRANCH branch)"
280 exit 0
281 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400282 \? ) echo "Invalid option: -$OPTARG"
283 exit 1
284 ;;
285 esac
286done
287
288# What to do
289if [[ $CLEANUP -eq 1 ]]
290then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800291 run_stage cleanup_from_previous_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400292fi
293
Andy Bavierd1165102017-01-13 16:38:57 -0500294echo ""
295echo "Preparing to install $VERSION_STRING ($REPO_BRANCH branch)"
296echo ""
297
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800298run_stage bootstrap
299run_stage cloudlab_setup
300run_stage elk_up
301run_stage vagrant_vms_up
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400302
303if [[ $SETUP_ONLY -ne 0 ]]
304then
305 echo "Finished build environment setup, exiting..."
306 exit 0
307fi
308
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800309run_stage install_head_node
310run_stage set_up_maas_user
311run_stage leaf_spine_up
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600312
Andy Bavier0f07bb32017-01-17 10:20:26 -0500313if [[ $NUM_COMPUTE_NODES -gt 3 ]]
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600314then
Andy Bavier0f07bb32017-01-17 10:20:26 -0500315 echo "currently max only three compute nodes can be supported..."
316 NUM_COMPUTE_NODES=3
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600317fi
318
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800319echo "==> Adding compute nodes: Starting"
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600320for i in `seq 1 $NUM_COMPUTE_NODES`;
321do
322 echo adding the compute node: compute-node-$i
Andy Bavier0f07bb32017-01-17 10:20:26 -0500323 add_compute_node compute-node-$i build_compute-node-$i
Srikanth Vavilapallib1c4da02016-11-17 15:24:28 -0600324done
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800325echo "==> Adding compute nodes: Complete"
Andy Bavier99c11d32016-09-14 17:21:20 -0400326
Zack Williams4fd3dcc2017-02-08 20:46:14 -0700327# run diagnostics both before/after the fabric/e2e tests
328if [[ $DIAGNOSTICS -eq 1 ]]
329then
330 run_diagnostics
331fi
332
333
Andy Bavier0f07bb32017-01-17 10:20:26 -0500334if [[ $FABRIC -ne 0 ]]
335then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800336 run_stage initialize_fabric
Andy Bavier0f07bb32017-01-17 10:20:26 -0500337fi
338
Andy Bavier99c11d32016-09-14 17:21:20 -0400339if [[ $RUN_TEST -eq 1 ]]
340then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800341 run_stage run_e2e_test
Andy Bavier99c11d32016-09-14 17:21:20 -0400342fi
343
344if [[ $DIAGNOSTICS -eq 1 ]]
345then
Sapan Bhatia01ddea62017-02-10 11:28:48 -0800346 run_stage run_diagnostics
Andy Bavier99c11d32016-09-14 17:21:20 -0400347fi
348
349exit 0