diff --git a/lib/vagrant/actions/vm/forward_ports.rb b/lib/vagrant/actions/vm/forward_ports.rb index 66da66232..98ea547e4 100644 --- a/lib/vagrant/actions/vm/forward_ports.rb +++ b/lib/vagrant/actions/vm/forward_ports.rb @@ -4,7 +4,7 @@ module Vagrant class ForwardPorts < Base def prepare VirtualBox::VM.all.each do |vm| - next unless vm.running? + next if !vm.running? || vm.uuid == @runner.uuid vm.forwarded_ports.each do |fp| Vagrant.config.vm.forwarded_ports.each do |name, options| diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 3fb06de29..5265353c2 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -20,7 +20,7 @@ module Vagrant end def uuid - @vm.uuid + vm ? vm.uuid : nil end def reload! diff --git a/test/vagrant/actions/vm/forward_ports_test.rb b/test/vagrant/actions/vm/forward_ports_test.rb index 7fae1ff3d..7dbfd3e83 100644 --- a/test/vagrant/actions/vm/forward_ports_test.rb +++ b/test/vagrant/actions/vm/forward_ports_test.rb @@ -15,6 +15,8 @@ class ForwardPortsActionTest < Test::Unit::TestCase @vm = mock("vm") @vm.stubs(:forwarded_ports).returns(@forwarded_ports) @vm.stubs(:running?).returns(true) + @vm.stubs(:uuid).returns("foo") + @mock_vm.stubs(:uuid).returns("bar") vms = [@vm] VirtualBox::VM.stubs(:all).returns(vms) @@ -30,6 +32,12 @@ class ForwardPortsActionTest < Test::Unit::TestCase @action.prepare end + should "ignore vms which are equivalent to ours" do + @mock_vm.expects(:uuid).returns(@vm.uuid) + @vm.expects(:forwarded_ports).never + @action.prepare + end + should "not raise any errors if no forwarded ports collide" do @forwarded_port.expects(:hostport).returns(80) assert_nothing_raised { @action.prepare } diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index bd9167074..e167e69d7 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -44,6 +44,11 @@ class VMTest < Test::Unit::TestCase @mock_vm.expects(:uuid).once.returns(uuid) assert_equal uuid, @vm.uuid end + + should "return nil if vm is nil" do + @vm.expects(:vm).returns(nil) + assert @vm.uuid.nil? + end end context "reloading" do