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