blob: a7c7b1c4cd08e71aa16c869a16fcd182e4f0bc37 [file] [log] [blame]
Andy Baviere92f3da2016-07-27 10:38:13 -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
Zack Williams79139902016-09-05 22:33:40 -070020 rm -rf ~/cord_apps
Zack Williamsa1a68032016-09-05 22:26:02 -070021 rm -rf ~/.ansible_async
Andy Bavier0acc3642016-05-04 16:17:07 -070022
Zack Williams5028fb42016-06-01 14:52:29 -070023 echo "Cleaning up libvirt/dnsmasq"
Zack Williams17508be2016-05-31 21:52:35 -070024 sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases
25 sudo killall dnsmasq
Zack Williams5028fb42016-06-01 14:52:29 -070026 sudo service libvirt-bin restart
Andy Bavier0acc3642016-05-04 16:17:07 -070027}
28
Andy Bavier76349042016-05-04 16:10:29 -070029function bootstrap() {
30 cd ~
31 sudo apt-get update
Zack Williams35624562016-08-28 17:12:26 -070032 sudo apt-get -y install software-properties-common curl git tmux dnsutils python-netaddr python-dnspython
Zack Williams65b72c82016-05-21 21:52:46 -070033 sudo add-apt-repository -y ppa:ansible/ansible
34 sudo apt-get update
35 sudo apt-get install -y ansible
36
37 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
38 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
39
Andy Bavier00467ab2016-08-04 14:41:21 -040040 [ -d ~/platform-install ] || git clone -b $SETUP_BRANCH $SETUP_REPO_URL ~/platform-install
Zack Williamsa3e40562016-07-05 12:05:39 -070041 cd ~/platform-install
Andy Bavierea5b44c2016-04-08 16:12:30 -040042
Zack Williams04106732016-06-27 20:55:32 -070043 sed -i "s/replaceme/`whoami`/" $INVENTORY
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 Williamsa3e40562016-07-05 12:05:39 -070050 cd ~/platform-install
Zack Williams1b2f1362016-06-20 09:57:34 -070051
Scott Baker55a0b882016-07-25 16:05:05 -070052 extra_vars="single_node_pod_script=true"
53
54 if [[ "$XOS_REPO_URL" != "" ]]; then
55 extra_vars="$extra_vars xos_repo_url=$XOS_REPO_URL"
56 fi
Zack Williams35624562016-08-28 17:12:26 -070057 if [[ "$XOS_BRANCH" != "" ]]; then
Scott Baker55a0b882016-07-25 16:05:05 -070058 extra_vars="$extra_vars xos_repo_branch=$XOS_BRANCH"
59 fi
Zack Williams1b2f1362016-06-20 09:57:34 -070060
61 # check if running on cloudlab
Zack Williamsf72e7b62016-06-02 09:57:23 -070062 if [[ -x /usr/testbed/bin/mkextrafs ]]
63 then
Zack Williams893e9c92016-06-20 13:40:32 -070064 extra_vars="$extra_vars on_cloudlab=True"
Zack Williamsf72e7b62016-06-02 09:57:23 -070065 fi
Zack Williams1b2f1362016-06-20 09:57:34 -070066
67 ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="$extra_vars"
Andy Bavier76349042016-05-04 16:10:29 -070068}
69
Andy Baviera27effe2016-07-18 19:23:26 -040070function run_e2e_test () {
71 ansible-playbook -i $INVENTORY cord-post-deploy-playbook.yml
Andy Bavier76349042016-05-04 16:10:29 -070072}
73
Zack Williams04106732016-06-27 20:55:32 -070074function run_diagnostics() {
75 echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node"
76 ansible-playbook -i $INVENTORY cord-diag-playbook.yml
77}
78
Andy Bavier76349042016-05-04 16:10:29 -070079# Parse options
80RUN_TEST=0
Zack Williams02f252b2016-06-13 12:24:26 -070081SETUP_BRANCH="master"
Zack Williamsa3e40562016-07-05 12:05:39 -070082SETUP_REPO_URL="https://github.com/opencord/platform-install"
Zack Williamsed9ced02016-05-24 06:37:04 -070083INVENTORY="inventory/single-localhost"
Zack Williams04106732016-06-27 20:55:32 -070084DIAGNOSTICS=1
Andy Bavier8a7b8b62016-07-26 18:35:06 -040085CLEANUP=0
Zack Williamsed9ced02016-05-24 06:37:04 -070086
Andy Bavier6494da92016-07-26 18:43:44 -040087while getopts "b:cdehi:p:r:ts:" opt; do
Andy Bavier76349042016-05-04 16:10:29 -070088 case ${opt} in
Zack Williams1b2f1362016-06-20 09:57:34 -070089 b ) XOS_BRANCH=$OPTARG
Andy Bavier76349042016-05-04 16:10:29 -070090 ;;
Andy Bavier8a7b8b62016-07-26 18:35:06 -040091 c ) CLEANUP=1
Zack Williams04106732016-06-27 20:55:32 -070092 ;;
Andy Bavier8a7b8b62016-07-26 18:35:06 -040093 d ) DIAGNOSTICS=0
Andy Bavier97faeec2016-05-10 13:23:04 -040094 ;;
Andy Bavier9927f962016-05-20 14:09:36 -040095 h ) echo "Usage:"
Zack Williamsed9ced02016-05-24 06:37:04 -070096 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
Zack Williamsa3e40562016-07-05 12:05:39 -070097 echo " $0 -b <branch> checkout <branch> of the xos git repo"
Andy Bavier8a7b8b62016-07-26 18:35:06 -040098 echo " $0 -c cleanup from previous test"
Zack Williams04106732016-06-27 20:55:32 -070099 echo " $0 -d don't run diagnostic collector"
Zack Williamsed9ced02016-05-24 06:37:04 -0700100 echo " $0 -h display this help message"
101 echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)"
Zack Williamsa3e40562016-07-05 12:05:39 -0700102 echo " $0 -p <git_url> use <git_url> to obtain the platform-install git repo"
103 echo " $0 -r <git_url> use <git_url> to obtain the xos git repo"
104 echo " $0 -s <branch> checkout <branch> of the platform-install git repo"
Zack Williamsed9ced02016-05-24 06:37:04 -0700105 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
Andy Baviercb024332016-04-29 15:52:26 -0400106 exit 0
107 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700108 i ) INVENTORY=$OPTARG
Andy Baviercb024332016-04-29 15:52:26 -0400109 ;;
Zack Williamsa3e40562016-07-05 12:05:39 -0700110 p ) SETUP_REPO_URL=$OPTARG
111 ;;
Zack Williams1b2f1362016-06-20 09:57:34 -0700112 r ) XOS_REPO_URL=$OPTARG
113 ;;
Zack Williamsed9ced02016-05-24 06:37:04 -0700114 t ) RUN_TEST=1
Andy Baviercb024332016-04-29 15:52:26 -0400115 ;;
Zack Williams02f252b2016-06-13 12:24:26 -0700116 s ) SETUP_BRANCH=$OPTARG
117 ;;
Andy Bavier9927f962016-05-20 14:09:36 -0400118 \? ) echo "Invalid option: -$OPTARG"
Andy Bavier76349042016-05-04 16:10:29 -0700119 exit 1
120 ;;
121 esac
Andy Bavierea5b44c2016-04-08 16:12:30 -0400122done
123
Andy Bavier76349042016-05-04 16:10:29 -0700124# What to do
Andy Bavier8a7b8b62016-07-26 18:35:06 -0400125if [[ $CLEANUP -eq 1 ]]
Andy Bavier0acc3642016-05-04 16:17:07 -0700126then
127 cleanup_from_previous_test
128fi
129
Andy Bavierf0001732016-05-05 09:21:49 -0700130set -e
131
Andy Bavier76349042016-05-04 16:10:29 -0700132bootstrap
133setup_openstack
Andy Bavier76349042016-05-04 16:10:29 -0700134
135if [[ $RUN_TEST -eq 1 ]]
136then
Andy Bavier76349042016-05-04 16:10:29 -0700137 run_e2e_test
138fi
Andy Bavier97faeec2016-05-10 13:23:04 -0400139
Zack Williams04106732016-06-27 20:55:32 -0700140if [[ $DIAGNOSTICS -eq 1 ]]
Zack Williamsb82afd82016-06-28 09:59:29 -0700141then
Zack Williams04106732016-06-27 20:55:32 -0700142 run_diagnostics
143fi
144
Andy Bavier97faeec2016-05-10 13:23:04 -0400145exit 0
Zack Williams961ffcd2016-05-20 07:03:35 -0700146