Skip to content

Commit

Permalink
guests/linux: Only match interfaces without special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisroberts committed Nov 10, 2016
1 parent c2d9e7e commit 5482692
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/guests/linux/cap/network_interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def self.network_interfaces(machine, path = "/sbin/ip")
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
Expand Down
6 changes: 6 additions & 0 deletions test/unit/plugins/guests/linux/cap/network_interfaces_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
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)
Expand Down

0 comments on commit 5482692

Please sign in to comment.