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