forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MINOR: Added scripts to automate Vagrant setup for system tests
Updated testing README accordingly. Author: Geoff Anderson <[email protected]> Reviewers: Ewen Cheslack-Postava, Gwen Shapira Closes apache#201 from granders/minor-vagrant-package-script
- Loading branch information
Showing
4 changed files
with
181 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env bash | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This script automates the process of setting up a local machine for running Kafka system tests | ||
|
||
# Helper function which prints version numbers so they can be compared lexically or numerically | ||
function version { echo "$@" | awk -F. '{ printf("%03d%03d%03d%03d\n", $1,$2,$3,$4); }'; } | ||
|
||
base_dir=`dirname $0`/.. | ||
cd $base_dir | ||
|
||
echo "Checking Virtual Box installation..." | ||
bad_vb=false | ||
if [ -z `vboxmanage --version` ]; then | ||
echo "It appears that Virtual Box is not installed. Please install and try again (see https://www.virtualbox.org/ for details)" | ||
bad_vb=true | ||
else | ||
echo "Virtual Box looks good." | ||
fi | ||
|
||
echo "Checking Vagrant installation..." | ||
vagrant_version=`vagrant --version | egrep -o "\d+\.\d+\.\d+"` | ||
bad_vagrant=false | ||
if [ "$(version $vagrant_version)" -lt "$(version 1.6.4)" ]; then | ||
echo "Found Vagrant version $vagrant_version. Please upgrade to 1.6.4 or higher (see http://www.vagrantup.com for details)" | ||
bad_vagrant=true | ||
else | ||
echo "Vagrant installation looks good." | ||
fi | ||
|
||
if [ "x$bad_vagrant" == "xtrue" -o "x$bad_vb" == "xtrue" ]; then | ||
exit 1 | ||
fi | ||
|
||
echo "Checking for necessary Vagrant plugins..." | ||
install_hostmanager=false | ||
hostmanager_version=`vagrant plugin list | grep vagrant-hostmanager | egrep -o "\d+\.\d+\.\d+"` | ||
if [ -z "$hostmanager_version" ]; then | ||
install_hostmanager=true | ||
elif [ "$hostmanager_version" != "1.5.0" ]; then | ||
echo "You have the wrong version of vagrant plugin vagrant-hostmanager. Uninstalling..." | ||
vagrant plugin uninstall vagrant-hostmanager | ||
install_hostmanager=true | ||
fi | ||
if [ "x$install_hostmanager" == "xtrue" ]; then | ||
vagrant plugin install vagrant-hostmanager --plugin-version 1.5.0 | ||
fi | ||
|
||
echo "Creating and packaging a reusable base box for Vagrant..." | ||
vagrant/package-base-box.sh | ||
|
||
# Set up Vagrantfile.local if necessary | ||
if [ ! -e Vagrantfile.local ]; then | ||
echo "Creating Vagrantfile.local..." | ||
cp vagrant/system-test-Vagrantfile.local Vagrantfile.local | ||
else | ||
echo "Found an existing Vagrantfile.local. Keeping without overwriting..." | ||
fi | ||
|
||
# Sanity check contents of Vagrantfile.local | ||
echo "Checking Vagrantfile.local..." | ||
vagrantfile_ok=true | ||
num_brokers=`egrep -o "num_brokers\s*=\s*\d+" Vagrantfile.local | cut -d '=' -f 2 | xargs` | ||
num_zookeepers=`egrep -o "num_zookeepers\s*=\s*\d+" Vagrantfile.local | cut -d '=' -f 2 | xargs` | ||
num_workers=`egrep -o "num_workers\s*=\s*\d+" Vagrantfile.local | cut -d '=' -f 2 | xargs` | ||
if [ "x$num_brokers" == "x" -o "$num_brokers" != 0 ]; then | ||
echo "Vagrantfile.local: bad num_brokers. Update to: num_brokers = 0" | ||
vagrantfile_ok=false | ||
fi | ||
if [ "x$num_zookeepers" == "x" -o "$num_zookeepers" != 0 ]; then | ||
echo "Vagrantfile.local: bad num_zookeepers. Update to: num_zookeepers = 0" | ||
vagrantfile_ok=false | ||
fi | ||
if [ "x$num_workers" == "x" -o "$num_workers" == 0 ]; then | ||
echo "Vagrantfile.local: bad num_workers (size of test cluster). Set num_workers high enough to run your tests." | ||
vagrantfile_ok=false | ||
fi | ||
|
||
if [ "$vagrantfile_ok" == "true" ]; then | ||
echo "Vagrantfile.local looks good." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env bash | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This script automates the process of creating and packaging | ||
# a new vagrant base_box. For use locally (not aws). | ||
|
||
base_dir=`dirname $0`/.. | ||
cd $base_dir | ||
|
||
backup_vagrantfile=backup_Vagrantfile.local | ||
local_vagrantfile=Vagrantfile.local | ||
|
||
# Restore original Vagrantfile.local, if it exists | ||
function revert_vagrantfile { | ||
rm -f $local_vagrantfile | ||
if [ -e $backup_vagrantfile ]; then | ||
mv $backup_vagrantfile $local_vagrantfile | ||
fi | ||
} | ||
|
||
function clean_up { | ||
echo "Cleaning up..." | ||
vagrant destroy -f | ||
rm -f package.box | ||
revert_vagrantfile | ||
} | ||
|
||
# Name of the new base box | ||
base_box="kafkatest-worker" | ||
|
||
# vagrant VM name | ||
worker_name="worker1" | ||
|
||
echo "Destroying vagrant machines..." | ||
vagrant destroy -f | ||
|
||
echo "Removing $base_box from vagrant..." | ||
vagrant box remove $base_box | ||
|
||
echo "Bringing up a single vagrant machine from scratch..." | ||
if [ -e $local_vagrantfile ]; then | ||
mv $local_vagrantfile $backup_vagrantfile | ||
fi | ||
echo "num_workers = 1" > $local_vagrantfile | ||
echo "num_brokers = 0" >> $local_vagrantfile | ||
echo "num_zookeepers = 0" >> $local_vagrantfile | ||
vagrant up | ||
up_status=$? | ||
if [ $up_status != 0 ]; then | ||
echo "Failed to bring up a template vm, please try running again." | ||
clean_up | ||
exit $up_status | ||
fi | ||
|
||
echo "Packaging $worker_name..." | ||
vagrant package $worker_name | ||
|
||
echo "Adding new base box $base_box to vagrant..." | ||
vagrant box add $base_box package.box | ||
|
||
clean_up | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ | |
num_zookeepers = 0 | ||
num_brokers = 0 | ||
num_workers = 9 | ||
base_box = "kafkatest-worker" |