diff options
author | Bryan McLellan <btm@loftninjas.org> | 2016-11-22 07:57:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-22 07:57:53 -0500 |
commit | d6eff109cdfabe99ee0be41cba443861bca6d851 (patch) | |
tree | 07fde151a6eac1c75e2ec4226579f52d2c398f18 | |
parent | c34212ea73a07260ab1e23370276124bae36371b (diff) | |
parent | 43d7d4d9121aa6205a9b04991fd71a0c66f9d0f6 (diff) | |
download | ohai-d6eff109cdfabe99ee0be41cba443861bca6d851.tar.gz |
Merge pull request #890 from n-marton/master
ip_scopes update
-rw-r--r-- | lib/ohai/plugins/ip_scopes.rb | 12 | ||||
-rw-r--r-- | spec/unit/plugins/ip_scopes_spec.rb | 33 |
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..e9367762 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 tunnel_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 |