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