Andy Bavier | e92f3da | 2016-07-27 10:38:13 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 2 | |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 3 | function cleanup_from_previous_test() { |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 4 | echo "## Cleanup ##" |
5 | |||||
6 | echo "Destroying juju environment" | ||||
7 | juju destroy-environment --force -y manual | ||||
8 | |||||
Andy Bavier | de3f467 | 2016-06-01 17:02:42 -0400 | [diff] [blame] | 9 | VMS=$( sudo uvt-kvm list ) |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 10 | for VM in $VMS |
11 | do | ||||
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 12 | echo "Destroying $VM" |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 13 | sudo uvt-kvm destroy $VM |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 14 | done |
15 | |||||
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 16 | echo "Cleaning up files" |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 17 | rm -rf ~/.juju |
18 | rm -f ~/.ssh/known_hosts | ||||
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 19 | rm -rf ~/platform-install |
Zack Williams | 7913990 | 2016-09-05 22:33:40 -0700 | [diff] [blame] | 20 | rm -rf ~/cord_apps |
Zack Williams | a1a6803 | 2016-09-05 22:26:02 -0700 | [diff] [blame] | 21 | rm -rf ~/.ansible_async |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 22 | |
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 23 | echo "Cleaning up libvirt/dnsmasq" |
Zack Williams | 17508be | 2016-05-31 21:52:35 -0700 | [diff] [blame] | 24 | sudo rm -f /var/lib/libvirt/dnsmasq/xos-mgmtbr.leases |
25 | sudo killall dnsmasq | ||||
Zack Williams | 5028fb4 | 2016-06-01 14:52:29 -0700 | [diff] [blame] | 26 | sudo service libvirt-bin restart |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 27 | } |
28 | |||||
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 29 | function bootstrap() { |
30 | cd ~ | ||||
31 | sudo apt-get update | ||||
Zack Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 32 | sudo apt-get -y install software-properties-common curl git tmux dnsutils python-netaddr python-dnspython |
Zack Williams | 65b72c8 | 2016-05-21 21:52:46 -0700 | [diff] [blame] | 33 | 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 Bavier | 00467ab | 2016-08-04 14:41:21 -0400 | [diff] [blame] | 40 | [ -d ~/platform-install ] || git clone -b $SETUP_BRANCH $SETUP_REPO_URL ~/platform-install |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 41 | cd ~/platform-install |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 42 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 43 | sed -i "s/replaceme/`whoami`/" $INVENTORY |
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 44 | |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 45 | # Log into the local node once to get host key |
46 | ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null" | ||||
47 | } | ||||
48 | |||||
49 | function setup_openstack() { | ||||
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 50 | cd ~/platform-install |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 51 | |
Scott Baker | 55a0b88 | 2016-07-25 16:05:05 -0700 | [diff] [blame] | 52 | 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 Williams | 3562456 | 2016-08-28 17:12:26 -0700 | [diff] [blame] | 57 | if [[ "$XOS_BRANCH" != "" ]]; then |
Scott Baker | 55a0b88 | 2016-07-25 16:05:05 -0700 | [diff] [blame] | 58 | extra_vars="$extra_vars xos_repo_branch=$XOS_BRANCH" |
59 | fi | ||||
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 60 | |
61 | # check if running on cloudlab | ||||
Zack Williams | f72e7b6 | 2016-06-02 09:57:23 -0700 | [diff] [blame] | 62 | if [[ -x /usr/testbed/bin/mkextrafs ]] |
63 | then | ||||
Zack Williams | 893e9c9 | 2016-06-20 13:40:32 -0700 | [diff] [blame] | 64 | extra_vars="$extra_vars on_cloudlab=True" |
Zack Williams | f72e7b6 | 2016-06-02 09:57:23 -0700 | [diff] [blame] | 65 | fi |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 66 | |
67 | ansible-playbook -i $INVENTORY cord-single-playbook.yml --extra-vars="$extra_vars" | ||||
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 68 | } |
69 | |||||
Andy Bavier | a27effe | 2016-07-18 19:23:26 -0400 | [diff] [blame] | 70 | function run_e2e_test () { |
71 | ansible-playbook -i $INVENTORY cord-post-deploy-playbook.yml | ||||
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 72 | } |
73 | |||||
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 74 | function 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 Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 79 | # Parse options |
80 | RUN_TEST=0 | ||||
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 81 | SETUP_BRANCH="master" |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 82 | SETUP_REPO_URL="https://github.com/opencord/platform-install" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 83 | INVENTORY="inventory/single-localhost" |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 84 | DIAGNOSTICS=1 |
Andy Bavier | 8a7b8b6 | 2016-07-26 18:35:06 -0400 | [diff] [blame] | 85 | CLEANUP=0 |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 86 | |
Andy Bavier | 6494da9 | 2016-07-26 18:43:44 -0400 | [diff] [blame] | 87 | while getopts "b:cdehi:p:r:ts:" opt; do |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 88 | case ${opt} in |
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 89 | b ) XOS_BRANCH=$OPTARG |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 90 | ;; |
Andy Bavier | 8a7b8b6 | 2016-07-26 18:35:06 -0400 | [diff] [blame] | 91 | c ) CLEANUP=1 |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 92 | ;; |
Andy Bavier | 8a7b8b6 | 2016-07-26 18:35:06 -0400 | [diff] [blame] | 93 | d ) DIAGNOSTICS=0 |
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 94 | ;; |
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 95 | h ) echo "Usage:" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 96 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 97 | echo " $0 -b <branch> checkout <branch> of the xos git repo" |
Andy Bavier | 8a7b8b6 | 2016-07-26 18:35:06 -0400 | [diff] [blame] | 98 | echo " $0 -c cleanup from previous test" |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 99 | echo " $0 -d don't run diagnostic collector" |
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 100 | echo " $0 -h display this help message" |
101 | echo " $0 -i <inv_file> specify an inventory file (default is inventory/single-localhost)" | ||||
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 102 | 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 Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 105 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 106 | exit 0 |
107 | ;; | ||||
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 108 | i ) INVENTORY=$OPTARG |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 109 | ;; |
Zack Williams | a3e4056 | 2016-07-05 12:05:39 -0700 | [diff] [blame] | 110 | p ) SETUP_REPO_URL=$OPTARG |
111 | ;; | ||||
Zack Williams | 1b2f136 | 2016-06-20 09:57:34 -0700 | [diff] [blame] | 112 | r ) XOS_REPO_URL=$OPTARG |
113 | ;; | ||||
Zack Williams | ed9ced0 | 2016-05-24 06:37:04 -0700 | [diff] [blame] | 114 | t ) RUN_TEST=1 |
Andy Bavier | cb02433 | 2016-04-29 15:52:26 -0400 | [diff] [blame] | 115 | ;; |
Zack Williams | 02f252b | 2016-06-13 12:24:26 -0700 | [diff] [blame] | 116 | s ) SETUP_BRANCH=$OPTARG |
117 | ;; | ||||
Andy Bavier | 9927f96 | 2016-05-20 14:09:36 -0400 | [diff] [blame] | 118 | \? ) echo "Invalid option: -$OPTARG" |
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 119 | exit 1 |
120 | ;; | ||||
121 | esac | ||||
Andy Bavier | ea5b44c | 2016-04-08 16:12:30 -0400 | [diff] [blame] | 122 | done |
123 | |||||
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 124 | # What to do |
Andy Bavier | 8a7b8b6 | 2016-07-26 18:35:06 -0400 | [diff] [blame] | 125 | if [[ $CLEANUP -eq 1 ]] |
Andy Bavier | 0acc364 | 2016-05-04 16:17:07 -0700 | [diff] [blame] | 126 | then |
127 | cleanup_from_previous_test | ||||
128 | fi | ||||
129 | |||||
Andy Bavier | f000173 | 2016-05-05 09:21:49 -0700 | [diff] [blame] | 130 | set -e |
131 | |||||
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 132 | bootstrap |
133 | setup_openstack | ||||
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 134 | |
135 | if [[ $RUN_TEST -eq 1 ]] | ||||
136 | then | ||||
Andy Bavier | 7634904 | 2016-05-04 16:10:29 -0700 | [diff] [blame] | 137 | run_e2e_test |
138 | fi | ||||
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 139 | |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 140 | if [[ $DIAGNOSTICS -eq 1 ]] |
Zack Williams | b82afd8 | 2016-06-28 09:59:29 -0700 | [diff] [blame] | 141 | then |
Zack Williams | 0410673 | 2016-06-27 20:55:32 -0700 | [diff] [blame] | 142 | run_diagnostics |
143 | fi | ||||
144 | |||||
Andy Bavier | 97faeec | 2016-05-10 13:23:04 -0400 | [diff] [blame] | 145 | exit 0 |
Zack Williams | 961ffcd | 2016-05-20 07:03:35 -0700 | [diff] [blame] | 146 |