Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -e |
| 4 | set -x |
| 5 | |
| 6 | CORDDIR=~/opencord |
| 7 | VMDIR=/cord/build/ |
| 8 | CONFIG=config/cord_in_a_box.yml |
| 9 | |
| 10 | function 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 | |
| 55 | function 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 Bavier | 8ce395f | 2016-10-14 12:51:30 -0400 | [diff] [blame] | 60 | sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 61 | |
| 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 Baker | 101b37c | 2016-10-24 16:22:43 -0700 | [diff] [blame] | 81 | repo init -u https://gerrit.opencord.org/manifest -b master -g build,onos,orchestration |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 82 | 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 Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 89 | SRC="'eth0'" |
| 90 | DST="'"$IFACE"'" |
| 91 | sed -i "s/$SRC/$DST/" $CONFIG |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 92 | fi |
| 93 | |
| 94 | cd $CORDDIR/build |
Andy Bavier | 45e30bb | 2016-10-07 15:45:18 -0400 | [diff] [blame] | 95 | vagrant plugin install vagrant-libvirt --plugin-version 0.0.35 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 96 | 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 | |
| 101 | function cloudlab_setup() { |
| 102 | if [ -e /usr/testbed/bin/mkextrafs ] |
| 103 | then |
Scott Baker | 8b9182d | 2016-10-27 17:53:52 -0700 | [diff] [blame] | 104 | sudo mkdir -p /var/extra |
| 105 | |
Andy Bavier | 8ce395f | 2016-10-14 12:51:30 -0400 | [diff] [blame] | 106 | # Sometimes this command fails on the first try |
Scott Baker | 8b9182d | 2016-10-27 17:53:52 -0700 | [diff] [blame] | 107 | 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 |
| 114 | [ ! -e /var/lib/libvirt/images ] && sudo ln -s /var/extra/libvirt_images /var/lib/libvirt/images |
| 115 | [ ! -e /var/lib/docker ] && sudo ln -s /var/extra/docker /var/lib/docker |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 116 | |
| 117 | cd $CORDDIR/build |
| 118 | SRC="#- 'on_cloudlab=True'" |
| 119 | DST="- 'on_cloudlab=True'" |
| 120 | sed -i "s/$SRC/$DST/" config/cord_in_a_box.yml |
| 121 | fi |
| 122 | } |
| 123 | |
| 124 | function unfortunate_hacks() { |
| 125 | cd $CORDDIR/build |
| 126 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 127 | # Allow compute nodes to PXE boot from mgmtbr |
| 128 | sed -i "s/@type='udp']/@type='udp' or @type='bridge']/" \ |
| 129 | ~/.vagrant.d/gems/gems/vagrant-libvirt-0.0.35/lib/vagrant-libvirt/action/set_boot_order.rb |
| 130 | |
| 131 | # Should get these keys inside the VM in another way |
| 132 | cp ~/.ssh/id_rsa* $CORDDIR |
| 133 | } |
| 134 | |
| 135 | function corddev_up() { |
| 136 | cd $CORDDIR/build |
| 137 | |
| 138 | sudo su $USER -c 'vagrant up corddev --provider libvirt' |
| 139 | } |
| 140 | |
| 141 | function install_head_node() { |
| 142 | cd $CORDDIR/build |
| 143 | |
| 144 | # Network setup to install physical server as head node |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 145 | BRIDGE=$( route -n | grep 10.100.198.0 | awk '{print $8}' ) |
| 146 | ip addr list dev $BRIDGE | grep 10.100.198.201 || sudo ip addr add dev $BRIDGE 10.100.198.201 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 147 | ifconfig mgmtbr || sudo brctl addbr mgmtbr |
| 148 | sudo ifconfig mgmtbr 10.1.0.1/24 up |
| 149 | |
| 150 | # User has been added to the libvirtd group, but su $USER to be safe |
| 151 | sudo su $USER -c "vagrant ssh corddev -c \"cp /cord/id_rsa* ~/.ssh\"" |
| 152 | sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew fetch\"" |
| 153 | sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew buildImages\"" |
| 154 | sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish\"" |
| 155 | sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy\"" |
| 156 | } |
| 157 | |
| 158 | function set_up_maas_user() { |
| 159 | # Set up MAAS user to restart nodes via libvirt |
| 160 | sudo mkdir -p /home/maas |
| 161 | sudo chown maas:maas /home/maas |
| 162 | sudo chsh -s /bin/bash maas |
| 163 | sudo adduser maas libvirtd |
| 164 | |
| 165 | sudo su maas -c 'cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys' |
| 166 | } |
| 167 | |
| 168 | function add_compute_node() { |
| 169 | cd $CORDDIR/build |
| 170 | sudo su $USER -c 'vagrant up compute_node --provider libvirt' |
| 171 | |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 172 | # Change MAC address of bridge to match cord-pod service profile |
| 173 | # This change won't survive a reboot |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 174 | BRIDGE=$( route -n | grep 10.6.1.0 | awk '{print $8}' ) |
| 175 | sudo ifconfig $BRIDGE hw ether 02:42:0a:06:01:01 |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 176 | |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 177 | # Add gateway IP addresses to $BRIDGE for vsg and exampleservice tests |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 178 | # This change won't survive a reboot |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 179 | sudo ip address add 10.6.1.129 dev $BRIDGE |
| 180 | sudo ip address add 10.6.1.193 dev $BRIDGE |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 181 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 182 | # Sign into MAAS |
| 183 | KEY=$(sudo maas-region-admin apikey --username=cord) |
| 184 | maas login cord http://localhost/MAAS/api/1.0 $KEY |
| 185 | |
| 186 | NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id') |
| 187 | until [ "$NODEID" ]; do |
| 188 | echo "Waiting for the compute node to transition to NEW state" |
| 189 | sleep 15 |
| 190 | NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id') |
| 191 | done |
| 192 | |
| 193 | # Add remote power state |
| 194 | maas cord node update $NODEID power_type="virsh" \ |
| 195 | power_parameters_power_address="qemu+ssh://maas@localhost/system" \ |
| 196 | power_parameters_power_id="build_compute_node" |
| 197 | |
| 198 | STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status") |
| 199 | until [ "$STATUS" == "2" ]; do |
| 200 | if [ "$STATUS" == "3" ]; then |
Andy Bavier | c758865 | 2016-11-03 13:55:22 -0400 | [diff] [blame] | 201 | echo "*** [WARNING] Possible error in node provisioning process" |
| 202 | echo "*** [WARNING] Check /etc/maas/ansible/logs/$NODEID.log" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 203 | fi |
| 204 | echo "Waiting for the compute node to be fully provisioned" |
| 205 | sleep 60 |
| 206 | STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status") |
| 207 | done |
| 208 | |
| 209 | echo "" |
| 210 | echo "compute_node is fully provisioned!" |
| 211 | } |
| 212 | |
| 213 | function run_e2e_test () { |
| 214 | cd $CORDDIR/build |
| 215 | |
| 216 | # User has been added to the libvirtd group, but su $USER to be safe |
| 217 | sudo su $USER -c "vagrant ssh corddev -c \"cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests\"" |
| 218 | } |
| 219 | |
| 220 | function run_diagnostics() { |
| 221 | echo "*** COLLECTING DIAGNOSTIC INFO NOT CURRENTLY IMPLEMENTED" |
| 222 | # Need to fix up inventory to collect info from compute nodes |
| 223 | # Using juju-ansible is one possibility |
| 224 | #echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node" |
| 225 | #ansible-playbook -i $INVENTORY cord-diag-playbook.yml |
| 226 | } |
| 227 | |
| 228 | # Parse options |
| 229 | RUN_TEST=0 |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 230 | SETUP_ONLY=0 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 231 | SETUP_BRANCH="master" |
| 232 | DIAGNOSTICS=0 |
| 233 | CLEANUP=0 |
| 234 | |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 235 | while getopts "b:cdhst" opt; do |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 236 | case ${opt} in |
| 237 | b ) XOS_BRANCH=$OPTARG |
| 238 | ;; |
| 239 | c ) CLEANUP=1 |
| 240 | ;; |
| 241 | d ) DIAGNOSTICS=1 |
| 242 | ;; |
| 243 | h ) echo "Usage:" |
| 244 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
| 245 | echo " $0 -b <branch> checkout <branch> of the xos git repo" |
| 246 | echo " $0 -c cleanup from previous test" |
| 247 | echo " $0 -d run diagnostic collector" |
| 248 | echo " $0 -h display this help message" |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 249 | echo " $0 -s run initial setup phase only (don't start building CORD)" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 250 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
| 251 | exit 0 |
| 252 | ;; |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 253 | s ) SETUP_ONLY=1 |
| 254 | ;; |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 255 | t ) RUN_TEST=1 |
| 256 | ;; |
| 257 | \? ) echo "Invalid option: -$OPTARG" |
| 258 | exit 1 |
| 259 | ;; |
| 260 | esac |
| 261 | done |
| 262 | |
| 263 | # What to do |
| 264 | if [[ $CLEANUP -eq 1 ]] |
| 265 | then |
| 266 | cleanup_from_previous_test |
| 267 | fi |
| 268 | |
| 269 | set -e |
| 270 | |
| 271 | bootstrap |
| 272 | cloudlab_setup |
| 273 | unfortunate_hacks |
| 274 | corddev_up |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 275 | |
| 276 | if [[ $SETUP_ONLY -ne 0 ]] |
| 277 | then |
| 278 | echo "Finished build environment setup, exiting..." |
| 279 | exit 0 |
| 280 | fi |
| 281 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 282 | install_head_node |
| 283 | set_up_maas_user |
| 284 | add_compute_node |
| 285 | |
| 286 | if [[ $RUN_TEST -eq 1 ]] |
| 287 | then |
| 288 | run_e2e_test |
| 289 | fi |
| 290 | |
| 291 | if [[ $DIAGNOSTICS -eq 1 ]] |
| 292 | then |
| 293 | run_diagnostics |
| 294 | fi |
| 295 | |
| 296 | exit 0 |