Skip to content

Commit

Permalink
Now checks for VirtualBox installation and proper version and gives s…
Browse files Browse the repository at this point in the history
…ensible error if not detected.
  • Loading branch information
mitchellh committed Mar 10, 2010
1 parent c759039 commit 47d46d4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
27 changes: 27 additions & 0 deletions lib/vagrant/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,36 @@ def load!
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")]
Expand Down
30 changes: 25 additions & 5 deletions test/vagrant/env_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ def mock_persisted_vm(returnvalue="foovm")
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)
Expand Down Expand Up @@ -130,11 +148,13 @@ def mock_persisted_vm(returnvalue="foovm")

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
Expand Down
6 changes: 3 additions & 3 deletions vagrant.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,22 @@ 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"])
s.add_dependency(%q<git-style-binaries>, [">= 0.1.10"])
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"])
Expand Down

0 comments on commit 47d46d4

Please sign in to comment.