blob: cf25de099d78e09e6f1634187d893db34fb5a12b [file] [log] [blame]
Andy Bavierea5b44c2016-04-08 16:12:30 -04001#!/bin/bash
2
Andy Bavierfec35de2016-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 Bavierfec35de2016-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 Baviercb024332016-04-29 15:52:26 -040018function bootstrap() {
19 cd ~
Andy Bavierb6a74cd2016-04-29 19:59:51 -040020 sudo apt-get update
21 sudo apt-get -y install git
Andy Baviercb024332016-04-29 15:52:26 -040022 git clone https://github.com/open-cloud/openstack-cluster-setup.git
23 cd ~/openstack-cluster-setup
24 ./bootstrap.sh
Andy Bavierea5b44c2016-04-08 16:12:30 -040025
Andy Baviercb024332016-04-29 15:52:26 -040026 # Log into the local node once to get host key
27 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
28}
Andy Bavierea5b44c2016-04-08 16:12:30 -040029
Andy Baviercb024332016-04-29 15:52:26 -040030function setup_openstack() {
31 # Run the playbook
32 ansible-playbook -i cord-test-hosts cord-setup.yml
33}
34
35function 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
44function 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
Andy Bavier97faeec2016-05-10 13:23:04 -040051 sleep 60
52 (( i += 1 ))
53 echo "Waited $i minutes"
Andy Baviercb024332016-04-29 15:52:26 -040054 done
55
56 echo "All OpenStack services are up."
57}
58
59function simulate_fabric() {
60 echo ""
61 echo "Setting up simulated fabric on nova-compute node"
Andy Bavier97faeec2016-05-10 13:23:04 -040062 if [[ $EXAMPLESERVICE -eq 1 ]]
63 then
64 SCRIPT=compute-ext-net-tutorial.sh
65 else
66 SCRIPT=compute-ext-net.sh
67 fi
68 ssh ubuntu@nova-compute "wget https://raw.githubusercontent.com/open-cloud/openstack-cluster-setup/master/scripts/$SCRIPT; sudo bash $SCRIPT"
69}
70
71function build_xos_with_exampleservice() {
72 echo ""
73 echo "Adding exampleservice to XOS"
74 ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'"
75 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
76 echo ""
77 echo "Rebuilding XOS containers"
78 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
79
Andy Baviercb024332016-04-29 15:52:26 -040080}
81
82function setup_xos() {
83 echo ""
84 echo "Setting up XOS, will take a few minutes"
85 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
86 echo ""
87 echo "Pause 2 minutes"
88 sleep 120
89
90 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
91 echo ""
92 echo "Pause 30 seconds"
93 sleep 30
94
95 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Andy Bavier97faeec2016-05-10 13:23:04 -040096
97 if [[ $EXAMPLESERVICE -eq 1 ]]
98 then
99 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
100 fi
Andy Baviercb024332016-04-29 15:52:26 -0400101}
102
103function setup_test_client() {
104 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
105
106 # Change default bridge
107 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
108
109 # Create test client
110 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
111 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
112
113 # Configure network interface inside of test client with s-tag and c-tag
114 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
115 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
116 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
117 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
118}
119
120function run_e2e_test() {
121 source ~/admin-openrc.sh
122
123 echo "*** Wait for vSG VM to come up"
124 i=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400125 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Baviercb024332016-04-29 15:52:26 -0400126 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400127 sleep 60
128 (( i += 1 ))
129 echo "Waited $i minutes"
Andy Baviercb024332016-04-29 15:52:26 -0400130 done
131
132 # get mgmt IP address
133 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
134 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
135
136 echo ""
137 echo "*** ssh into vsg VM, wait for Docker container to come up"
138 i=0
139 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
140 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400141 sleep 60
142 (( i += 1 ))
143 echo "Waited $i minutes"
Andy Baviercb024332016-04-29 15:52:26 -0400144 done
145
146 echo ""
147 echo "*** Run dhclient in test client"
148 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
149
150 echo ""
151 echo "*** Routes in test client"
152 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
153
154
155 echo ""
156 echo "*** Test external connectivity in test client"
157 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
158
159 echo ""
160 if [ $? -eq 0 ]
161 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400162 echo "*** [PASSED] End-to-end connectivity test"
Andy Baviercb024332016-04-29 15:52:26 -0400163 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400164 echo "*** [FAILED] End-to-end connectivity test"
165 exit 1
Andy Baviercb024332016-04-29 15:52:26 -0400166 fi
167}
168
Andy Bavier97faeec2016-05-10 13:23:04 -0400169function run_exampleservice_test () {
170 source ~/admin-openrc.sh
171
172 echo "*** Wait for exampleservice VM to come up."
173 echo "!!! NOTE that currently the VM will only be created after you login"
174 echo "!!! to XOS and manually create an ExampleService tenant."
175 i=0
176 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
177 do
178 sleep 60
179 (( i += 1 ))
180 echo "Waited $i minutes"
181 done
182
183 # get mgmt IP address
184 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
185 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
186 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
187
188 echo ""
189 echo "*** ssh into exampleservice VM, wait for Apache come up"
190 i=0
191 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
192 do
193 sleep 60
194 (( i += 1 ))
195 echo "Waited $i minutes"
196 done
197
198
199 echo ""
200 echo "*** Install curl in test client"
201 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
202
203 echo ""
204 echo "*** Test connectivity to ExampleService from test client"
205 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
206}
207
Andy Baviercb024332016-04-29 15:52:26 -0400208# Parse options
209RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400210EXAMPLESERVICE=0
211while getopts ":eht" opt; do
Andy Baviercb024332016-04-29 15:52:26 -0400212 case ${opt} in
213 h ) "echo Usage:"
214 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Andy Bavier97faeec2016-05-10 13:23:04 -0400215 echo " $0 -e add exampleservice to XOS"
Andy Baviercb024332016-04-29 15:52:26 -0400216 echo " $0 -h display this help message"
217 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
218 exit 0
219 ;;
220 t ) RUN_TEST=1
221 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400222 e ) EXAMPLESERVICE=1
223 ;;
Andy Baviercb024332016-04-29 15:52:26 -0400224 \? ) echo "Invalid option"
225 exit 1
226 ;;
227 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400228done
229
Andy Baviercb024332016-04-29 15:52:26 -0400230# What to do
Andy Bavierfec35de2016-05-04 16:17:07 -0700231if [[ $RUN_TEST -eq 1 ]]
232then
233 cleanup_from_previous_test
234fi
235
Andy Bavierdead1782016-05-05 09:08:45 -0700236set -e
237
Andy Baviercb024332016-04-29 15:52:26 -0400238bootstrap
239setup_openstack
240pull_docker_images
241wait_for_openstack
242simulate_fabric
243
244if [[ $RUN_TEST -eq 1 ]]
245then
Andy Bavier97faeec2016-05-10 13:23:04 -0400246 if [[ $EXAMPLESERVICE -eq 1 ]]
247 then
248 build_xos_with_exampleservice
249 fi
Andy Baviercb024332016-04-29 15:52:26 -0400250 setup_xos
251 setup_test_client
252 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400253 if [[ $EXAMPLESERVICE -eq 1 ]]
254 then
255 run_exampleservice_test
256 fi
Andy Baviercb024332016-04-29 15:52:26 -0400257fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400258
259exit 0