blob: 35af39cdc7649d497a52600974a320b0615b28af [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 Williams7e19a8a2016-05-24 06:42:47 -070033 sed -i "s/ubuntu/`whoami`/" $INVENTORY
Zack Williams65b72c82016-05-21 21:52:46 -070034 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"
Zack Williams97225f82016-05-24 08:23:37 -070050
Andy Bavier9927f962016-05-20 14:09:36 -040051 if [[ $EXAMPLESERVICE -eq 1 ]]
52 then
53 echo ""
54 echo "Adding exampleservice to XOS"
55 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
56 fi
Zack Williams97225f82016-05-24 08:23:37 -070057
Andy Bavier97faeec2016-05-10 13:23:04 -040058 echo "Rebuilding XOS containers"
59 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070060}
61
62function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070063
Andy Bavier76349042016-05-04 16:10:29 -070064 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070065 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070066 echo ""
67 echo "Pause 2 minutes"
68 sleep 120
69
Zack Williams3ecbfd02016-05-22 15:30:21 -070070 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070071 echo ""
72 echo "Pause 30 seconds"
73 sleep 30
74
Zack Williams3ecbfd02016-05-22 15:30:21 -070075 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Andy Bavier76349042016-05-04 16:10:29 -070076}
77
78function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -070079 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -070080
81 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -070082 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -070083
84 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -070085 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
86 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -070087
88 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -070089 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
90 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
91 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
92 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier97faeec2016-05-10 13:23:04 -040093
94 if [[ $EXAMPLESERVICE -eq 1 ]]
95 then
96 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
97 fi
Andy Bavier76349042016-05-04 16:10:29 -070098}
99
100function run_e2e_test() {
101 source ~/admin-openrc.sh
102
103 echo "*** Wait for vSG VM to come up"
104 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700105
Andy Bavier97faeec2016-05-10 13:23:04 -0400106 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700107 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400108 sleep 60
109 (( i += 1 ))
110 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700111 done
112
113 # get mgmt IP address
114 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
115 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
116
117 echo ""
118 echo "*** ssh into vsg VM, wait for Docker container to come up"
119 i=0
120 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
121 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400122 sleep 60
123 (( i += 1 ))
124 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700125 done
126
127 echo ""
128 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700129
Zack Williams3ecbfd02016-05-22 15:30:21 -0700130 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700131
132 echo ""
133 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700134 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700135
Andy Bavier76349042016-05-04 16:10:29 -0700136 echo ""
137 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700138 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700139
140 echo ""
141 if [ $? -eq 0 ]
142 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400143 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700144 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400145 echo "*** [FAILED] End-to-end connectivity test"
146 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700147 fi
148}
149
Andy Bavier97faeec2016-05-10 13:23:04 -0400150function run_exampleservice_test () {
151 source ~/admin-openrc.sh
152
153 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400154 echo "!!! NOTE that currently the VM will only be created after you login"
155 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400156 i=0
157 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
158 do
159 sleep 60
160 (( i += 1 ))
161 echo "Waited $i minutes"
162 done
163
164 # get mgmt IP address
165 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
166 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
167 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
168
169 echo ""
170 echo "*** ssh into exampleservice VM, wait for Apache come up"
171 i=0
172 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
173 do
174 sleep 60
175 (( i += 1 ))
176 echo "Waited $i minutes"
177 done
178
179
180 echo ""
181 echo "*** Install curl in test client"
182 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
183
184 echo ""
185 echo "*** Test connectivity to ExampleService from test client"
186 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
187}
188
Andy Bavier76349042016-05-04 16:10:29 -0700189# Parse options
190RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400191EXAMPLESERVICE=0
Andy Bavier9927f962016-05-20 14:09:36 -0400192BUILD_BRANCH=""
Zack Williamsed9ced02016-05-24 06:37:04 -0700193INVENTORY="inventory/single-localhost"
194
Zack Williams7bc0cbb2016-05-24 06:57:22 -0700195while getopts "b:ehi:t" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700196 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400197 b ) BUILD_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700198 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400199 e ) EXAMPLESERVICE=1
200 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400201 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700202 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
203 echo " $0 -b <branch> build XOS containers based on GitHub <branch> instead of pulling them from Docker Hub"
204 echo " $0 -e add exampleservice to XOS"
205 echo " $0 -h display this help message"
206 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
207 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400208 exit 0
209 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700210 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400211 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700212 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400213 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400214 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700215 exit 1
216 ;;
217 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400218done
219
Andy Bavier76349042016-05-04 16:10:29 -0700220# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700221if [[ $RUN_TEST -eq 1 ]]
222then
223 cleanup_from_previous_test
224fi
225
Andy Bavierf0001732016-05-05 09:21:49 -0700226set -e
227
Andy Bavier76349042016-05-04 16:10:29 -0700228bootstrap
229setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700230
231if [[ $RUN_TEST -eq 1 ]]
232then
Andy Bavier9927f962016-05-20 14:09:36 -0400233 if [[ -n $BUILD_BRANCH || $EXAMPLESERVICE -eq 1 ]]
Andy Bavier97faeec2016-05-10 13:23:04 -0400234 then
Andy Bavier9927f962016-05-20 14:09:36 -0400235 build_xos_docker_images
Andy Bavier97faeec2016-05-10 13:23:04 -0400236 fi
Andy Bavier76349042016-05-04 16:10:29 -0700237 setup_xos
238 setup_test_client
239 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400240 if [[ $EXAMPLESERVICE -eq 1 ]]
241 then
242 run_exampleservice_test
243 fi
Andy Bavier76349042016-05-04 16:10:29 -0700244fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400245
246exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700247