Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -e |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 4 | |
| 5 | CORDDIR=~/opencord |
| 6 | VMDIR=/cord/build/ |
| 7 | CONFIG=config/cord_in_a_box.yml |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 8 | SSHCONFIG=~/.ssh/config |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 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 | 1a35ae6 | 2016-11-15 19:58:13 -0800 | [diff] [blame] | 60 | sudo apt-get -y install qemu-kvm libvirt-bin libvirt-dev curl nfs-kernel-server git build-essential |
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 | |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 84 | # check out gerrit branches using repo |
| 85 | for gerrit_branch in ${GERRIT_BRANCHES[@]}; do |
| 86 | echo "checking out opencord gerrit branch: $gerrit_branch" |
| 87 | repo download ${gerrit_branch/:/ } |
| 88 | done |
| 89 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 90 | cd $CORDDIR/build |
| 91 | sed -i "s/user: 'ubuntu'/user: \"$USER\"/" $CONFIG |
| 92 | |
| 93 | # Set external interface in config file |
| 94 | IFACE=$(route | grep default | awk '{print $8}' ) |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 95 | SRC="'eth0'" |
| 96 | DST="'"$IFACE"'" |
| 97 | sed -i "s/$SRC/$DST/" $CONFIG |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 98 | fi |
| 99 | |
| 100 | cd $CORDDIR/build |
Andy Bavier | 45e30bb | 2016-10-07 15:45:18 -0400 | [diff] [blame] | 101 | vagrant plugin install vagrant-libvirt --plugin-version 0.0.35 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 102 | vagrant plugin install vagrant-mutate |
| 103 | vagrant box list ubuntu/trusty64 | grep virtualbox || vagrant box add ubuntu/trusty64 |
| 104 | vagrant box list ubuntu/trusty64 | grep libvirt || vagrant mutate ubuntu/trusty64 libvirt --input-provider virtualbox |
| 105 | } |
| 106 | |
| 107 | function cloudlab_setup() { |
| 108 | if [ -e /usr/testbed/bin/mkextrafs ] |
| 109 | then |
Andy Bavier | 9c0835e | 2016-11-11 15:56:47 -0500 | [diff] [blame] | 110 | sudo mkdir -p /mnt/extra |
Scott Baker | 8b9182d | 2016-10-27 17:53:52 -0700 | [diff] [blame] | 111 | |
Andy Bavier | 8ce395f | 2016-10-14 12:51:30 -0400 | [diff] [blame] | 112 | # Sometimes this command fails on the first try |
Andy Bavier | 9c0835e | 2016-11-11 15:56:47 -0500 | [diff] [blame] | 113 | sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" || sudo /usr/testbed/bin/mkextrafs -r /dev/sdb -qf "/mnt/extra/" |
| 114 | |
| 115 | # Check that the mount succeeded (sometimes mkextrafs succeeds but device not mounted) |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 116 | mount | grep sdb || (echo "ERROR: mkextrafs failed, exiting!" && exit 1) |
Scott Baker | 8b9182d | 2016-10-27 17:53:52 -0700 | [diff] [blame] | 117 | |
| 118 | # we'll replace /var/lib/libvirt/images with a symlink below |
| 119 | [ -d /var/lib/libvirt/images/ ] && [ ! -h /var/lib/libvirt/images ] && sudo rmdir /var/lib/libvirt/images |
| 120 | |
Andy Bavier | 9c0835e | 2016-11-11 15:56:47 -0500 | [diff] [blame] | 121 | sudo mkdir -p /mnt/extra/libvirt_images |
| 122 | sudo mkdir -p /mnt/extra/docker |
| 123 | sudo mkdir -p /mnt/extra/docker-registry |
| 124 | [ ! -e /var/lib/libvirt/images ] && sudo ln -s /mnt/extra/libvirt_images /var/lib/libvirt/images |
| 125 | [ ! -e /var/lib/docker ] && sudo ln -s /mnt/extra/docker /var/lib/docker |
| 126 | [ ! -e /docker-registry ] && sudo ln -s /mnt/extra/docker-registry /docker-registry |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 127 | |
| 128 | cd $CORDDIR/build |
| 129 | SRC="#- 'on_cloudlab=True'" |
| 130 | DST="- 'on_cloudlab=True'" |
| 131 | sed -i "s/$SRC/$DST/" config/cord_in_a_box.yml |
| 132 | fi |
| 133 | } |
| 134 | |
| 135 | function unfortunate_hacks() { |
| 136 | cd $CORDDIR/build |
| 137 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 138 | # Allow compute nodes to PXE boot from mgmtbr |
| 139 | sed -i "s/@type='udp']/@type='udp' or @type='bridge']/" \ |
| 140 | ~/.vagrant.d/gems/gems/vagrant-libvirt-0.0.35/lib/vagrant-libvirt/action/set_boot_order.rb |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | function corddev_up() { |
| 144 | cd $CORDDIR/build |
| 145 | |
| 146 | sudo su $USER -c 'vagrant up corddev --provider libvirt' |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 147 | |
| 148 | # This is a workaround for a weird issue with ARP cache timeout breaking 'vagrant ssh' |
| 149 | # It allows SSH'ing to the machine via 'ssh corddev' |
| 150 | sudo su $USER -c "grep corddev $SSHCONFIG || vagrant ssh-config corddev >> $SSHCONFIG" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | function install_head_node() { |
| 154 | cd $CORDDIR/build |
| 155 | |
| 156 | # Network setup to install physical server as head node |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 157 | BRIDGE=$( route -n | grep 10.100.198.0 | awk '{print $8}' ) |
| 158 | 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] | 159 | ifconfig mgmtbr || sudo brctl addbr mgmtbr |
| 160 | sudo ifconfig mgmtbr 10.1.0.1/24 up |
| 161 | |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 162 | # SSH config saved earlier allows us to connect to VM without running 'vagrant' |
| 163 | scp ~/.ssh/id_rsa* corddev:.ssh |
| 164 | ssh corddev "cd /cord/build; ./gradlew fetch" |
| 165 | ssh corddev "cd /cord/build; ./gradlew buildImages" |
| 166 | ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish" |
| 167 | ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy" |
| 168 | |
| 169 | # SSH config was overwritten by the deploy step |
| 170 | # Will go away when head node runs in 'prod' VM |
| 171 | sudo su $USER -c "grep corddev $SSHCONFIG || vagrant ssh-config corddev >> $SSHCONFIG" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | function set_up_maas_user() { |
| 175 | # Set up MAAS user to restart nodes via libvirt |
| 176 | sudo mkdir -p /home/maas |
| 177 | sudo chown maas:maas /home/maas |
| 178 | sudo chsh -s /bin/bash maas |
| 179 | sudo adduser maas libvirtd |
| 180 | |
| 181 | sudo su maas -c 'cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys' |
| 182 | } |
| 183 | |
| 184 | function add_compute_node() { |
| 185 | cd $CORDDIR/build |
| 186 | sudo su $USER -c 'vagrant up compute_node --provider libvirt' |
| 187 | |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 188 | # Change MAC address of bridge to match cord-pod service profile |
| 189 | # This change won't survive a reboot |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 190 | BRIDGE=$( route -n | grep 10.6.1.0 | awk '{print $8}' ) |
| 191 | sudo ifconfig $BRIDGE hw ether 02:42:0a:06:01:01 |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 192 | |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 193 | # Add gateway IP addresses to $BRIDGE for vsg and exampleservice tests |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 194 | # This change won't survive a reboot |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 195 | sudo ip address add 10.6.1.129 dev $BRIDGE |
| 196 | sudo ip address add 10.6.1.193 dev $BRIDGE |
Andy Bavier | b5796fb | 2016-10-20 12:06:47 -0400 | [diff] [blame] | 197 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 198 | # Sign into MAAS |
| 199 | KEY=$(sudo maas-region-admin apikey --username=cord) |
| 200 | maas login cord http://localhost/MAAS/api/1.0 $KEY |
| 201 | |
| 202 | NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id') |
| 203 | until [ "$NODEID" ]; do |
| 204 | echo "Waiting for the compute node to transition to NEW state" |
| 205 | sleep 15 |
| 206 | NODEID=$(maas cord nodes list|jq -r '.[] | select(.status == 0).system_id') |
| 207 | done |
| 208 | |
| 209 | # Add remote power state |
| 210 | maas cord node update $NODEID power_type="virsh" \ |
| 211 | power_parameters_power_address="qemu+ssh://maas@localhost/system" \ |
| 212 | power_parameters_power_id="build_compute_node" |
| 213 | |
| 214 | STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status") |
| 215 | until [ "$STATUS" == "2" ]; do |
| 216 | if [ "$STATUS" == "3" ]; then |
Andy Bavier | c758865 | 2016-11-03 13:55:22 -0400 | [diff] [blame] | 217 | echo "*** [WARNING] Possible error in node provisioning process" |
| 218 | echo "*** [WARNING] Check /etc/maas/ansible/logs/$NODEID.log" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 219 | fi |
| 220 | echo "Waiting for the compute node to be fully provisioned" |
| 221 | sleep 60 |
| 222 | STATUS=$(sudo /usr/local/bin/get-node-prov-state |jq ".[] | select(.id == \"$NODEID\").status") |
| 223 | done |
| 224 | |
| 225 | echo "" |
| 226 | echo "compute_node is fully provisioned!" |
| 227 | } |
| 228 | |
| 229 | function run_e2e_test () { |
| 230 | cd $CORDDIR/build |
| 231 | |
| 232 | # User has been added to the libvirtd group, but su $USER to be safe |
Andy Bavier | a69ee72 | 2016-11-17 07:26:01 -0800 | [diff] [blame] | 233 | ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG postDeployTests" |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | function run_diagnostics() { |
| 237 | echo "*** COLLECTING DIAGNOSTIC INFO NOT CURRENTLY IMPLEMENTED" |
| 238 | # Need to fix up inventory to collect info from compute nodes |
| 239 | # Using juju-ansible is one possibility |
| 240 | #echo "*** COLLECTING DIAGNOSTIC INFO - check ~/diag-* on the head node" |
| 241 | #ansible-playbook -i $INVENTORY cord-diag-playbook.yml |
| 242 | } |
| 243 | |
| 244 | # Parse options |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 245 | GERRIT_BRANCHES= |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 246 | RUN_TEST=0 |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 247 | SETUP_ONLY=0 |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 248 | DIAGNOSTICS=0 |
| 249 | CLEANUP=0 |
| 250 | |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 251 | while getopts "b:cdhst" opt; do |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 252 | case ${opt} in |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 253 | b ) GERRIT_BRANCHES+=("$OPTARG") |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 254 | ;; |
| 255 | c ) CLEANUP=1 |
| 256 | ;; |
| 257 | d ) DIAGNOSTICS=1 |
| 258 | ;; |
| 259 | h ) echo "Usage:" |
| 260 | echo " $0 install OpenStack and prep XOS and ONOS VMs [default]" |
Zack Williams | dae7ff6 | 2016-11-14 15:20:06 -0700 | [diff] [blame] | 261 | echo " $0 -b <project:changeset/revision> checkout a changesets from gerrit. Can" |
| 262 | echo " be used multiple times." |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 263 | echo " $0 -c cleanup from previous test" |
| 264 | echo " $0 -d run diagnostic collector" |
| 265 | echo " $0 -h display this help message" |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 266 | 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] | 267 | echo " $0 -t do install, bring up cord-pod configuration, run E2E test" |
| 268 | exit 0 |
| 269 | ;; |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 270 | s ) SETUP_ONLY=1 |
| 271 | ;; |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 272 | t ) RUN_TEST=1 |
| 273 | ;; |
| 274 | \? ) echo "Invalid option: -$OPTARG" |
| 275 | exit 1 |
| 276 | ;; |
| 277 | esac |
| 278 | done |
| 279 | |
| 280 | # What to do |
| 281 | if [[ $CLEANUP -eq 1 ]] |
| 282 | then |
| 283 | cleanup_from_previous_test |
| 284 | fi |
| 285 | |
| 286 | set -e |
| 287 | |
| 288 | bootstrap |
| 289 | cloudlab_setup |
| 290 | unfortunate_hacks |
| 291 | corddev_up |
Andy Bavier | 5c2e4fa | 2016-10-31 13:50:52 -0400 | [diff] [blame] | 292 | |
| 293 | if [[ $SETUP_ONLY -ne 0 ]] |
| 294 | then |
| 295 | echo "Finished build environment setup, exiting..." |
| 296 | exit 0 |
| 297 | fi |
| 298 | |
Andy Bavier | 99c11d3 | 2016-09-14 17:21:20 -0400 | [diff] [blame] | 299 | install_head_node |
| 300 | set_up_maas_user |
| 301 | add_compute_node |
| 302 | |
| 303 | if [[ $RUN_TEST -eq 1 ]] |
| 304 | then |
| 305 | run_e2e_test |
| 306 | fi |
| 307 | |
| 308 | if [[ $DIAGNOSTICS -eq 1 ]] |
| 309 | then |
| 310 | run_diagnostics |
| 311 | fi |
| 312 | |
| 313 | exit 0 |