Skip to content

Commit

Permalink
config.vm.guest now forces guest setting again [hashicorpGH-1800]
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jun 9, 2013
1 parent 2209204 commit 80f0660
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion config/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion lib/vagrant/guest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions plugins/kernel_v2/config/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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?
Expand Down
13 changes: 13 additions & 0 deletions test/unit/vagrant/guest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 80f0660

Please sign in to comment.