Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [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 |
| 19 | rm -rf ~/openstack-cluster-setup |
| 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 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 38 | git clone https://github.com/open-cloud/openstack-cluster-setup.git |
| 39 | cd ~/openstack-cluster-setup |
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 |
Zack Williams | 65b72c8 | 2016-05-21 21:52:46 -0700 | [diff] [blame] | 43 | cp vars/example_keystone.yml vars/cord_keystone.yml |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 44 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 45 | # Log into the local node once to get host key |
| 46 | ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null" |
| 47 | } |
| 48 | |
| 49 | function setup_openstack() { |
Andy Bavier | 3a1d064 | 2016-07-01 14:11:39 -0400 | [diff] [blame] | 50 | cd ~/openstack-cluster-setup |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 51 | |
Zack Williams | 7a5aa72 | 2016-07-01 19:51:40 -0700 | [diff] [blame] | 52 | extra_vars="xos_repo_url=$XOS_REPO_URL xos_repo_branch=$XOS_BRANCH" |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 53 | |
| 54 | # check if running on cloudlab |
Zack Williams | f72e7b6 | 2016-06-02 09:57:23 -0700 | [diff] [blame] | 55 | if [[ -x /usr/testbed/bin/mkextrafs ]] |
| 56 | then |
Zack Williams | 893e9c9 | 2016-06-20 13:40:32 -0700 | [diff] [blame] | 57 | extra_vars="$extra_vars on_cloudlab=True" |
Zack Williams | f72e7b6 | 2016-06-02 09:57:23 -0700 | [diff] [blame] | 58 | fi |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 59 | |
| 60 | ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="$extra_vars" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 63 | function setup_xos() { |
Zack Williams | d78bbb4 | 2016-05-23 08:53:20 -0700 | [diff] [blame] | 64 | |
Andy Bavier | 3a1d064 | 2016-07-01 14:11:39 -0400 | [diff] [blame] | 65 | ssh ubuntu@xos "cd service-profile/cord-pod; make cord-subscriber" |
Zack Williams | 455cec4 | 2016-05-25 16:07:36 -0700 | [diff] [blame] | 66 | |
| 67 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 68 | then |
Scott Baker | 333a315 | 2016-06-29 08:58:42 -0700 | [diff] [blame] | 69 | ssh ubuntu@xos "cd service-profile/cord-pod; make exampleservice" |
Zack Williams | 455cec4 | 2016-05-25 16:07:36 -0700 | [diff] [blame] | 70 | fi |
Andy Bavier | 0d0d0f7 | 2016-06-12 13:47:12 -0400 | [diff] [blame] | 71 | |
| 72 | echo "" |
| 73 | echo "(Temp workaround for bug in Synchronizer) Pause 60 seconds" |
| 74 | sleep 60 |
Scott Baker | 333a315 | 2016-06-29 08:58:42 -0700 | [diff] [blame] | 75 | ssh ubuntu@xos "cd service-profile/cord-pod; make vtn" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | function setup_test_client() { |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 79 | ssh ubuntu@nova-compute "sudo apt-get -y install lxc" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 80 | |
| 81 | # Change default bridge |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 82 | ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 83 | |
| 84 | # Create test client |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 85 | ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient" |
| 86 | ssh ubuntu@nova-compute "sudo lxc-start -n testclient" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 87 | |
| 88 | # Configure network interface inside of test client with s-tag and c-tag |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 89 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222" |
| 90 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111" |
| 91 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up" |
| 92 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | function run_e2e_test() { |
| 96 | source ~/admin-openrc.sh |
| 97 | |
| 98 | echo "*** Wait for vSG VM to come up" |
| 99 | i=0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 100 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 101 | until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 102 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 103 | sleep 60 |
| 104 | (( i += 1 )) |
| 105 | echo "Waited $i minutes" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 106 | done |
| 107 | |
| 108 | # get mgmt IP address |
| 109 | ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' ) |
| 110 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 111 | |
| 112 | echo "" |
| 113 | echo "*** ssh into vsg VM, wait for Docker container to come up" |
| 114 | i=0 |
| 115 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null |
| 116 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 117 | sleep 60 |
| 118 | (( i += 1 )) |
| 119 | echo "Waited $i minutes" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 120 | done |
| 121 | |
| 122 | echo "" |
| 123 | echo "*** Run dhclient in test client" |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 124 | |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 125 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 126 | |
| 127 | echo "" |
| 128 | echo "*** Routes in test client" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 129 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 130 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 131 | echo "" |
| 132 | echo "*** Test external connectivity in test client" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 133 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 134 | |
| 135 | echo "" |
| 136 | if [ $? -eq 0 ] |
| 137 | then |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 138 | echo "*** [PASSED] End-to-end connectivity test" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 139 | else |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 140 | echo "*** [FAILED] End-to-end connectivity test" |
| 141 | exit 1 |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 142 | fi |
| 143 | } |
| 144 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 145 | function run_exampleservice_test () { |
| 146 | source ~/admin-openrc.sh |
| 147 | |
| 148 | echo "*** Wait for exampleservice VM to come up." |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 149 | echo "!!! NOTE that currently the VM will only be created after you login" |
| 150 | echo "!!! to XOS and manually create an ExampleService tenant." |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 151 | i=0 |
| 152 | until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null |
| 153 | do |
| 154 | sleep 60 |
| 155 | (( i += 1 )) |
| 156 | echo "Waited $i minutes" |
| 157 | done |
| 158 | |
| 159 | # get mgmt IP address |
| 160 | ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' ) |
| 161 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 162 | PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' ) |
| 163 | |
| 164 | echo "" |
| 165 | echo "*** ssh into exampleservice VM, wait for Apache come up" |
| 166 | i=0 |
| 167 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid" |
| 168 | do |
| 169 | sleep 60 |
| 170 | (( i += 1 )) |
| 171 | echo "Waited $i minutes" |
| 172 | done |
| 173 | |
| 174 | |
| 175 | echo "" |
| 176 | echo "*** Install curl in test client" |
| 177 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl" |
| 178 | |
| 179 | echo "" |
| 180 | echo "*** Test connectivity to ExampleService from test client" |
| 181 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP" |
| 182 | } |
| 183 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 184 | function run_diagnostics() { |
| 185 | echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node" |
| 186 | ansible-playbook -i $INVENTORY cord-diag-playbook.yml |
| 187 | } |
| 188 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 189 | # Parse options |
| 190 | RUN_TEST=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 191 | EXAMPLESERVICE=0 |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 192 | SETUP_BRANCH="master" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 193 | INVENTORY="inventory/single-localhost" |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 194 | XOS_BRANCH="master" |
| 195 | XOS_REPO_URL="https://gerrit.opencord.org/xos" |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 196 | DIAGNOSTICS=1 |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 197 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 198 | while getopts "b:dehi:r:ts:" opt; do |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 199 | case ${opt} in |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 200 | b ) XOS_BRANCH=$OPTARG |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 201 | ;; |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 202 | d ) DIAGNOSTICS=0 |
| 203 | ;; |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 204 | e ) EXAMPLESERVICE=1 |
| 205 | ;; |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 206 | h ) echo "Usage:" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 207 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 208 | echo " $0 -b <branch> build XOS containers using the <branch> branch of XOS git repo" |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 209 | echo " $0 -d don't run diagnostic collector" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 210 | echo " $0 -e add exampleservice to XOS" |
| 211 | echo " $0 -h display this help message" |
| 212 | echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)" |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 213 | echo " $0 -r <url> use <url> to obtain the the XOS repo" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 214 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 215 | echo " $0 -s <branch> use branch <branch> of the openstack-cluster-setup git repo" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 216 | exit 0 |
| 217 | ;; |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 218 | i ) INVENTORY=$OPTARG |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 219 | ;; |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 220 | r ) XOS_REPO_URL=$OPTARG |
| 221 | ;; |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 222 | t ) RUN_TEST=1 |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 223 | ;; |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 224 | s ) SETUP_BRANCH=$OPTARG |
| 225 | ;; |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 226 | \? ) echo "Invalid option: -$OPTARG" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 227 | exit 1 |
| 228 | ;; |
| 229 | esac |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 230 | done |
| 231 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 232 | # What to do |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 233 | if [[ $RUN_TEST -eq 1 ]] |
| 234 | then |
| 235 | cleanup_from_previous_test |
| 236 | fi |
| 237 | |
Andy Bavier | f000173 | 2016-05-05 09:21:49 -0700 | [diff] [blame] | 238 | set -e |
| 239 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 240 | bootstrap |
| 241 | setup_openstack |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 242 | |
| 243 | if [[ $RUN_TEST -eq 1 ]] |
| 244 | then |
| 245 | setup_xos |
| 246 | setup_test_client |
| 247 | run_e2e_test |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 248 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 249 | then |
| 250 | run_exampleservice_test |
| 251 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 252 | fi |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 253 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 254 | if [[ $DIAGNOSTICS -eq 1 ]] |
Zack Williams | b82afd8 | 2016-06-28 09:59:29 -0700 | [diff] [blame] | 255 | then |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 256 | run_diagnostics |
| 257 | fi |
| 258 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 259 | exit 0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 260 | |