From 548269212709cd31992d65aada966e711593b60a Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 10 Nov 2016 07:19:26 -0800 Subject: [PATCH] guests/linux: Only match interfaces without special characters --- plugins/guests/linux/cap/network_interfaces.rb | 2 +- .../plugins/guests/linux/cap/network_interfaces_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/guests/linux/cap/network_interfaces.rb b/plugins/guests/linux/cap/network_interfaces.rb index 9a7db83d1..372c1b9c6 100644 --- a/plugins/guests/linux/cap/network_interfaces.rb +++ b/plugins/guests/linux/cap/network_interfaces.rb @@ -55,7 +55,7 @@ module VagrantPlugins resorted_ifaces = [] resorted_ifaces += ifaces.find_all do |iface| POSSIBLE_ETHERNET_PREFIXES.any?{|prefix| iface.start_with?(prefix)} && - !iface.include?(':') + iface.match(/^[a-zA-Z0-9]+$/) end resorted_ifaces += ifaces - resorted_ifaces ifaces = resorted_ifaces diff --git a/test/unit/plugins/guests/linux/cap/network_interfaces_test.rb b/test/unit/plugins/guests/linux/cap/network_interfaces_test.rb index 5142beaa2..a7d34fe5f 100644 --- a/test/unit/plugins/guests/linux/cap/network_interfaces_test.rb +++ b/test/unit/plugins/guests/linux/cap/network_interfaces_test.rb @@ -69,6 +69,12 @@ describe "VagrantPlugins::GuestLinux::Cap::NetworkInterfaces" do expect(result).to eq(["eth0", "eth1", "eth2", "bridge0", "docker0", "docker1", "eth0:0"]) end + it "does not include ethernet devices aliases within prefix device listing with dot separators" do + expect(comm).to receive(:sudo).and_yield(:stdout, "eth1\neth2\ndocker0\nbridge0\neth0\ndocker1\neth0.1@eth0") + result = cap.network_interfaces(machine) + expect(result).to eq(["eth0", "eth1", "eth2", "bridge0", "docker0", "docker1", "eth0.1@eth0"]) + end + it "properly sorts non-consistent device name formats" do expect(comm).to receive(:sudo).and_yield(:stdout, "eth0\neth1\ndocker0\nveth437f7f9\nveth06b3e44\nveth8bb7081") result = cap.network_interfaces(machine)