blob: 448910e2aca4600b0dac576e9bd076477b331268 [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 Williams4e5d1d22016-06-13 11:10:03 -070030 sudo apt-get -y install software-properties-common curl git mosh tmux dnsutils python-netaddr
Zack Williams65b72c82016-05-21 21:52:46 -070031 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
Zack Williams02f252b2016-06-13 12:24:26 -070040 git checkout $SETUP_BRANCH
Andy Bavierea5b44c2016-04-08 16:12:30 -040041
Zack Williams7e19a8a2016-05-24 06:42:47 -070042 sed -i "s/ubuntu/`whoami`/" $INVENTORY
Zack Williams65b72c82016-05-21 21:52:46 -070043 cp vars/example_keystone.yml vars/cord_keystone.yml
Andy Bavierea5b44c2016-04-08 16:12:30 -040044
Andy Bavier76349042016-05-04 16:10:29 -070045 # Log into the local node once to get host key
46 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
47}
48
49function setup_openstack() {
Zack Williams1b2f1362016-06-20 09:57:34 -070050
51 extra_vars="xos_repo_url=$XOS_REPO_URL"
52
53 # check if running on cloudlab
Zack Williamsf72e7b62016-06-02 09:57:23 -070054 if [[ -x /usr/testbed/bin/mkextrafs ]]
55 then
Zack Williams1b2f1362016-06-20 09:57:34 -070056 extra_vars="$extra_vars,on_cloudlab=True"
Zack Williamsf72e7b62016-06-02 09:57:23 -070057 fi
Zack Williams1b2f1362016-06-20 09:57:34 -070058
59 ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="$extra_vars"
Andy Bavier76349042016-05-04 16:10:29 -070060}
61
Andy Bavier9927f962016-05-20 14:09:36 -040062function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040063 echo ""
Zack Williams1b2f1362016-06-20 09:57:34 -070064 echo "Checking out XOS branch $XOS_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040065 ssh ubuntu@xos "cd xos; git config --global user.email 'ubuntu@localhost'; git config --global user.name 'XOS ExampleService'"
Zack Williams1b2f1362016-06-20 09:57:34 -070066 ssh ubuntu@xos "cd xos; git checkout $XOS_BRANCH"
Zack Williams97225f82016-05-24 08:23:37 -070067
Andy Bavier97faeec2016-05-10 13:23:04 -040068 echo "Rebuilding XOS containers"
Zack Williams72a9ab42016-06-08 08:32:49 -070069 ssh ubuntu@xos "cd xos/containers/xos; make base"
Andy Bavier97faeec2016-05-10 13:23:04 -040070 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070071}
72
73function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070074
Andy Bavier76349042016-05-04 16:10:29 -070075 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070076 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070077 echo ""
78 echo "Pause 2 minutes"
79 sleep 120
80
Andy Bavierada2b3b2016-06-12 10:33:01 -040081 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn; make fabric"
Andy Bavier76349042016-05-04 16:10:29 -070082 echo ""
83 echo "Pause 30 seconds"
84 sleep 30
85
Andy Bavier0d0d0f72016-06-12 13:47:12 -040086 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Zack Williams455cec42016-05-25 16:07:36 -070087
88 if [[ $EXAMPLESERVICE -eq 1 ]]
89 then
90 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
91 fi
Andy Bavier0d0d0f72016-06-12 13:47:12 -040092
93 echo ""
94 echo "(Temp workaround for bug in Synchronizer) Pause 60 seconds"
95 sleep 60
96 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070097}
98
99function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -0700100 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -0700101
102 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -0700103 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -0700104
105 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -0700106 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
107 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -0700108
109 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -0700110 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
111 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
112 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
113 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier76349042016-05-04 16:10:29 -0700114}
115
116function run_e2e_test() {
117 source ~/admin-openrc.sh
118
119 echo "*** Wait for vSG VM to come up"
120 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700121
Andy Bavier97faeec2016-05-10 13:23:04 -0400122 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700123 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 # get mgmt IP address
130 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
131 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
132
133 echo ""
134 echo "*** ssh into vsg VM, wait for Docker container to come up"
135 i=0
136 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
137 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400138 sleep 60
139 (( i += 1 ))
140 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700141 done
142
143 echo ""
144 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700145
Zack Williams3ecbfd02016-05-22 15:30:21 -0700146 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700147
148 echo ""
149 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700150 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700151
Andy Bavier76349042016-05-04 16:10:29 -0700152 echo ""
153 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700154 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700155
156 echo ""
157 if [ $? -eq 0 ]
158 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400159 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700160 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400161 echo "*** [FAILED] End-to-end connectivity test"
162 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700163 fi
164}
165
Andy Bavier97faeec2016-05-10 13:23:04 -0400166function run_exampleservice_test () {
167 source ~/admin-openrc.sh
168
169 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400170 echo "!!! NOTE that currently the VM will only be created after you login"
171 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400172 i=0
173 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
174 do
175 sleep 60
176 (( i += 1 ))
177 echo "Waited $i minutes"
178 done
179
180 # get mgmt IP address
181 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
182 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
183 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
184
185 echo ""
186 echo "*** ssh into exampleservice VM, wait for Apache come up"
187 i=0
188 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
189 do
190 sleep 60
191 (( i += 1 ))
192 echo "Waited $i minutes"
193 done
194
195
196 echo ""
197 echo "*** Install curl in test client"
198 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
199
200 echo ""
201 echo "*** Test connectivity to ExampleService from test client"
202 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
203}
204
Andy Bavier76349042016-05-04 16:10:29 -0700205# Parse options
206RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400207EXAMPLESERVICE=0
Zack Williams02f252b2016-06-13 12:24:26 -0700208SETUP_BRANCH="master"
Zack Williamsed9ced02016-05-24 06:37:04 -0700209INVENTORY="inventory/single-localhost"
Zack Williams1b2f1362016-06-20 09:57:34 -0700210XOS_BRANCH="master"
211XOS_REPO_URL="https://gerrit.opencord.org/xos"
Zack Williamsed9ced02016-05-24 06:37:04 -0700212
Zack Williams1b2f1362016-06-20 09:57:34 -0700213while getopts "b:ehi:r:ts:" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700214 case ${opt} in
Zack Williams1b2f1362016-06-20 09:57:34 -0700215 b ) XOS_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700216 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400217 e ) EXAMPLESERVICE=1
218 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400219 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700220 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williams02f252b2016-06-13 12:24:26 -0700221 echo " $0 -b <branch> build XOS containers using the <branch> branch of XOS git repo"
Zack Williamsed9ced02016-05-24 06:37:04 -0700222 echo " $0 -e add exampleservice to XOS"
223 echo " $0 -h display this help message"
224 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
Zack Williams1b2f1362016-06-20 09:57:34 -0700225 echo " $0 -r <url> use <url> to obtain the the XOS repo"
Zack Williamsed9ced02016-05-24 06:37:04 -0700226 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Zack Williams02f252b2016-06-13 12:24:26 -0700227 echo " $0 -s <branch> use branch <branch> of the openstack-cluster-setup git repo"
Andy Baviercb024332016-04-29 15:52:26 -0400228 exit 0
229 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700230 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400231 ;;
Zack Williams1b2f1362016-06-20 09:57:34 -0700232 r ) XOS_REPO_URL=$OPTARG
233 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700234 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400235 ;;
Zack Williams02f252b2016-06-13 12:24:26 -0700236 s ) SETUP_BRANCH=$OPTARG
237 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400238 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700239 exit 1
240 ;;
241 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400242done
243
Andy Bavier76349042016-05-04 16:10:29 -0700244# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700245if [[ $RUN_TEST -eq 1 ]]
246then
247 cleanup_from_previous_test
248fi
249
Andy Bavierf0001732016-05-05 09:21:49 -0700250set -e
251
Andy Bavier76349042016-05-04 16:10:29 -0700252bootstrap
253setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700254
255if [[ $RUN_TEST -eq 1 ]]
256then
Zack Williams80d4f222016-06-01 15:42:03 -0700257 build_xos_docker_images
Andy Bavier76349042016-05-04 16:10:29 -0700258 setup_xos
259 setup_test_client
260 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400261 if [[ $EXAMPLESERVICE -eq 1 ]]
262 then
263 run_exampleservice_test
264 fi
Andy Bavier76349042016-05-04 16:10:29 -0700265fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400266
267exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700268