summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-04-27 17:25:04 +0100
committerThom May <thom@may.lt>2015-04-27 17:25:04 +0100
commit695c4c1bffded035ff37268da56669a1e6ad9924 (patch)
tree9e655ff25f04dec88359b0b1a521d3fadceee381
parent04d8188c1090955d95bae5e5ce68c5dfae911dcf (diff)
parent0a2655b1ef473b9ee2c6766b949634cb9cd0dad8 (diff)
downloadohai-695c4c1bffded035ff37268da56669a1e6ad9924.tar.gz
Merge pull request #527 from chef/tm/avoid_v6
Work correctly when IPv6 is disabled on Linux
-rw-r--r--lib/ohai/plugins/linux/network.rb10
-rw-r--r--spec/unit/plugins/linux/network_spec.rb14
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 314c8676..50360bb6 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 ipv6_enabled?
+ File.exist? "/proc/net/if_inet6"
+ end
+
def iproute2_binary_available?
["/sbin/ip", "/usr/bin/ip", "/bin/ip"].any? { |path| File.exist?(path) }
end
@@ -60,12 +64,14 @@ Ohai.plugin(:Network) do
:default_route => "0.0.0.0/0",
:default_prefix => :default,
:neighbour_attribute => :arp
- },{
+ }]
+
+ families << {
:name => "inet6",
:default_route => "::/0",
:default_prefix => :default_inet6,
:neighbour_attribute => :neighbour_inet6
- }]
+ } if ipv6_enabled?
so = shell_out("ip addr")
cint = nil
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index 1369b600..696a874e 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -314,7 +314,7 @@ fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
end
describe "#iproute2_binary_available?" do
- ["/sbin/ip", "/usr/bin/ip"].each do |path|
+ ["/sbin/ip", "/usr/bin/ip", "/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)
@@ -546,6 +546,7 @@ Destination Gateway Genmask Flags Metric Ref Use Iface
describe "for newer network features using iproute2 only" do
before(:each) do
allow(File).to receive(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
+ allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(true) # ipv6 is enabled
plugin.run
end
@@ -591,6 +592,17 @@ Destination Gateway Genmask Flags Metric Ref Use Iface
expect(plugin['network']['interfaces']['eth3']['state']).to eq('up')
end
+ describe "when IPv6 is disabled" do
+ before :each do
+ allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(false)
+ plugin.run
+ end
+
+ it "doesn't set ip6address" do
+ expect(plugin['ip6address']).to be_nil
+ end
+ end
+
describe "when dealing with routes" do
it "adds routes" do
plugin.run