From 435a32684fa64833766a1353e3bc843478b19e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Fri, 26 Jul 2019 15:47:29 +0200 Subject: [PATCH 1/2] Only return interfaces where addr is not nil tunnel interfaces on Linux have addr set to nil which makes the function list_interfaces fail with a backtrace. --- plugins/providers/docker/action/prepare_networks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/providers/docker/action/prepare_networks.rb b/plugins/providers/docker/action/prepare_networks.rb index 036651d46..0de587d46 100644 --- a/plugins/providers/docker/action/prepare_networks.rb +++ b/plugins/providers/docker/action/prepare_networks.rb @@ -34,7 +34,7 @@ module VagrantPlugins # @return [Array] interface list def list_interfaces Socket.getifaddrs.find_all do |i| - i.addr.ip? && !i.addr.ipv4_loopback? && + !i.addr.nil? && i.addr.ip? && !i.addr.ipv4_loopback? && !i.addr.ipv6_loopback? && !i.addr.ipv6_linklocal? end end From 7c93151f67646e68a7a206703b47b4011ffb66af Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 10 Oct 2019 11:38:57 -0700 Subject: [PATCH 2/2] Add test for listing interfaces with docker networks --- .../docker/action/prepare_networks_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb index 17424b9a2..524db9533 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -197,6 +197,25 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do end end + describe "#list_interfaces" do + let(:interfaces){ ["192.168.1.2", "192.168.10.10"] } + + it "returns an array of interfaces to use" do + allow(Socket).to receive(:getifaddrs). + and_return(interfaces.map{|i| double(:socket, addr: Addrinfo.ip(i))}) + interfaces = subject.list_interfaces + + expect(subject.list_interfaces.size).to eq(2) + end + + it "does not include an interface with the address is nil" do + allow(Socket).to receive(:getifaddrs). + and_return(interfaces.map{|i| double(:socket, addr: nil)}) + + expect(subject.list_interfaces.size).to eq(0) + end + end + describe "#generate_create_cli_arguments" do let(:network_options) { {:ip=>"172.20.128.2",