diff options
author | Tim Smith <tsmith@chef.io> | 2017-07-14 21:39:50 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-07-14 21:39:50 -0700 |
commit | b1aee761f1c1e650bc3b7b0c6231e82f76be56b2 (patch) | |
tree | 01f7a734b1e0cddc98907d39d7f399713901d5fd | |
parent | 44974f03f6810cc1d37fce3b922d89600c6088b9 (diff) | |
download | ohai-ipscopes.tar.gz |
Remove the IPScopes pluginipscopes
Per OHAI-13 this is being deprecated.
https://docs.chef.io/deprecations_ohai_ipscopes.html
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/ip_scopes.rb | 67 | ||||
-rw-r--r-- | spec/unit/plugins/ip_scopes_spec.rb | 139 |
2 files changed, 0 insertions, 206 deletions
diff --git a/lib/ohai/plugins/ip_scopes.rb b/lib/ohai/plugins/ip_scopes.rb deleted file mode 100644 index 6d2b635c..00000000 --- a/lib/ohai/plugins/ip_scopes.rb +++ /dev/null @@ -1,67 +0,0 @@ -# -# Author:: James Harton (<james@sociable.co.nz>) -# Copyright:: Copyright (c) 2010 Sociable Limited. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -Ohai.plugin(:IpScopes) do - provides "network_ip_scope", "privateaddress" - - depends "network/interfaces" - - collect_data do - begin - require "ipaddr_extensions" - - Ohai::Log.warn("The IpScopes Ohai plugin has been deprecated and will be removed from Ohai 14 (April 2018).") - - network["interfaces"].keys.sort.each do |if_name| - next if network["interfaces"][if_name]["addresses"].nil? - - interface = network["interfaces"][if_name] - interface["addresses"].each do |address, attrs| - begin - attrs["ip_scope"] = address.to_ip.scope - - if private_addr?(address) && !tunnel_iface?(interface) && !ppp_iface?(interface) && !docker_iface?(interface) - privateaddress(address) - end - rescue ArgumentError - # Just silently fail if we can't create an IP from the string. - end - end - end - - rescue LoadError => e - # our favourite gem is not installed. Boohoo. - Ohai::Log.debug("Plugin IpScopes: cannot load gem, plugin disabled: #{e}") - end - end - - def private_addr?(address) - address.to_ip.scope =~ /PRIVATE/ - end - - 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 deleted file mode 100644 index 9e754650..00000000 --- a/spec/unit/plugins/ip_scopes_spec.rb +++ /dev/null @@ -1,139 +0,0 @@ -# -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require_relative "../../spec_helper.rb" -require "ipaddr_extensions" - -describe Ohai::System, "plugin ip_scopes" do - let(:plugin) { get_plugin("ip_scopes") } - let(:network) { Mash.new(:interfaces => interfaces) } - let(:interfaces) do - Hash[ - interface1, { :addresses => addresses1, :type => interface1_type }, - 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 } - - if defined?(IPAddrExtensions) - context "with ipaddr_extensions gem" do - let(:ip1) { "10.0.0.1" } - let(:ip2) { "1.2.3.4" } - let(:ip3) { "fe80::8638:35ff:fe4e:dc74" } - - let(:addresses1) { Hash[ip1, {}] } - let(:addresses2) { Hash[ip2, {}, ip3, {}] } - - it "adds ip_scope to each address's information hash" do - plugin.run - expect(plugin[:network][:interfaces][:eth0][:addresses]["10.0.0.1"][:ip_scope]).to eq("RFC1918 PRIVATE") - expect(plugin[:network][:interfaces][:eth1][:addresses]["1.2.3.4"][:ip_scope]).to eq("GLOBAL UNICAST") - expect(plugin[:network][:interfaces][:eth1][:addresses]["fe80::8638:35ff:fe4e:dc74"][:ip_scope]).to eq("LINK LOCAL UNICAST") - end - - describe "privateaddress attribute" do - before { plugin.run } - - context "when host has multiple RFC1918 ethernet addresses" do - let(:ip1) { "10.0.0.1" } - let(:ip2) { "192.168.1.1" } - let(:interface1_type) { "eth" } - let(:interface2_type) { "eth" } - - it "picks the last RFC1918 address" do - expect(plugin[:privateaddress]).to eq("192.168.1.1") - end - end - - context "when host has virtual and ethernet RFC1918 addresses" do - let(:ip1) { "10.0.0.1" } - let(:ip2) { "192.168.1.1" } - let(:interface1_type) { "eth" } - let(:interface2_type) { "ppp" } - - it "picks the non-virtual address" do - expect(plugin[:privateaddress]).to eq("10.0.0.1") - 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) { "tunl" } - let(:interface3_type) { "docker" } - - it "ignores them" do - expect(plugin[:privateaddress]).to be nil - end - end - end - end - end - - unless defined?(IPAddrExtensions) - context "without the ipaddr_extensions gem" do - let(:addresses1) { Hash["10.0.0.1", {}] } - - before do - # standin for raising on `require 'ipaddr_extensions'` - allow(plugin[:network][:interfaces]).to receive(:keys).and_raise(LoadError) - plugin.run - end - - it "does not add ip_scope to addresses" do - expect(plugin[:network][:interfaces][:eth0][:addresses]["10.0.0.1"][:ip_scope]).to be nil - end - - it "does not add a privateaddress attribute" do - expect(plugin[:privateaddress]).to be nil - end - end - end -end |