blob: 1d9c2ee82f58546b57632eb6e17b5c8eb6f35220 [file] [log] [blame]
Zack Williams961ffcd2016-05-20 07:03:35 -07001#!/usr/bin/env bash
Andy Bavierea5b44c2016-04-08 16:12:30 -04002
Andy Bavier0acc3642016-05-04 16:17:07 -07003function cleanup_from_previous_test() {
4 VMS=$( sudo virsh list|grep running|awk '{print $2}' )
5 for VM in $VMS
6 do
Andy Bavier97faeec2016-05-10 13:23:04 -04007 sudo uvt-kvm destroy $VM
Andy Bavier0acc3642016-05-04 16:17:07 -07008 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 Bavier76349042016-05-04 16:10:29 -070018function bootstrap() {
19 cd ~
20 sudo apt-get update
Zack Williams65b72c82016-05-21 21:52:46 -070021 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 Bavier76349042016-05-04 16:10:29 -070029 git clone https://github.com/open-cloud/openstack-cluster-setup.git
30 cd ~/openstack-cluster-setup
31 git checkout roles
Andy Bavierea5b44c2016-04-08 16:12:30 -040032
Zack Williams65b72c82016-05-21 21:52:46 -070033 sed -i "s/ubuntu/`whoami`/" inventory/cord-cloudlab
34 cp vars/example_keystone.yml vars/cord_keystone.yml
Andy Bavierea5b44c2016-04-08 16:12:30 -040035
Andy Bavier76349042016-05-04 16:10:29 -070036 # Log into the local node once to get host key
37 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
38}
39
40function setup_openstack() {
41 # Run the playbook
42 ansible-playbook -i inventory/cord-cloudlab cord-single-playbook.yml
43}
44
Andy Bavier97faeec2016-05-10 13:23:04 -040045function build_xos_with_exampleservice() {
46 echo ""
47 echo "Adding exampleservice to XOS"
48 ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'"
49 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
Andy Bavier76349042016-05-04 16:10:29 -070050}
51
52function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070053
54 echo "Rebuilding XOS containers"
55 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
56
Andy Bavier76349042016-05-04 16:10:29 -070057 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070058 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070059 echo ""
60 echo "Pause 2 minutes"
61 sleep 120
62
Zack Williams3ecbfd02016-05-22 15:30:21 -070063 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070064 echo ""
65 echo "Pause 30 seconds"
66 sleep 30
67
Zack Williams3ecbfd02016-05-22 15:30:21 -070068 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Andy Bavier76349042016-05-04 16:10:29 -070069}
70
71function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -070072 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -070073
74 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -070075 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -070076
77 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -070078 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
79 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -070080
81 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -070082 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
83 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
84 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
85 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier97faeec2016-05-10 13:23:04 -040086
87 if [[ $EXAMPLESERVICE -eq 1 ]]
88 then
89 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
90 fi
Andy Bavier76349042016-05-04 16:10:29 -070091}
92
93function run_e2e_test() {
94 source ~/admin-openrc.sh
95
96 echo "*** Wait for vSG VM to come up"
97 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -070098
Andy Bavier97faeec2016-05-10 13:23:04 -040099 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700100 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400101 sleep 60
102 (( i += 1 ))
103 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700104 done
105
106 # get mgmt IP address
107 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
108 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
109
110 echo ""
111 echo "*** ssh into vsg VM, wait for Docker container to come up"
112 i=0
113 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
114 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400115 sleep 60
116 (( i += 1 ))
117 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700118 done
119
120 echo ""
121 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700122
Zack Williams3ecbfd02016-05-22 15:30:21 -0700123 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700124
125 echo ""
126 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700127 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700128
Andy Bavier76349042016-05-04 16:10:29 -0700129 echo ""
130 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700131 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700132
133 echo ""
134 if [ $? -eq 0 ]
135 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400136 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700137 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400138 echo "*** [FAILED] End-to-end connectivity test"
139 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700140 fi
141}
142
Andy Bavier97faeec2016-05-10 13:23:04 -0400143function run_exampleservice_test () {
144 source ~/admin-openrc.sh
145
146 echo "*** Wait for exampleservice VM to come up."
Andy Bavier97faeec2016-05-10 13:23:04 -0400147 i=0
148 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
149 do
150 sleep 60
151 (( i += 1 ))
152 echo "Waited $i minutes"
153 done
154
155 # get mgmt IP address
156 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
157 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
158 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
159
160 echo ""
161 echo "*** ssh into exampleservice VM, wait for Apache come up"
162 i=0
163 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
164 do
165 sleep 60
166 (( i += 1 ))
167 echo "Waited $i minutes"
168 done
169
170
171 echo ""
172 echo "*** Install curl in test client"
173 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
174
175 echo ""
176 echo "*** Test connectivity to ExampleService from test client"
177 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
178}
179
Andy Bavier76349042016-05-04 16:10:29 -0700180# Parse options
181RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400182EXAMPLESERVICE=0
183while getopts ":eht" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700184 case ${opt} in
185 h ) "echo Usage:"
186 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Andy Bavier97faeec2016-05-10 13:23:04 -0400187 echo " $0 -e add exampleservice to XOS"
Andy Bavier76349042016-05-04 16:10:29 -0700188 echo " $0 -h display this help message"
189 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
190 exit 0
191 ;;
192 t ) RUN_TEST=1
193 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400194 e ) EXAMPLESERVICE=1
195 ;;
Andy Bavier76349042016-05-04 16:10:29 -0700196 \? ) echo "Invalid option"
197 exit 1
198 ;;
199 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400200done
201
Andy Bavier76349042016-05-04 16:10:29 -0700202# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700203if [[ $RUN_TEST -eq 1 ]]
204then
205 cleanup_from_previous_test
206fi
207
Andy Bavierf0001732016-05-05 09:21:49 -0700208set -e
209
Andy Bavier76349042016-05-04 16:10:29 -0700210bootstrap
211setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700212
213if [[ $RUN_TEST -eq 1 ]]
214then
Andy Bavier97faeec2016-05-10 13:23:04 -0400215 if [[ $EXAMPLESERVICE -eq 1 ]]
216 then
217 build_xos_with_exampleservice
218 fi
Andy Bavier76349042016-05-04 16:10:29 -0700219 setup_xos
220 setup_test_client
221 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400222 if [[ $EXAMPLESERVICE -eq 1 ]]
223 then
224 run_exampleservice_test
225 fi
Andy Bavier76349042016-05-04 16:10:29 -0700226fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400227
228exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700229