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