Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Andy Bavier | fec35de | 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 | fec35de | 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 | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 18 | function bootstrap() { |
| 19 | cd ~ |
Andy Bavier | b6a74cd | 2016-04-29 19:59:51 -0400 | [diff] [blame] | 20 | sudo apt-get update |
| 21 | sudo apt-get -y install git |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 22 | git clone https://github.com/open-cloud/openstack-cluster-setup.git |
| 23 | cd ~/openstack-cluster-setup |
| 24 | ./bootstrap.sh |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 25 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 26 | # Log into the local node once to get host key |
| 27 | ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null" |
| 28 | } |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 29 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 30 | function setup_openstack() { |
| 31 | # Run the playbook |
| 32 | ansible-playbook -i cord-test-hosts cord-setup.yml |
| 33 | } |
| 34 | |
| 35 | function pull_docker_images() { |
| 36 | # Pull down the Docker images |
| 37 | echo "" |
| 38 | echo "Pull down the Docker images for ONOS and XOS" |
| 39 | echo "This can take 20 minutes or more, be patient!" |
| 40 | ssh ubuntu@onos-cord "cd cord; sudo docker-compose up -d" |
| 41 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; sudo docker-compose pull" |
| 42 | } |
| 43 | |
| 44 | function wait_for_openstack() { |
| 45 | # Need to wait for OpenStack services to come up before running any XOS "make" commands |
| 46 | echo "Waiting for the OpenStack services to fully come up." |
| 47 | echo "This can take 30 minutes or more, be patient!" |
| 48 | i=0 |
| 49 | until juju status --format=summary|grep "started: 23" > /dev/null |
| 50 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 51 | sleep 60 |
| 52 | (( i += 1 )) |
| 53 | echo "Waited $i minutes" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 54 | done |
| 55 | |
| 56 | echo "All OpenStack services are up." |
| 57 | } |
| 58 | |
| 59 | function simulate_fabric() { |
| 60 | echo "" |
| 61 | echo "Setting up simulated fabric on nova-compute node" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 62 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 63 | then |
| 64 | SCRIPT=compute-ext-net-tutorial.sh |
| 65 | else |
| 66 | SCRIPT=compute-ext-net.sh |
| 67 | fi |
| 68 | ssh ubuntu@nova-compute "wget https://raw.githubusercontent.com/open-cloud/openstack-cluster-setup/master/scripts/$SCRIPT; sudo bash $SCRIPT" |
| 69 | } |
| 70 | |
| 71 | function build_xos_with_exampleservice() { |
| 72 | echo "" |
| 73 | echo "Adding exampleservice to XOS" |
| 74 | ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'" |
| 75 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83" |
| 76 | echo "" |
| 77 | echo "Rebuilding XOS containers" |
| 78 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers" |
| 79 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | function setup_xos() { |
| 83 | echo "" |
| 84 | echo "Setting up XOS, will take a few minutes" |
| 85 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make" |
| 86 | echo "" |
| 87 | echo "Pause 2 minutes" |
| 88 | sleep 120 |
| 89 | |
| 90 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn" |
| 91 | echo "" |
| 92 | echo "Pause 30 seconds" |
| 93 | sleep 30 |
| 94 | |
| 95 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 96 | |
| 97 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 98 | then |
| 99 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice" |
| 100 | fi |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | function setup_test_client() { |
| 104 | ssh ubuntu@nova-compute "sudo apt-get -y install lxc" |
| 105 | |
| 106 | # Change default bridge |
| 107 | ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf" |
| 108 | |
| 109 | # Create test client |
| 110 | ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient" |
| 111 | ssh ubuntu@nova-compute "sudo lxc-start -n testclient" |
| 112 | |
| 113 | # Configure network interface inside of test client with s-tag and c-tag |
| 114 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222" |
| 115 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111" |
| 116 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up" |
| 117 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up" |
| 118 | } |
| 119 | |
| 120 | function run_e2e_test() { |
| 121 | source ~/admin-openrc.sh |
| 122 | |
| 123 | echo "*** Wait for vSG VM to come up" |
| 124 | i=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 125 | until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 126 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 127 | sleep 60 |
| 128 | (( i += 1 )) |
| 129 | echo "Waited $i minutes" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 130 | done |
| 131 | |
| 132 | # get mgmt IP address |
| 133 | ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' ) |
| 134 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 135 | |
| 136 | echo "" |
| 137 | echo "*** ssh into vsg VM, wait for Docker container to come up" |
| 138 | i=0 |
| 139 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null |
| 140 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 141 | sleep 60 |
| 142 | (( i += 1 )) |
| 143 | echo "Waited $i minutes" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 144 | done |
| 145 | |
| 146 | echo "" |
| 147 | echo "*** Run dhclient in test client" |
| 148 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null |
| 149 | |
| 150 | echo "" |
| 151 | echo "*** Routes in test client" |
| 152 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n" |
| 153 | |
| 154 | |
| 155 | echo "" |
| 156 | echo "*** Test external connectivity in test client" |
| 157 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8" |
| 158 | |
| 159 | echo "" |
| 160 | if [ $? -eq 0 ] |
| 161 | then |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 162 | echo "*** [PASSED] End-to-end connectivity test" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 163 | else |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 164 | echo "*** [FAILED] End-to-end connectivity test" |
| 165 | exit 1 |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 166 | fi |
| 167 | } |
| 168 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 169 | function run_exampleservice_test () { |
| 170 | source ~/admin-openrc.sh |
| 171 | |
| 172 | echo "*** Wait for exampleservice VM to come up." |
| 173 | echo "!!! NOTE that currently the VM will only be created after you login" |
| 174 | echo "!!! to XOS and manually create an ExampleService tenant." |
| 175 | i=0 |
| 176 | until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null |
| 177 | do |
| 178 | sleep 60 |
| 179 | (( i += 1 )) |
| 180 | echo "Waited $i minutes" |
| 181 | done |
| 182 | |
| 183 | # get mgmt IP address |
| 184 | ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' ) |
| 185 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 186 | PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' ) |
| 187 | |
| 188 | echo "" |
| 189 | echo "*** ssh into exampleservice VM, wait for Apache come up" |
| 190 | i=0 |
| 191 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid" |
| 192 | do |
| 193 | sleep 60 |
| 194 | (( i += 1 )) |
| 195 | echo "Waited $i minutes" |
| 196 | done |
| 197 | |
| 198 | |
| 199 | echo "" |
| 200 | echo "*** Install curl in test client" |
| 201 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl" |
| 202 | |
| 203 | echo "" |
| 204 | echo "*** Test connectivity to ExampleService from test client" |
| 205 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP" |
| 206 | } |
| 207 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 208 | # Parse options |
| 209 | RUN_TEST=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 210 | EXAMPLESERVICE=0 |
| 211 | while getopts ":eht" opt; do |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 212 | case ${opt} in |
| 213 | h ) "echo Usage:" |
| 214 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 215 | echo " $0 -e add exampleservice to XOS" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 216 | echo " $0 -h display this help message" |
| 217 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
| 218 | exit 0 |
| 219 | ;; |
| 220 | t ) RUN_TEST=1 |
| 221 | ;; |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 222 | e ) EXAMPLESERVICE=1 |
| 223 | ;; |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 224 | \? ) echo "Invalid option" |
| 225 | exit 1 |
| 226 | ;; |
| 227 | esac |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 228 | done |
| 229 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 230 | # What to do |
Andy Bavier | fec35de | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 231 | if [[ $RUN_TEST -eq 1 ]] |
| 232 | then |
| 233 | cleanup_from_previous_test |
| 234 | fi |
| 235 | |
Andy Bavier | dead178 | 2016-05-05 09:08:45 -0700 | [diff] [blame] | 236 | set -e |
| 237 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 238 | bootstrap |
| 239 | setup_openstack |
| 240 | pull_docker_images |
| 241 | wait_for_openstack |
| 242 | simulate_fabric |
| 243 | |
| 244 | if [[ $RUN_TEST -eq 1 ]] |
| 245 | then |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 246 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 247 | then |
| 248 | build_xos_with_exampleservice |
| 249 | fi |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 250 | setup_xos |
| 251 | setup_test_client |
| 252 | run_e2e_test |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 253 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 254 | then |
| 255 | run_exampleservice_test |
| 256 | fi |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 257 | fi |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 258 | |
| 259 | exit 0 |