summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarton Natko <martonnatko@Martons-MacBook-Pro.local>2016-10-25 15:04:45 +0200
committerMarton Natko <martonnatko@Martons-MacBook-Pro.local>2016-10-25 15:05:11 +0200
commit81d291169b3e5f85c611600bdc240572372c288d (patch)
tree35edc87b4e855b95c5a50dd875195208133558d5
parentbd4ba9c2b5b87ff46cffbf20039fa6435b6a7db4 (diff)
downloadohai-81d291169b3e5f85c611600bdc240572372c288d.tar.gz
plus the files
Signed-off-by: Marton Natko <marton.natko@gmail.com>
-rw-r--r--lib/ohai/plugins/ip_scopes.rb12
-rw-r--r--spec/unit/plugins/ip_scopes_spec.rb33
2 files changed, 41 insertions, 4 deletions
diff --git a/lib/ohai/plugins/ip_scopes.rb b/lib/ohai/plugins/ip_scopes.rb
index 4d8d61d8..045e7897 100644
--- a/lib/ohai/plugins/ip_scopes.rb
+++ b/lib/ohai/plugins/ip_scopes.rb
@@ -32,7 +32,7 @@ Ohai.plugin(:IpScopes) do
begin
attrs["ip_scope"] = address.to_ip.scope
- if private_addr?(address) && !tunnel_iface?(interface)
+ if private_addr?(address) && !tunnel_iface?(interface) && !ppp_iface(interface) && !docker_iface(interface)
privateaddress(address)
end
rescue ArgumentError
@@ -51,7 +51,15 @@ Ohai.plugin(:IpScopes) do
address.to_ip.scope =~ /PRIVATE/
end
- def tunnel_iface?(interface)
+ def ppp_iface?(interface)
interface["type"] == "ppp"
end
+
+ def tunel_iface?(interface)
+ interface["type"] == "tunl"
+ end
+
+ def docker_iface?(interface)
+ interface["type"] == "docker"
+ end
end
diff --git a/spec/unit/plugins/ip_scopes_spec.rb b/spec/unit/plugins/ip_scopes_spec.rb
index 4a808949..4dd778c4 100644
--- a/spec/unit/plugins/ip_scopes_spec.rb
+++ b/spec/unit/plugins/ip_scopes_spec.rb
@@ -11,13 +11,17 @@ describe Ohai::System, "plugin ip_scopes" do
let(:interfaces) do
Hash[
interface1, { :addresses => addresses1, :type => interface1_type },
- interface2, { :addresses => addresses2, :type => interface2_type }] end
+ interface2, { :addresses => addresses2, :type => interface2_type },
+ interface3, { :addresses => addresses3, :type => interface3_type }] end
let(:interface1) { :eth0 }
let(:interface2) { :eth1 }
+ let(:interface3) { :eth2 }
let(:addresses1) { {} }
let(:addresses2) { {} }
+ let(:addresses3) { {} }
let(:interface1_type) { "eth" }
let(:interface2_type) { "eth" }
+ let(:interface3_type) { "eth" }
before { plugin[:network] = network }
@@ -62,11 +66,36 @@ describe Ohai::System, "plugin ip_scopes" do
end
end
+ context "when host has tunl" do
+ let(:ip1) { "10.0.0.1" }
+ let(:ip2) { "192.168.1.1" }
+ let(:interface1_type) { "eth" }
+ let(:interface2_type) { "tunl" }
+
+ it "picks the non-virtual address" do
+ expect(plugin[:privateaddress]).to eq("10.0.0.1")
+ end
+ end
+
+ context "when host has docker" do
+ let(:ip1) { "10.0.0.1" }
+ let(:ip2) { "192.168.1.1" }
+ let(:interface1_type) { "eth" }
+ let(:interface2_type) { "docker" }
+
+ it "picks the non-virtual address" do
+ expect(plugin[:privateaddress]).to eq("10.0.0.1")
+ end
+ end
+
context "when host only has virtual RFC1918 addresses" do
let(:ip1) { "10.0.0.1" }
let(:ip2) { "192.168.1.1" }
+ let(:ip3) { "172.16.1.1" }
+
let(:interface1_type) { "ppp" }
- let(:interface2_type) { "ppp" }
+ let(:interface2_type) { "tunl" }
+ let(:interface3_type) { "docker" }
it "ignores them" do
expect(plugin[:privateaddress]).to be nil