blob: ec8bb4e481ef923f0c41c4308115edaa823c80e7 [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() {
Zack Williams5028fb42016-06-01 14:52:29 -07004
5 echo "## Cleanup ##"
6
7 echo "Destroying juju environment"
8 juju destroy-environment --force -y manual
9
Andy Bavier0acc3642016-05-04 16:17:07 -070010 VMS=$( sudo virsh list|grep running|awk '{print $2}' )
11 for VM in $VMS
12 do
Zack Williams5028fb42016-06-01 14:52:29 -070013 echo "Destroying $VM"
Andy Bavier97faeec2016-05-10 13:23:04 -040014 sudo uvt-kvm destroy $VM
Andy Bavier0acc3642016-05-04 16:17:07 -070015 done
16
Zack Williams5028fb42016-06-01 14:52:29 -070017 echo "Cleaning up files"
Andy Bavier0acc3642016-05-04 16:17:07 -070018 rm -rf ~/.juju
19 rm -f ~/.ssh/known_hosts
20 rm -rf ~/openstack-cluster-setup
21
Zack Williams5028fb42016-06-01 14:52:29 -070022 echo "Cleaning up libvirt/dnsmasq"
Zack Williams17508be2016-05-31 21:52:35 -070023 sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases
24 sudo killall dnsmasq
Zack Williams5028fb42016-06-01 14:52:29 -070025 sudo service libvirt-bin restart
Andy Bavier0acc3642016-05-04 16:17:07 -070026}
27
Andy Bavier76349042016-05-04 16:10:29 -070028function bootstrap() {
29 cd ~
30 sudo apt-get update
Zack Williams65b72c82016-05-21 21:52:46 -070031 sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr
32 sudo add-apt-repository -y ppa:ansible/ansible
33 sudo apt-get update
34 sudo apt-get install -y ansible
35
36 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
37 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
38
Andy Bavier76349042016-05-04 16:10:29 -070039 git clone https://github.com/open-cloud/openstack-cluster-setup.git
40 cd ~/openstack-cluster-setup
41 git checkout roles
Andy Bavierea5b44c2016-04-08 16:12:30 -040042
Zack Williams7e19a8a2016-05-24 06:42:47 -070043 sed -i "s/ubuntu/`whoami`/" $INVENTORY
Zack Williams65b72c82016-05-21 21:52:46 -070044 cp vars/example_keystone.yml vars/cord_keystone.yml
Andy Bavierea5b44c2016-04-08 16:12:30 -040045
Andy Bavier76349042016-05-04 16:10:29 -070046 # Log into the local node once to get host key
47 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
48}
49
50function setup_openstack() {
51 # Run the playbook
Zack Williamsed9ced02016-05-24 06:37:04 -070052 ansible-playbook -i $INVENTORY cord-single-playbook.yml
Andy Bavier76349042016-05-04 16:10:29 -070053}
54
Andy Bavier9927f962016-05-20 14:09:36 -040055function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040056 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040057 echo "Checking out XOS branch $BUILD_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040058 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 -040059 ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"
Zack Williams97225f82016-05-24 08:23:37 -070060
Andy Bavier9927f962016-05-20 14:09:36 -040061 if [[ $EXAMPLESERVICE -eq 1 ]]
62 then
63 echo ""
64 echo "Adding exampleservice to XOS"
65 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
66 fi
Zack Williams97225f82016-05-24 08:23:37 -070067
Andy Bavier97faeec2016-05-10 13:23:04 -040068 echo "Rebuilding XOS containers"
69 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070070}
71
72function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070073
Andy Bavier76349042016-05-04 16:10:29 -070074 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070075 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070076 echo ""
77 echo "Pause 2 minutes"
78 sleep 120
79
Zack Williams3ecbfd02016-05-22 15:30:21 -070080 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070081 echo ""
82 echo "Pause 30 seconds"
83 sleep 30
84
Zack Williams3ecbfd02016-05-22 15:30:21 -070085 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Zack Williams455cec42016-05-25 16:07:36 -070086
87 if [[ $EXAMPLESERVICE -eq 1 ]]
88 then
89 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
90 fi
Andy Bavier76349042016-05-04 16:10:29 -070091}
92
93function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -070094 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -070095
96 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -070097 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -070098
99 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -0700100 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
101 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -0700102
103 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -0700104 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
105 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
106 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
107 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier76349042016-05-04 16:10:29 -0700108}
109
110function run_e2e_test() {
111 source ~/admin-openrc.sh
112
113 echo "*** Wait for vSG VM to come up"
114 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700115
Andy Bavier97faeec2016-05-10 13:23:04 -0400116 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700117 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400118 sleep 60
119 (( i += 1 ))
120 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700121 done
122
123 # get mgmt IP address
124 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
125 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
126
127 echo ""
128 echo "*** ssh into vsg VM, wait for Docker container to come up"
129 i=0
130 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
131 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400132 sleep 60
133 (( i += 1 ))
134 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700135 done
136
137 echo ""
138 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700139
Zack Williams3ecbfd02016-05-22 15:30:21 -0700140 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700141
142 echo ""
143 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700144 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700145
Andy Bavier76349042016-05-04 16:10:29 -0700146 echo ""
147 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700148 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700149
150 echo ""
151 if [ $? -eq 0 ]
152 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400153 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700154 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400155 echo "*** [FAILED] End-to-end connectivity test"
156 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700157 fi
158}
159
Andy Bavier97faeec2016-05-10 13:23:04 -0400160function run_exampleservice_test () {
161 source ~/admin-openrc.sh
162
163 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400164 echo "!!! NOTE that currently the VM will only be created after you login"
165 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400166 i=0
167 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
168 do
169 sleep 60
170 (( i += 1 ))
171 echo "Waited $i minutes"
172 done
173
174 # get mgmt IP address
175 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
176 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
177 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
178
179 echo ""
180 echo "*** ssh into exampleservice VM, wait for Apache come up"
181 i=0
182 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
183 do
184 sleep 60
185 (( i += 1 ))
186 echo "Waited $i minutes"
187 done
188
189
190 echo ""
191 echo "*** Install curl in test client"
192 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
193
194 echo ""
195 echo "*** Test connectivity to ExampleService from test client"
196 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
197}
198
Andy Bavier76349042016-05-04 16:10:29 -0700199# Parse options
200RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400201EXAMPLESERVICE=0
Andy Bavier9927f962016-05-20 14:09:36 -0400202BUILD_BRANCH=""
Zack Williamsed9ced02016-05-24 06:37:04 -0700203INVENTORY="inventory/single-localhost"
204
Zack Williams7bc0cbb2016-05-24 06:57:22 -0700205while getopts "b:ehi:t" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700206 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400207 b ) BUILD_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700208 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400209 e ) EXAMPLESERVICE=1
210 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400211 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700212 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
213 echo " $0 -b <branch> build XOS containers based on GitHub <branch> instead of pulling them from Docker Hub"
214 echo " $0 -e add exampleservice to XOS"
215 echo " $0 -h display this help message"
216 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
217 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400218 exit 0
219 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700220 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400221 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700222 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400223 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400224 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700225 exit 1
226 ;;
227 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400228done
229
Andy Bavier76349042016-05-04 16:10:29 -0700230# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700231if [[ $RUN_TEST -eq 1 ]]
232then
233 cleanup_from_previous_test
234fi
235
Andy Bavierf0001732016-05-05 09:21:49 -0700236set -e
237
Andy Bavier76349042016-05-04 16:10:29 -0700238bootstrap
239setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700240
241if [[ $RUN_TEST -eq 1 ]]
242then
Andy Bavier9927f962016-05-20 14:09:36 -0400243 if [[ -n $BUILD_BRANCH || $EXAMPLESERVICE -eq 1 ]]
Andy Bavier97faeec2016-05-10 13:23:04 -0400244 then
Andy Bavier9927f962016-05-20 14:09:36 -0400245 build_xos_docker_images
Andy Bavier97faeec2016-05-10 13:23:04 -0400246 fi
Andy Bavier76349042016-05-04 16:10:29 -0700247 setup_xos
248 setup_test_client
249 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400250 if [[ $EXAMPLESERVICE -eq 1 ]]
251 then
252 run_exampleservice_test
253 fi
Andy Bavier76349042016-05-04 16:10:29 -0700254fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400255
256exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700257