Merge pull request #2674 from phinze/static-nfs-guest-ips
core: problems with using VirtualBox guest properties for reading NFS Guest IP
This commit is contained in:
commit
7141be065a
|
@ -34,8 +34,7 @@ module VagrantPlugins
|
|||
# The ! indicates that this method modifies its argument.
|
||||
def add_ips_to_env!(env)
|
||||
adapter, host_ip = find_host_only_adapter
|
||||
machine_ip = nil
|
||||
machine_ip = read_machine_ip(adapter) if adapter
|
||||
machine_ip = read_static_machine_ips || read_dynamic_machine_ip(adapter)
|
||||
|
||||
raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip
|
||||
|
||||
|
@ -61,6 +60,25 @@ module VagrantPlugins
|
|||
nil
|
||||
end
|
||||
|
||||
# Returns the IP address(es) of the guest by looking for static IPs
|
||||
# given to host only adapters in the Vagrantfile
|
||||
#
|
||||
# @return [Array]<String> Configured static IPs
|
||||
def read_static_machine_ips
|
||||
ips = []
|
||||
@machine.config.vm.networks.each do |type, options|
|
||||
if type == :private_network && options[:ip].is_a?(String)
|
||||
ips << options[:ip]
|
||||
end
|
||||
end
|
||||
|
||||
if ips.empty?
|
||||
return nil
|
||||
end
|
||||
|
||||
ips
|
||||
end
|
||||
|
||||
# Returns the IP address of the guest by looking at vbox guest property
|
||||
# for the appropriate guest adapter.
|
||||
#
|
||||
|
@ -69,7 +87,9 @@ module VagrantPlugins
|
|||
#
|
||||
# @param [Integer] adapter number to read IP for
|
||||
# @return [String] ip address of adapter
|
||||
def read_machine_ip(adapter)
|
||||
def read_dynamic_machine_ip(adapter)
|
||||
return nil unless adapter
|
||||
|
||||
# vbox guest properties are 0-indexed, while showvminfo network
|
||||
# interfaces are 1-indexed. go figure.
|
||||
guestproperty_adapter = adapter - 1
|
||||
|
|
|
@ -51,6 +51,10 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
|
|||
{name: "vmnet2", ip: "1.2.3.4"},
|
||||
])
|
||||
driver.stub(:read_guest_ip).with(1).and_return("2.3.4.5")
|
||||
|
||||
# override sleep to 0 so test does not take seconds
|
||||
retry_options = subject.retry_options
|
||||
subject.stub(:retry_options).and_return(retry_options.merge(sleep: 0))
|
||||
end
|
||||
|
||||
it "sets nfs_host_ip and nfs_machine_ip properly" do
|
||||
|
@ -74,10 +78,6 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
|
|||
]
|
||||
driver.stub(:read_guest_ip) { raise_then_return.shift.call }
|
||||
|
||||
# override sleep to 0 so test does not take seconds
|
||||
retry_options = subject.retry_options
|
||||
subject.stub(:retry_options).and_return(retry_options.merge(sleep: 0))
|
||||
|
||||
subject.call(env)
|
||||
|
||||
env[:nfs_host_ip].should == "1.2.3.4"
|
||||
|
@ -89,12 +89,21 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
|
|||
raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => 'stub'
|
||||
}
|
||||
|
||||
# override sleep to 0 so test does not take seconds
|
||||
retry_options = subject.retry_options
|
||||
subject.stub(:retry_options).and_return(retry_options.merge(sleep: 0))
|
||||
|
||||
expect { subject.call(env) }.
|
||||
to raise_error(Vagrant::Errors::NFSNoGuestIP)
|
||||
end
|
||||
|
||||
it "allows statically configured guest IPs to work for NFS, even when guest property would fail" do
|
||||
env[:machine].config.vm.network :private_network, ip: "11.12.13.14"
|
||||
|
||||
driver.stub(:read_guest_ip) {
|
||||
raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound, :guest_property => "stub"
|
||||
}
|
||||
|
||||
subject.call(env)
|
||||
|
||||
env[:nfs_host_ip].should == "1.2.3.4"
|
||||
env[:nfs_machine_ip].should == ["11.12.13.14"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue