blob: 82dffacd684cb02b71fb078590fef6894967c9b0 [file] [log] [blame]
Andy Bavier99c11d32016-09-14 17:21:20 -04001#!/usr/bin/env bash
2
3set -e
4set -x
5
6CORDDIR=~/opencord
7VMDIR=/cord/build/
8CONFIG=config/cord_in_a_box.yml
9
10function cleanup_from_previous_test() {
11 set +e
12
13 echo "## Cleanup ##"
14
15 echo "Shutting down all Vagrant VMs"
16 cd $CORDDIR/build
17 vagrant destroy
18
19 echo "Destroying juju environment"
20 juju destroy-environment --force -y manual
21
22 VMS=$( sudo uvt-kvm list )
23 for VM in $VMS
24 do
25 echo "Destroying $VM"
26 sudo uvt-kvm destroy $VM
27 done
28
29 echo "Cleaning up files"
30 rm -rf ~/.juju
31 rm -f ~/.ssh/known_hosts
32 rm -rf ~/platform-install
33 rm -rf ~/cord_apps
34 rm -rf ~/.ansible_async
35
36 echo "Removing MAAS"
37 [ -e /usr/local/bin/remove-maas-components ] && /usr/local/bin/remove-maas-components
38
39 echo "Remove apt-cacher-ng"
40 sudo apt-get remove -y apt-cacher-ng
41 sudo rm -f /etc/apt/apt.conf.d/02apt-cacher-ng
42
43 echo "Removing mgmtbr"
44 ifconfig mgmtbr && sudo ip link set dev mgmtbr down && sudo brctl delbr mgmtbr
45
46 echo "Removing Juju packages"
47 sudo apt-get remove --purge -y $(dpkg --get-selections | grep "juju\|nova\|neutron\|keystone\|glance" | awk '{print $1}')
48 sudo apt-get autoremove -y
49
50 rm -rf $CORDDIR
51
52 set -e
53}
54
55function bootstrap() {
56 cd ~
57 sudo apt-get update
58 [ -e vagrant_1.8.5_x86_64.deb ] || wget https://releases.hashicorp.com/vagrant/1.8.5/vagrant_1.8.5_x86_64.deb
59 sudo dpkg -i vagrant_1.8.5_x86_64.deb
Andy Bavier8ce395f2016-10-14 12:51:30 -040060 sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server
Andy Bavier99c11d32016-09-14 17:21:20 -040061
62 [ -e ~/.ssh/id_rsa ] || ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
63 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
64
65 # Log into the local node once to get host key
66 ssh -o StrictHostKeyChecking=no localhost "ls > /dev/null"
67
68 USER=$(whoami)
69 sudo adduser $USER libvirtd
70
71 sudo curl -o /usr/local/bin/repo https://storage.googleapis.com/git-repo-downloads/repo
72 sudo chmod a+x /usr/local/bin/repo
73
74 if [ ! -d "$CORDDIR" ]
75 then
76 mkdir $CORDDIR && cd $CORDDIR
77 git config --global user.name 'Test User'
78 git config --global user.email 'test@null.com'
79 git config --global color.ui false
80
Scott Baker101b37c2016-10-24 16:22:43 -070081 repo init -u https://gerrit.opencord.org/manifest -b master -g build,onos,orchestration
Andy Bavier99c11d32016-09-14 17:21:20 -040082 repo sync
83
84 cd $CORDDIR/build
85 sed -i "s/user: 'ubuntu'/user: \"$USER\"/" $CONFIG
86
87 # Set external interface in config file
88 IFACE=$(route | grep default | awk '{print $8}' )
Andy Bavierb5796fb2016-10-20 12:06:47 -040089 SRC="'eth0'"
90 DST="'"$IFACE"'"
91 sed -i "s/$SRC/$DST/" $CONFIG
Andy Bavier99c11d32016-09-14 17:21:20 -040092 fi
93
94 cd $CORDDIR/build
Andy Bavier45e30bb2016-10-07 15:45:18 -040095 vagrant plugin install vagrant-libvirt --plugin-version 0.0.35
Andy Bavier99c11d32016-09-14 17:21:20 -040096 vagrant plugin install vagrant-mutate
97 vagrant box list ubuntu/trusty64 | grep virtualbox || vagrant box add ubuntu/trusty64
98 vagrant box list ubuntu/trusty64 | grep libvirt || vagrant mutate ubuntu/trusty64 libvirt --input-provider virtualbox
99}
100
101function cloudlab_setup() {
102 if [ -e /usr/testbed/bin/mkextrafs ]
103 then
Scott Baker8b9182d2016-10-27 17:53:52 -0700104 sudo mkdir -p /var/extra
105
Andy Bavier8ce395f2016-10-14 12:51:30 -0400106 # Sometimes this command fails on the first try
Scott Baker8b9182d2016-10-27 17:53:52 -0700107 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/var/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/var/extra/"
108
109 # we'll replace /var/lib/libvirt/images with a symlink below
110 [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images
111
112 sudo mkdir -p /var/extra/libvirt_images
113 sudo mkdir -p /var/extra/docker
Scott Baker172ebd22016-11-08 14:00:38 -0800114 sudo mkdir -p /var/extra/docker-registry
Scott Baker8b9182d2016-10-27 17:53:52 -0700115 [ ! -e /var/lib/libvirt/images ] && sudo ln -s /var/extra/libvirt_images /var/lib/libvirt/images
116 [ ! -e /var/lib/docker ] && sudo ln -s /var/extra/docker /var/lib/docker
Scott Baker172ebd22016-11-08 14:00:38 -0800117 [ ! -e /docker-registry ] && sudo ln -s /var/extra/docker-registry /docker-registry
Andy Bavier99c11d32016-09-14 17:21:20 -0400118
119 cd $CORDDIR/build
120 SRC="#- 'on_cloudlab=True'"
121 DST="- 'on_cloudlab=True'"
122 sed -i "s/$SRC/$DST/" config/cord_in_a_box.yml
123 fi
124}
125
126function unfortunate_hacks() {
127 cd $CORDDIR/build
128
Andy Bavier99c11d32016-09-14 17:21:20 -0400129 # Allow compute nodes to PXE boot from mgmtbr
130 sed -i "s/@type='udp']/@type='udp' or @type='bridge']/" \
131 ~/.vagrant.d/gems/gems/vagrant-libvirt-0.0.35/lib/vagrant-libvirt/action/set_boot_order.rb
132
133 # Should get these keys inside the VM in another way
134 cp ~/.ssh/id_rsa* $CORDDIR
135}
136
137function corddev_up() {
138 cd $CORDDIR/build
139
140 sudo su $USER -c 'vagrant up corddev --provider libvirt'
141}
142
143function install_head_node() {
144 cd $CORDDIR/build
145
146 # Network setup to install physical server as head node
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400147 BRIDGE=$( route -n | grep 10.100.198.0 | awk '{print $8}' )
148 ip addr list dev $BRIDGE | grep 10.100.198.201 || sudo ip addr add dev $BRIDGE 10.100.198.201
Andy Bavier99c11d32016-09-14 17:21:20 -0400149 ifconfig mgmtbr || sudo brctl addbr mgmtbr
150 sudo ifconfig mgmtbr 10.1.0.1/24 up
151
152 # User has been added to the libvirtd group, but su $USER to be safe
153 sudo su $USER -c "vagrant ssh corddev -c \"cp /cord/id_rsa* ~/.ssh\""
154 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew fetch\""
155 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew buildImages\""
156 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish\""
157 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy\""
158}
159
160function set_up_maas_user() {
161 # Set up MAAS user to restart nodes via libvirt
162 sudo mkdir -p /home/maas
163 sudo chown maas:maas /home/maas
164 sudo chsh -s /bin/bash maas
165 sudo adduser maas libvirtd
166
167 sudo su maas -c 'cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys'
168}
169
170function add_compute_node() {
171 cd $CORDDIR/build
172 sudo su $USER -c 'vagrant up compute_node --provider libvirt'
173
Andy Bavierb5796fb2016-10-20 12:06:47 -0400174 # Change MAC address of bridge to match cord-pod service profile
175 # This change won't survive a reboot
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400176 BRIDGE=$( route -n | grep 10.6.1.0 | awk '{print $8}' )
177 sudo ifconfig $BRIDGE hw ether 02:42:0a:06:01:01
Andy Bavierb5796fb2016-10-20 12:06:47 -0400178
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400179 # Add gateway IP addresses to $BRIDGE for vsg and exampleservice tests
Andy Bavierb5796fb2016-10-20 12:06:47 -0400180 # This change won't survive a reboot
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400181 sudo ip address add 10.6.1.129 dev $BRIDGE
182 sudo ip address add 10.6.1.193 dev $BRIDGE
Andy Bavierb5796fb2016-10-20 12:06:47 -0400183
Andy Bavier99c11d32016-09-14 17:21:20 -0400184 # Sign into MAAS
185 KEY=$(sudo maas-region-admin apikey --username=cord)
186 maas login cord http://localhost/MAAS/api/1.0 $KEY
187
188 NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id')
189 until [ "$NODEID" ]; do
190 echo "Waiting for the compute node to transition to NEW state"
191 sleep 15
192 NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id')
193 done
194
195 # Add remote power state
196 maas cord node update $NODEID power_type="virsh" \
197 power_parameters_power_address="qemu+ssh://maas@localhost/system" \
198 power_parameters_power_id="build_compute_node"
199
200 STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status")
201 until [ "$STATUS" == "2" ]; do
202 if [ "$STATUS" == "3" ]; then
Andy Bavierc7588652016-11-03 13:55:22 -0400203 echo "*** [WARNING] Possible error in node provisioning process"
204 echo "*** [WARNING] Check /etc/maas/ansible/logs/$NODEID.log"
Andy Bavier99c11d32016-09-14 17:21:20 -0400205 fi
206 echo "Waiting for the compute node to be fully provisioned"
207 sleep 60
208 STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status")
209 done
210
211 echo ""
212 echo "compute_node is fully provisioned!"
213}
214
215function run_e2e_test () {
216 cd $CORDDIR/build
217
218 # User has been added to the libvirtd group, but su $USER to be safe
219 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests\""
220}
221
222function run_diagnostics() {
223 echo "*** COLLECTING DIAGNOSTIC INFO NOT CURRENTLY IMPLEMENTED"
224 # Need to fix up inventory to collect info from compute nodes
225 # Using juju-ansible is one possibility
226 #echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node"
227 #ansible-playbook -i $INVENTORY cord-diag-playbook.yml
228}
229
230# Parse options
231RUN_TEST=0
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400232SETUP_ONLY=0
Andy Bavier99c11d32016-09-14 17:21:20 -0400233SETUP_BRANCH="master"
234DIAGNOSTICS=0
235CLEANUP=0
236
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400237while getopts "b:cdhst" opt; do
Andy Bavier99c11d32016-09-14 17:21:20 -0400238 case ${opt} in
239 b ) XOS_BRANCH=$OPTARG
240 ;;
241 c ) CLEANUP=1
242 ;;
243 d ) DIAGNOSTICS=1
244 ;;
245 h ) echo "Usage:"
246 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
247 echo " $0 -b <branch> checkout <branch> of the xos git repo"
248 echo " $0 -c cleanup from previous test"
249 echo " $0 -d run diagnostic collector"
250 echo " $0 -h display this help message"
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400251 echo " $0 -s run initial setup phase only (don't start building CORD)"
Andy Bavier99c11d32016-09-14 17:21:20 -0400252 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
253 exit 0
254 ;;
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400255 s ) SETUP_ONLY=1
256 ;;
Andy Bavier99c11d32016-09-14 17:21:20 -0400257 t ) RUN_TEST=1
258 ;;
259 \? ) echo "Invalid option: -$OPTARG"
260 exit 1
261 ;;
262 esac
263done
264
265# What to do
266if [[ $CLEANUP -eq 1 ]]
267then
268 cleanup_from_previous_test
269fi
270
271set -e
272
273bootstrap
274cloudlab_setup
275unfortunate_hacks
276corddev_up
Andy Bavier5c2e4fa2016-10-31 13:50:52 -0400277
278if [[ $SETUP_ONLY -ne 0 ]]
279then
280 echo "Finished build environment setup, exiting..."
281 exit 0
282fi
283
Andy Bavier99c11d32016-09-14 17:21:20 -0400284install_head_node
285set_up_maas_user
286add_compute_node
287
288if [[ $RUN_TEST -eq 1 ]]
289then
290 run_e2e_test
291fi
292
293if [[ $DIAGNOSTICS -eq 1 ]]
294then
295 run_diagnostics
296fi
297
298exit 0