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." |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 173 | i=0 |
| 174 | until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null |
| 175 | do |
| 176 | sleep 60 |
| 177 | (( i += 1 )) |
| 178 | echo "Waited $i minutes" |
| 179 | done |
| 180 | |
| 181 | # get mgmt IP address |
| 182 | ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' ) |
| 183 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 184 | PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' ) |
| 185 | |
| 186 | echo "" |
| 187 | echo "*** ssh into exampleservice VM, wait for Apache come up" |
| 188 | i=0 |
| 189 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid" |
| 190 | do |
| 191 | sleep 60 |
| 192 | (( i += 1 )) |
| 193 | echo "Waited $i minutes" |
| 194 | done |
| 195 | |
| 196 | |
| 197 | echo "" |
| 198 | echo "*** Install curl in test client" |
| 199 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl" |
| 200 | |
| 201 | echo "" |
| 202 | echo "*** Test connectivity to ExampleService from test client" |
| 203 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP" |
| 204 | } |
| 205 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 206 | # Parse options |
| 207 | RUN_TEST=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 208 | EXAMPLESERVICE=0 |
| 209 | while getopts ":eht" opt; do |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 210 | case ${opt} in |
| 211 | h ) "echo Usage:" |
| 212 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 213 | echo " $0 -e add exampleservice to XOS" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 214 | echo " $0 -h display this help message" |
| 215 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
| 216 | exit 0 |
| 217 | ;; |
| 218 | t ) RUN_TEST=1 |
| 219 | ;; |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 220 | e ) EXAMPLESERVICE=1 |
| 221 | ;; |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 222 | \? ) echo "Invalid option" |
| 223 | exit 1 |
| 224 | ;; |
| 225 | esac |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 226 | done |
| 227 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 228 | # What to do |
Andy Bavier | fec35de | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 229 | if [[ $RUN_TEST -eq 1 ]] |
| 230 | then |
| 231 | cleanup_from_previous_test |
| 232 | fi |
| 233 | |
Andy Bavier | dead178 | 2016-05-05 09:08:45 -0700 | [diff] [blame] | 234 | set -e |
| 235 | |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 236 | bootstrap |
| 237 | setup_openstack |
| 238 | pull_docker_images |
| 239 | wait_for_openstack |
| 240 | simulate_fabric |
| 241 | |
| 242 | if [[ $RUN_TEST -eq 1 ]] |
| 243 | then |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 244 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 245 | then |
| 246 | build_xos_with_exampleservice |
| 247 | fi |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 248 | setup_xos |
| 249 | setup_test_client |
| 250 | run_e2e_test |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 251 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 252 | then |
| 253 | run_exampleservice_test |
| 254 | fi |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 255 | fi |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 256 | |
| 257 | exit 0 |