Fix #8704: Raise an error if the guest IP ends with .1 (#11500)

If the VirtualBox guest property /VirtualBox/GuestInfo/Net/1/V4/IP
returns an IP address ending in .1, raise an error.

This addresses an issue that was revealed as an NFS error, where Vagrant
was creating an exports file with the wrong IP address. This was thought
to be caused by the presence of a docker0 interface, but it manifested
itself even without Docker installed.

This issue is difficult to reproduce, but hopefully this PR will get us
closer to the root cause.
This commit is contained in:
Jeff Bonhag 2020-04-20 13:28:37 -04:00 committed by GitHub
parent 8ea70b2bf2
commit f593bb54d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -481,7 +481,7 @@ module VagrantPlugins
end
end
return get_machine_id specified_name
return get_machine_id(specified_name)
end
def max_network_adapters
@ -587,6 +587,11 @@ module VagrantPlugins
def read_guest_ip(adapter_number)
ip = read_guest_property("/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP")
if ip.end_with?(".1")
@logger.warn("VBoxManage guest property returned: #{ip}. Result resembles IP of DHCP server and is being ignored.")
ip = nil
end
if !valid_ip_address?(ip)
raise Vagrant::Errors::VirtualBoxGuestPropertyNotFound,
guest_property: "/VirtualBox/GuestInfo/Net/#{adapter_number}/V4/IP"
@ -923,7 +928,7 @@ module VagrantPlugins
def valid_ip_address?(ip)
# Filter out invalid IP addresses
# GH-4658 VirtualBox can report an IP address of 0.0.0.0 for FreeBSD guests.
if ip == "0.0.0.0"
if ip == "0.0.0.0" || ip.nil?
return false
else
return true

View File

@ -125,4 +125,40 @@ shared_examples "a version 5.x virtualbox driver" do |options|
end
end
end
describe "#read_guest_ip" do
context "when guest ip ends in .1" do
before do
key = "/VirtualBox/GuestInfo/Net/1/V4/IP"
expect(subprocess).to receive(:execute).
with("VBoxManage", "guestproperty", "get", uuid, key, an_instance_of(Hash)).
and_return(subprocess_result(stdout: "Value: 172.28.128.1"))
end
it "should raise an error" do
expect { subject.read_guest_ip(1) }.to raise_error(Vagrant::Errors::VirtualBoxGuestPropertyNotFound)
end
end
end
describe "#valid_ip_address?" do
context "when ip is 0.0.0.0" do
let(:ip) { "0.0.0.0" }
it "should be false" do
result = subject.send(:valid_ip_address?, ip)
expect(result).to be(false)
end
end
context "when ip address is nil" do
let(:ip) { nil }
it "should be false" do
result = subject.send(:valid_ip_address?, ip)
expect(result).to be(false)
end
end
end
end