summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schmidt <michael.j.schmidt@gmail.com>2014-10-17 14:55:32 +0200
committerBryan McLellan <btm@opscode.com>2015-02-17 12:20:24 -0500
commit4391f97158597395660f5d6cb1cecbdd0cd76dec (patch)
tree88ad3f397fd768202edfab6c2a53ac2b5d429575
parentf0b89f760099e5d773b6dd815245123ae412b30e (diff)
downloadohai-4391f97158597395660f5d6cb1cecbdd0cd76dec.tar.gz
fix network on coreos/gentoo
On Gentoo based distributions the `ip` executable is not linked to `/sbin/ip` but to `/usr/bin/ip`. Check for both locations. A general fix could be: ``` ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory| File.executable?(File.join(directory, "ip")) end ``` But maybe overkill. So, let's keep it simple. :)
-rw-r--r--lib/ohai/plugins/linux/network.rb7
-rw-r--r--spec/unit/plugins/linux/network_spec.rb16
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index d550a9da..42251bd7 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -33,6 +33,10 @@ Ohai.plugin(:Network) do
encap
end
+ def iproute2_binary_available?
+ ["/sbin/ip", "/usr/bin/ip"].any? { |path| File.exist?(path) }
+ end
+
collect_data(:linux) do
require 'ipaddr'
@@ -49,8 +53,7 @@ Ohai.plugin(:Network) do
# The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex
IPROUTE_INT_REGEX = /^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z]+|):\s/ unless defined? IPROUTE_INT_REGEX
- if File.exist?("/sbin/ip")
-
+ if iproute2_binary_available?
# families to get default routes from
families = [{
:name => "inet",
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index dbb6643e..1369b600 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -313,11 +313,21 @@ fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
allow(plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, linux_arp_an, ""))
end
+ describe "#iproute2_binary_available?" do
+ ["/sbin/ip", "/usr/bin/ip"].each do |path|
+ it "accepts #{path}" do
+ allow(File).to receive(:exist?).and_return(false)
+ allow(File).to receive(:exist?).with(path).and_return(true)
+ expect(plugin.iproute2_binary_available?).to be_truthy
+ end
+ end
+ end
+
["ifconfig","iproute2"].each do |network_method|
describe "gathering IP layer address info via #{network_method}" do
before(:each) do
- allow(File).to receive(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
+ allow(plugin).to receive(:iproute2_binary_available?).and_return( network_method == "iproute2" )
plugin.run
end
@@ -423,7 +433,7 @@ fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
describe "gathering interface counters via #{network_method}" do
before(:each) do
- allow(File).to receive(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
+ allow(plugin).to receive(:iproute2_binary_available?).and_return( network_method == "iproute2" )
plugin.run
end
@@ -461,7 +471,7 @@ fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
describe "setting the node's default IP address attribute with #{network_method}" do
before(:each) do
- allow(File).to receive(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
+ allow(plugin).to receive(:iproute2_binary_available?).and_return( network_method == "iproute2" )
plugin.run
end