Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -e |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 4 | |
| 5 | CORDDIR=~/opencord |
| 6 | VMDIR=/cord/build/ |
| 7 | CONFIG=config/cord_in_a_box.yml |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 8 | SSHCONFIG=~/.ssh/config |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 9 | |
| 10 | function cleanup_from_previous_test() { |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 11 | echo "## Cleanup ##" |
| 12 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 13 | echo "Destroying all Vagrant VMs" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 14 | cd $CORDDIR/build |
Andy Bavier | b22860a | 2016-12-06 12:05:02 -0500 | [diff] [blame] | 15 | sudo su $USER -c 'vagrant destroy' |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 16 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 17 | echo "Removing $CORDDIR" |
| 18 | cd ~ |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 19 | rm -rf $CORDDIR |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | function bootstrap() { |
| 23 | cd ~ |
| 24 | sudo apt-get update |
| 25 | [ -e vagrant_1.8.5_x86_64.deb ] || wget https://releases.hashicorp.com/vagrant/1.8.5/vagrant_1.8.5_x86_64.deb |
| 26 | sudo dpkg -i vagrant_1.8.5_x86_64.deb |
Andy Bavier | 1a35ae6 | 2016-11-15 19:58:13 -0800 | [diff] [blame] | 27 | sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 28 | |
| 29 | [ -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] | 30 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 31 | sudo adduser $USER libvirtd |
| 32 | |
| 33 | sudo curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo |
| 34 | sudo chmod a+x /usr/local/bin/repo |
| 35 | |
| 36 | if [ ! -d "$CORDDIR" ] |
| 37 | then |
| 38 | mkdir $CORDDIR && cd $CORDDIR |
| 39 | git config --global user.name 'Test User' |
| 40 | git config --global user.email 'test@null.com' |
| 41 | git config --global color.ui false |
| 42 | |
Scott Baker | 101b37c | 2016-10-24 16:22:43 -0700 | [diff] [blame] | 43 | repo init -u https://gerrit.opencord.org/manifest -b master -g build,onos,orchestration |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 44 | repo sync |
| 45 | |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 46 | # check out gerrit branches using repo |
| 47 | for gerrit_branch in ${GERRIT_BRANCHES[@]}; do |
| 48 | echo "checking out opencord gerrit branch: $gerrit_branch" |
| 49 | repo download ${gerrit_branch/:/ } |
| 50 | done |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 51 | fi |
| 52 | |
| 53 | cd $CORDDIR/build |
Andy Bavier | 45e30bb | 2016-10-07 15:45:18 -0400 | [diff] [blame] | 54 | vagrant plugin install vagrant-libvirt --plugin-version 0.0.35 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 55 | vagrant plugin install vagrant-mutate |
| 56 | vagrant box list ubuntu/trusty64 | grep virtualbox || vagrant box add ubuntu/trusty64 |
| 57 | vagrant box list ubuntu/trusty64 | grep libvirt || vagrant mutate ubuntu/trusty64 libvirt --input-provider virtualbox |
| 58 | } |
| 59 | |
| 60 | function cloudlab_setup() { |
| 61 | if [ -e /usr/testbed/bin/mkextrafs ] |
| 62 | then |
Andy Bavier | 9c0835e | 2016-11-11 15:56:47 -0500 | [diff] [blame] | 63 | sudo mkdir -p /mnt/extra |
Scott Baker | 8b9182d | 2016-10-27 17:53:52 -0700 | [diff] [blame] | 64 | |
Andy Bavier | 8ce395f | 2016-10-14 12:51:30 -0400 | [diff] [blame] | 65 | # Sometimes this command fails on the first try |
Andy Bavier | 9c0835e | 2016-11-11 15:56:47 -0500 | [diff] [blame] | 66 | sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" |
| 67 | |
| 68 | # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted) |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 69 | mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1) |
Scott Baker | 8b9182d | 2016-10-27 17:53:52 -0700 | [diff] [blame] | 70 | |
| 71 | # we'll replace /var/lib/libvirt/images with a symlink below |
| 72 | [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images |
| 73 | |
Andy Bavier | 9c0835e | 2016-11-11 15:56:47 -0500 | [diff] [blame] | 74 | sudo mkdir -p /mnt/extra/libvirt_images |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 75 | if [ ! -e /var/lib/libvirt/images ] |
| 76 | then |
| 77 | sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images |
| 78 | fi |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 79 | fi |
| 80 | } |
| 81 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 82 | function vagrant_vms_up() { |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 83 | cd $CORDDIR/build |
| 84 | |
| 85 | sudo su $USER -c 'vagrant up corddev --provider libvirt' |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 86 | sudo su $USER -c 'vagrant up prod --provider libvirt' |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 87 | |
| 88 | # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh' |
| 89 | # It allows SSH'ing to the machine via 'ssh corddev' |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 90 | sudo su $USER -c "vagrant ssh-config corddev prod > $SSHCONFIG" |
| 91 | |
| 92 | scp ~/.ssh/id_rsa* corddev:.ssh |
| 93 | ssh corddev "chmod go-r ~/.ssh/id_rsa" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | function install_head_node() { |
| 97 | cd $CORDDIR/build |
| 98 | |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 99 | # SSH config saved earlier allows us to connect to VM without running 'vagrant' |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 100 | ssh corddev "cd /cord/build; ./gradlew fetch" |
| 101 | ssh corddev "cd /cord/build; ./gradlew buildImages" |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 102 | 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] | 103 | ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | function set_up_maas_user() { |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 107 | # Set up MAAS user on server to restart nodes via libvirt |
| 108 | grep maas /etc/passwd || sudo useradd -m maas |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 109 | sudo adduser maas libvirtd |
| 110 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 111 | # Copy generated public key to maas user's authorized_keys |
| 112 | sudo su maas -c "mkdir -p ~/.ssh" |
| 113 | sudo cp $HOME/.ssh/id_rsa.pub ~maas/.ssh/authorized_keys |
| 114 | sudo chown maas:maas ~maas/.ssh/authorized_keys |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 115 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 116 | # Copy generated private key to maas user's home dir in prod VM |
| 117 | scp $HOME/.ssh/id_rsa prod:/tmp |
| 118 | ssh prod "sudo mkdir -p ~maas/.ssh" |
| 119 | ssh prod "sudo cp /tmp/id_rsa ~maas/.ssh/id_rsa" |
| 120 | ssh prod "sudo chown -R maas:maas ~maas/.ssh" |
| 121 | } |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 122 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 123 | function add_compute_node() { |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 124 | echo add_compute_node: $1 $2 |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 125 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 126 | cd $CORDDIR/build |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 127 | sudo su $USER -c "vagrant up $1 --provider libvirt" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 128 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 129 | # Change MAC address of bridge to match cord-pod service profile |
| 130 | # This change won't survive a reboot |
| 131 | BRIDGE=$( route -n | grep 10.6.1.0 | awk '{print $8}' ) |
| 132 | sudo ifconfig $BRIDGE hw ether 02:42:0a:06:01:01 |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 133 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 134 | ip addr list | grep 10.6.1.129 || sudo ip address add 10.6.1.129 dev $BRIDGE |
| 135 | ip addr list | grep 10.6.1.193 || sudo ip address add 10.6.1.193 dev $BRIDGE |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 136 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 137 | # Set up power cycling for the compute node and wait for it to be provisioned |
| 138 | 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] | 139 | |
| 140 | echo "" |
| 141 | echo "compute_node is fully provisioned!" |
| 142 | } |
| 143 | |
| 144 | function run_e2e_test () { |
| 145 | cd $CORDDIR/build |
| 146 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 147 | # 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] | 148 | ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | function run_diagnostics() { |
| 152 | echo "*** COLLECTING DIAGNOSTIC INFO NOT CURRENTLY IMPLEMENTED" |
| 153 | # Need to fix up inventory to collect info from compute nodes |
| 154 | # Using juju-ansible is one possibility |
| 155 | #echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node" |
| 156 | #ansible-playbook -i $INVENTORY cord-diag-playbook.yml |
| 157 | } |
| 158 | |
| 159 | # Parse options |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 160 | GERRIT_BRANCHES= |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 161 | RUN_TEST=0 |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 162 | SETUP_ONLY=0 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 163 | DIAGNOSTICS=0 |
| 164 | CLEANUP=0 |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 165 | #By default, cord-in-a-box creates 1 compute node. If more than one compute is |
| 166 | #needed, use -n option |
| 167 | NUM_COMPUTE_NODES=1 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 168 | |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 169 | while getopts "b:cdhn:st" opt; do |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 170 | case ${opt} in |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 171 | b ) GERRIT_BRANCHES+=("$OPTARG") |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 172 | ;; |
| 173 | c ) CLEANUP=1 |
| 174 | ;; |
| 175 | d ) DIAGNOSTICS=1 |
| 176 | ;; |
| 177 | h ) echo "Usage:" |
| 178 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 179 | echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can" |
| 180 | echo " be used multiple times." |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 181 | echo " $0 -c cleanup from previous test" |
| 182 | echo " $0 -d run diagnostic collector" |
| 183 | echo " $0 -h display this help message" |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 184 | 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] | 185 | 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] | 186 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
| 187 | exit 0 |
| 188 | ;; |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 189 | n ) NUM_COMPUTE_NODES=$OPTARG |
| 190 | ;; |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 191 | s ) SETUP_ONLY=1 |
| 192 | ;; |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 193 | t ) RUN_TEST=1 |
| 194 | ;; |
| 195 | \? ) echo "Invalid option: -$OPTARG" |
| 196 | exit 1 |
| 197 | ;; |
| 198 | esac |
| 199 | done |
| 200 | |
| 201 | # What to do |
| 202 | if [[ $CLEANUP -eq 1 ]] |
| 203 | then |
| 204 | cleanup_from_previous_test |
| 205 | fi |
| 206 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 207 | bootstrap |
| 208 | cloudlab_setup |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 209 | vagrant_vms_up |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 210 | |
| 211 | if [[ $SETUP_ONLY -ne 0 ]] |
| 212 | then |
| 213 | echo "Finished build environment setup, exiting..." |
| 214 | exit 0 |
| 215 | fi |
| 216 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 217 | install_head_node |
| 218 | set_up_maas_user |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 219 | |
Andy Bavier | 2505f59 | 2016-11-11 15:58:55 -0500 | [diff] [blame] | 220 | #Limiting the maximum number of compute nodes that can be supported to 2. If |
Srikanth Vavilapalli | b1c4da0 | 2016-11-17 15:24:28 -0600 | [diff] [blame] | 221 | #more than 2 compute nodes are needed, this script need to be enhanced to set |
| 222 | #the environment variable NUM_COMPUTE_NODES before invoking the Vagrant commands |
| 223 | if [[ $NUM_COMPUTE_NODES -gt 2 ]] |
| 224 | then |
| 225 | echo "currently max only two compute nodes can be supported..." |
| 226 | NUM_COMPUTE_NODES=2 |
| 227 | fi |
| 228 | |
| 229 | for i in `seq 1 $NUM_COMPUTE_NODES`; |
| 230 | do |
| 231 | echo adding the compute node: compute-node-$i |
| 232 | add_compute_node compute_node-$i build_compute_node-$i |
| 233 | done |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 234 | |
| 235 | if [[ $RUN_TEST -eq 1 ]] |
| 236 | then |
| 237 | run_e2e_test |
| 238 | fi |
| 239 | |
| 240 | if [[ $DIAGNOSTICS -eq 1 ]] |
| 241 | then |
| 242 | run_diagnostics |
| 243 | fi |
| 244 | |
| 245 | exit 0 |