VirtualBox minimum version bumped to 3.2
This commit is contained in:
parent
e7c6168745
commit
9e931dd350
|
@ -100,18 +100,10 @@ module Vagrant
|
||||||
def used_ports
|
def used_ports
|
||||||
result = VirtualBox::VM.all.collect do |vm|
|
result = VirtualBox::VM.all.collect do |vm|
|
||||||
if vm.running? && vm.uuid != runner.uuid
|
if vm.running? && vm.uuid != runner.uuid
|
||||||
if VirtualBox.version =~ /^3\.1\./
|
vm.network_adapters.collect do |na|
|
||||||
# VirtualBox 3.1.x uses forwarded ports via extra-data
|
na.nat_driver.forwarded_ports.collect do |fp|
|
||||||
vm.forwarded_ports.collect do |fp|
|
|
||||||
fp.hostport.to_s
|
fp.hostport.to_s
|
||||||
end
|
end
|
||||||
else
|
|
||||||
# VirtualBox 3.2.x uses forwarded ports via NAT engines
|
|
||||||
vm.network_adapters.collect do |na|
|
|
||||||
na.nat_driver.forwarded_ports.collect do |fp|
|
|
||||||
fp.hostport.to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -121,34 +113,20 @@ module Vagrant
|
||||||
|
|
||||||
# Deletes existing forwarded ports.
|
# Deletes existing forwarded ports.
|
||||||
def clear_ports
|
def clear_ports
|
||||||
if VirtualBox.version =~ /^3\.1\./
|
runner.vm.network_adapters.each do |na|
|
||||||
fp = runner.vm.forwarded_ports.dup
|
na.nat_driver.forwarded_ports.dup.each do |fp|
|
||||||
fp.each { |p| p.destroy }
|
fp.destroy
|
||||||
else
|
|
||||||
runner.vm.network_adapters.each do |na|
|
|
||||||
na.nat_driver.forwarded_ports.dup.each do |fp|
|
|
||||||
fp.destroy
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Forwards a port.
|
# Forwards a port.
|
||||||
def forward_port(name, options)
|
def forward_port(name, options)
|
||||||
if VirtualBox.version =~ /^3\.1\./
|
port = VirtualBox::NATForwardedPort.new
|
||||||
port = VirtualBox::ForwardedPort.new
|
port.name = name
|
||||||
port.name = name
|
port.guestport = options[:guestport]
|
||||||
port.hostport = options[:hostport]
|
port.hostport = options[:hostport]
|
||||||
port.guestport = options[:guestport]
|
runner.vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
|
||||||
port.instance = options[:adapter]
|
|
||||||
runner.vm.forwarded_ports << port
|
|
||||||
else
|
|
||||||
port = VirtualBox::NATForwardedPort.new
|
|
||||||
port.name = name
|
|
||||||
port.guestport = options[:guestport]
|
|
||||||
port.hostport = options[:hostport]
|
|
||||||
runner.vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@ module Vagrant
|
||||||
version = VirtualBox.version
|
version = VirtualBox.version
|
||||||
if version.nil?
|
if version.nil?
|
||||||
error_and_exit(:virtualbox_not_detected)
|
error_and_exit(:virtualbox_not_detected)
|
||||||
elsif version.to_f < 3.1
|
elsif version.to_f < 3.2
|
||||||
error_and_exit(:virtualbox_invalid_version, :version => version.to_s)
|
error_and_exit(:virtualbox_invalid_version, :version => version.to_s)
|
||||||
elsif version.to_s.downcase.include?("ose")
|
elsif version.to_s.downcase.include?("ose")
|
||||||
error_and_exit(:virtualbox_invalid_ose, :version => version.to_s)
|
error_and_exit(:virtualbox_invalid_ose, :version => version.to_s)
|
||||||
|
|
|
@ -132,20 +132,13 @@ module Vagrant
|
||||||
return pnum if pnum
|
return pnum if pnum
|
||||||
|
|
||||||
# Check if we have an SSH forwarded port
|
# Check if we have an SSH forwarded port
|
||||||
if VirtualBox.version =~ /^3\.1\./
|
pnum = nil
|
||||||
pnum = env.vm.vm.forwarded_ports.detect do |fp|
|
env.vm.vm.network_adapters.each do |na|
|
||||||
|
pnum = na.nat_driver.forwarded_ports.detect do |fp|
|
||||||
fp.name == env.config.ssh.forwarded_port_key
|
fp.name == env.config.ssh.forwarded_port_key
|
||||||
end
|
end
|
||||||
else
|
|
||||||
# VirtualBox 3.2 specific
|
|
||||||
pnum = nil
|
|
||||||
env.vm.vm.network_adapters.each do |na|
|
|
||||||
pnum = na.nat_driver.forwarded_ports.detect do |fp|
|
|
||||||
fp.name == env.config.ssh.forwarded_port_key
|
|
||||||
end
|
|
||||||
|
|
||||||
break if pnum
|
break if pnum
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return pnum.hostport if pnum
|
return pnum.hostport if pnum
|
||||||
|
|
|
@ -219,7 +219,7 @@
|
||||||
manually for more verbose error output.
|
manually for more verbose error output.
|
||||||
:virtualbox_invalid_version: |-
|
:virtualbox_invalid_version: |-
|
||||||
Vagrant has detected that you have VirtualBox version <%= version %> installed!
|
Vagrant has detected that you have VirtualBox version <%= version %> installed!
|
||||||
Vagrant requires that you use at least VirtualBox version 3.1. Please install
|
Vagrant requires that you use at least VirtualBox version 3.2. Please install
|
||||||
a more recent version of VirtualBox to continue.
|
a more recent version of VirtualBox to continue.
|
||||||
:virtualbox_not_detected: |-
|
:virtualbox_not_detected: |-
|
||||||
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
|
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
|
||||||
|
|
|
@ -103,9 +103,10 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
forwarded_ports = mock("forwarded_ports")
|
forwarded_ports = mock("forwarded_ports")
|
||||||
network_adapter = mock("network_adapter")
|
network_adapter = mock("network_adapter")
|
||||||
|
|
||||||
@vm.expects(:network_adapters).returns([network_adapter])
|
@vm.stubs(:network_adapters).returns([network_adapter])
|
||||||
network_adapter.expects(:attachment_type).returns(:nat)
|
network_adapter.expects(:attachment_type).returns(:nat)
|
||||||
|
|
||||||
|
@action.expects(:forward_port).once
|
||||||
@vm.expects(:save).once
|
@vm.expects(:save).once
|
||||||
@runner.expects(:reload!).once
|
@runner.expects(:reload!).once
|
||||||
@action.forward_ports
|
@action.forward_ports
|
||||||
|
@ -182,13 +183,6 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
@action.used_ports
|
@action.used_ports
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return the forwarded ports for VB 3.1.x" do
|
|
||||||
VirtualBox.stubs(:version).returns("3.1.4")
|
|
||||||
fps = [mock_fp(2222), mock_fp(80)]
|
|
||||||
@vms << mock_vm(:forwarded_ports => fps)
|
|
||||||
assert_equal %W[2222 80], @action.used_ports
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return the forwarded ports for VB 3.2.x" do
|
should "return the forwarded ports for VB 3.2.x" do
|
||||||
VirtualBox.stubs(:version).returns("3.2.4")
|
VirtualBox.stubs(:version).returns("3.2.4")
|
||||||
fps = [mock_fp(2222), mock_fp(80)]
|
fps = [mock_fp(2222), mock_fp(80)]
|
||||||
|
@ -208,92 +202,52 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
fp
|
fp
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in VB 3.1.x" do
|
setup do
|
||||||
setup do
|
VirtualBox.stubs(:version).returns("3.2.8")
|
||||||
VirtualBox.stubs(:version).returns("3.1.4")
|
@adapters = []
|
||||||
@fps = []
|
@vm.stubs(:network_adapters).returns(@adapters)
|
||||||
@vm.stubs(:forwarded_ports).returns(@fps)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "destroy each forwarded port" do
|
|
||||||
@fps << mock_fp
|
|
||||||
@fps << mock_fp
|
|
||||||
@action.clear_ports
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in VB 3.2.x" do
|
def mock_adapter
|
||||||
setup do
|
na = mock("adapter")
|
||||||
VirtualBox.stubs(:version).returns("3.2.8")
|
engine = mock("engine")
|
||||||
@adapters = []
|
engine.stubs(:forwarded_ports).returns([mock_fp])
|
||||||
@vm.stubs(:network_adapters).returns(@adapters)
|
na.stubs(:nat_driver).returns(engine)
|
||||||
end
|
na
|
||||||
|
end
|
||||||
|
|
||||||
def mock_adapter
|
should "destroy each forwarded port" do
|
||||||
na = mock("adapter")
|
@adapters << mock_adapter
|
||||||
engine = mock("engine")
|
@adapters << mock_adapter
|
||||||
engine.stubs(:forwarded_ports).returns([mock_fp])
|
@action.clear_ports
|
||||||
na.stubs(:nat_driver).returns(engine)
|
|
||||||
na
|
|
||||||
end
|
|
||||||
|
|
||||||
should "destroy each forwarded port" do
|
|
||||||
@adapters << mock_adapter
|
|
||||||
@adapters << mock_adapter
|
|
||||||
@action.clear_ports
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "forwarding ports" do
|
context "forwarding ports implementation" do
|
||||||
context "in VB 3.1.x" do
|
setup do
|
||||||
setup do
|
VirtualBox.stubs(:version).returns("3.2.8")
|
||||||
VirtualBox.stubs(:version).returns("3.1.4")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "forward ports" do
|
|
||||||
forwarded_ports = mock("forwarded_ports")
|
|
||||||
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
|
||||||
@runner.env.config.vm.forwarded_ports.each do |name, opts|
|
|
||||||
forwarded_ports.expects(:<<).with do |port|
|
|
||||||
assert_equal name, port.name
|
|
||||||
assert_equal opts[:hostport], port.hostport
|
|
||||||
assert_equal opts[:guestport], port.guestport
|
|
||||||
assert_equal opts[:adapter], port.instance
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
@action.forward_port(name, opts)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in VB 3.2.x" do
|
should "forward ports" do
|
||||||
setup do
|
name, opts = @runner.env.config.vm.forwarded_ports.first
|
||||||
VirtualBox.stubs(:version).returns("3.2.8")
|
|
||||||
|
adapters = []
|
||||||
|
adapter = mock("adapter")
|
||||||
|
engine = mock("engine")
|
||||||
|
fps = mock("forwarded ports")
|
||||||
|
adapter.stubs(:nat_driver).returns(engine)
|
||||||
|
engine.stubs(:forwarded_ports).returns(fps)
|
||||||
|
fps.expects(:<<).with do |port|
|
||||||
|
assert_equal name, port.name
|
||||||
|
assert_equal opts[:hostport], port.hostport
|
||||||
|
assert_equal opts[:guestport], port.guestport
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
should "forward ports" do
|
adapters[opts[:adapter]] = adapter
|
||||||
name, opts = @runner.env.config.vm.forwarded_ports.first
|
@vm.stubs(:network_adapters).returns(adapters)
|
||||||
|
|
||||||
adapters = []
|
@action.forward_port(name, opts)
|
||||||
adapter = mock("adapter")
|
|
||||||
engine = mock("engine")
|
|
||||||
fps = mock("forwarded ports")
|
|
||||||
adapter.stubs(:nat_driver).returns(engine)
|
|
||||||
engine.stubs(:forwarded_ports).returns(fps)
|
|
||||||
fps.expects(:<<).with do |port|
|
|
||||||
assert_equal name, port.name
|
|
||||||
assert_equal opts[:hostport], port.hostport
|
|
||||||
assert_equal opts[:guestport], port.guestport
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
adapters[opts[:adapter]] = adapter
|
|
||||||
@vm.stubs(:network_adapters).returns(adapters)
|
|
||||||
|
|
||||||
@action.forward_port(name, opts)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,9 @@ class SshTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
@forwarded_ports = []
|
@forwarded_ports = []
|
||||||
|
@network_adapters = []
|
||||||
@vm = mock("vm")
|
@vm = mock("vm")
|
||||||
@vm.stubs(:forwarded_ports).returns(@forwarded_ports)
|
@vm.stubs(:network_adapters).returns(@network_adapters)
|
||||||
|
|
||||||
@env.stubs(:vm).returns(mock_vm(@env))
|
@env.stubs(:vm).returns(mock_vm(@env))
|
||||||
@env.vm.stubs(:vm).returns(@vm)
|
@env.vm.stubs(:vm).returns(@vm)
|
||||||
|
@ -213,18 +214,6 @@ class SshTest < Test::Unit::TestCase
|
||||||
mock_ssh
|
mock_ssh
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return the configured port by default in VB 3.1.x" do
|
|
||||||
VirtualBox.stubs(:version).returns("3.1.4")
|
|
||||||
|
|
||||||
port = 2222
|
|
||||||
fp = mock("fp")
|
|
||||||
fp.stubs(:name).returns(@env.config.ssh.forwarded_port_key)
|
|
||||||
fp.stubs(:hostport).returns(port)
|
|
||||||
@forwarded_ports << fp
|
|
||||||
|
|
||||||
assert_equal port, @ssh.port
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return the port given in options if it exists" do
|
should "return the port given in options if it exists" do
|
||||||
assert_equal "47", @ssh.port({ :port => "47" })
|
assert_equal "47", @ssh.port({ :port => "47" })
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue