blob: 72050d9370fd507401077f20c40dce79dcefcc63 [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 echo "## Cleanup ##"
5
6 echo "Destroying juju environment"
7 juju destroy-environment --force -y manual
8
Andy Bavierde3f4672016-06-01 17:02:42 -04009 VMS=$( sudo uvt-kvm list )
Andy Bavier0acc3642016-05-04 16:17:07 -070010 for VM in $VMS
11 do
Zack Williams5028fb42016-06-01 14:52:29 -070012 echo "Destroying $VM"
Andy Bavier97faeec2016-05-10 13:23:04 -040013 sudo uvt-kvm destroy $VM
Andy Bavier0acc3642016-05-04 16:17:07 -070014 done
15
Zack Williams5028fb42016-06-01 14:52:29 -070016 echo "Cleaning up files"
Andy Bavier0acc3642016-05-04 16:17:07 -070017 rm -rf ~/.juju
18 rm -f ~/.ssh/known_hosts
19 rm -rf ~/openstack-cluster-setup
20
Zack Williams5028fb42016-06-01 14:52:29 -070021 echo "Cleaning up libvirt/dnsmasq"
Zack Williams17508be2016-05-31 21:52:35 -070022 sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases
23 sudo killall dnsmasq
Zack Williams5028fb42016-06-01 14:52:29 -070024 sudo service libvirt-bin restart
Andy Bavier0acc3642016-05-04 16:17:07 -070025}
26
Andy Bavier76349042016-05-04 16:10:29 -070027function bootstrap() {
28 cd ~
29 sudo apt-get update
Zack Williams65b72c82016-05-21 21:52:46 -070030 sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr
31 sudo add-apt-repository -y ppa:ansible/ansible
32 sudo apt-get update
33 sudo apt-get install -y ansible
34
35 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
36 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
37
Andy Bavier76349042016-05-04 16:10:29 -070038 git clone https://github.com/open-cloud/openstack-cluster-setup.git
39 cd ~/openstack-cluster-setup
Andy Bavierea5b44c2016-04-08 16:12:30 -040040
Zack Williams7e19a8a2016-05-24 06:42:47 -070041 sed -i "s/ubuntu/`whoami`/" $INVENTORY
Zack Williams65b72c82016-05-21 21:52:46 -070042 cp vars/example_keystone.yml vars/cord_keystone.yml
Andy Bavierea5b44c2016-04-08 16:12:30 -040043
Andy Bavier76349042016-05-04 16:10:29 -070044 # Log into the local node once to get host key
45 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
46}
47
48function setup_openstack() {
49 # Run the playbook
Zack Williamsed9ced02016-05-24 06:37:04 -070050 ansible-playbook -i $INVENTORY cord-single-playbook.yml
Andy Bavier76349042016-05-04 16:10:29 -070051}
52
Andy Bavier9927f962016-05-20 14:09:36 -040053function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040054 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040055 echo "Checking out XOS branch $BUILD_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040056 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 -040057 ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"
Zack Williams97225f82016-05-24 08:23:37 -070058
Andy Bavier9927f962016-05-20 14:09:36 -040059 if [[ $EXAMPLESERVICE -eq 1 ]]
60 then
61 echo ""
62 echo "Adding exampleservice to XOS"
63 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
64 fi
Zack Williams97225f82016-05-24 08:23:37 -070065
Andy Bavier97faeec2016-05-10 13:23:04 -040066 echo "Rebuilding XOS containers"
67 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070068}
69
70function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070071
Andy Bavier76349042016-05-04 16:10:29 -070072 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070073 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070074 echo ""
75 echo "Pause 2 minutes"
76 sleep 120
77
Zack Williams3ecbfd02016-05-22 15:30:21 -070078 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070079 echo ""
80 echo "Pause 30 seconds"
81 sleep 30
82
Zack Williams3ecbfd02016-05-22 15:30:21 -070083 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Zack Williams455cec42016-05-25 16:07:36 -070084
85 if [[ $EXAMPLESERVICE -eq 1 ]]
86 then
87 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
88 fi
Andy Bavier76349042016-05-04 16:10:29 -070089}
90
91function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -070092 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -070093
94 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -070095 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -070096
97 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -070098 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
99 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -0700100
101 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -0700102 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
103 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
104 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
105 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier76349042016-05-04 16:10:29 -0700106}
107
108function run_e2e_test() {
109 source ~/admin-openrc.sh
110
111 echo "*** Wait for vSG VM to come up"
112 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700113
Andy Bavier97faeec2016-05-10 13:23:04 -0400114 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700115 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400116 sleep 60
117 (( i += 1 ))
118 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700119 done
120
121 # get mgmt IP address
122 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
123 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
124
125 echo ""
126 echo "*** ssh into vsg VM, wait for Docker container to come up"
127 i=0
128 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
129 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400130 sleep 60
131 (( i += 1 ))
132 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700133 done
134
135 echo ""
136 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700137
Zack Williams3ecbfd02016-05-22 15:30:21 -0700138 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700139
140 echo ""
141 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700142 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700143
Andy Bavier76349042016-05-04 16:10:29 -0700144 echo ""
145 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700146 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700147
148 echo ""
149 if [ $? -eq 0 ]
150 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400151 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700152 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400153 echo "*** [FAILED] End-to-end connectivity test"
154 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700155 fi
156}
157
Andy Bavier97faeec2016-05-10 13:23:04 -0400158function run_exampleservice_test () {
159 source ~/admin-openrc.sh
160
161 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400162 echo "!!! NOTE that currently the VM will only be created after you login"
163 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400164 i=0
165 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
166 do
167 sleep 60
168 (( i += 1 ))
169 echo "Waited $i minutes"
170 done
171
172 # get mgmt IP address
173 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
174 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
175 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
176
177 echo ""
178 echo "*** ssh into exampleservice VM, wait for Apache come up"
179 i=0
180 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
181 do
182 sleep 60
183 (( i += 1 ))
184 echo "Waited $i minutes"
185 done
186
187
188 echo ""
189 echo "*** Install curl in test client"
190 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
191
192 echo ""
193 echo "*** Test connectivity to ExampleService from test client"
194 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
195}
196
Andy Bavier76349042016-05-04 16:10:29 -0700197# Parse options
198RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400199EXAMPLESERVICE=0
Zack Williams80d4f222016-06-01 15:42:03 -0700200BUILD_BRANCH="master"
Zack Williamsed9ced02016-05-24 06:37:04 -0700201INVENTORY="inventory/single-localhost"
202
Zack Williams7bc0cbb2016-05-24 06:57:22 -0700203while getopts "b:ehi:t" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700204 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400205 b ) BUILD_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700206 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400207 e ) EXAMPLESERVICE=1
208 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400209 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700210 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williams80d4f222016-06-01 15:42:03 -0700211 echo " $0 -b <branch> build XOS containers based on GitHub <branch>"
Zack Williamsed9ced02016-05-24 06:37:04 -0700212 echo " $0 -e add exampleservice to XOS"
213 echo " $0 -h display this help message"
214 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
215 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400216 exit 0
217 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700218 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400219 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700220 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400221 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400222 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700223 exit 1
224 ;;
225 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400226done
227
Andy Bavier76349042016-05-04 16:10:29 -0700228# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700229if [[ $RUN_TEST -eq 1 ]]
230then
231 cleanup_from_previous_test
232fi
233
Andy Bavierf0001732016-05-05 09:21:49 -0700234set -e
235
Andy Bavier76349042016-05-04 16:10:29 -0700236bootstrap
237setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700238
239if [[ $RUN_TEST -eq 1 ]]
240then
Zack Williams80d4f222016-06-01 15:42:03 -0700241 build_xos_docker_images
Andy Bavier76349042016-05-04 16:10:29 -0700242 setup_xos
243 setup_test_client
244 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400245 if [[ $EXAMPLESERVICE -eq 1 ]]
246 then
247 run_exampleservice_test
248 fi
Andy Bavier76349042016-05-04 16:10:29 -0700249fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400250
251exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700252