blob: 57de0f8b4de9c34cdda02e1f0e299d802c16371b [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
Zack Williams65b72c82016-05-21 21:52:46 -070021 sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr
22 sudo add-apt-repository -y ppa:ansible/ansible
23 sudo apt-get update
24 sudo apt-get install -y ansible
25
26 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
27 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
28
Andy Bavier76349042016-05-04 16:10:29 -070029 git clone https://github.com/open-cloud/openstack-cluster-setup.git
30 cd ~/openstack-cluster-setup
31 git checkout roles
Andy Bavierea5b44c2016-04-08 16:12:30 -040032
Zack Williams65b72c82016-05-21 21:52:46 -070033 sed -i "s/ubuntu/`whoami`/" inventory/cord-cloudlab
34 cp vars/example_keystone.yml vars/cord_keystone.yml
Andy Bavierea5b44c2016-04-08 16:12:30 -040035
Andy Bavier76349042016-05-04 16:10:29 -070036 # Log into the local node once to get host key
37 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
38}
39
40function setup_openstack() {
41 # Run the playbook
Zack Williamsed9ced02016-05-24 06:37:04 -070042 ansible-playbook -i $INVENTORY cord-single-playbook.yml
Andy Bavier76349042016-05-04 16:10:29 -070043}
44
Andy Bavier9927f962016-05-20 14:09:36 -040045function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040046 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040047 echo "Checking out XOS branch $BUILD_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040048 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 -040049 ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"
50 if [[ $EXAMPLESERVICE -eq 1 ]]
51 then
52 echo ""
53 echo "Adding exampleservice to XOS"
54 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
55 fi
Andy Bavier97faeec2016-05-10 13:23:04 -040056 echo ""
57 echo "Rebuilding XOS containers"
58 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070059}
60
61function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070062
63 echo "Rebuilding XOS containers"
64 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
65
Andy Bavier76349042016-05-04 16:10:29 -070066 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070067 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070068 echo ""
69 echo "Pause 2 minutes"
70 sleep 120
71
Zack Williams3ecbfd02016-05-22 15:30:21 -070072 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070073 echo ""
74 echo "Pause 30 seconds"
75 sleep 30
76
Zack Williams3ecbfd02016-05-22 15:30:21 -070077 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Andy Bavier76349042016-05-04 16:10:29 -070078}
79
80function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -070081 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -070082
83 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -070084 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -070085
86 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -070087 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
88 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -070089
90 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -070091 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
92 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
93 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
94 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier97faeec2016-05-10 13:23:04 -040095
96 if [[ $EXAMPLESERVICE -eq 1 ]]
97 then
98 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
99 fi
Andy Bavier76349042016-05-04 16:10:29 -0700100}
101
102function run_e2e_test() {
103 source ~/admin-openrc.sh
104
105 echo "*** Wait for vSG VM to come up"
106 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700107
Andy Bavier97faeec2016-05-10 13:23:04 -0400108 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700109 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400110 sleep 60
111 (( i += 1 ))
112 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700113 done
114
115 # get mgmt IP address
116 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
117 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
118
119 echo ""
120 echo "*** ssh into vsg VM, wait for Docker container to come up"
121 i=0
122 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
123 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400124 sleep 60
125 (( i += 1 ))
126 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700127 done
128
129 echo ""
130 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700131
Zack Williams3ecbfd02016-05-22 15:30:21 -0700132 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700133
134 echo ""
135 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700136 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700137
Andy Bavier76349042016-05-04 16:10:29 -0700138 echo ""
139 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700140 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700141
142 echo ""
143 if [ $? -eq 0 ]
144 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400145 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700146 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400147 echo "*** [FAILED] End-to-end connectivity test"
148 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700149 fi
150}
151
Andy Bavier97faeec2016-05-10 13:23:04 -0400152function run_exampleservice_test () {
153 source ~/admin-openrc.sh
154
155 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400156 echo "!!! NOTE that currently the VM will only be created after you login"
157 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400158 i=0
159 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
160 do
161 sleep 60
162 (( i += 1 ))
163 echo "Waited $i minutes"
164 done
165
166 # get mgmt IP address
167 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
168 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
169 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
170
171 echo ""
172 echo "*** ssh into exampleservice VM, wait for Apache come up"
173 i=0
174 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
175 do
176 sleep 60
177 (( i += 1 ))
178 echo "Waited $i minutes"
179 done
180
181
182 echo ""
183 echo "*** Install curl in test client"
184 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
185
186 echo ""
187 echo "*** Test connectivity to ExampleService from test client"
188 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
189}
190
Andy Bavier76349042016-05-04 16:10:29 -0700191# Parse options
192RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400193EXAMPLESERVICE=0
Andy Bavier9927f962016-05-20 14:09:36 -0400194BUILD_BRANCH=""
Zack Williamsed9ced02016-05-24 06:37:04 -0700195INVENTORY="inventory/single-localhost"
196
Andy Bavier9927f962016-05-20 14:09:36 -0400197while getopts "b:eht" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700198 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400199 b ) BUILD_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700200 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400201 e ) EXAMPLESERVICE=1
202 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400203 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700204 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
205 echo " $0 -b <branch> build XOS containers based on GitHub <branch> instead of pulling them from Docker Hub"
206 echo " $0 -e add exampleservice to XOS"
207 echo " $0 -h display this help message"
208 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
209 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400210 exit 0
211 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700212 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400213 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700214 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400215 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400216 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700217 exit 1
218 ;;
219 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400220done
221
Andy Bavier76349042016-05-04 16:10:29 -0700222# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700223if [[ $RUN_TEST -eq 1 ]]
224then
225 cleanup_from_previous_test
226fi
227
Andy Bavierf0001732016-05-05 09:21:49 -0700228set -e
229
Andy Bavier76349042016-05-04 16:10:29 -0700230bootstrap
231setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700232
233if [[ $RUN_TEST -eq 1 ]]
234then
Andy Bavier9927f962016-05-20 14:09:36 -0400235 if [[ -n $BUILD_BRANCH || $EXAMPLESERVICE -eq 1 ]]
Andy Bavier97faeec2016-05-10 13:23:04 -0400236 then
Andy Bavier9927f962016-05-20 14:09:36 -0400237 build_xos_docker_images
Andy Bavier97faeec2016-05-10 13:23:04 -0400238 fi
Andy Bavier76349042016-05-04 16:10:29 -0700239 setup_xos
240 setup_test_client
241 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400242 if [[ $EXAMPLESERVICE -eq 1 ]]
243 then
244 run_exampleservice_test
245 fi
Andy Bavier76349042016-05-04 16:10:29 -0700246fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400247
248exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700249