Port collision detection now checks every VirtualBox VM, not just the active list

This commit is contained in:
Mitchell Hashimoto 2010-03-14 17:54:30 -07:00
parent 98d5454936
commit f6057bf80a
2 changed files with 4 additions and 7 deletions

View File

@ -3,8 +3,7 @@ module Vagrant
module VM module VM
class ForwardPorts < Base class ForwardPorts < Base
def prepare def prepare
ActiveList.vms.each do |vagrant_vm| VirtualBox::VM.all.each do |vm|
vm = vagrant_vm.vm
next unless vm.running? next unless vm.running?
vm.forwarded_ports.each do |fp| vm.forwarded_ports.each do |fp|
@ -12,7 +11,7 @@ module Vagrant
if fp.hostport.to_s == options[:hostport].to_s if fp.hostport.to_s == options[:hostport].to_s
raise ActionException.new(<<-msg) raise ActionException.new(<<-msg)
Vagrant cannot forward the specified ports on this VM, since they Vagrant cannot forward the specified ports on this VM, since they
would collide with another Vagrant-managed virtual machine's forwarded would collide with another VirtualBox virtual machine's forwarded
ports! The "#{name}" forwarded port (#{fp.hostport}) is already in use on the host ports! The "#{name}" forwarded port (#{fp.hostport}) is already in use on the host
machine. machine.

View File

@ -15,10 +15,8 @@ class ForwardPortsActionTest < Test::Unit::TestCase
@vm = mock("vm") @vm = mock("vm")
@vm.stubs(:forwarded_ports).returns(@forwarded_ports) @vm.stubs(:forwarded_ports).returns(@forwarded_ports)
@vm.stubs(:running?).returns(true) @vm.stubs(:running?).returns(true)
vagrant_vm = mock("vagrant_vm") vms = [@vm]
vagrant_vm.stubs(:vm).returns(@vm) VirtualBox::VM.stubs(:all).returns(vms)
vms = [vagrant_vm]
Vagrant::ActiveList.stubs(:vms).returns(vms)
mock_config do |config| mock_config do |config|
config.vm.forwarded_ports.clear config.vm.forwarded_ports.clear