|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# This script automates the process of setting up a local machine for running Kafka system tests |
| 18 | + |
| 19 | +# Helper function which prints version numbers so they can be compared lexically or numerically |
| 20 | +function version { echo "$@" | awk -F. '{ printf("%03d%03d%03d%03d\n", $1,$2,$3,$4); }'; } |
| 21 | + |
| 22 | +base_dir=`dirname $0`/.. |
| 23 | +cd $base_dir |
| 24 | + |
| 25 | +echo "Checking Virtual Box installation..." |
| 26 | +bad_vb=false |
| 27 | +if [ -z `vboxmanage --version` ]; then |
| 28 | + echo "It appears that Virtual Box is not installed. Please install and try again (see https://www.virtualbox.org/ for details)" |
| 29 | + bad_vb=true |
| 30 | +else |
| 31 | + echo "Virtual Box looks good." |
| 32 | +fi |
| 33 | + |
| 34 | +echo "Checking Vagrant installation..." |
| 35 | +vagrant_version=`vagrant --version | egrep -o "\d+\.\d+\.\d+"` |
| 36 | +bad_vagrant=false |
| 37 | +if [ "$(version $vagrant_version)" -lt "$(version 1.6.4)" ]; then |
| 38 | + echo "Found Vagrant version $vagrant_version. Please upgrade to 1.6.4 or higher (see http://www.vagrantup.com for details)" |
| 39 | + bad_vagrant=true |
| 40 | +else |
| 41 | + echo "Vagrant installation looks good." |
| 42 | +fi |
| 43 | + |
| 44 | +if [ "x$bad_vagrant" == "xtrue" -o "x$bad_vb" == "xtrue" ]; then |
| 45 | + exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +echo "Checking for necessary Vagrant plugins..." |
| 49 | +install_hostmanager=false |
| 50 | +hostmanager_version=`vagrant plugin list | grep vagrant-hostmanager | egrep -o "\d+\.\d+\.\d+"` |
| 51 | +if [ -z "$hostmanager_version" ]; then |
| 52 | + install_hostmanager=true |
| 53 | +elif [ "$hostmanager_version" != "1.5.0" ]; then |
| 54 | + echo "You have the wrong version of vagrant plugin vagrant-hostmanager. Uninstalling..." |
| 55 | + vagrant plugin uninstall vagrant-hostmanager |
| 56 | + install_hostmanager=true |
| 57 | +fi |
| 58 | +if [ "x$install_hostmanager" == "xtrue" ]; then |
| 59 | + vagrant plugin install vagrant-hostmanager --plugin-version 1.5.0 |
| 60 | +fi |
| 61 | + |
| 62 | +echo "Creating and packaging a reusable base box for Vagrant..." |
| 63 | +vagrant/package-base-box.sh |
| 64 | + |
| 65 | +# Set up Vagrantfile.local if necessary |
| 66 | +if [ ! -e Vagrantfile.local ]; then |
| 67 | + echo "Creating Vagrantfile.local..." |
| 68 | + cp vagrant/system-test-Vagrantfile.local Vagrantfile.local |
| 69 | +else |
| 70 | + echo "Found an existing Vagrantfile.local. Keeping without overwriting..." |
| 71 | +fi |
| 72 | + |
| 73 | +# Sanity check contents of Vagrantfile.local |
| 74 | +echo "Checking Vagrantfile.local..." |
| 75 | +vagrantfile_ok=true |
| 76 | +num_brokers=`egrep -o "num_brokers\s*=\s*\d+" Vagrantfile.local | cut -d '=' -f 2 | xargs` |
| 77 | +num_zookeepers=`egrep -o "num_zookeepers\s*=\s*\d+" Vagrantfile.local | cut -d '=' -f 2 | xargs` |
| 78 | +num_workers=`egrep -o "num_workers\s*=\s*\d+" Vagrantfile.local | cut -d '=' -f 2 | xargs` |
| 79 | +if [ "x$num_brokers" == "x" -o "$num_brokers" != 0 ]; then |
| 80 | + echo "Vagrantfile.local: bad num_brokers. Update to: num_brokers = 0" |
| 81 | + vagrantfile_ok=false |
| 82 | +fi |
| 83 | +if [ "x$num_zookeepers" == "x" -o "$num_zookeepers" != 0 ]; then |
| 84 | + echo "Vagrantfile.local: bad num_zookeepers. Update to: num_zookeepers = 0" |
| 85 | + vagrantfile_ok=false |
| 86 | +fi |
| 87 | +if [ "x$num_workers" == "x" -o "$num_workers" == 0 ]; then |
| 88 | + echo "Vagrantfile.local: bad num_workers (size of test cluster). Set num_workers high enough to run your tests." |
| 89 | + vagrantfile_ok=false |
| 90 | +fi |
| 91 | + |
| 92 | +if [ "$vagrantfile_ok" == "true" ]; then |
| 93 | + echo "Vagrantfile.local looks good." |
| 94 | +fi |
0 commit comments