When handling collisions, the fixer won't set the port to something which is used by that VM later
This commit is contained in:
parent
61bcc761bc
commit
cc0a1930d8
|
@ -41,9 +41,11 @@ module Vagrant
|
||||||
raise ActionException.new(:vm_port_collision, :name => name, :hostport => options[:hostport].to_s, :guestport => options[:guestport].to_s, :adapter => options[:adapter])
|
raise ActionException.new(:vm_port_collision, :name => name, :hostport => options[:hostport].to_s, :guestport => options[:guestport].to_s, :adapter => options[:adapter])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the auto port range and get rid of the used ports so
|
# Get the auto port range and get rid of the used ports and
|
||||||
# all we're left with is available ports
|
# ports which are being used in other forwards so we're just
|
||||||
|
# left with available ports.
|
||||||
range = runner.env.config.vm.auto_port_range.to_a
|
range = runner.env.config.vm.auto_port_range.to_a
|
||||||
|
range -= runner.env.config.vm.forwarded_ports.collect { |n, o| o[:hostport].to_i }
|
||||||
range -= used_ports
|
range -= used_ports
|
||||||
|
|
||||||
if range.empty?
|
if range.empty?
|
||||||
|
|
|
@ -94,6 +94,14 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
assert @used_ports.include?(4)
|
assert @used_ports.include?(4)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not use a host port which is being forwarded later" do
|
||||||
|
@runner.env.config.vm.forward_port("http", 80, 4)
|
||||||
|
|
||||||
|
assert_equal 0, @options[:hostport]
|
||||||
|
@action.handle_collision(@name, @options, @used_ports)
|
||||||
|
assert_equal 5, @options[:hostport]
|
||||||
|
end
|
||||||
|
|
||||||
should "raise an exception if there are no auto ports available" do
|
should "raise an exception if there are no auto ports available" do
|
||||||
@runner.env.config.vm.auto_port_range = (1..3)
|
@runner.env.config.vm.auto_port_range = (1..3)
|
||||||
assert_raises(Vagrant::Actions::ActionException) {
|
assert_raises(Vagrant::Actions::ActionException) {
|
||||||
|
|
Loading…
Reference in New Issue