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