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