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