Ignore non-hostonly adapters for host only networking [closes GH-101]

This commit is contained in:
Mitchell Hashimoto 2010-07-01 14:26:56 -07:00
parent e4b13ea758
commit 0896f096e9
3 changed files with 81 additions and 57 deletions

View File

@ -62,6 +62,10 @@ module Vagrant
# First try to find a matching network
interfaces = VirtualBox::Global.global.host.network_interfaces
interfaces.each do |ni|
# Ignore non-host only interfaces which may also match,
# since they're not valid options.
next if ni.interface_type != :host_only
if net_options[:name]
return ni.name if net_options[:name] == ni.name
else

View File

@ -122,23 +122,43 @@ class NetworkTest < Test::Unit::TestCase
@options = { :ip => :foo, :netmask => :bar, :name => nil }
end
def mock_interface(options=nil)
options = {
:interface_type => :host_only,
:name => "foo"
}.merge(options || {})
interface = mock("interface")
options.each do |k,v|
interface.stubs(k).returns(v)
end
@interfaces << interface
interface
end
should "return the network which matches" do
result = mock("result")
interface = mock("interface")
interface.stubs(:name).returns(result)
@interfaces << interface
interface = mock_interface(:name => result)
@action.expects(:matching_network?).with(interface, @options).returns(true)
assert_equal result, @action.network_name(@options)
end
should "ignore non-host only interfaces" do
@options[:name] = "foo"
mock_interface(:name => @options[:name],
:interface_type => :bridged)
assert_raises(Vagrant::Actions::ActionException) {
@action.network_name(@options)
}
end
should "return the network which matches the name if given" do
@options[:name] = "foo"
interface = mock("interface")
interface.stubs(:name).returns(@options[:name])
@interfaces << interface
interface = mock_interface(:name => @options[:name])
assert_equal @options[:name], @action.network_name(@options)
end
@ -154,12 +174,12 @@ class NetworkTest < Test::Unit::TestCase
should "create a network for the IP and netmask" do
result = mock("result")
interface = mock("interface")
network_ip = :foo
interface = mock_interface(:name => result)
interface.expects(:enable_static).with(network_ip, @options[:netmask])
@interfaces.expects(:create).returns(interface)
@action.expects(:network_ip).with(@options[:ip], @options[:netmask]).once.returns(network_ip)
interface.expects(:enable_static).with(network_ip, @options[:netmask])
interface.expects(:name).returns(result)
assert_equal result, @action.network_name(@options)
end

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mitchell Hashimoto", "John Bender"]
s.date = %q{2010-06-29}
s.date = %q{2010-07-01}
s.default_executable = %q{vagrant}
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
@ -186,85 +186,85 @@ Gem::Specification.new do |s|
s.homepage = %q{http://github.com/mitchellh/vagrant}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.6}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.test_files = [
"test/test_helper.rb",
"test/vagrant/vm_test.rb",
"test/vagrant/command_test.rb",
"test/vagrant/environment_test.rb",
"test/vagrant/util_test.rb",
"test/vagrant/box_test.rb",
"test/vagrant/busy_test.rb",
"test/vagrant/provisioners/base_test.rb",
"test/vagrant/provisioners/chef_test.rb",
"test/vagrant/provisioners/chef_server_test.rb",
"test/vagrant/provisioners/chef_solo_test.rb",
"test/vagrant/systems/linux_test.rb",
"test/vagrant/config_test.rb",
"test/vagrant/actions/base_test.rb",
"test/vagrant/actions/runner_test.rb",
"test/vagrant/actions/box/verify_test.rb",
"test/vagrant/actions/box/destroy_test.rb",
"test/vagrant/actions/box/add_test.rb",
"test/vagrant/actions/box/unpackage_test.rb",
"test/vagrant/actions/box/destroy_test.rb",
"test/vagrant/actions/box/download_test.rb",
"test/vagrant/actions/box/unpackage_test.rb",
"test/vagrant/actions/box/verify_test.rb",
"test/vagrant/actions/collection_test.rb",
"test/vagrant/actions/vm/reload_test.rb",
"test/vagrant/actions/vm/suspend_test.rb",
"test/vagrant/actions/runner_test.rb",
"test/vagrant/actions/vm/boot_test.rb",
"test/vagrant/actions/vm/package_test.rb",
"test/vagrant/actions/vm/down_test.rb",
"test/vagrant/actions/vm/shared_folders_test.rb",
"test/vagrant/actions/vm/customize_test.rb",
"test/vagrant/actions/vm/destroy_test.rb",
"test/vagrant/actions/vm/down_test.rb",
"test/vagrant/actions/vm/export_test.rb",
"test/vagrant/actions/vm/forward_ports_test.rb",
"test/vagrant/actions/vm/halt_test.rb",
"test/vagrant/actions/vm/import_test.rb",
"test/vagrant/actions/vm/customize_test.rb",
"test/vagrant/actions/vm/start_test.rb",
"test/vagrant/actions/vm/network_test.rb",
"test/vagrant/actions/vm/move_hard_drive_test.rb",
"test/vagrant/actions/vm/up_test.rb",
"test/vagrant/actions/vm/export_test.rb",
"test/vagrant/actions/vm/network_test.rb",
"test/vagrant/actions/vm/package_test.rb",
"test/vagrant/actions/vm/provision_test.rb",
"test/vagrant/actions/vm/reload_test.rb",
"test/vagrant/actions/vm/resume_test.rb",
"test/vagrant/actions/vm/forward_ports_test.rb",
"test/vagrant/actions/vm/shared_folders_test.rb",
"test/vagrant/actions/vm/start_test.rb",
"test/vagrant/actions/vm/suspend_test.rb",
"test/vagrant/actions/vm/up_test.rb",
"test/vagrant/active_list_test.rb",
"test/vagrant/box_test.rb",
"test/vagrant/busy_test.rb",
"test/vagrant/command_test.rb",
"test/vagrant/commands/base_test.rb",
"test/vagrant/commands/reload_test.rb",
"test/vagrant/commands/ssh_config_test.rb",
"test/vagrant/commands/suspend_test.rb",
"test/vagrant/commands/package_test.rb",
"test/vagrant/commands/status_test.rb",
"test/vagrant/commands/init_test.rb",
"test/vagrant/commands/destroy_test.rb",
"test/vagrant/commands/halt_test.rb",
"test/vagrant/commands/box/remove_test.rb",
"test/vagrant/commands/box/add_test.rb",
"test/vagrant/commands/box/list_test.rb",
"test/vagrant/commands/up_test.rb",
"test/vagrant/commands/box/remove_test.rb",
"test/vagrant/commands/destroy_test.rb",
"test/vagrant/commands/halt_test.rb",
"test/vagrant/commands/init_test.rb",
"test/vagrant/commands/package_test.rb",
"test/vagrant/commands/provision_test.rb",
"test/vagrant/commands/reload_test.rb",
"test/vagrant/commands/resume_test.rb",
"test/vagrant/commands/ssh_config_test.rb",
"test/vagrant/commands/ssh_test.rb",
"test/vagrant/resource_logger_test.rb",
"test/vagrant/commands/status_test.rb",
"test/vagrant/commands/suspend_test.rb",
"test/vagrant/commands/up_test.rb",
"test/vagrant/config_test.rb",
"test/vagrant/downloaders/base_test.rb",
"test/vagrant/downloaders/file_test.rb",
"test/vagrant/downloaders/http_test.rb",
"test/vagrant/util/stacked_proc_runner_test.rb",
"test/vagrant/environment_test.rb",
"test/vagrant/provisioners/base_test.rb",
"test/vagrant/provisioners/chef_server_test.rb",
"test/vagrant/provisioners/chef_solo_test.rb",
"test/vagrant/provisioners/chef_test.rb",
"test/vagrant/resource_logger_test.rb",
"test/vagrant/ssh_session_test.rb",
"test/vagrant/ssh_test.rb",
"test/vagrant/systems/linux_test.rb",
"test/vagrant/util/error_helper_test.rb",
"test/vagrant/util/output_helper_test.rb",
"test/vagrant/util/plain_logger_test.rb",
"test/vagrant/util/platform_test.rb",
"test/vagrant/util/stacked_proc_runner_test.rb",
"test/vagrant/util/template_renderer_test.rb",
"test/vagrant/util/translator_test.rb",
"test/vagrant/util/platform_test.rb",
"test/vagrant/util/error_helper_test.rb",
"test/vagrant/util/plain_logger_test.rb",
"test/vagrant/ssh_session_test.rb",
"test/vagrant/ssh_test.rb"
"test/vagrant/util_test.rb",
"test/vagrant/vm_test.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<virtualbox>, ["~> 0.7.0"])
s.add_runtime_dependency(%q<net-ssh>, [">= 2.0.19"])
s.add_runtime_dependency(%q<net-scp>, [">= 1.0.2"])