VirtualBox minimum version bumped to 3.2
This commit is contained in:
parent
e7c6168745
commit
9e931dd350
|
@ -100,13 +100,6 @@ 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\./
|
|
||||||
# VirtualBox 3.1.x uses forwarded ports via extra-data
|
|
||||||
vm.forwarded_ports.collect do |fp|
|
|
||||||
fp.hostport.to_s
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# VirtualBox 3.2.x uses forwarded ports via NAT engines
|
|
||||||
vm.network_adapters.collect do |na|
|
vm.network_adapters.collect do |na|
|
||||||
na.nat_driver.forwarded_ports.collect do |fp|
|
na.nat_driver.forwarded_ports.collect do |fp|
|
||||||
fp.hostport.to_s
|
fp.hostport.to_s
|
||||||
|
@ -114,35 +107,21 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
result.flatten.uniq
|
result.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
# Deletes existing forwarded ports.
|
# Deletes existing forwarded ports.
|
||||||
def clear_ports
|
def clear_ports
|
||||||
if VirtualBox.version =~ /^3\.1\./
|
|
||||||
fp = runner.vm.forwarded_ports.dup
|
|
||||||
fp.each { |p| p.destroy }
|
|
||||||
else
|
|
||||||
runner.vm.network_adapters.each do |na|
|
runner.vm.network_adapters.each do |na|
|
||||||
na.nat_driver.forwarded_ports.dup.each do |fp|
|
na.nat_driver.forwarded_ports.dup.each do |fp|
|
||||||
fp.destroy
|
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::ForwardedPort.new
|
|
||||||
port.name = name
|
|
||||||
port.hostport = options[:hostport]
|
|
||||||
port.guestport = options[:guestport]
|
|
||||||
port.instance = options[:adapter]
|
|
||||||
runner.vm.forwarded_ports << port
|
|
||||||
else
|
|
||||||
port = VirtualBox::NATForwardedPort.new
|
port = VirtualBox::NATForwardedPort.new
|
||||||
port.name = name
|
port.name = name
|
||||||
port.guestport = options[:guestport]
|
port.guestport = options[:guestport]
|
||||||
|
@ -153,4 +132,3 @@ module Vagrant
|
||||||
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,12 +132,6 @@ 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 = env.vm.vm.forwarded_ports.detect do |fp|
|
|
||||||
fp.name == env.config.ssh.forwarded_port_key
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# VirtualBox 3.2 specific
|
|
||||||
pnum = nil
|
pnum = nil
|
||||||
env.vm.vm.network_adapters.each do |na|
|
env.vm.vm.network_adapters.each do |na|
|
||||||
pnum = na.nat_driver.forwarded_ports.detect do |fp|
|
pnum = na.nat_driver.forwarded_ports.detect do |fp|
|
||||||
|
@ -146,7 +140,6 @@ module Vagrant
|
||||||
|
|
||||||
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,21 +202,6 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
fp
|
fp
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in VB 3.1.x" do
|
|
||||||
setup do
|
|
||||||
VirtualBox.stubs(:version).returns("3.1.4")
|
|
||||||
@fps = []
|
|
||||||
@vm.stubs(:forwarded_ports).returns(@fps)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "destroy each forwarded port" do
|
|
||||||
@fps << mock_fp
|
|
||||||
@fps << mock_fp
|
|
||||||
@action.clear_ports
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "in VB 3.2.x" do
|
|
||||||
setup do
|
setup do
|
||||||
VirtualBox.stubs(:version).returns("3.2.8")
|
VirtualBox.stubs(:version).returns("3.2.8")
|
||||||
@adapters = []
|
@adapters = []
|
||||||
|
@ -243,32 +222,8 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
@action.clear_ports
|
@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
|
|
||||||
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
|
|
||||||
|
|
||||||
context "in VB 3.2.x" do
|
|
||||||
setup do
|
setup do
|
||||||
VirtualBox.stubs(:version).returns("3.2.8")
|
VirtualBox.stubs(:version).returns("3.2.8")
|
||||||
end
|
end
|
||||||
|
@ -296,4 +251,3 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
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