Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 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 |
| 7 | sudo uvt-kvm destroy $VM |
| 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 |
| 55 | sleep 60 |
| 56 | (( i += 1 )) |
| 57 | echo "Waited $i minutes" |
| 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" |
| 67 | } |
| 68 | |
| 69 | function setup_xos() { |
| 70 | echo "" |
| 71 | echo "Setting up XOS, will take a few minutes" |
| 72 | ssh ubuntu@xos.cordtest.opencloud.us "cd xos/xos/configurations/cord-pod; make" |
| 73 | echo "" |
| 74 | echo "Pause 2 minutes" |
| 75 | sleep 120 |
| 76 | |
| 77 | ssh ubuntu@xos.cordtest.opencloud.us "cd xos/xos/configurations/cord-pod; make vtn" |
| 78 | echo "" |
| 79 | echo "Pause 30 seconds" |
| 80 | sleep 30 |
| 81 | |
| 82 | ssh ubuntu@xos.cordtest.opencloud.us "cd xos/xos/configurations/cord-pod; make cord" |
| 83 | } |
| 84 | |
| 85 | function setup_test_client() { |
| 86 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo apt-get -y install lxc" |
| 87 | |
| 88 | # Change default bridge |
| 89 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf" |
| 90 | |
| 91 | # Create test client |
| 92 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-create -t ubuntu -n testclient" |
| 93 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-start -n testclient" |
| 94 | |
| 95 | # Configure network interface inside of test client with s-tag and c-tag |
| 96 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222" |
| 97 | 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" |
| 98 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ifconfig eth0.222 up" |
| 99 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up" |
| 100 | } |
| 101 | |
| 102 | function run_e2e_test() { |
| 103 | source ~/admin-openrc.sh |
| 104 | |
| 105 | echo "*** Wait for vSG VM to come up" |
| 106 | i=0 |
| 107 | until nova list --all-tenants|grep ACTIVE > /dev/null |
| 108 | do |
| 109 | sleep 60 |
| 110 | (( i += 1 )) |
| 111 | echo "Waited $i minutes" |
| 112 | done |
| 113 | |
| 114 | # get mgmt IP address |
| 115 | ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' ) |
| 116 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 117 | |
| 118 | echo "" |
| 119 | echo "*** ssh into vsg VM, wait for Docker container to come up" |
| 120 | i=0 |
| 121 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null |
| 122 | do |
| 123 | sleep 60 |
| 124 | (( i += 1 )) |
| 125 | echo "Waited $i minutes" |
| 126 | done |
| 127 | |
| 128 | echo "" |
| 129 | echo "*** Run dhclient in test client" |
| 130 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null |
| 131 | |
| 132 | echo "" |
| 133 | echo "*** Routes in test client" |
| 134 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- route -n" |
| 135 | |
| 136 | |
| 137 | echo "" |
| 138 | echo "*** Test external connectivity in test client" |
| 139 | ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8" |
| 140 | |
| 141 | echo "" |
| 142 | if [ $? -eq 0 ] |
| 143 | then |
| 144 | echo "*** [PASSED] End-to-end connectivity test" |
| 145 | exit 0 |
| 146 | else |
| 147 | echo "*** [FAILED] End-to-end connectivity test" |
| 148 | exit 1 |
| 149 | fi |
| 150 | } |
| 151 | |
| 152 | # Parse options |
| 153 | RUN_TEST=0 |
| 154 | while getopts ":ht" opt; do |
| 155 | case ${opt} in |
| 156 | h ) "echo Usage:" |
| 157 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
| 158 | echo " $0 -h display this help message" |
| 159 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
| 160 | exit 0 |
| 161 | ;; |
| 162 | t ) RUN_TEST=1 |
| 163 | ;; |
| 164 | \? ) echo "Invalid option" |
| 165 | exit 1 |
| 166 | ;; |
| 167 | esac |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 168 | done |
| 169 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 170 | # What to do |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 171 | if [[ $RUN_TEST -eq 1 ]] |
| 172 | then |
| 173 | cleanup_from_previous_test |
| 174 | fi |
| 175 | |
Andy Bavier | f000173 | 2016-05-05 09:21:49 -0700 | [diff] [blame] | 176 | set -e |
| 177 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 178 | bootstrap |
| 179 | setup_openstack |
| 180 | pull_docker_images |
| 181 | wait_for_openstack |
| 182 | simulate_fabric |
| 183 | |
| 184 | if [[ $RUN_TEST -eq 1 ]] |
| 185 | then |
| 186 | setup_xos |
| 187 | setup_test_client |
| 188 | run_e2e_test |
| 189 | fi |