blob: 789a879e1ba23c6e8861e95c62282fa9f6ff00db [file] [log] [blame]
Andy Bavier2c0ec052016-07-18 19:23:26 -04001!/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
Zack Williamsa3e40562016-07-05 12:05:39 -070019 rm -rf ~/platform-install
Andy Bavier0acc3642016-05-04 16:17:07 -070020
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
Zack Williamsa3e40562016-07-05 12:05:39 -070038 git clone $SETUP_REPO_URL platform-install
39 cd ~/platform-install
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
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 Williamsa3e40562016-07-05 12:05:39 -070049 cd ~/platform-install
Zack Williams1b2f1362016-06-20 09:57:34 -070050
Zack Williams7a5aa722016-07-01 19:51:40 -070051 extra_vars="xos_repo_url=$XOS_REPO_URL xos_repo_branch=$XOS_BRANCH"
Zack Williams1b2f1362016-06-20 09:57:34 -070052
53 # check if running on cloudlab
Zack Williamsf72e7b62016-06-02 09:57:23 -070054 if [[ -x /usr/testbed/bin/mkextrafs ]]
55 then
Zack Williams893e9c92016-06-20 13:40:32 -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 Bavier76349042016-05-04 16:10:29 -070062function setup_xos() {
Zack Williamsd78bbb42016-05-23 08:53:20 -070063
Zack Williams455cec42016-05-25 16:07:36 -070064 if [[ $EXAMPLESERVICE -eq 1 ]]
65 then
Scott Baker333a3152016-06-29 08:58:42 -070066 ssh ubuntu@xos "cd service-profile/cord-pod; make exampleservice"
Andy Bavier2c0ec052016-07-18 19:23:26 -040067
68 echo "(Temp workaround for bug in Synchronizer) Pause 60 seconds"
69 sleep 60
70 ssh ubuntu@xos "cd service-profile/cord-pod; make vtn"
Zack Williams455cec42016-05-25 16:07:36 -070071 fi
Andy Bavier0d0d0f72016-06-12 13:47:12 -040072
Andy Bavier76349042016-05-04 16:10:29 -070073}
74
Andy Bavier2c0ec052016-07-18 19:23:26 -040075function run_e2e_test () {
76 ansible-playbook -i $INVENTORY cord-post-deploy-playbook.yml
Andy Bavier76349042016-05-04 16:10:29 -070077}
78
Andy Bavier97faeec2016-05-10 13:23:04 -040079function run_exampleservice_test () {
80 source ~/admin-openrc.sh
81
82 echo "*** Wait for exampleservice VM to come up."
Andy Bavier9927f962016-05-20 14:09:36 -040083 echo "!!! NOTE that currently the VM will only be created after you login"
84 echo "!!! to XOS and manually create an ExampleService tenant."
Andy Bavier97faeec2016-05-10 13:23:04 -040085 i=0
86 until nova list --all-tenants|grep exampleservice.*ACTIVE > /dev/null
87 do
88 sleep 60
89 (( i += 1 ))
90 echo "Waited $i minutes"
91 done
92
93 # get mgmt IP address
94 ID=$( nova list --all-tenants|grep mysite_exampleservice|awk '{print $2}' )
95 MGMTIP=$( nova interface-list $ID|grep 172.27|awk '{print $8}' )
96 PUBLICIP=$( nova interface-list $ID|grep 10.168|awk '{print $8}' )
97
98 echo ""
99 echo "*** ssh into exampleservice VM, wait for Apache come up"
100 i=0
101 until ssh -o ProxyCommand="ssh -W %h:%p ubuntu@nova-compute" ubuntu@$MGMTIP "ls /var/run/apache2/apache2.pid"
102 do
103 sleep 60
104 (( i += 1 ))
105 echo "Waited $i minutes"
106 done
107
108
109 echo ""
110 echo "*** Install curl in test client"
111 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- apt-get -y install curl"
112
113 echo ""
114 echo "*** Test connectivity to ExampleService from test client"
115 ssh ubuntu@nova-compute "sudo lxc-attach -n testclient -- curl -s http://$PUBLICIP"
116}
117
Zack Williams04106732016-06-27 20:55:32 -0700118function run_diagnostics() {
119 echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node"
120 ansible-playbook -i $INVENTORY cord-diag-playbook.yml
121}
122
Andy Bavier76349042016-05-04 16:10:29 -0700123# Parse options
124RUN_TEST=0
Andy Bavier97faeec2016-05-10 13:23:04 -0400125EXAMPLESERVICE=0
Zack Williams02f252b2016-06-13 12:24:26 -0700126SETUP_BRANCH="master"
Zack Williamsa3e40562016-07-05 12:05:39 -0700127SETUP_REPO_URL="https://github.com/opencord/platform-install"
Zack Williamsed9ced02016-05-24 06:37:04 -0700128INVENTORY="inventory/single-localhost"
Zack Williams1b2f1362016-06-20 09:57:34 -0700129XOS_BRANCH="master"
Zack Williamsa3e40562016-07-05 12:05:39 -0700130XOS_REPO_URL="https://github.com/opencord/xos"
Zack Williams04106732016-06-27 20:55:32 -0700131DIAGNOSTICS=1
Zack Williamsed9ced02016-05-24 06:37:04 -0700132
Zack Williamsa3e40562016-07-05 12:05:39 -0700133while getopts "b:dehi:p:r:ts:" opt; do
Andy Bavier76349042016-05-04 16:10:29 -0700134 case ${opt} in
Zack Williams1b2f1362016-06-20 09:57:34 -0700135 b ) XOS_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -0700136 ;;
Zack Williams04106732016-06-27 20:55:32 -0700137 d ) DIAGNOSTICS=0
138 ;;
Andy Bavier97faeec2016-05-10 13:23:04 -0400139 e ) EXAMPLESERVICE=1
140 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400141 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -0700142 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsa3e40562016-07-05 12:05:39 -0700143 echo " $0 -b <branch> checkout <branch> of the xos git repo"
Zack Williams04106732016-06-27 20:55:32 -0700144 echo " $0 -d don't run diagnostic collector"
Zack Williamsed9ced02016-05-24 06:37:04 -0700145 echo " $0 -e add exampleservice to XOS"
146 echo " $0 -h display this help message"
147 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
Zack Williamsa3e40562016-07-05 12:05:39 -0700148 echo " $0 -p <git_url> use <git_url> to obtain the platform-install git repo"
149 echo " $0 -r <git_url> use <git_url> to obtain the xos git repo"
150 echo " $0 -s <branch> checkout <branch> of the platform-install git repo"
Zack Williamsed9ced02016-05-24 06:37:04 -0700151 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400152 exit 0
153 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700154 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400155 ;;
Zack Williamsa3e40562016-07-05 12:05:39 -0700156 p ) SETUP_REPO_URL=$OPTARG
157 ;;
Zack Williams1b2f1362016-06-20 09:57:34 -0700158 r ) XOS_REPO_URL=$OPTARG
159 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700160 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400161 ;;
Zack Williams02f252b2016-06-13 12:24:26 -0700162 s ) SETUP_BRANCH=$OPTARG
163 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400164 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700165 exit 1
166 ;;
167 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400168done
169
Andy Bavier76349042016-05-04 16:10:29 -0700170# What to do
Andy Bavier0acc3642016-05-04 16:17:07 -0700171if [[ $RUN_TEST -eq 1 ]]
172then
173 cleanup_from_previous_test
174fi
175
Andy Bavierf0001732016-05-05 09:21:49 -0700176set -e
177
Andy Bavier76349042016-05-04 16:10:29 -0700178bootstrap
179setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700180
181if [[ $RUN_TEST -eq 1 ]]
182then
Andy Bavier76349042016-05-04 16:10:29 -0700183 run_e2e_test
Andy Bavier2c0ec052016-07-18 19:23:26 -0400184
Andy Bavier97faeec2016-05-10 13:23:04 -0400185 if [[ $EXAMPLESERVICE -eq 1 ]]
186 then
Andy Bavier2c0ec052016-07-18 19:23:26 -0400187 setup_xos
Andy Bavier97faeec2016-05-10 13:23:04 -0400188 run_exampleservice_test
189 fi
Andy Bavier76349042016-05-04 16:10:29 -0700190fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400191
Zack Williams04106732016-06-27 20:55:32 -0700192if [[ $DIAGNOSTICS -eq 1 ]]
Zack Williamsb82afd82016-06-28 09:59:29 -0700193then
Zack Williams04106732016-06-27 20:55:32 -0700194 run_diagnostics
195fi
196
Andy Bavier97faeec2016-05-10 13:23:04 -0400197exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700198