From 47d46d4b12b0e08b66e7ff4dee14e4d57b244b15 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Mar 2010 21:47:07 -0800 Subject: [PATCH] Now checks for VirtualBox installation and proper version and gives sensible error if not detected. --- Gemfile | 2 +- Rakefile | 2 +- lib/vagrant/env.rb | 27 +++++++++++++++++++++++++++ test/vagrant/env_test.rb | 30 +++++++++++++++++++++++++----- vagrant.gemspec | 6 +++--- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 691ee4b51..df3042d3c 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Rakefile b/Rakefile index ee53ee1c0..f8a5d6268 100644 --- a/Rakefile +++ b/Rakefile @@ -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') diff --git a/lib/vagrant/env.rb b/lib/vagrant/env.rb index 83fb4d5ff..c3ed1bea9 100644 --- a/lib/vagrant/env.rb +++ b/lib/vagrant/env.rb @@ -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")] diff --git a/test/vagrant/env_test.rb b/test/vagrant/env_test.rb index 75b2da9a6..bb88e52c6 100644 --- a/test/vagrant/env_test.rb +++ b/test/vagrant/env_test.rb @@ -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 diff --git a/vagrant.gemspec b/vagrant.gemspec index bc1b181e2..dbb4525f3 100644 --- a/vagrant.gemspec +++ b/vagrant.gemspec @@ -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, [">= 0.5.0"]) + s.add_runtime_dependency(%q, [">= 0.5.1"]) s.add_runtime_dependency(%q, [">= 2.0.19"]) s.add_runtime_dependency(%q, [">= 1.0.2"]) s.add_runtime_dependency(%q, [">= 1.2.0"]) s.add_runtime_dependency(%q, [">= 0.1.10"]) s.add_runtime_dependency(%q, ["= 0.5.2"]) else - s.add_dependency(%q, [">= 0.5.0"]) + s.add_dependency(%q, [">= 0.5.1"]) s.add_dependency(%q, [">= 2.0.19"]) s.add_dependency(%q, [">= 1.0.2"]) s.add_dependency(%q, [">= 1.2.0"]) @@ -171,7 +171,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["= 0.5.2"]) end else - s.add_dependency(%q, [">= 0.5.0"]) + s.add_dependency(%q, [">= 0.5.1"]) s.add_dependency(%q, [">= 2.0.19"]) s.add_dependency(%q, [">= 1.0.2"]) s.add_dependency(%q, [">= 1.2.0"])