VirtualBox minimum version bumped to 3.2

This commit is contained in:
Mitchell Hashimoto 2010-06-17 23:08:38 -07:00
parent e7c6168745
commit 9e931dd350
6 changed files with 55 additions and 141 deletions

View File

@ -100,18 +100,10 @@ module Vagrant
def used_ports
result = VirtualBox::VM.all.collect do |vm|
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|
vm.network_adapters.collect do |na|
na.nat_driver.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|
na.nat_driver.forwarded_ports.collect do |fp|
fp.hostport.to_s
end
end
end
end
end
@ -121,34 +113,20 @@ module Vagrant
# Deletes existing forwarded 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|
na.nat_driver.forwarded_ports.dup.each do |fp|
fp.destroy
end
runner.vm.network_adapters.each do |na|
na.nat_driver.forwarded_ports.dup.each do |fp|
fp.destroy
end
end
end
# Forwards a port.
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.name = name
port.guestport = options[:guestport]
port.hostport = options[:hostport]
runner.vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
end
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

View File

@ -40,7 +40,7 @@ module Vagrant
version = VirtualBox.version
if version.nil?
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)
elsif version.to_s.downcase.include?("ose")
error_and_exit(:virtualbox_invalid_ose, :version => version.to_s)

View File

@ -132,20 +132,13 @@ module Vagrant
return pnum if pnum
# Check if we have an SSH forwarded port
if VirtualBox.version =~ /^3\.1\./
pnum = env.vm.vm.forwarded_ports.detect do |fp|
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
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
end
break if pnum
end
return pnum.hostport if pnum

View File

@ -219,7 +219,7 @@
manually for more verbose error output.
:virtualbox_invalid_version: |-
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.
:virtualbox_not_detected: |-
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.

View File

@ -103,9 +103,10 @@ class ForwardPortsActionTest < Test::Unit::TestCase
forwarded_ports = mock("forwarded_ports")
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)
@action.expects(:forward_port).once
@vm.expects(:save).once
@runner.expects(:reload!).once
@action.forward_ports
@ -182,13 +183,6 @@ class ForwardPortsActionTest < Test::Unit::TestCase
@action.used_ports
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
VirtualBox.stubs(:version).returns("3.2.4")
fps = [mock_fp(2222), mock_fp(80)]
@ -208,92 +202,52 @@ class ForwardPortsActionTest < Test::Unit::TestCase
fp
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
setup do
VirtualBox.stubs(:version).returns("3.2.8")
@adapters = []
@vm.stubs(:network_adapters).returns(@adapters)
end
context "in VB 3.2.x" do
setup do
VirtualBox.stubs(:version).returns("3.2.8")
@adapters = []
@vm.stubs(:network_adapters).returns(@adapters)
end
def mock_adapter
na = mock("adapter")
engine = mock("engine")
engine.stubs(:forwarded_ports).returns([mock_fp])
na.stubs(:nat_driver).returns(engine)
na
end
def mock_adapter
na = mock("adapter")
engine = mock("engine")
engine.stubs(:forwarded_ports).returns([mock_fp])
na.stubs(:nat_driver).returns(engine)
na
end
should "destroy each forwarded port" do
@adapters << mock_adapter
@adapters << mock_adapter
@action.clear_ports
end
should "destroy each forwarded port" do
@adapters << mock_adapter
@adapters << mock_adapter
@action.clear_ports
end
end
context "forwarding ports" 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
context "forwarding ports implementation" do
setup do
VirtualBox.stubs(:version).returns("3.2.8")
end
context "in VB 3.2.x" do
setup do
VirtualBox.stubs(:version).returns("3.2.8")
should "forward ports" do
name, opts = @runner.env.config.vm.forwarded_ports.first
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
should "forward ports" do
name, opts = @runner.env.config.vm.forwarded_ports.first
adapters[opts[:adapter]] = adapter
@vm.stubs(:network_adapters).returns(adapters)
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
adapters[opts[:adapter]] = adapter
@vm.stubs(:network_adapters).returns(adapters)
@action.forward_port(name, opts)
end
@action.forward_port(name, opts)
end
end
end

View File

@ -7,8 +7,9 @@ class SshTest < Test::Unit::TestCase
end
@forwarded_ports = []
@network_adapters = []
@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.vm.stubs(:vm).returns(@vm)
@ -213,18 +214,6 @@ class SshTest < Test::Unit::TestCase
mock_ssh
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
assert_equal "47", @ssh.port({ :port => "47" })
end