blob: a44b3d0c72dcf95335fe0c23cb21e3338ac18c97 [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() {
Zack Williamsf72e7b62016-06-02 09:57:23 -070049 # Run the playbook, but check to see if we're on cloudlab
50 if [[ -x /usr/testbed/bin/mkextrafs ]]
51 then
Zack Williams32d711d2016-06-02 10:53:30 -070052 ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="on_cloudlab=True"
Zack Williamsf72e7b62016-06-02 09:57:23 -070053 else
54 ansible-playbook -i $INVENTORY cord-single-playbook.yml
55 fi
Andy Bavier76349042016-05-04 16:10:29 -070056}
57
Andy Bavier9927f962016-05-20 14:09:36 -040058function build_xos_docker_images() {
Andy Bavier97faeec2016-05-10 13:23:04 -040059 echo ""
Andy Bavier9927f962016-05-20 14:09:36 -040060 echo "Checking out XOS branch $BUILD_BRANCH"
Andy Bavier97faeec2016-05-10 13:23:04 -040061 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 -040062 ssh ubuntu@xos "cd xos; git checkout $BUILD_BRANCH"
Zack Williams97225f82016-05-24 08:23:37 -070063
Andy Bavier9927f962016-05-20 14:09:36 -040064 if [[ $EXAMPLESERVICE -eq 1 ]]
65 then
66 echo ""
67 echo "Adding exampleservice to XOS"
68 ssh ubuntu@xos "cd xos; git cherry-pick 775e00549e535803522fbcd70152e5e1b0629c83"
69 fi
Zack Williams97225f82016-05-24 08:23:37 -070070
Andy Bavier97faeec2016-05-10 13:23:04 -040071 echo "Rebuilding XOS containers"
Zack Williams72a9ab42016-06-08 08:32:49 -070072 ssh ubuntu@xos "cd xos/containers/xos; make base"
Andy Bavier97faeec2016-05-10 13:23:04 -040073 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make local_containers"
Andy Bavier76349042016-05-04 16:10:29 -070074}
75
76function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070077
Andy Bavier76349042016-05-04 16:10:29 -070078 echo "Setting up XOS, will take a few minutes"
Zack Williams3ecbfd02016-05-22 15:30:21 -070079 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make"
Andy Bavier76349042016-05-04 16:10:29 -070080 echo ""
81 echo "Pause 2 minutes"
82 sleep 120
83
Zack Williams3ecbfd02016-05-22 15:30:21 -070084 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make vtn"
Andy Bavier76349042016-05-04 16:10:29 -070085 echo ""
86 echo "Pause 30 seconds"
87 sleep 30
88
Zack Williams3ecbfd02016-05-22 15:30:21 -070089 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make cord"
Zack Williams455cec42016-05-25 16:07:36 -070090
91 if [[ $EXAMPLESERVICE -eq 1 ]]
92 then
93 ssh ubuntu@xos "cd xos/xos/configurations/cord-pod; make exampleservice"
94 fi
Andy Bavier76349042016-05-04 16:10:29 -070095}
96
97function setup_test_client() {
Zack Williams3ecbfd02016-05-22 15:30:21 -070098 ssh ubuntu@nova-compute "sudo apt-get -y install lxc"
Andy Bavier76349042016-05-04 16:10:29 -070099
100 # Change default bridge
Zack Williams3ecbfd02016-05-22 15:30:21 -0700101 ssh ubuntu@nova-compute "sudo sed -i 's/lxcbr0/databr/' /etc/lxc/default.conf"
Andy Bavier76349042016-05-04 16:10:29 -0700102
103 # Create test client
Zack Williams3ecbfd02016-05-22 15:30:21 -0700104 ssh ubuntu@nova-compute "sudo lxc-create -t ubuntu -n testclient"
105 ssh ubuntu@nova-compute "sudo lxc-start -n testclient"
Andy Bavier76349042016-05-04 16:10:29 -0700106
107 # Configure network interface inside of test client with s-tag and c-tag
Zack Williams3ecbfd02016-05-22 15:30:21 -0700108 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0 name eth0.222 type vlan id 222"
109 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ip link add link eth0.222 name eth0.222.111 type vlan id 111"
110 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222 up"
111 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ifconfig eth0.222.111 up"
Andy Bavier76349042016-05-04 16:10:29 -0700112}
113
114function run_e2e_test() {
115 source ~/admin-openrc.sh
116
117 echo "*** Wait for vSG VM to come up"
118 i=0
Zack Williams961ffcd2016-05-20 07:03:35 -0700119
Andy Bavier97faeec2016-05-10 13:23:04 -0400120 until nova list --all-tenants|grep 'vsg.*ACTIVE' > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700121 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400122 sleep 60
123 (( i += 1 ))
124 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700125 done
126
127 # get mgmt IP address
128 ID=$( nova list --all-tenants|grep mysite_vsg|awk '{print $2}' )
129 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
130
131 echo ""
132 echo "*** ssh into vsg VM, wait for Docker container to come up"
133 i=0
134 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "sudo docker ps|grep vcpe" > /dev/null
135 do
Andy Bavier97faeec2016-05-10 13:23:04 -0400136 sleep 60
137 (( i += 1 ))
138 echo "Waited $i minutes"
Andy Bavier76349042016-05-04 16:10:29 -0700139 done
140
141 echo ""
142 echo "*** Run dhclient in test client"
Zack Williams961ffcd2016-05-20 07:03:35 -0700143
Zack Williams3ecbfd02016-05-22 15:30:21 -0700144 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- dhclient eth0.222.111" > /dev/null
Andy Bavier76349042016-05-04 16:10:29 -0700145
146 echo ""
147 echo "*** Routes in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700148 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- route -n"
Andy Bavier76349042016-05-04 16:10:29 -0700149
Andy Bavier76349042016-05-04 16:10:29 -0700150 echo ""
151 echo "*** Test external connectivity in test client"
Zack Williams3ecbfd02016-05-22 15:30:21 -0700152 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- ping -c 3 8.8.8.8"
Andy Bavier76349042016-05-04 16:10:29 -0700153
154 echo ""
155 if [ $? -eq 0 ]
156 then
Andy Bavier97faeec2016-05-10 13:23:04 -0400157 echo "*** [PASSED] End-to-end connectivity test"
Andy Bavier76349042016-05-04 16:10:29 -0700158 else
Andy Bavier97faeec2016-05-10 13:23:04 -0400159 echo "*** [FAILED] End-to-end connectivity test"
160 exit 1
Andy Bavier76349042016-05-04 16:10:29 -0700161 fi
162}
163
Andy Bavier97faeec2016-05-10 13:23:04 -0400164function run_exampleservice_test () {
165 source ~/admin-openrc.sh
166
167 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -0400168 echo "!!! NOTE that currently the VM will only be created after you login"
169 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -0400170 i=0
171 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
172 do
173 sleep 60
174 (( i += 1 ))
175 echo "Waited $i minutes"
176 done
177
178 # get mgmt IP address
179 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
180 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
181 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
182
183 echo ""
184 echo "*** ssh into exampleservice VM, wait for Apache come up"
185 i=0
186 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
187 do
188 sleep 60
189 (( i += 1 ))
190 echo "Waited $i minutes"
191 done
192
193
194 echo ""
195 echo "*** Install curl in test client"
196 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
197
198 echo ""
199 echo "*** Test connectivity to ExampleService from test client"
200 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
201}
202
Andy Bavier76349042016-05-04 16:10:29 -0700203# Parse options
204RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400205EXAMPLESERVICE=0
Zack Williams80d4f222016-06-01 15:42:03 -0700206BUILD_BRANCH="master"
Zack Williamsed9ced02016-05-24 06:37:04 -0700207INVENTORY="inventory/single-localhost"
208
Zack Williams7bc0cbb2016-05-24 06:57:22 -0700209while getopts "b:ehi:t" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700210 case ${opt} in
Andy Bavier9927f962016-05-20 14:09:36 -0400211 b ) BUILD_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700212 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400213 e ) EXAMPLESERVICE=1
214 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400215 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700216 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williams80d4f222016-06-01 15:42:03 -0700217 echo " $0 -b <branch> build XOS containers based on GitHub <branch>"
Zack Williamsed9ced02016-05-24 06:37:04 -0700218 echo " $0 -e add exampleservice to XOS"
219 echo " $0 -h display this help message"
220 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
221 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400222 exit 0
223 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700224 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400225 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700226 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400227 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400228 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700229 exit 1
230 ;;
231 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400232done
233
Andy Bavier76349042016-05-04 16:10:29 -0700234# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700235if [[ $RUN_TEST -eq 1 ]]
236then
237 cleanup_from_previous_test
238fi
239
Andy Bavierf0001732016-05-05 09:21:49 -0700240set -e
241
Andy Bavier76349042016-05-04 16:10:29 -0700242bootstrap
243setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700244
245if [[ $RUN_TEST -eq 1 ]]
246then
Zack Williams80d4f222016-06-01 15:42:03 -0700247 build_xos_docker_images
Andy Bavier76349042016-05-04 16:10:29 -0700248 setup_xos
249 setup_test_client
250 run_e2e_test
Andy Bavier97faeec2016-05-10 13:23:04 -0400251 if [[ $EXAMPLESERVICE -eq 1 ]]
252 then
253 run_exampleservice_test
254 fi
Andy Bavier76349042016-05-04 16:10:29 -0700255fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400256
257exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700258