blob: 48970447dac2a33871f18f3f0be38f4bfd9de5c5 [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
Andy Bavier8ce395f2016-10-14 12:51:30 -0400104 # Sometimes this command fails on the first try
105 sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/var/lib/libvirt/images/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/var/lib/libvirt/images/"
Andy Bavier99c11d32016-09-14 17:21:20 -0400106
107 cd $CORDDIR/build
108 SRC="#- 'on_cloudlab=True'"
109 DST="- 'on_cloudlab=True'"
110 sed -i "s/$SRC/$DST/" config/cord_in_a_box.yml
111 fi
112}
113
114function unfortunate_hacks() {
115 cd $CORDDIR/build
116
Andy Bavier99c11d32016-09-14 17:21:20 -0400117 # Allow compute nodes to PXE boot from mgmtbr
118 sed -i "s/@type='udp']/@type='udp' or @type='bridge']/" \
119 ~/.vagrant.d/gems/gems/vagrant-libvirt-0.0.35/lib/vagrant-libvirt/action/set_boot_order.rb
120
121 # Should get these keys inside the VM in another way
122 cp ~/.ssh/id_rsa* $CORDDIR
123}
124
125function corddev_up() {
126 cd $CORDDIR/build
127
128 sudo su $USER -c 'vagrant up corddev --provider libvirt'
129}
130
131function install_head_node() {
132 cd $CORDDIR/build
133
134 # Network setup to install physical server as head node
135 ip addr list dev virbr2 | grep 10.100.198.201 || sudo ip addr add dev virbr2 10.100.198.201
136 ifconfig mgmtbr || sudo brctl addbr mgmtbr
137 sudo ifconfig mgmtbr 10.1.0.1/24 up
138
139 # User has been added to the libvirtd group, but su $USER to be safe
140 sudo su $USER -c "vagrant ssh corddev -c \"cp /cord/id_rsa* ~/.ssh\""
141 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew fetch\""
142 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew buildImages\""
143 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish\""
144 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy\""
145}
146
147function set_up_maas_user() {
148 # Set up MAAS user to restart nodes via libvirt
149 sudo mkdir -p /home/maas
150 sudo chown maas:maas /home/maas
151 sudo chsh -s /bin/bash maas
152 sudo adduser maas libvirtd
153
154 sudo su maas -c 'cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys'
155}
156
157function add_compute_node() {
158 cd $CORDDIR/build
159 sudo su $USER -c 'vagrant up compute_node --provider libvirt'
160
Andy Bavierb5796fb2016-10-20 12:06:47 -0400161 # Change MAC address of bridge to match cord-pod service profile
162 # This change won't survive a reboot
163 sudo ifconfig virbr3 hw ether 02:42:0a:06:01:01
164
165 # Add gateway IP addresses to virbr3 for vsg and exampleservice tests
166 # This change won't survive a reboot
167 sudo ip address add 10.6.1.129 dev virbr3
168 sudo ip address add 10.6.1.193 dev virbr3
169
Andy Bavier99c11d32016-09-14 17:21:20 -0400170 # Sign into MAAS
171 KEY=$(sudo maas-region-admin apikey --username=cord)
172 maas login cord http://localhost/MAAS/api/1.0 $KEY
173
174 NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id')
175 until [ "$NODEID" ]; do
176 echo "Waiting for the compute node to transition to NEW state"
177 sleep 15
178 NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id')
179 done
180
181 # Add remote power state
182 maas cord node update $NODEID power_type="virsh" \
183 power_parameters_power_address="qemu+ssh://maas@localhost/system" \
184 power_parameters_power_id="build_compute_node"
185
186 STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status")
187 until [ "$STATUS" == "2" ]; do
188 if [ "$STATUS" == "3" ]; then
189 echo "*** ERROR in provisioning!"
190 echo "*** Check /etc/maas/ansible/logs/$NODEID.log"
191 exit 1
192 fi
193 echo "Waiting for the compute node to be fully provisioned"
194 sleep 60
195 STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status")
196 done
197
198 echo ""
199 echo "compute_node is fully provisioned!"
200}
201
202function run_e2e_test () {
203 cd $CORDDIR/build
204
205 # User has been added to the libvirtd group, but su $USER to be safe
206 sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests\""
207}
208
209function run_diagnostics() {
210 echo "*** COLLECTING DIAGNOSTIC INFO NOT CURRENTLY IMPLEMENTED"
211 # Need to fix up inventory to collect info from compute nodes
212 # Using juju-ansible is one possibility
213 #echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node"
214 #ansible-playbook -i $INVENTORY cord-diag-playbook.yml
215}
216
217# Parse options
218RUN_TEST=0
219SETUP_BRANCH="master"
220DIAGNOSTICS=0
221CLEANUP=0
222
223while getopts "b:cdehi:p:r:ts:" opt; do
224 case ${opt} in
225 b ) XOS_BRANCH=$OPTARG
226 ;;
227 c ) CLEANUP=1
228 ;;
229 d ) DIAGNOSTICS=1
230 ;;
231 h ) echo "Usage:"
232 echo " $0 install OpenStack and prep XOS and ONOS VMs [default]"
233 echo " $0 -b <branch> checkout <branch> of the xos git repo"
234 echo " $0 -c cleanup from previous test"
235 echo " $0 -d run diagnostic collector"
236 echo " $0 -h display this help message"
237 echo " $0 -t do install, bring up cord-pod configuration, run E2E test"
238 exit 0
239 ;;
240 t ) RUN_TEST=1
241 ;;
242 \? ) echo "Invalid option: -$OPTARG"
243 exit 1
244 ;;
245 esac
246done
247
248# What to do
249if [[ $CLEANUP -eq 1 ]]
250then
251 cleanup_from_previous_test
252fi
253
254set -e
255
256bootstrap
257cloudlab_setup
258unfortunate_hacks
259corddev_up
260install_head_node
261set_up_maas_user
262add_compute_node
263
264if [[ $RUN_TEST -eq 1 ]]
265then
266 run_e2e_test
267fi
268
269if [[ $DIAGNOSTICS -eq 1 ]]
270then
271 run_diagnostics
272fi
273
274exit 0