Andy Bavier | c4a4051 | 2017-08-10 07:06:25 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
Matteo Scandolo | 60b640f | 2017-08-08 13:05:22 -0700 | [diff] [blame] | 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 17 | # cord-in-a-box.sh |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 18 | |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 19 | set -e -x |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 20 | |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 21 | # start time, used to name logfiles |
| 22 | START_T=$(date -u "+%Y%m%d_%H%M%SZ") |
| 23 | |
| 24 | # Paths |
Zack Williams | 0620c93 | 2017-01-25 14:36:31 -0700 | [diff] [blame] | 25 | CORDDIR=~/cord |
Andy Bavier | f55e7f9 | 2017-06-22 10:16:44 -0400 | [diff] [blame] | 26 | VMDIR=/opt/cord/build/ |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 27 | CONFIG=config/cord_in_a_box.yml |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 28 | SSHCONFIG=~/.ssh/config |
Zack Williams | 1bffc16 | 2017-04-12 16:31:15 -0700 | [diff] [blame] | 29 | VAGRANT_CWD=${CORDDIR}/build/ |
Zack Williams | 03a20ec | 2017-04-12 17:39:36 -0700 | [diff] [blame] | 30 | VAGRANT_VM_PREFIX=build |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 31 | |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 32 | # CORD versioning |
Sapan Bhatia | 7d17b9e | 2017-09-05 15:34:26 -0400 | [diff] [blame] | 33 | REPO_BRANCH="cord-4.0" |
| 34 | VERSION_STRING="CiaB 4.0" |
Andy Bavier | d116510 | 2017-01-13 16:38:57 -0500 | [diff] [blame] | 35 | |
Sapan Bhatia | a94c2db | 2017-02-27 20:18:24 +0100 | [diff] [blame] | 36 | function finish { |
Sapan Bhatia | 9569209 | 2017-03-01 06:48:19 +0100 | [diff] [blame] | 37 | EXIT=$? |
Sapan Bhatia | eb7819c | 2017-03-01 15:26:17 +0100 | [diff] [blame] | 38 | python $CORDDIR/build/elk-logger/mixpanel --event FINISH --corddir $CORDDIR --finish --status $EXIT |
Sapan Bhatia | a94c2db | 2017-02-27 20:18:24 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 41 | function add_box() { |
| 42 | vagrant box list | grep $1 | grep virtualbox || vagrant box add $1 |
| 43 | vagrant box list | grep $1 | grep libvirt || vagrant mutate $1 libvirt --input-provider virtualbox |
| 44 | } |
| 45 | |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 46 | function run_stage { |
Sapan Bhatia | a94c2db | 2017-02-27 20:18:24 +0100 | [diff] [blame] | 47 | cd $CORDDIR |
Sapan Bhatia | eb7819c | 2017-03-01 15:26:17 +0100 | [diff] [blame] | 48 | python build/elk-logger/mixpanel --event $1-start --corddir $CORDDIR |
Sapan Bhatia | a94c2db | 2017-02-27 20:18:24 +0100 | [diff] [blame] | 49 | |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 50 | echo "==> "$1": Starting" |
| 51 | $1 |
| 52 | echo "==> "$1": Complete" |
Sapan Bhatia | a94c2db | 2017-02-27 20:18:24 +0100 | [diff] [blame] | 53 | |
| 54 | cd $CORDDIR |
Sapan Bhatia | eb7819c | 2017-03-01 15:26:17 +0100 | [diff] [blame] | 55 | python build/elk-logger/mixpanel --event $1-end --corddir $CORDDIR |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 58 | function cleanup_from_previous_test() { |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 59 | echo "## Cleanup ##" |
| 60 | |
Andy Bavier | a4883ba | 2016-12-21 15:46:58 -0500 | [diff] [blame] | 61 | if [ -d $CORDDIR/build ] |
| 62 | then |
| 63 | echo "Destroying all Vagrant VMs" |
| 64 | cd $CORDDIR/build |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 65 | for i in `seq 12`; do |
Zack Williams | 9e7249a | 2017-03-28 13:07:41 -0700 | [diff] [blame] | 66 | sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant destroy" && break |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 67 | done |
Andy Bavier | a4883ba | 2016-12-21 15:46:58 -0500 | [diff] [blame] | 68 | fi |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 69 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 70 | echo "Removing $CORDDIR" |
| 71 | cd ~ |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 72 | rm -rf $CORDDIR |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | function bootstrap() { |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 76 | |
Sapan Bhatia | 9569209 | 2017-03-01 06:48:19 +0100 | [diff] [blame] | 77 | echo "Generating build id" |
Sapan Bhatia | 77f2667 | 2017-03-13 18:30:25 +0100 | [diff] [blame] | 78 | rm -f /tmp/cord-build-version |
Sapan Bhatia | 9569209 | 2017-03-01 06:48:19 +0100 | [diff] [blame] | 79 | dd bs=18 count=1 if=/dev/urandom | base64 | tr +/ _. > /tmp/cord-build |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 80 | |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 81 | if [ ! -x "/usr/local/bin/repo" ] |
| 82 | then |
| 83 | echo "Installing repo..." |
Luca Prete | 5a97ca5 | 2017-11-30 14:31:21 -0800 | [diff] [blame^] | 84 | REPO_SHA256SUM="394d93ac7261d59db58afa49bb5f88386fea8518792491ee3db8baab49c3ecda" |
| 85 | curl -o /tmp/repo 'https://gerrit.opencord.org/gitweb?p=repo.git;a=blob_plain;f=repo;hb=refs/heads/stable' |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 86 | echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c - |
| 87 | sudo mv /tmp/repo /usr/local/bin/repo |
| 88 | sudo chmod a+x /usr/local/bin/repo |
| 89 | fi |
| 90 | |
| 91 | if [ ! -x "/usr/bin/vagrant" ] |
| 92 | then |
| 93 | echo "Installing vagrant and associated tools..." |
| 94 | VAGRANT_SHA256SUM="faff6befacc7eed3978b4b71f0dbb9c135c01d8a4d13236bda2f9ed53482d2c4" # version 1.9.3 |
| 95 | curl -o /tmp/vagrant.deb https://releases.hashicorp.com/vagrant/1.9.3/vagrant_1.9.3_x86_64.deb |
| 96 | echo "$VAGRANT_SHA256SUM /tmp/vagrant.deb" | sha256sum -c - |
| 97 | sudo apt-get update |
| 98 | sudo dpkg -i /tmp/vagrant.deb |
Andy Bavier | 1e6cf6e | 2017-09-07 08:25:20 -0700 | [diff] [blame] | 99 | sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential python-pip |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 100 | sudo adduser $USER libvirtd |
| 101 | sudo pip install pyparsing python-logstash mixpanel |
| 102 | fi |
| 103 | |
| 104 | echo "Installing vagrant plugins..." |
Andy Bavier | 1e6cf6e | 2017-09-07 08:25:20 -0700 | [diff] [blame] | 105 | vagrant plugin list | grep vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version 0.0.35 |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 106 | vagrant plugin list | grep vagrant-mutate || vagrant plugin install vagrant-mutate |
| 107 | |
| 108 | add_box ubuntu/trusty64 |
| 109 | |
| 110 | echo "Creating SSH key..." |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 111 | [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 112 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 113 | if [ ! -d "$CORDDIR" ] |
| 114 | then |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 115 | echo "Downloading CORD/XOS..." |
| 116 | |
| 117 | if [ ! -e "~/.gitconfig" ] |
| 118 | then |
| 119 | echo "No ~/.gitconfig, setting testing defaults" |
| 120 | git config --global user.name 'Test User' |
| 121 | git config --global user.email 'test@null.com' |
| 122 | git config --global color.ui false |
| 123 | fi |
| 124 | |
| 125 | # make sure we can find gerrit.opencord.org as DNS failures will fail the build |
| 126 | dig +short gerrit.opencord.org || (echo "ERROR: gerrit.opencord.org can't be looked up in DNS" && exit 1) |
| 127 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 128 | mkdir $CORDDIR && cd $CORDDIR |
Matteo Scandolo | 4d7d166 | 2017-05-30 11:20:57 -0700 | [diff] [blame] | 129 | repo init -u https://gerrit.opencord.org/manifest -b $REPO_BRANCH |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 130 | repo sync |
| 131 | |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 132 | # check out gerrit branches using repo |
| 133 | for gerrit_branch in ${GERRIT_BRANCHES[@]}; do |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 134 | echo "Checking out opencord gerrit branch: $gerrit_branch" |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 135 | repo download ${gerrit_branch/:/ } |
| 136 | done |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 137 | fi |
| 138 | |
Sapan Bhatia | 868e001 | 2017-02-15 22:14:11 -0800 | [diff] [blame] | 139 | exec > >(tee -i $CORDDIR/install.out) |
| 140 | exec 2>&1 |
| 141 | |
Sapan Bhatia | 9569209 | 2017-03-01 06:48:19 +0100 | [diff] [blame] | 142 | # Start tracking failures from this point |
| 143 | trap finish EXIT |
| 144 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | function cloudlab_setup() { |
Andy Bavier | 8b4ed1f | 2017-02-13 17:06:58 -0800 | [diff] [blame] | 148 | |
Andy Bavier | 46dfda6 | 2017-03-02 05:40:08 -0500 | [diff] [blame] | 149 | # Don't do anything if not a CloudLab node |
| 150 | [ ! -d /usr/local/etc/emulab ] && return |
| 151 | |
Andy Bavier | 8b4ed1f | 2017-02-13 17:06:58 -0800 | [diff] [blame] | 152 | # The watchdog will sometimes reset groups, turn it off |
| 153 | if [ -e /usr/local/etc/emulab/watchdog ] |
| 154 | then |
| 155 | sudo /usr/bin/perl -w /usr/local/etc/emulab/watchdog stop |
| 156 | sudo mv /usr/local/etc/emulab/watchdog /usr/local/etc/emulab/watchdog-disabled |
| 157 | fi |
| 158 | |
Zack Williams | f4e6522 | 2017-03-01 14:22:37 -0700 | [diff] [blame] | 159 | # Mount extra space, if haven't already |
| 160 | if [ ! -d /mnt/extra ] |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 161 | then |
Zack Williams | f4e6522 | 2017-03-01 14:22:37 -0700 | [diff] [blame] | 162 | # for NVME SSD on Utah Cloudlab, not supported by mkextrafs |
| 163 | if $(df | grep -q nvme0n1p1) && [ -e /usr/testbed/bin/mkextrafs ] |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 164 | then |
Zack Williams | f4e6522 | 2017-03-01 14:22:37 -0700 | [diff] [blame] | 165 | sudo mkdir -p /mnt/extra |
| 166 | |
| 167 | # set partition type of 4th partition to Linux, ignore errors |
| 168 | echo -e "t\n4\n82\np\nw\nq" | sudo fdisk /dev/nvme0n1 || true |
| 169 | |
| 170 | sudo mkfs.ext4 /dev/nvme0n1p4 |
| 171 | echo "/dev/nvme0n1p4 /mnt/extra/ ext4 defaults 0 0" | sudo tee -a /etc/fstab |
| 172 | sudo mount /mnt/extra |
| 173 | mount | grep nvme0n1p4 || (echo "ERROR: NVME mkfs/mount failed, exiting!" && exit 1) |
| 174 | |
| 175 | elif [ -e /usr/testbed/bin/mkextrafs ] # if on Clemson/Wisconsin Cloudlab |
| 176 | then |
| 177 | sudo mkdir -p /mnt/extra |
| 178 | |
| 179 | # Sometimes this command fails on the first try |
| 180 | sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" |
| 181 | |
| 182 | # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted) |
| 183 | mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1) |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 184 | fi |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 185 | fi |
Zack Williams | f4e6522 | 2017-03-01 14:22:37 -0700 | [diff] [blame] | 186 | |
| 187 | # replace /var/lib/libvirt/images with a symlink |
| 188 | [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images |
| 189 | sudo mkdir -p /mnt/extra/libvirt_images |
| 190 | |
| 191 | if [ ! -e /var/lib/libvirt/images ] |
| 192 | then |
| 193 | sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images |
| 194 | fi |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 197 | function elk_up() { |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 198 | |
| 199 | cd $CORDDIR |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 200 | sudo chmod +x build/elk-logger/logstash_tail |
Zack Williams | 49af5e6 | 2017-03-24 18:02:56 -0700 | [diff] [blame] | 201 | |
| 202 | build/elk-logger/logstash_tail --file install.out --hostport 10.100.198.201:5617 & |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 205 | function vagrant_vms_up() { |
Zack Williams | a1f5508 | 2017-02-28 22:41:36 -0700 | [diff] [blame] | 206 | |
| 207 | echo "Bringing up CORD-in-a-Box Vagrant VM's..." |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 208 | cd $CORDDIR/build |
| 209 | |
Zack Williams | 9e7249a | 2017-03-28 13:07:41 -0700 | [diff] [blame] | 210 | sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant up corddev prod --provider libvirt" |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 211 | |
| 212 | # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh' |
| 213 | # It allows SSH'ing to the machine via 'ssh corddev' |
Zack Williams | 9e7249a | 2017-03-28 13:07:41 -0700 | [diff] [blame] | 214 | sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant ssh-config corddev prod > $SSHCONFIG" |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 215 | |
Andy Bavier | a2acd2a | 2017-06-19 09:57:32 -0400 | [diff] [blame] | 216 | # copy host SSH keypair to corddev |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 217 | scp ~/.ssh/id_rsa* corddev:.ssh |
| 218 | ssh corddev "chmod go-r ~/.ssh/id_rsa" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | function install_head_node() { |
| 222 | cd $CORDDIR/build |
| 223 | |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 224 | # SSH config saved earlier allows us to connect to VM without running 'vagrant' |
Andy Bavier | f55e7f9 | 2017-06-22 10:16:44 -0400 | [diff] [blame] | 225 | ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch" |
| 226 | ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages" |
| 227 | ssh corddev "cd $VMDIR; ping -c 3 prod; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish" |
| 228 | ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | function set_up_maas_user() { |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 232 | # Set up MAAS user on server to restart nodes via libvirt |
| 233 | grep maas /etc/passwd || sudo useradd -m maas |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 234 | sudo adduser maas libvirtd |
| 235 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 236 | # Copy generated public key to maas user's authorized_keys |
| 237 | sudo su maas -c "mkdir -p ~/.ssh" |
| 238 | sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys |
| 239 | sudo chown maas:maas ~maas/.ssh/authorized_keys |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 240 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 241 | # Copy generated private key to maas user's home dir in prod VM |
| 242 | scp $HOME/.ssh/id_rsa prod:/tmp |
| 243 | ssh prod "sudo mkdir -p ~maas/.ssh" |
| 244 | ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa" |
| 245 | ssh prod "sudo chown -R maas:maas ~maas/.ssh" |
| 246 | } |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 247 | |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 248 | function turn_off_learning () { |
| 249 | NET=$1 |
| 250 | BRIDGE=`sudo virsh net-info $NET|grep "Bridge:"|awk '{print $2}'` |
| 251 | sudo brctl setageing $BRIDGE 0 |
| 252 | sudo brctl stp $BRIDGE off |
| 253 | } |
| 254 | |
| 255 | function leaf_spine_up() { |
| 256 | cd $CORDDIR/build |
| 257 | |
| 258 | if [[ $FABRIC -ne 0 ]] |
| 259 | then |
Zack Williams | 9e7249a | 2017-03-28 13:07:41 -0700 | [diff] [blame] | 260 | sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 spine-2 --provider libvirt" |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 261 | else |
| 262 | # Linux bridging seems to be having issues with two spine switches |
Zack Williams | 9e7249a | 2017-03-28 13:07:41 -0700 | [diff] [blame] | 263 | sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD FABRIC=$FABRIC vagrant up leaf-1 leaf-2 spine-1 --provider libvirt" |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 264 | fi |
| 265 | |
| 266 | # Turn off MAC learning on "links" -- i.e., bridges created by libvirt. |
| 267 | # Without this, sometimes packets are dropped because the bridges |
| 268 | # think they are not local -- this needs further investigation. |
| 269 | # A better solution might be to replace the bridges with UDP tunnels, but this |
| 270 | # is not supported with the version of libvirt available on Ubuntu 14.04. |
| 271 | turn_off_learning head-node-leaf-1 |
| 272 | turn_off_learning compute-node-1-leaf-1 |
| 273 | turn_off_learning compute-node-2-leaf-2 |
| 274 | turn_off_learning compute-node-3-leaf-2 |
| 275 | turn_off_learning leaf-1-spine-1 |
| 276 | turn_off_learning leaf-1-spine-2 |
| 277 | turn_off_learning leaf-2-spine-1 |
| 278 | turn_off_learning leaf-2-spine-2 |
| 279 | } |
| 280 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 281 | function add_compute_node() { |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 282 | echo add_compute_node: $1 $2 |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 283 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 284 | cd $CORDDIR/build |
Zack Williams | 9e7249a | 2017-03-28 13:07:41 -0700 | [diff] [blame] | 285 | sudo su $USER -c "VAGRANT_CWD=$VAGRANT_CWD vagrant up $1 --provider libvirt" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 286 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 287 | # Set up power cycling for the compute node and wait for it to be provisioned |
Andy Bavier | f55e7f9 | 2017-06-22 10:16:44 -0400 | [diff] [blame] | 288 | ssh prod "cd $VMDIR/ansible; ansible-playbook maas-provision.yml --extra-vars \"maas_user=maas vagrant_name=$2\"" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 289 | |
| 290 | echo "" |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 291 | echo "$1 is fully provisioned!" |
| 292 | } |
| 293 | |
| 294 | function initialize_fabric() { |
| 295 | echo "Initializing fabric" |
Andy Bavier | f55e7f9 | 2017-06-22 10:16:44 -0400 | [diff] [blame] | 296 | ssh prod "cd $VMDIR/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-refresh-fabric.yml" |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 297 | |
| 298 | echo "Fabric ping test" |
Andy Bavier | f55e7f9 | 2017-06-22 10:16:44 -0400 | [diff] [blame] | 299 | ssh prod "cd $VMDIR/platform-install; ansible-playbook -i /etc/maas/ansible/pod-inventory cord-fabric-pingtest.yml" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | function run_e2e_test () { |
| 303 | cd $CORDDIR/build |
| 304 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 305 | # User has been added to the lbvirtd group, but su $USER to be safe |
Andy Bavier | f55e7f9 | 2017-06-22 10:16:44 -0400 | [diff] [blame] | 306 | ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | function run_diagnostics() { |
Andy Bavier | f55e7f9 | 2017-06-22 10:16:44 -0400 | [diff] [blame] | 310 | ssh corddev "cd $VMDIR; ./gradlew -PdeployConfig=$VMDIR/$CONFIG PIrunDiag" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | # Parse options |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 314 | GERRIT_BRANCHES= |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 315 | RUN_TEST=0 |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 316 | SETUP_ONLY=0 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 317 | DIAGNOSTICS=0 |
| 318 | CLEANUP=0 |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 319 | FABRIC=0 |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 320 | #By default, cord-in-a-box creates 1 compute node. If more than one compute is |
| 321 | #needed, use -n option |
| 322 | NUM_COMPUTE_NODES=1 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 323 | |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 324 | while getopts "b:cdfhn:stv" opt; do |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 325 | case ${opt} in |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 326 | b ) GERRIT_BRANCHES+=("$OPTARG") |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 327 | ;; |
| 328 | c ) CLEANUP=1 |
| 329 | ;; |
| 330 | d ) DIAGNOSTICS=1 |
| 331 | ;; |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 332 | f ) FABRIC=1 |
| 333 | ;; |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 334 | h ) echo "Usage:" |
| 335 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 336 | echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can" |
| 337 | echo " be used multiple times." |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 338 | echo " $0 -c cleanup from previous test" |
| 339 | echo " $0 -d run diagnostic collector" |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 340 | echo " $0 -f use ONOS fabric (EXPERIMENTAL)" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 341 | echo " $0 -h display this help message" |
Zack Williams | a9e76ec | 2017-01-20 16:17:35 -0700 | [diff] [blame] | 342 | echo " $0 -n # number of compute nodes to setup. Currently max 2 nodes can be supported" |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 343 | echo " $0 -s run initial setup phase only (don't start building CORD)" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 344 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
Andy Bavier | d116510 | 2017-01-13 16:38:57 -0500 | [diff] [blame] | 345 | echo " $0 -v print CiaB version and exit" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 346 | exit 0 |
| 347 | ;; |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 348 | n ) NUM_COMPUTE_NODES=$OPTARG |
| 349 | ;; |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 350 | s ) SETUP_ONLY=1 |
| 351 | ;; |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 352 | t ) RUN_TEST=1 |
| 353 | ;; |
Andy Bavier | d116510 | 2017-01-13 16:38:57 -0500 | [diff] [blame] | 354 | v ) echo "$VERSION_STRING ($REPO_BRANCH branch)" |
| 355 | exit 0 |
| 356 | ;; |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 357 | \? ) echo "Invalid option: -$OPTARG" |
| 358 | exit 1 |
| 359 | ;; |
| 360 | esac |
| 361 | done |
| 362 | |
| 363 | # What to do |
| 364 | if [[ $CLEANUP -eq 1 ]] |
| 365 | then |
Sapan Bhatia | 3f454b3 | 2017-03-01 05:24:19 +0100 | [diff] [blame] | 366 | cleanup_from_previous_test |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 367 | fi |
| 368 | |
Andy Bavier | d116510 | 2017-01-13 16:38:57 -0500 | [diff] [blame] | 369 | echo "" |
| 370 | echo "Preparing to install $VERSION_STRING ($REPO_BRANCH branch)" |
| 371 | echo "" |
| 372 | |
Sapan Bhatia | a94c2db | 2017-02-27 20:18:24 +0100 | [diff] [blame] | 373 | bootstrap |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 374 | run_stage cloudlab_setup |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 375 | run_stage vagrant_vms_up |
Zack Williams | 49af5e6 | 2017-03-24 18:02:56 -0700 | [diff] [blame] | 376 | run_stage elk_up |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 377 | |
| 378 | if [[ $SETUP_ONLY -ne 0 ]] |
| 379 | then |
| 380 | echo "Finished build environment setup, exiting..." |
| 381 | exit 0 |
| 382 | fi |
| 383 | |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 384 | run_stage install_head_node |
| 385 | run_stage set_up_maas_user |
| 386 | run_stage leaf_spine_up |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 387 | |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 388 | if [[ $NUM_COMPUTE_NODES -gt 3 ]] |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 389 | then |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 390 | echo "currently max only three compute nodes can be supported..." |
| 391 | NUM_COMPUTE_NODES=3 |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 392 | fi |
| 393 | |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 394 | echo "==> Adding compute nodes: Starting" |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 395 | for i in `seq 1 $NUM_COMPUTE_NODES`; |
| 396 | do |
| 397 | echo adding the compute node: compute-node-$i |
Zack Williams | 03a20ec | 2017-04-12 17:39:36 -0700 | [diff] [blame] | 398 | add_compute_node compute-node-$i ${VAGRANT_VM_PREFIX}_compute-node-$i |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 399 | done |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 400 | echo "==> Adding compute nodes: Complete" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 401 | |
Zack Williams | 4fd3dcc | 2017-02-08 20:46:14 -0700 | [diff] [blame] | 402 | # run diagnostics both before/after the fabric/e2e tests |
| 403 | if [[ $DIAGNOSTICS -eq 1 ]] |
| 404 | then |
| 405 | run_diagnostics |
| 406 | fi |
| 407 | |
| 408 | |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 409 | if [[ $FABRIC -ne 0 ]] |
| 410 | then |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 411 | run_stage initialize_fabric |
Andy Bavier | 0f07bb3 | 2017-01-17 10:20:26 -0500 | [diff] [blame] | 412 | fi |
| 413 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 414 | if [[ $RUN_TEST -eq 1 ]] |
| 415 | then |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 416 | run_stage run_e2e_test |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 417 | fi |
| 418 | |
| 419 | if [[ $DIAGNOSTICS -eq 1 ]] |
| 420 | then |
Sapan Bhatia | 01ddea6 | 2017-02-10 11:28:48 -0800 | [diff] [blame] | 421 | run_stage run_diagnostics |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 422 | fi |
| 423 | |
| 424 | exit 0 |