blob: 9e505d49bd0265dc39961d8d36da59b2ca6e74e9 [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 Williams04106732016-06-27 20:55:32 -070042 sed -i "s/replaceme/`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() {
Andy Bavier3a1d0642016-07-01 14:11:39 -040050 cd ~/openstack-cluster-setup
Zack Williams1b2f1362016-06-20 09:57:34 -070051
Zack Williams7a5aa722016-07-01 19:51:40 -070052 extra_vars="xos_repo_url=$XOS_REPO_URL xos_repo_branch=$XOS_BRANCH"
Zack Williams1b2f1362016-06-20 09:57:34 -070053
54 # check if running on cloudlab
Zack Williamsf72e7b62016-06-02 09:57:23 -070055 if [[ -x /usr/testbed/bin/mkextrafs ]]
56 then
Zack Williams893e9c92016-06-20 13:40:32 -070057 extra_vars="$extra_vars on_cloudlab=True"
Zack Williamsf72e7b62016-06-02 09:57:23 -070058 fi
Zack Williams1b2f1362016-06-20 09:57:34 -070059
60 ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="$extra_vars"
Andy Bavier76349042016-05-04 16:10:29 -070061}
62
Andy Bavier76349042016-05-04 16:10:29 -070063function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070064
Andy Bavier3a1d0642016-07-01 14:11:39 -040065 ssh ubuntu@xos "cd service-profile/cord-pod; make cord-subscriber"
Zack Williams455cec42016-05-25 16:07:36 -070066
67 if [[ $EXAMPLESERVICE -eq 1 ]]
68 then
Scott Baker333a3152016-06-29 08:58:42 -070069 ssh ubuntu@xos "cd service-profile/cord-pod; make exampleservice"
Zack Williams455cec42016-05-25 16:07:36 -070070 fi
Andy Bavier0d0d0f72016-06-12 13:47:12 -040071
72 echo ""
73 echo "(Temp workaround for bug in Synchronizer) Pause 60 seconds"
74 sleep 60
Scott Baker333a3152016-06-29 08:58:42 -070075 ssh ubuntu@xos "cd service-profile/cord-pod; make vtn"
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 Bavier76349042016-05-04 16:10:29 -070093}
94
95function run_e2e_test() {
96 source ~/admin-openrc.sh
97
98 echo "*** Wait for vSG VM to come up"
99 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700100
Andy Bavier97faeec2016-05-10 13:23:04 -0400101 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700102 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400103 sleep 60
104 (( i += 1 ))
105 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700106 done
107
108 # get mgmt IP address
109 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
110 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
111
112 echo ""
113 echo "*** ssh into vsg VM, wait for Docker container to come up"
114 i=0
115 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
116 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400117 sleep 60
118 (( i += 1 ))
119 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700120 done
121
122 echo ""
123 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700124
Zack Williams3ecbfd02016-05-22 15:30:21 -0700125 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700126
127 echo ""
128 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700129 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700130
Andy Bavier76349042016-05-04 16:10:29 -0700131 echo ""
132 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700133 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700134
135 echo ""
136 if [ $? -eq 0 ]
137 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400138 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700139 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400140 echo "*** [FAILED] End-to-end connectivity test"
141 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700142 fi
143}
144
Andy Bavier97faeec2016-05-10 13:23:04 -0400145function run_exampleservice_test () {
146 source ~/admin-openrc.sh
147
148 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400149 echo "!!! NOTE that currently the VM will only be created after you login"
150 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400151 i=0
152 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
153 do
154 sleep 60
155 (( i += 1 ))
156 echo "Waited $i minutes"
157 done
158
159 # get mgmt IP address
160 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
161 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
162 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
163
164 echo ""
165 echo "*** ssh into exampleservice VM, wait for Apache come up"
166 i=0
167 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
168 do
169 sleep 60
170 (( i += 1 ))
171 echo "Waited $i minutes"
172 done
173
174
175 echo ""
176 echo "*** Install curl in test client"
177 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
178
179 echo ""
180 echo "*** Test connectivity to ExampleService from test client"
181 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
182}
183
Zack Williams04106732016-06-27 20:55:32 -0700184function run_diagnostics() {
185 echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node"
186 ansible-playbook -i $INVENTORY cord-diag-playbook.yml
187}
188
Andy Bavier76349042016-05-04 16:10:29 -0700189# Parse options
190RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400191EXAMPLESERVICE=0
Zack Williams02f252b2016-06-13 12:24:26 -0700192SETUP_BRANCH="master"
Zack Williamsed9ced02016-05-24 06:37:04 -0700193INVENTORY="inventory/single-localhost"
Zack Williams1b2f1362016-06-20 09:57:34 -0700194XOS_BRANCH="master"
195XOS_REPO_URL="https://gerrit.opencord.org/xos"
Zack Williams04106732016-06-27 20:55:32 -0700196DIAGNOSTICS=1
Zack Williamsed9ced02016-05-24 06:37:04 -0700197
Zack Williams04106732016-06-27 20:55:32 -0700198while getopts "b:dehi:r:ts:" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700199 case ${opt} in
Zack Williams1b2f1362016-06-20 09:57:34 -0700200 b ) XOS_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700201 ;;
Zack Williams04106732016-06-27 20:55:32 -0700202 d ) DIAGNOSTICS=0
203 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400204 e ) EXAMPLESERVICE=1
205 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400206 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700207 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williams02f252b2016-06-13 12:24:26 -0700208 echo " $0 -b <branch> build XOS containers using the <branch> branch of XOS git repo"
Zack Williams04106732016-06-27 20:55:32 -0700209 echo " $0 -d don't run diagnostic collector"
Zack Williamsed9ced02016-05-24 06:37:04 -0700210 echo " $0 -e add exampleservice to XOS"
211 echo " $0 -h display this help message"
212 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
Zack Williams1b2f1362016-06-20 09:57:34 -0700213 echo " $0 -r <url> use <url> to obtain the the XOS repo"
Zack Williamsed9ced02016-05-24 06:37:04 -0700214 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Zack Williams02f252b2016-06-13 12:24:26 -0700215 echo " $0 -s <branch> use branch <branch> of the openstack-cluster-setup git repo"
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 Williams1b2f1362016-06-20 09:57:34 -0700220 r ) XOS_REPO_URL=$OPTARG
221 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700222 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400223 ;;
Zack Williams02f252b2016-06-13 12:24:26 -0700224 s ) SETUP_BRANCH=$OPTARG
225 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400226 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700227 exit 1
228 ;;
229 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400230done
231
Andy Bavier76349042016-05-04 16:10:29 -0700232# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700233if [[ $RUN_TEST -eq 1 ]]
234then
235 cleanup_from_previous_test
236fi
237
Andy Bavierf0001732016-05-05 09:21:49 -0700238set -e
239
Andy Bavier76349042016-05-04 16:10:29 -0700240bootstrap
241setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700242
243if [[ $RUN_TEST -eq 1 ]]
244then
245 setup_xos
246 setup_test_client
247 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400248 if [[ $EXAMPLESERVICE -eq 1 ]]
249 then
250 run_exampleservice_test
251 fi
Andy Bavier76349042016-05-04 16:10:29 -0700252fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400253
Zack Williams04106732016-06-27 20:55:32 -0700254if [[ $DIAGNOSTICS -eq 1 ]]
Zack Williamsb82afd82016-06-28 09:59:29 -0700255then
Zack Williams04106732016-06-27 20:55:32 -0700256 run_diagnostics
257fi
258
Andy Bavier97faeec2016-05-10 13:23:04 -0400259exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700260