diff --git a/CHANGELOG.md b/CHANGELOG.md index c896848ebcb..5951b55e2b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ BUG FIXES: - Finding V1 boxes now works properly again to avoid "box not found" errors. [GH-1691] - Setting hostname on SLES 11 works again. [GH-1781] + - `config.vm.guest` properly forces guests again. [GH-1800] ## 1.2.2 (April 23, 2013) diff --git a/config/default.rb b/config/default.rb index 97f92fc53c7..d4cb3aa8727 100644 --- a/config/default.rb +++ b/config/default.rb @@ -16,7 +16,6 @@ config.vm.base_mac = nil config.vm.graceful_halt_retry_count = 60 config.vm.graceful_halt_retry_interval = 1 - config.vm.guest = :linux # Share SSH locally by default config.vm.network :forwarded_port, diff --git a/lib/vagrant/guest.rb b/lib/vagrant/guest.rb index ad4f06ecba5..1c0dab15820 100644 --- a/lib/vagrant/guest.rb +++ b/lib/vagrant/guest.rb @@ -69,7 +69,16 @@ def detect! guest_info = @guests[name] guest = guest_info[0].new - if guest.detect?(@machine) + # If a specific guest was specified, then attempt to use that + # guest no matter what. Otherwise, only use it if it was detected. + use_this_guest = false + if @machine.config.vm.guest.nil? + use_this_guest = guest.detect?(@machine) + else + use_this_guest = @machine.config.vm.guest.to_sym == name.to_sym + end + + if use_this_guest @logger.info("Detected: #{name}!") @chain << [name, guest] @name = name diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 89f70b5c51f..e57042f6138 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -26,6 +26,7 @@ class VMConfig < Vagrant.plugin("2", :config) def initialize @graceful_halt_retry_count = UNSET_VALUE @graceful_halt_retry_interval = UNSET_VALUE + @guest = UNSET_VALUE @hostname = UNSET_VALUE @provisioners = [] @@ -225,8 +226,12 @@ def define(name, options=nil, &block) def finalize! # Defaults + @guest = nil if @guest == UNSET_VALUE @hostname = nil if @hostname == UNSET_VALUE + # Set the guest properly + @guest = @guest.to_sym if @guest + # If we haven't defined a single VM, then we need to define a # default VM which just inherits the rest of the configuration. define(DEFAULT_VM_NAME) if defined_vm_keys.empty? diff --git a/test/unit/vagrant/guest_test.rb b/test/unit/vagrant/guest_test.rb index d778ccd0517..b66ccc70872 100644 --- a/test/unit/vagrant/guest_test.rb +++ b/test/unit/vagrant/guest_test.rb @@ -10,6 +10,9 @@ let(:machine) do double("machine").tap do |m| m.stub(:inspect => "machine") + m.stub(:config => double("config")) + m.config.stub(:vm => double("vm_config")) + m.config.vm.stub(:guest => nil) end end @@ -143,6 +146,16 @@ def register_guest(name, parent, detect) subject.chain.map { |x| x[1] }.map(&:name).should == [:baz, :bar, :foo] end + it "detects the forced guest setting" do + register_guest(:foo, nil, false) + register_guest(:bar, nil, false) + + machine.config.vm.stub(:guest => :bar) + + subject.detect! + subject.name.should == :bar + end + it "raises an exception if no guest can be detected" do expect { subject.detect! }. to raise_error(Vagrant::Errors::GuestNotDetected)