blob: 1457f3c66135a504a0fd3f18e60607b7660a5cef [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
21 sudo apt-get -y install git
22 git clone https://github.com/open-cloud/openstack-cluster-setup.git
23 cd ~/openstack-cluster-setup
24 git checkout roles
25 sed -i "s/zdw/acb/" inventory/cord-cloudlab
26 cp vars/example_keystone.yml vars/cord_keystone.yml
Andy Bavierea5b44c2016-04-08 16:12:30 -040027
Andy Bavier76349042016-05-04 16:10:29 -070028 ./bootstrap.sh
Andy Bavierea5b44c2016-04-08 16:12:30 -040029
Andy Bavier76349042016-05-04 16:10:29 -070030 # Log into the local node once to get host key
31 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
32}
33
34function setup_openstack() {
35 # Run the playbook
36 ansible-playbook -i inventory/cord-cloudlab cord-single-playbook.yml
37}
38
39function pull_docker_images() {
40 # Pull down the Docker images
41 echo ""
42 echo "Pull down the Docker images for ONOS and XOS"
43 echo "This can take 20 minutes or more, be patient!"
44 ssh ubuntu@onos-cord.cordtest.opencloud.us "cd cord; sudo docker-compose up -d"
45 ssh ubuntu@xos.cordtest.opencloud.us "cd xos/xos/configurations/cord-pod; git checkout feature/roles-setup; sudo docker-compose pull"
46}
47
48function wait_for_openstack() {
49 # Need to wait for OpenStack services to come up before running any XOS "make" commands
50 echo "Waiting for the OpenStack services to fully come up."
51 echo "This can take 30 minutes or more, be patient!"
52 i=0
53 until juju status --format=summary|grep "started: 22" > /dev/null
54 do
Zack Williams961ffcd2016-05-20 07:03:35 -070055 sleep 60
56 (( i += 1 ))
57 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -070058 done
59
60 echo "All OpenStack services are up."
61}
62
63function simulate_fabric() {
64 echo ""
65 echo "Setting up simulated fabric on nova-compute node"
66 ssh ubuntu@nova-compute.cordtest.opencloud.us "wget https://raw.githubusercontent.com/open-cloud/openstack-cluster-setup/master/scripts/compute-ext-net.sh; sudo bash compute-ext-net.sh"
Zack Williams961ffcd2016-05-20 07:03:35 -070067
Andy Bavier97faeec2016-05-10 13:23:04 -040068 if [[ $EXAMPLESERVICE -eq 1 ]]
69 then
70 SCRIPT=compute-ext-net-tutorial.sh
71 else
72 SCRIPT=compute-ext-net.sh
73 fi
74 ssh ubuntu@nova-compute "wget https://raw.githubusercontent.com/open-cloud/openstack-cluster-setup/master/scripts/$SCRIPT; sudo bash $SCRIPT"
75}
76
77function build_xos_with_exampleservice() {
78 echo ""
79 echo "Adding exampleservice to XOS"
80 ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'"
81 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
82 echo ""
83 echo "Rebuilding XOS containers"
84 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070085}
86
87function setup_xos() {
88 echo ""
89 echo "Setting up XOS, will take a few minutes"
90 ssh ubuntu@xos.cordtest.opencloud.us "cd xos/xos/configurations/cord-pod; make"
91 echo ""
92 echo "Pause 2 minutes"
93 sleep 120
94
95 ssh ubuntu@xos.cordtest.opencloud.us "cd xos/xos/configurations/cord-pod; make vtn"
96 echo ""
97 echo "Pause 30 seconds"
98 sleep 30
99
100 ssh ubuntu@xos.cordtest.opencloud.us "cd xos/xos/configurations/cord-pod; make cord"
101}
102
103function setup_test_client() {
104 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo apt-get -y install lxc"
105
106 # Change default bridge
107 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
108
109 # Create test client
110 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-create -t ubuntu -n testclient"
111 ssh ubuntu@nova-compute.cordtest.opencloud.us "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.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
115 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
116 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
117 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier97faeec2016-05-10 13:23:04 -0400118
119 if [[ $EXAMPLESERVICE -eq 1 ]]
120 then
121 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
122 fi
Andy Bavier76349042016-05-04 16:10:29 -0700123}
124
125function run_e2e_test() {
126 source ~/admin-openrc.sh
127
128 echo "*** Wait for vSG VM to come up"
129 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700130
Andy Bavier97faeec2016-05-10 13:23:04 -0400131 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700132 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400133 sleep 60
134 (( i += 1 ))
135 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700136 done
137
138 # get mgmt IP address
139 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
140 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
141
142 echo ""
143 echo "*** ssh into vsg VM, wait for Docker container to come up"
144 i=0
145 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
146 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400147 sleep 60
148 (( i += 1 ))
149 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700150 done
151
152 echo ""
153 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700154
Andy Bavier76349042016-05-04 16:10:29 -0700155 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
156
157 echo ""
158 echo "*** Routes in test client"
159 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- route -n"
160
Andy Bavier76349042016-05-04 16:10:29 -0700161 echo ""
162 echo "*** Test external connectivity in test client"
163 ssh ubuntu@nova-compute.cordtest.opencloud.us "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
164
165 echo ""
166 if [ $? -eq 0 ]
167 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400168 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700169 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400170 echo "*** [FAILED] End-to-end connectivity test"
171 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700172 fi
173}
174
Andy Bavier97faeec2016-05-10 13:23:04 -0400175function run_exampleservice_test () {
176 source ~/admin-openrc.sh
177
178 echo "*** Wait for exampleservice VM to come up."
Andy Bavier97faeec2016-05-10 13:23:04 -0400179 i=0
180 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
181 do
182 sleep 60
183 (( i += 1 ))
184 echo "Waited $i minutes"
185 done
186
187 # get mgmt IP address
188 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
189 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
190 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
191
192 echo ""
193 echo "*** ssh into exampleservice VM, wait for Apache come up"
194 i=0
195 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
196 do
197 sleep 60
198 (( i += 1 ))
199 echo "Waited $i minutes"
200 done
201
202
203 echo ""
204 echo "*** Install curl in test client"
205 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
206
207 echo ""
208 echo "*** Test connectivity to ExampleService from test client"
209 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
210}
211
Andy Bavier76349042016-05-04 16:10:29 -0700212# Parse options
213RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400214EXAMPLESERVICE=0
215while getopts ":eht" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700216 case ${opt} in
217 h ) "echo Usage:"
218 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Andy Bavier97faeec2016-05-10 13:23:04 -0400219 echo " $0 -e add exampleservice to XOS"
Andy Bavier76349042016-05-04 16:10:29 -0700220 echo " $0 -h display this help message"
221 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
222 exit 0
223 ;;
224 t ) RUN_TEST=1
225 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400226 e ) EXAMPLESERVICE=1
227 ;;
Andy Bavier76349042016-05-04 16:10:29 -0700228 \? ) echo "Invalid option"
229 exit 1
230 ;;
231 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400232done
233
Andy Bavier76349042016-05-04 16:10:29 -0700234# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700235if [[ $RUN_TEST -eq 1 ]]
236then
237 cleanup_from_previous_test
238fi
239
Andy Bavierf0001732016-05-05 09:21:49 -0700240set -e
241
Andy Bavier76349042016-05-04 16:10:29 -0700242bootstrap
243setup_openstack
244pull_docker_images
245wait_for_openstack
246simulate_fabric
247
248if [[ $RUN_TEST -eq 1 ]]
249then
Andy Bavier97faeec2016-05-10 13:23:04 -0400250 if [[ $EXAMPLESERVICE -eq 1 ]]
251 then
252 build_xos_with_exampleservice
253 fi
Andy Bavier76349042016-05-04 16:10:29 -0700254 setup_xos
255 setup_test_client
256 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400257 if [[ $EXAMPLESERVICE -eq 1 ]]
258 then
259 run_exampleservice_test
260 fi
Andy Bavier76349042016-05-04 16:10:29 -0700261fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400262
263exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700264