blob: e610bdfc07d2916166415840dbb6bb1b454ab15c [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
Andy Bavier9927f962016-05-20 14:09:36 -040035function pull_onos_docker_image() {
Andy Baviercb024332016-04-29 15:52:26 -040036 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040037 echo "Pull down the ONOS Docker image"
Andy Baviercb024332016-04-29 15:52:26 -040038 ssh ubuntu@onos-cord "cd cord; sudo docker-compose up -d"
Andy Baviercb024332016-04-29 15:52:26 -040039}
40
41function wait_for_openstack() {
42 # Need to wait for OpenStack services to come up before running any XOS "make" commands
43 echo "Waiting for the OpenStack services to fully come up."
44 echo "This can take 30 minutes or more, be patient!"
45 i=0
46 until juju status --format=summary|grep "started: 23" > /dev/null
47 do
Andy Bavier97faeec2016-05-10 13:23:04 -040048 sleep 60
49 (( i += 1 ))
50 echo "Waited $i minutes"
Andy Baviercb024332016-04-29 15:52:26 -040051 done
52
53 echo "All OpenStack services are up."
54}
55
56function simulate_fabric() {
57 echo ""
58 echo "Setting up simulated fabric on nova-compute node"
Andy Bavier97faeec2016-05-10 13:23:04 -040059 if [[ $EXAMPLESERVICE -eq 1 ]]
60 then
61 SCRIPT=compute-ext-net-tutorial.sh
62 else
63 SCRIPT=compute-ext-net.sh
64 fi
65 ssh ubuntu@nova-compute "wget https://raw.githubusercontent.com/open-cloud/openstack-cluster-setup/master/scripts/$SCRIPT; sudo bash $SCRIPT"
66}
67
Andy Bavier9927f962016-05-20 14:09:36 -040068function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040069 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040070 echo "Checking out XOS branch $BUILD_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040071 ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'"
Andy Bavier9927f962016-05-20 14:09:36 -040072 ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"
73 if [[ $EXAMPLESERVICE -eq 1 ]]
74 then
75 echo ""
76 echo "Adding exampleservice to XOS"
77 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
78 fi
Andy Bavier97faeec2016-05-10 13:23:04 -040079 echo ""
80 echo "Rebuilding XOS containers"
81 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
82
Andy Baviercb024332016-04-29 15:52:26 -040083}
84
85function setup_xos() {
86 echo ""
87 echo "Setting up XOS, will take a few minutes"
88 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
89 echo ""
90 echo "Pause 2 minutes"
91 sleep 120
92
93 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
94 echo ""
95 echo "Pause 30 seconds"
96 sleep 30
97
98 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Andy Bavier97faeec2016-05-10 13:23:04 -040099
100 if [[ $EXAMPLESERVICE -eq 1 ]]
101 then
102 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
103 fi
Andy Baviercb024332016-04-29 15:52:26 -0400104}
105
106function setup_test_client() {
107 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
108
109 # Change default bridge
110 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
111
112 # Create test client
113 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
114 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
115
116 # Configure network interface inside of test client with s-tag and c-tag
117 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
118 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
119 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
120 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
121}
122
123function run_e2e_test() {
124 source ~/admin-openrc.sh
125
126 echo "*** Wait for vSG VM to come up"
127 i=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400128 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Baviercb024332016-04-29 15:52:26 -0400129 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400130 sleep 60
131 (( i += 1 ))
132 echo "Waited $i minutes"
Andy Baviercb024332016-04-29 15:52:26 -0400133 done
134
135 # get mgmt IP address
136 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
137 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
138
139 echo ""
140 echo "*** ssh into vsg VM, wait for Docker container to come up"
141 i=0
142 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
143 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400144 sleep 60
145 (( i += 1 ))
146 echo "Waited $i minutes"
Andy Baviercb024332016-04-29 15:52:26 -0400147 done
148
149 echo ""
150 echo "*** Run dhclient in test client"
151 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
152
153 echo ""
154 echo "*** Routes in test client"
155 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
156
157
158 echo ""
159 echo "*** Test external connectivity in test client"
160 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
161
162 echo ""
163 if [ $? -eq 0 ]
164 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400165 echo "*** [PASSED] End-to-end connectivity test"
Andy Baviercb024332016-04-29 15:52:26 -0400166 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400167 echo "*** [FAILED] End-to-end connectivity test"
168 exit 1
Andy Baviercb024332016-04-29 15:52:26 -0400169 fi
170}
171
Andy Bavier97faeec2016-05-10 13:23:04 -0400172function run_exampleservice_test () {
173 source ~/admin-openrc.sh
174
175 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400176 echo "!!! NOTE that currently the VM will only be created after you login"
177 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400178 i=0
179 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
180 do
181 sleep 60
182 (( i += 1 ))
183 echo "Waited $i minutes"
184 done
185
186 # get mgmt IP address
187 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
188 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
189 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
190
191 echo ""
192 echo "*** ssh into exampleservice VM, wait for Apache come up"
193 i=0
194 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
195 do
196 sleep 60
197 (( i += 1 ))
198 echo "Waited $i minutes"
199 done
200
201
202 echo ""
203 echo "*** Install curl in test client"
204 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
205
206 echo ""
207 echo "*** Test connectivity to ExampleService from test client"
208 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
209}
210
Andy Baviercb024332016-04-29 15:52:26 -0400211# Parse options
212RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400213EXAMPLESERVICE=0
Andy Bavier9927f962016-05-20 14:09:36 -0400214BUILD_BRANCH=""
215while getopts "b:eht" opt; do
Andy Baviercb024332016-04-29 15:52:26 -0400216 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400217 b ) BUILD_BRANCH=$OPTARG
218 ;;
219 h ) echo "Usage:"
220 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
221 echo " $0 -b <branch> build XOS containers based on GitHub <branch> instead of pulling them from Docker Hub"
222 echo " $0 -e add exampleservice to XOS"
223 echo " $0 -h display this help message"
224 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400225 exit 0
226 ;;
227 t ) RUN_TEST=1
228 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400229 e ) EXAMPLESERVICE=1
230 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400231 \? ) echo "Invalid option: -$OPTARG"
Andy Baviercb024332016-04-29 15:52:26 -0400232 exit 1
233 ;;
234 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400235done
236
Andy Baviercb024332016-04-29 15:52:26 -0400237# What to do
Andy Bavierfec35de2016-05-04 16:17:07 -0700238if [[ $RUN_TEST -eq 1 ]]
239then
240 cleanup_from_previous_test
241fi
242
Andy Bavierdead1782016-05-05 09:08:45 -0700243set -e
244
Andy Baviercb024332016-04-29 15:52:26 -0400245bootstrap
246setup_openstack
Andy Bavier9927f962016-05-20 14:09:36 -0400247pull_onos_docker_image
Andy Baviercb024332016-04-29 15:52:26 -0400248wait_for_openstack
249simulate_fabric
250
251if [[ $RUN_TEST -eq 1 ]]
252then
Andy Bavier9927f962016-05-20 14:09:36 -0400253 if [[ -n $BUILD_BRANCH || $EXAMPLESERVICE -eq 1 ]]
Andy Bavier97faeec2016-05-10 13:23:04 -0400254 then
Andy Bavier9927f962016-05-20 14:09:36 -0400255 build_xos_docker_images
Andy Bavier97faeec2016-05-10 13:23:04 -0400256 fi
Andy Baviercb024332016-04-29 15:52:26 -0400257 setup_xos
258 setup_test_client
259 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400260 if [[ $EXAMPLESERVICE -eq 1 ]]
261 then
262 run_exampleservice_test
263 fi
Andy Baviercb024332016-04-29 15:52:26 -0400264fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400265
266exit 0