Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 1 | !/usr/bin/env bash |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 2 | |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 3 | function cleanup_from_previous_test() { |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 4 | echo "## Cleanup ##" |
| 5 | |
| 6 | echo "Destroying juju environment" |
| 7 | juju destroy-environment --force -y manual |
| 8 | |
Andy Bavier | de3f467 | 2016-06-01 17:02:42 -0400 | [diff] [blame] | 9 | VMS=$( sudo uvt-kvm list ) |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 10 | for VM in $VMS |
| 11 | do |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 12 | echo "Destroying $VM" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 13 | sudo uvt-kvm destroy $VM |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 14 | done |
| 15 | |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 16 | echo "Cleaning up files" |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 17 | rm -rf ~/.juju |
| 18 | rm -f ~/.ssh/known_hosts |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 19 | rm -rf ~/platform-install |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 20 | |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 21 | echo "Cleaning up libvirt/dnsmasq" |
Zack Williams | 17508be | 2016-05-31 21:52:35 -0700 | [diff] [blame] | 22 | sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases |
| 23 | sudo killall dnsmasq |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 24 | sudo service libvirt-bin restart |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 27 | function bootstrap() { |
| 28 | cd ~ |
| 29 | sudo apt-get update |
Zack Williams | 4e5d1d2 | 2016-06-13 11:10:03 -0700 | [diff] [blame] | 30 | sudo apt-get -y install software-properties-common curl git mosh tmux dnsutils python-netaddr |
Zack Williams | 65b72c8 | 2016-05-21 21:52:46 -0700 | [diff] [blame] | 31 | sudo add-apt-repository -y ppa:ansible/ansible |
| 32 | sudo apt-get update |
| 33 | sudo apt-get install -y ansible |
| 34 | |
| 35 | [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa |
| 36 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
| 37 | |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 38 | git clone $SETUP_REPO_URL platform-install |
| 39 | cd ~/platform-install |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 40 | git checkout $SETUP_BRANCH |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 41 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 42 | sed -i "s/replaceme/`whoami`/" $INVENTORY |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 43 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 44 | # Log into the local node once to get host key |
| 45 | ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null" |
| 46 | } |
| 47 | |
| 48 | function setup_openstack() { |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 49 | cd ~/platform-install |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 50 | |
Scott Baker | 55a0b88 | 2016-07-25 16:05:05 -0700 | [diff] [blame] | 51 | extra_vars="single_node_pod_script=true" |
| 52 | |
| 53 | if [[ "$XOS_REPO_URL" != "" ]]; then |
| 54 | extra_vars="$extra_vars xos_repo_url=$XOS_REPO_URL" |
| 55 | fi |
| 56 | if [[ "$XOS_BRANCH" != "" ]]; then |
| 57 | extra_vars="$extra_vars xos_repo_branch=$XOS_BRANCH" |
| 58 | fi |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 59 | |
| 60 | # check if running on cloudlab |
Zack Williams | f72e7b6 | 2016-06-02 09:57:23 -0700 | [diff] [blame] | 61 | if [[ -x /usr/testbed/bin/mkextrafs ]] |
| 62 | then |
Zack Williams | 893e9c9 | 2016-06-20 13:40:32 -0700 | [diff] [blame] | 63 | extra_vars="$extra_vars on_cloudlab=True" |
Zack Williams | f72e7b6 | 2016-06-02 09:57:23 -0700 | [diff] [blame] | 64 | fi |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 65 | |
| 66 | ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="$extra_vars" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 69 | function setup_xos() { |
Zack Williams | d78bbb4 | 2016-05-23 08:53:20 -0700 | [diff] [blame] | 70 | |
Zack Williams | 455cec4 | 2016-05-25 16:07:36 -0700 | [diff] [blame] | 71 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 72 | then |
Scott Baker | 333a315 | 2016-06-29 08:58:42 -0700 | [diff] [blame] | 73 | ssh ubuntu@xos "cd service-profile/cord-pod; make exampleservice" |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 74 | |
| 75 | echo "(Temp workaround for bug in Synchronizer) Pause 60 seconds" |
| 76 | sleep 60 |
| 77 | ssh ubuntu@xos "cd service-profile/cord-pod; make vtn" |
Zack Williams | 455cec4 | 2016-05-25 16:07:36 -0700 | [diff] [blame] | 78 | fi |
Andy Bavier | 0d0d0f7 | 2016-06-12 13:47:12 -0400 | [diff] [blame] | 79 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 82 | function run_e2e_test () { |
| 83 | ansible-playbook -i $INVENTORY cord-post-deploy-playbook.yml |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 86 | function run_exampleservice_test () { |
| 87 | source ~/admin-openrc.sh |
| 88 | |
| 89 | echo "*** Wait for exampleservice VM to come up." |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 90 | echo "!!! NOTE that currently the VM will only be created after you login" |
| 91 | echo "!!! to XOS and manually create an ExampleService tenant." |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 92 | i=0 |
| 93 | until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null |
| 94 | do |
| 95 | sleep 60 |
| 96 | (( i += 1 )) |
| 97 | echo "Waited $i minutes" |
| 98 | done |
| 99 | |
| 100 | # get mgmt IP address |
| 101 | ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' ) |
| 102 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 103 | PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' ) |
| 104 | |
| 105 | echo "" |
| 106 | echo "*** ssh into exampleservice VM, wait for Apache come up" |
| 107 | i=0 |
| 108 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid" |
| 109 | do |
| 110 | sleep 60 |
| 111 | (( i += 1 )) |
| 112 | echo "Waited $i minutes" |
| 113 | done |
| 114 | |
| 115 | |
| 116 | echo "" |
| 117 | echo "*** Install curl in test client" |
| 118 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl" |
| 119 | |
| 120 | echo "" |
| 121 | echo "*** Test connectivity to ExampleService from test client" |
| 122 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP" |
| 123 | } |
| 124 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 125 | function run_diagnostics() { |
| 126 | echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node" |
| 127 | ansible-playbook -i $INVENTORY cord-diag-playbook.yml |
| 128 | } |
| 129 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 130 | # Parse options |
| 131 | RUN_TEST=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 132 | EXAMPLESERVICE=0 |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 133 | SETUP_BRANCH="master" |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 134 | SETUP_REPO_URL="https://github.com/opencord/platform-install" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 135 | INVENTORY="inventory/single-localhost" |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 136 | DIAGNOSTICS=1 |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 137 | |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 138 | while getopts "b:dehi:p:r:ts:" opt; do |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 139 | case ${opt} in |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 140 | b ) XOS_BRANCH=$OPTARG |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 141 | ;; |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 142 | d ) DIAGNOSTICS=0 |
| 143 | ;; |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 144 | e ) EXAMPLESERVICE=1 |
| 145 | ;; |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 146 | h ) echo "Usage:" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 147 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 148 | echo " $0 -b <branch> checkout <branch> of the xos git repo" |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 149 | echo " $0 -d don't run diagnostic collector" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 150 | echo " $0 -e add exampleservice to XOS" |
| 151 | echo " $0 -h display this help message" |
| 152 | echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)" |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 153 | echo " $0 -p <git_url> use <git_url> to obtain the platform-install git repo" |
| 154 | echo " $0 -r <git_url> use <git_url> to obtain the xos git repo" |
| 155 | echo " $0 -s <branch> checkout <branch> of the platform-install git repo" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 156 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 157 | exit 0 |
| 158 | ;; |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 159 | i ) INVENTORY=$OPTARG |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 160 | ;; |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 161 | p ) SETUP_REPO_URL=$OPTARG |
| 162 | ;; |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 163 | r ) XOS_REPO_URL=$OPTARG |
| 164 | ;; |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 165 | t ) RUN_TEST=1 |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 166 | ;; |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 167 | s ) SETUP_BRANCH=$OPTARG |
| 168 | ;; |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 169 | \? ) echo "Invalid option: -$OPTARG" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 170 | exit 1 |
| 171 | ;; |
| 172 | esac |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 173 | done |
| 174 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 175 | # What to do |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 176 | if [[ $RUN_TEST -eq 1 ]] |
| 177 | then |
| 178 | cleanup_from_previous_test |
| 179 | fi |
| 180 | |
Andy Bavier | f000173 | 2016-05-05 09:21:49 -0700 | [diff] [blame] | 181 | set -e |
| 182 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 183 | bootstrap |
| 184 | setup_openstack |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 185 | |
| 186 | if [[ $RUN_TEST -eq 1 ]] |
| 187 | then |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 188 | run_e2e_test |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 189 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 190 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 191 | then |
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 192 | setup_xos |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 193 | run_exampleservice_test |
| 194 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 195 | fi |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 196 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 197 | if [[ $DIAGNOSTICS -eq 1 ]] |
Zack Williams | b82afd8 | 2016-06-28 09:59:29 -0700 | [diff] [blame] | 198 | then |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 199 | run_diagnostics |
| 200 | fi |
| 201 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 202 | exit 0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 203 | |