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 |
Zack Williams | 65b72c8 | 2016-05-21 21:52:46 -0700 | [diff] [blame] | 21 | sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr |
| 22 | sudo add-apt-repository -y ppa:ansible/ansible |
| 23 | sudo apt-get update |
| 24 | sudo apt-get install -y ansible |
| 25 | |
| 26 | [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa |
| 27 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
| 28 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 29 | git clone https://github.com/open-cloud/openstack-cluster-setup.git |
| 30 | cd ~/openstack-cluster-setup |
| 31 | git checkout roles |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 32 | |
Zack Williams | 7e19a8a | 2016-05-24 06:42:47 -0700 | [diff] [blame] | 33 | sed -i "s/ubuntu/`whoami`/" $INVENTORY |
Zack Williams | 65b72c8 | 2016-05-21 21:52:46 -0700 | [diff] [blame] | 34 | cp vars/example_keystone.yml vars/cord_keystone.yml |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 35 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 36 | # Log into the local node once to get host key |
| 37 | ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null" |
| 38 | } |
| 39 | |
| 40 | function setup_openstack() { |
| 41 | # Run the playbook |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 42 | ansible-playbook -i $INVENTORY cord-single-playbook.yml |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 45 | function build_xos_docker_images() { |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 46 | echo "" |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 47 | echo "Checking out XOS branch $BUILD_BRANCH" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 48 | ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'" |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 49 | ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH" |
Zack Williams | 97225f8 | 2016-05-24 08:23:37 -0700 | [diff] [blame] | 50 | |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 51 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 52 | then |
| 53 | echo "" |
| 54 | echo "Adding exampleservice to XOS" |
| 55 | ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83" |
| 56 | fi |
Zack Williams | 97225f8 | 2016-05-24 08:23:37 -0700 | [diff] [blame] | 57 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 58 | echo "Rebuilding XOS containers" |
| 59 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | function setup_xos() { |
Zack Williams | d78bbb4 | 2016-05-23 08:53:20 -0700 | [diff] [blame] | 63 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 64 | echo "Setting up XOS, will take a few minutes" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 65 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 66 | echo "" |
| 67 | echo "Pause 2 minutes" |
| 68 | sleep 120 |
| 69 | |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 70 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 71 | echo "" |
| 72 | echo "Pause 30 seconds" |
| 73 | sleep 30 |
| 74 | |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 75 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | function setup_test_client() { |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 79 | ssh ubuntu@nova-compute "sudo apt-get -y install lxc" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 80 | |
| 81 | # Change default bridge |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 82 | ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 83 | |
| 84 | # Create test client |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 85 | ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient" |
| 86 | ssh ubuntu@nova-compute "sudo lxc-start -n testclient" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 87 | |
| 88 | # Configure network interface inside of test client with s-tag and c-tag |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 89 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222" |
| 90 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111" |
| 91 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up" |
| 92 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 93 | |
| 94 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 95 | then |
| 96 | ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice" |
| 97 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | function run_e2e_test() { |
| 101 | source ~/admin-openrc.sh |
| 102 | |
| 103 | echo "*** Wait for vSG VM to come up" |
| 104 | i=0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 105 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 106 | until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 107 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 108 | sleep 60 |
| 109 | (( i += 1 )) |
| 110 | echo "Waited $i minutes" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 111 | done |
| 112 | |
| 113 | # get mgmt IP address |
| 114 | ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' ) |
| 115 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 116 | |
| 117 | echo "" |
| 118 | echo "*** ssh into vsg VM, wait for Docker container to come up" |
| 119 | i=0 |
| 120 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null |
| 121 | do |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 122 | sleep 60 |
| 123 | (( i += 1 )) |
| 124 | echo "Waited $i minutes" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 125 | done |
| 126 | |
| 127 | echo "" |
| 128 | echo "*** Run dhclient in test client" |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 129 | |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 130 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 131 | |
| 132 | echo "" |
| 133 | echo "*** Routes in test client" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 134 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 135 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 136 | echo "" |
| 137 | echo "*** Test external connectivity in test client" |
Zack Williams | 3ecbfd0 | 2016-05-22 15:30:21 -0700 | [diff] [blame] | 138 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 139 | |
| 140 | echo "" |
| 141 | if [ $? -eq 0 ] |
| 142 | then |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 143 | echo "*** [PASSED] End-to-end connectivity test" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 144 | else |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 145 | echo "*** [FAILED] End-to-end connectivity test" |
| 146 | exit 1 |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 147 | fi |
| 148 | } |
| 149 | |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 150 | function run_exampleservice_test () { |
| 151 | source ~/admin-openrc.sh |
| 152 | |
| 153 | echo "*** Wait for exampleservice VM to come up." |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 154 | echo "!!! NOTE that currently the VM will only be created after you login" |
| 155 | echo "!!! to XOS and manually create an ExampleService tenant." |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 156 | i=0 |
| 157 | until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null |
| 158 | do |
| 159 | sleep 60 |
| 160 | (( i += 1 )) |
| 161 | echo "Waited $i minutes" |
| 162 | done |
| 163 | |
| 164 | # get mgmt IP address |
| 165 | ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' ) |
| 166 | MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' ) |
| 167 | PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' ) |
| 168 | |
| 169 | echo "" |
| 170 | echo "*** ssh into exampleservice VM, wait for Apache come up" |
| 171 | i=0 |
| 172 | until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid" |
| 173 | do |
| 174 | sleep 60 |
| 175 | (( i += 1 )) |
| 176 | echo "Waited $i minutes" |
| 177 | done |
| 178 | |
| 179 | |
| 180 | echo "" |
| 181 | echo "*** Install curl in test client" |
| 182 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl" |
| 183 | |
| 184 | echo "" |
| 185 | echo "*** Test connectivity to ExampleService from test client" |
| 186 | ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP" |
| 187 | } |
| 188 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 189 | # Parse options |
| 190 | RUN_TEST=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 191 | EXAMPLESERVICE=0 |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 192 | BUILD_BRANCH="" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 193 | INVENTORY="inventory/single-localhost" |
| 194 | |
Zack Williams | 7bc0cbb | 2016-05-24 06:57:22 -0700 | [diff] [blame] | 195 | while getopts "b:ehi:t" opt; do |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 196 | case ${opt} in |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 197 | b ) BUILD_BRANCH=$OPTARG |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 198 | ;; |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 199 | e ) EXAMPLESERVICE=1 |
| 200 | ;; |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 201 | h ) echo "Usage:" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 202 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
| 203 | echo " $0 -b <branch> build XOS containers based on GitHub <branch> instead of pulling them from Docker Hub" |
| 204 | echo " $0 -e add exampleservice to XOS" |
| 205 | echo " $0 -h display this help message" |
| 206 | echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)" |
| 207 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 208 | exit 0 |
| 209 | ;; |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 210 | i ) INVENTORY=$OPTARG |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 211 | ;; |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 212 | t ) RUN_TEST=1 |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 213 | ;; |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 214 | \? ) echo "Invalid option: -$OPTARG" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 215 | exit 1 |
| 216 | ;; |
| 217 | esac |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 218 | done |
| 219 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 220 | # What to do |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 221 | if [[ $RUN_TEST -eq 1 ]] |
| 222 | then |
| 223 | cleanup_from_previous_test |
| 224 | fi |
| 225 | |
Andy Bavier | f000173 | 2016-05-05 09:21:49 -0700 | [diff] [blame] | 226 | set -e |
| 227 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 228 | bootstrap |
| 229 | setup_openstack |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 230 | |
| 231 | if [[ $RUN_TEST -eq 1 ]] |
| 232 | then |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 233 | if [[ -n $BUILD_BRANCH || $EXAMPLESERVICE -eq 1 ]] |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 234 | then |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 235 | build_xos_docker_images |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 236 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 237 | setup_xos |
| 238 | setup_test_client |
| 239 | run_e2e_test |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 240 | if [[ $EXAMPLESERVICE -eq 1 ]] |
| 241 | then |
| 242 | run_exampleservice_test |
| 243 | fi |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 244 | fi |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 245 | |
| 246 | exit 0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 247 | |