Now checks for VirtualBox installation and proper version and gives sensible error if not detected.

This commit is contained in:
Mitchell Hashimoto 2010-03-09 21:47:07 -08:00
parent c75903959c
commit 47d46d4b12
5 changed files with 57 additions and 10 deletions

View File

@ -1,7 +1,7 @@
source :gemcutter
# Gems required for the lib to even run
gem "virtualbox", ">= 0.5.0"
gem "virtualbox", ">= 0.5.1"
gem "net-ssh", ">= 2.0.19"
gem "net-scp", ">= 1.0.2"
gem "git-style-binaries", ">= 0.1.10"

View File

@ -10,7 +10,7 @@ begin
gemspec.homepage = "http://github.com/mitchellh/vagrant"
gemspec.authors = ["Mitchell Hashimoto", "John Bender"]
gemspec.add_dependency('virtualbox', '>= 0.5.0')
gemspec.add_dependency('virtualbox', '>= 0.5.1')
gemspec.add_dependency('net-ssh', '>= 2.0.19')
gemspec.add_dependency('net-scp', '>= 1.0.2')
gemspec.add_dependency('json', '>= 1.2.0')

View File

@ -24,9 +24,36 @@ module Vagrant
load_config!
load_home_directory!
load_box!
check_virtualbox!
load_vm!
end
def check_virtualbox!
version = VirtualBox::Command.version
if version.nil?
error_and_exit(<<-msg)
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
If VirtualBox is installed, you may need to tweak the paths to the `VBoxManage`
application which ships with VirtualBox and the path to the global XML configuration
which VirtualBox typically stores somewhere in your home directory.
The following shows how to configure VirtualBox. This can be done in the
Vagrantfile. Note that 90% of the time, you shouldn't need to do this if VirtualBox
is installed. Please use the various Vagrant support lines to request more information
if you can't get this working.
VirtualBox::Command.vboxmanage = "/path/to/my/VBoxManage"
VirtualBox::Global.vboxconfig = "~/path/to/VirtualBox.xml"
msg
elsif version.to_f < 3.0
error_and_exit(<<-msg)
Vagrant has detected that you have VirtualBox version #{version} installed!
Vagrant requires that you use at least VirtualBox version 3. Please install
a more recent version of VirtualBox to continue.
msg
end
end
def load_config!
# Prepare load paths for config files
load_paths = [File.join(PROJECT_ROOT, "config", "default.rb")]

View File

@ -15,6 +15,24 @@ class EnvTest < Test::Unit::TestCase
Vagrant::Box.stubs(:find).returns("foo")
end
context "checking virtualbox version" do
setup do
VirtualBox::Command.stubs(:version)
end
should "error and exit if VirtualBox is not installed or detected" do
Vagrant::Env.expects(:error_and_exit).once
VirtualBox::Command.expects(:version).returns(nil)
Vagrant::Env.check_virtualbox!
end
should "error and exit if VirtualBox is lower than version 3" do
Vagrant::Env.expects(:error_and_exit).once
VirtualBox::Command.expects(:version).returns("2.1.3r1041")
Vagrant::Env.check_virtualbox!
end
end
context "requiring a VM" do
setup do
Vagrant::Env.stubs(:require_root_path)
@ -130,11 +148,13 @@ class EnvTest < Test::Unit::TestCase
context "initial load" do
test "load! should load the config and set the persisted_uid" do
Vagrant::Env.expects(:load_config!).once
Vagrant::Env.expects(:load_vm!).once
Vagrant::Env.expects(:load_root_path!).once
Vagrant::Env.expects(:load_home_directory!).once
Vagrant::Env.expects(:load_box!).once
call_seq = sequence("call_sequence")
Vagrant::Env.expects(:load_root_path!).once.in_sequence(call_seq)
Vagrant::Env.expects(:load_config!).once.in_sequence(call_seq)
Vagrant::Env.expects(:load_home_directory!).once.in_sequence(call_seq)
Vagrant::Env.expects(:load_box!).once.in_sequence(call_seq)
Vagrant::Env.expects(:check_virtualbox!).once.in_sequence(call_seq)
Vagrant::Env.expects(:load_vm!).once.in_sequence(call_seq)
Vagrant::Env.load!
end
end

View File

@ -156,14 +156,14 @@ Gem::Specification.new do |s|
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<virtualbox>, [">= 0.5.0"])
s.add_runtime_dependency(%q<virtualbox>, [">= 0.5.1"])
s.add_runtime_dependency(%q<net-ssh>, [">= 2.0.19"])
s.add_runtime_dependency(%q<net-scp>, [">= 1.0.2"])
s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
s.add_runtime_dependency(%q<git-style-binaries>, [">= 0.1.10"])
s.add_runtime_dependency(%q<archive-tar-minitar>, ["= 0.5.2"])
else
s.add_dependency(%q<virtualbox>, [">= 0.5.0"])
s.add_dependency(%q<virtualbox>, [">= 0.5.1"])
s.add_dependency(%q<net-ssh>, [">= 2.0.19"])
s.add_dependency(%q<net-scp>, [">= 1.0.2"])
s.add_dependency(%q<json>, [">= 1.2.0"])
@ -171,7 +171,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<archive-tar-minitar>, ["= 0.5.2"])
end
else
s.add_dependency(%q<virtualbox>, [">= 0.5.0"])
s.add_dependency(%q<virtualbox>, [">= 0.5.1"])
s.add_dependency(%q<net-ssh>, [">= 2.0.19"])
s.add_dependency(%q<net-scp>, [">= 1.0.2"])
s.add_dependency(%q<json>, [">= 1.2.0"])