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() { |
| 4 | VMS=$( sudo virsh list|grep running|awk '{print $2}' ) |
| 5 | for VM in $VMS |
| 6 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 7 | sudo uvt-kvm destroy $VM |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 8 | done |
| 9 | |
| 10 | rm -rf ~/.juju |
| 11 | rm -f ~/.ssh/known_hosts |
| 12 | rm -rf ~/openstack-cluster-setup |
| 13 | |
| 14 | sudo rm -f /var/lib/libvirt/dnsmasq/default.leases |
| 15 | sudo killall -HUP dnsmasq |
| 16 | } |
| 17 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 18 | function bootstrap() { |
| 19 | cd ~ |
| 20 | sudo apt-get update |
Zack Williams | 65b72c8 | 2016-05-21 21:52:46 -0700 | [diff] [blame] | 21 | sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr |
| 22 | sudo add-apt-repository -y ppa:ansible/ansible |
| 23 | sudo apt-get update |
| 24 | sudo apt-get install -y ansible |
| 25 | |
| 26 | [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa |
| 27 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
| 28 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 29 | git clone https://github.com/open-cloud/openstack-cluster-setup.git |
| 30 | cd ~/openstack-cluster-setup |
| 31 | git checkout roles |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 32 | |
Zack Williams | 65b72c8 | 2016-05-21 21:52:46 -0700 | [diff] [blame] | 33 | sed -i "s/ubuntu/`whoami`/" inventory/cord-cloudlab |
| 34 | cp vars/example_keystone.yml vars/cord_keystone.yml |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 35 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 36 | # Log into the local node once to get host key |
| 37 | ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null" |
| 38 | } |
| 39 | |
| 40 | function setup_openstack() { |
| 41 | # Run the playbook |
| 42 | ansible-playbook -i inventory/cord-cloudlab cord-single-playbook.yml |
| 43 | } |
| 44 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 45 | function build_xos_with_exampleservice() { |
| 46 | echo "" |
| 47 | echo "Adding exampleservice to XOS" |
| 48 | ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'" |
| 49 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | function setup_xos() { |
Zack Williams | d78bbb4 | 2016-05-23 08:53:20 -0700 | [diff] [blame^] | 53 | |
| 54 | echo "Rebuilding XOS containers" |
| 55 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers" |
| 56 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 57 | echo "Setting up XOS, will take a few minutes" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 58 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 59 | echo "" |
| 60 | echo "Pause 2 minutes" |
| 61 | sleep 120 |
| 62 | |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 63 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 64 | echo "" |
| 65 | echo "Pause 30 seconds" |
| 66 | sleep 30 |
| 67 | |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 68 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | function setup_test_client() { |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 72 | ssh ubuntu@nova-compute "sudo apt-get -y install lxc" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 73 | |
| 74 | # Change default bridge |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 75 | 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] | 76 | |
| 77 | # Create test client |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 78 | ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient" |
| 79 | ssh ubuntu@nova-compute "sudo lxc-start -n testclient" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 80 | |
| 81 | # 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] | 82 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222" |
| 83 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111" |
| 84 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up" |
| 85 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 86 | |
| 87 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 88 | then |
| 89 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice" |
| 90 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | function run_e2e_test() { |
| 94 | source ~/admin-openrc.sh |
| 95 | |
| 96 | echo "*** Wait for vSG VM to come up" |
| 97 | i=0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 98 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 99 | until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 100 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 101 | sleep 60 |
| 102 | (( i += 1 )) |
| 103 | echo "Waited $i minutes" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 104 | done |
| 105 | |
| 106 | # get mgmt IP address |
| 107 | ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' ) |
| 108 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 109 | |
| 110 | echo "" |
| 111 | echo "*** ssh into vsg VM, wait for Docker container to come up" |
| 112 | i=0 |
| 113 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null |
| 114 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 115 | sleep 60 |
| 116 | (( i += 1 )) |
| 117 | echo "Waited $i minutes" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 118 | done |
| 119 | |
| 120 | echo "" |
| 121 | echo "*** Run dhclient in test client" |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 122 | |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 123 | 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] | 124 | |
| 125 | echo "" |
| 126 | echo "*** Routes in test client" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 127 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 128 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 129 | echo "" |
| 130 | echo "*** Test external connectivity in test client" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 131 | 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] | 132 | |
| 133 | echo "" |
| 134 | if [ $? -eq 0 ] |
| 135 | then |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 136 | echo "*** [PASSED] End-to-end connectivity test" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 137 | else |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 138 | echo "*** [FAILED] End-to-end connectivity test" |
| 139 | exit 1 |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 140 | fi |
| 141 | } |
| 142 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 143 | function run_exampleservice_test () { |
| 144 | source ~/admin-openrc.sh |
| 145 | |
| 146 | echo "*** Wait for exampleservice VM to come up." |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 147 | i=0 |
| 148 | until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null |
| 149 | do |
| 150 | sleep 60 |
| 151 | (( i += 1 )) |
| 152 | echo "Waited $i minutes" |
| 153 | done |
| 154 | |
| 155 | # get mgmt IP address |
| 156 | ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' ) |
| 157 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 158 | PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' ) |
| 159 | |
| 160 | echo "" |
| 161 | echo "*** ssh into exampleservice VM, wait for Apache come up" |
| 162 | i=0 |
| 163 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid" |
| 164 | do |
| 165 | sleep 60 |
| 166 | (( i += 1 )) |
| 167 | echo "Waited $i minutes" |
| 168 | done |
| 169 | |
| 170 | |
| 171 | echo "" |
| 172 | echo "*** Install curl in test client" |
| 173 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl" |
| 174 | |
| 175 | echo "" |
| 176 | echo "*** Test connectivity to ExampleService from test client" |
| 177 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP" |
| 178 | } |
| 179 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 180 | # Parse options |
| 181 | RUN_TEST=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 182 | EXAMPLESERVICE=0 |
| 183 | while getopts ":eht" opt; do |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 184 | case ${opt} in |
| 185 | h ) "echo Usage:" |
| 186 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 187 | echo " $0 -e add exampleservice to XOS" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 188 | echo " $0 -h display this help message" |
| 189 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
| 190 | exit 0 |
| 191 | ;; |
| 192 | t ) RUN_TEST=1 |
| 193 | ;; |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 194 | e ) EXAMPLESERVICE=1 |
| 195 | ;; |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 196 | \? ) echo "Invalid option" |
| 197 | exit 1 |
| 198 | ;; |
| 199 | esac |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 200 | done |
| 201 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 202 | # What to do |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 203 | if [[ $RUN_TEST -eq 1 ]] |
| 204 | then |
| 205 | cleanup_from_previous_test |
| 206 | fi |
| 207 | |
Andy Bavier | f000173 | 2016-05-05 09:21:49 -0700 | [diff] [blame] | 208 | set -e |
| 209 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 210 | bootstrap |
| 211 | setup_openstack |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 212 | |
| 213 | if [[ $RUN_TEST -eq 1 ]] |
| 214 | then |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 215 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 216 | then |
| 217 | build_xos_with_exampleservice |
| 218 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 219 | setup_xos |
| 220 | setup_test_client |
| 221 | run_e2e_test |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 222 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 223 | then |
| 224 | run_exampleservice_test |
| 225 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 226 | fi |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 227 | |
| 228 | exit 0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 229 | |