blob: 9d5d5fed8d82bf2ac6b12b2376505bdef5c80542 [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
Zack Williams17508be2016-05-31 21:52:35 -070014 sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases
15 sudo killall dnsmasq
16 sudo service libvirt-bin restart
Andy Bavier0acc3642016-05-04 16:17:07 -070017}
18
Andy Bavier76349042016-05-04 16:10:29 -070019function bootstrap() {
20 cd ~
21 sudo apt-get update
Zack Williams65b72c82016-05-21 21:52:46 -070022 sudo apt-get -y install software-properties-common git mosh tmux dnsutils python-netaddr
23 sudo add-apt-repository -y ppa:ansible/ansible
24 sudo apt-get update
25 sudo apt-get install -y ansible
26
27 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
28 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
29
Andy Bavier76349042016-05-04 16:10:29 -070030 git clone https://github.com/open-cloud/openstack-cluster-setup.git
31 cd ~/openstack-cluster-setup
32 git checkout roles
Andy Bavierea5b44c2016-04-08 16:12:30 -040033
Zack Williams7e19a8a2016-05-24 06:42:47 -070034 sed -i "s/ubuntu/`whoami`/" $INVENTORY
Zack Williams65b72c82016-05-21 21:52:46 -070035 cp vars/example_keystone.yml vars/cord_keystone.yml
Andy Bavierea5b44c2016-04-08 16:12:30 -040036
Andy Bavier76349042016-05-04 16:10:29 -070037 # Log into the local node once to get host key
38 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
39}
40
41function setup_openstack() {
42 # Run the playbook
Zack Williamsed9ced02016-05-24 06:37:04 -070043 ansible-playbook -i $INVENTORY cord-single-playbook.yml
Andy Bavier76349042016-05-04 16:10:29 -070044}
45
Andy Bavier9927f962016-05-20 14:09:36 -040046function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040047 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040048 echo "Checking out XOS branch $BUILD_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040049 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 -040050 ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"
Zack Williams97225f82016-05-24 08:23:37 -070051
Andy Bavier9927f962016-05-20 14:09:36 -040052 if [[ $EXAMPLESERVICE -eq 1 ]]
53 then
54 echo ""
55 echo "Adding exampleservice to XOS"
56 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
57 fi
Zack Williams97225f82016-05-24 08:23:37 -070058
Andy Bavier97faeec2016-05-10 13:23:04 -040059 echo "Rebuilding XOS containers"
60 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070061}
62
63function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070064
Andy Bavier76349042016-05-04 16:10:29 -070065 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070066 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070067 echo ""
68 echo "Pause 2 minutes"
69 sleep 120
70
Zack Williams3ecbfd02016-05-22 15:30:21 -070071 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070072 echo ""
73 echo "Pause 30 seconds"
74 sleep 30
75
Zack Williams3ecbfd02016-05-22 15:30:21 -070076 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Zack Williams455cec42016-05-25 16:07:36 -070077
78 if [[ $EXAMPLESERVICE -eq 1 ]]
79 then
80 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
81 fi
Andy Bavier76349042016-05-04 16:10:29 -070082}
83
84function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -070085 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -070086
87 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -070088 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -070089
90 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -070091 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
92 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -070093
94 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -070095 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
96 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
97 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
98 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier76349042016-05-04 16:10:29 -070099}
100
101function run_e2e_test() {
102 source ~/admin-openrc.sh
103
104 echo "*** Wait for vSG VM to come up"
105 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700106
Andy Bavier97faeec2016-05-10 13:23:04 -0400107 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700108 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400109 sleep 60
110 (( i += 1 ))
111 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700112 done
113
114 # get mgmt IP address
115 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
116 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
117
118 echo ""
119 echo "*** ssh into vsg VM, wait for Docker container to come up"
120 i=0
121 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
122 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400123 sleep 60
124 (( i += 1 ))
125 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700126 done
127
128 echo ""
129 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700130
Zack Williams3ecbfd02016-05-22 15:30:21 -0700131 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700132
133 echo ""
134 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700135 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700136
Andy Bavier76349042016-05-04 16:10:29 -0700137 echo ""
138 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700139 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700140
141 echo ""
142 if [ $? -eq 0 ]
143 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400144 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700145 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400146 echo "*** [FAILED] End-to-end connectivity test"
147 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700148 fi
149}
150
Andy Bavier97faeec2016-05-10 13:23:04 -0400151function run_exampleservice_test () {
152 source ~/admin-openrc.sh
153
154 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400155 echo "!!! NOTE that currently the VM will only be created after you login"
156 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400157 i=0
158 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
159 do
160 sleep 60
161 (( i += 1 ))
162 echo "Waited $i minutes"
163 done
164
165 # get mgmt IP address
166 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
167 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
168 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
169
170 echo ""
171 echo "*** ssh into exampleservice VM, wait for Apache come up"
172 i=0
173 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
174 do
175 sleep 60
176 (( i += 1 ))
177 echo "Waited $i minutes"
178 done
179
180
181 echo ""
182 echo "*** Install curl in test client"
183 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
184
185 echo ""
186 echo "*** Test connectivity to ExampleService from test client"
187 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
188}
189
Andy Bavier76349042016-05-04 16:10:29 -0700190# Parse options
191RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400192EXAMPLESERVICE=0
Andy Bavier9927f962016-05-20 14:09:36 -0400193BUILD_BRANCH=""
Zack Williamsed9ced02016-05-24 06:37:04 -0700194INVENTORY="inventory/single-localhost"
195
Zack Williams7bc0cbb2016-05-24 06:57:22 -0700196while getopts "b:ehi:t" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700197 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400198 b ) BUILD_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700199 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400200 e ) EXAMPLESERVICE=1
201 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400202 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700203 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
204 echo " $0 -b <branch> build XOS containers based on GitHub <branch> instead of pulling them from Docker Hub"
205 echo " $0 -e add exampleservice to XOS"
206 echo " $0 -h display this help message"
207 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
208 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400209 exit 0
210 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700211 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400212 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700213 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400214 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400215 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700216 exit 1
217 ;;
218 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400219done
220
Andy Bavier76349042016-05-04 16:10:29 -0700221# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700222if [[ $RUN_TEST -eq 1 ]]
223then
224 cleanup_from_previous_test
225fi
226
Andy Bavierf0001732016-05-05 09:21:49 -0700227set -e
228
Andy Bavier76349042016-05-04 16:10:29 -0700229bootstrap
230setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700231
232if [[ $RUN_TEST -eq 1 ]]
233then
Andy Bavier9927f962016-05-20 14:09:36 -0400234 if [[ -n $BUILD_BRANCH || $EXAMPLESERVICE -eq 1 ]]
Andy Bavier97faeec2016-05-10 13:23:04 -0400235 then
Andy Bavier9927f962016-05-20 14:09:36 -0400236 build_xos_docker_images
Andy Bavier97faeec2016-05-10 13:23:04 -0400237 fi
Andy Bavier76349042016-05-04 16:10:29 -0700238 setup_xos
239 setup_test_client
240 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400241 if [[ $EXAMPLESERVICE -eq 1 ]]
242 then
243 run_exampleservice_test
244 fi
Andy Bavier76349042016-05-04 16:10:29 -0700245fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400246
247exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700248