blob: 946b32d4974ef918ef24a9c50ee92b7ad568e449 [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."
Andy Bavier97faeec2016-05-10 13:23:04 -0400173 i=0
174 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
175 do
176 sleep 60
177 (( i += 1 ))
178 echo "Waited $i minutes"
179 done
180
181 # get mgmt IP address
182 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
183 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
184 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
185
186 echo ""
187 echo "*** ssh into exampleservice VM, wait for Apache come up"
188 i=0
189 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
190 do
191 sleep 60
192 (( i += 1 ))
193 echo "Waited $i minutes"
194 done
195
196
197 echo ""
198 echo "*** Install curl in test client"
199 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
200
201 echo ""
202 echo "*** Test connectivity to ExampleService from test client"
203 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
204}
205
Andy Baviercb024332016-04-29 15:52:26 -0400206# Parse options
207RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400208EXAMPLESERVICE=0
209while getopts ":eht" opt; do
Andy Baviercb024332016-04-29 15:52:26 -0400210 case ${opt} in
211 h ) "echo Usage:"
212 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Andy Bavier97faeec2016-05-10 13:23:04 -0400213 echo " $0 -e add exampleservice to XOS"
Andy Baviercb024332016-04-29 15:52:26 -0400214 echo " $0 -h display this help message"
215 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
216 exit 0
217 ;;
218 t ) RUN_TEST=1
219 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400220 e ) EXAMPLESERVICE=1
221 ;;
Andy Baviercb024332016-04-29 15:52:26 -0400222 \? ) echo "Invalid option"
223 exit 1
224 ;;
225 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400226done
227
Andy Baviercb024332016-04-29 15:52:26 -0400228# What to do
Andy Bavierfec35de2016-05-04 16:17:07 -0700229if [[ $RUN_TEST -eq 1 ]]
230then
231 cleanup_from_previous_test
232fi
233
Andy Bavierdead1782016-05-05 09:08:45 -0700234set -e
235
Andy Baviercb024332016-04-29 15:52:26 -0400236bootstrap
237setup_openstack
238pull_docker_images
239wait_for_openstack
240simulate_fabric
241
242if [[ $RUN_TEST -eq 1 ]]
243then
Andy Bavier97faeec2016-05-10 13:23:04 -0400244 if [[ $EXAMPLESERVICE -eq 1 ]]
245 then
246 build_xos_with_exampleservice
247 fi
Andy Baviercb024332016-04-29 15:52:26 -0400248 setup_xos
249 setup_test_client
250 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400251 if [[ $EXAMPLESERVICE -eq 1 ]]
252 then
253 run_exampleservice_test
254 fi
Andy Baviercb024332016-04-29 15:52:26 -0400255fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400256
257exit 0