blob: c3f06abd277ddaffb93aaa5ab483a6dd520dbc38 [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() {
Andy Bavierde3f4672016-06-01 17:02:42 -04004 VMS=$( sudo uvt-kvm list )
Andy Bavierfec35de2016-05-04 16:17:07 -07005 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
Andy Bavierde3f4672016-06-01 17:02:42 -040014 # Attempt to flush out old leases from dnsmasq, for repeated runs
15 sudo cp /var/lib/libvirt/dnsmasq/default.leases /var/lib/libvirt/dnsmasq/default.leases.bak
16 sudo truncate -s 0 /var/lib/libvirt/dnsmasq/default.leases
17 sudo killall dnsmasq
18 sudo /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf
Andy Bavierfec35de2016-05-04 16:17:07 -070019}
20
Andy Baviercb024332016-04-29 15:52:26 -040021function bootstrap() {
22 cd ~
Andy Bavierb6a74cd2016-04-29 19:59:51 -040023 sudo apt-get update
24 sudo apt-get -y install git
Andy Baviercb024332016-04-29 15:52:26 -040025 git clone https://github.com/open-cloud/openstack-cluster-setup.git
26 cd ~/openstack-cluster-setup
27 ./bootstrap.sh
Andy Bavierea5b44c2016-04-08 16:12:30 -040028
Andy Baviercb024332016-04-29 15:52:26 -040029 # Log into the local node once to get host key
30 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
31}
Andy Bavierea5b44c2016-04-08 16:12:30 -040032
Andy Baviercb024332016-04-29 15:52:26 -040033function setup_openstack() {
34 # Run the playbook
35 ansible-playbook -i cord-test-hosts cord-setup.yml
36}
37
Andy Bavier9927f962016-05-20 14:09:36 -040038function pull_onos_docker_image() {
Andy Baviercb024332016-04-29 15:52:26 -040039 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040040 echo "Pull down the ONOS Docker image"
Andy Baviercb024332016-04-29 15:52:26 -040041 ssh ubuntu@onos-cord "cd cord; sudo docker-compose up -d"
Andy Baviercb024332016-04-29 15:52:26 -040042}
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
Andy Bavier9927f962016-05-20 14:09:36 -040071function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040072 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040073 echo "Checking out XOS branch $BUILD_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040074 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 -040075 ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"
76 if [[ $EXAMPLESERVICE -eq 1 ]]
77 then
78 echo ""
79 echo "Adding exampleservice to XOS"
80 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
81 fi
Andy Bavier97faeec2016-05-10 13:23:04 -040082 echo ""
83 echo "Rebuilding XOS containers"
84 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
85
Andy Baviercb024332016-04-29 15:52:26 -040086}
87
88function setup_xos() {
89 echo ""
90 echo "Setting up XOS, will take a few minutes"
91 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
92 echo ""
93 echo "Pause 2 minutes"
94 sleep 120
95
96 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
97 echo ""
98 echo "Pause 30 seconds"
99 sleep 30
100
101 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Andy Bavier97faeec2016-05-10 13:23:04 -0400102
103 if [[ $EXAMPLESERVICE -eq 1 ]]
104 then
105 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
106 fi
Andy Baviercb024332016-04-29 15:52:26 -0400107}
108
109function setup_test_client() {
110 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
111
112 # Change default bridge
113 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
114
115 # Create test client
116 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
117 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
118
119 # Configure network interface inside of test client with s-tag and c-tag
120 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
121 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
122 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
123 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
124}
125
126function run_e2e_test() {
127 source ~/admin-openrc.sh
128
129 echo "*** Wait for vSG VM to come up"
130 i=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400131 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Baviercb024332016-04-29 15:52:26 -0400132 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400133 sleep 60
134 (( i += 1 ))
135 echo "Waited $i minutes"
Andy Baviercb024332016-04-29 15:52:26 -0400136 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 Baviercb024332016-04-29 15:52:26 -0400150 done
151
152 echo ""
153 echo "*** Run dhclient in test client"
154 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
155
156 echo ""
157 echo "*** Routes in test client"
158 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
159
160
161 echo ""
162 echo "*** Test external connectivity in test client"
163 ssh ubuntu@nova-compute "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 Baviercb024332016-04-29 15:52:26 -0400169 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400170 echo "*** [FAILED] End-to-end connectivity test"
171 exit 1
Andy Baviercb024332016-04-29 15:52:26 -0400172 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 Bavier9927f962016-05-20 14:09:36 -0400179 echo "!!! NOTE that currently the VM will only be created after you login"
180 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400181 i=0
182 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
183 do
184 sleep 60
185 (( i += 1 ))
186 echo "Waited $i minutes"
187 done
188
189 # get mgmt IP address
190 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
191 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
192 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
193
194 echo ""
195 echo "*** ssh into exampleservice VM, wait for Apache come up"
196 i=0
197 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
198 do
199 sleep 60
200 (( i += 1 ))
201 echo "Waited $i minutes"
202 done
203
204
205 echo ""
206 echo "*** Install curl in test client"
207 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
208
209 echo ""
210 echo "*** Test connectivity to ExampleService from test client"
211 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
212}
213
Andy Baviercb024332016-04-29 15:52:26 -0400214# Parse options
215RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400216EXAMPLESERVICE=0
Andy Bavier9927f962016-05-20 14:09:36 -0400217BUILD_BRANCH=""
218while getopts "b:eht" opt; do
Andy Baviercb024332016-04-29 15:52:26 -0400219 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400220 b ) BUILD_BRANCH=$OPTARG
221 ;;
222 h ) echo "Usage:"
223 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
224 echo " $0 -b <branch> build XOS containers based on GitHub <branch> instead of pulling them from Docker Hub"
225 echo " $0 -e add exampleservice to XOS"
226 echo " $0 -h display this help message"
227 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400228 exit 0
229 ;;
230 t ) RUN_TEST=1
231 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400232 e ) EXAMPLESERVICE=1
233 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400234 \? ) echo "Invalid option: -$OPTARG"
Andy Baviercb024332016-04-29 15:52:26 -0400235 exit 1
236 ;;
237 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400238done
239
Andy Baviercb024332016-04-29 15:52:26 -0400240# What to do
Andy Bavierfec35de2016-05-04 16:17:07 -0700241if [[ $RUN_TEST -eq 1 ]]
242then
243 cleanup_from_previous_test
244fi
245
Andy Bavierdead1782016-05-05 09:08:45 -0700246set -e
247
Andy Baviercb024332016-04-29 15:52:26 -0400248bootstrap
249setup_openstack
Andy Bavier9927f962016-05-20 14:09:36 -0400250pull_onos_docker_image
Andy Baviercb024332016-04-29 15:52:26 -0400251wait_for_openstack
252simulate_fabric
253
254if [[ $RUN_TEST -eq 1 ]]
255then
Andy Bavier9927f962016-05-20 14:09:36 -0400256 if [[ -n $BUILD_BRANCH || $EXAMPLESERVICE -eq 1 ]]
Andy Bavier97faeec2016-05-10 13:23:04 -0400257 then
Andy Bavier9927f962016-05-20 14:09:36 -0400258 build_xos_docker_images
Andy Bavier97faeec2016-05-10 13:23:04 -0400259 fi
Andy Baviercb024332016-04-29 15:52:26 -0400260 setup_xos
261 setup_test_client
262 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400263 if [[ $EXAMPLESERVICE -eq 1 ]]
264 then
265 run_exampleservice_test
266 fi
Andy Baviercb024332016-04-29 15:52:26 -0400267fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400268
269exit 0