summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2016-12-20 10:57:58 -0800
committerTim Smith <tsmith@chef.io>2016-12-20 10:57:58 -0800
commit9e85c83f36165612e85118091029d4332e6ce5d0 (patch)
tree4959852edf2ad2a0f485aa4c57ec6cf1a706eb2b
parentf6daf869b0460c8e60411010a6c2f7bb7347c915 (diff)
downloadohai-sigar.tar.gz
Remove usage of the Sigar gemsigar
Sigar was a really cool idea, but it’s a dead project now. The data is questionable at best and not getting any better as time goes on. We should figure out how to support these platforms vs. hoping that Sigar is doing the right thing. This does remove a lot of support for HP-UX, but I seriously doubt it worked to begin with. We should do that right sometime. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--Gemfile2
-rw-r--r--lib/ohai/mixin/network_constants.rb5
-rw-r--r--lib/ohai/plugins/hostname.rb17
-rw-r--r--lib/ohai/plugins/network_listeners.rb60
-rw-r--r--lib/ohai/plugins/sigar/cpu.rb44
-rw-r--r--lib/ohai/plugins/sigar/filesystem.rb50
-rw-r--r--lib/ohai/plugins/sigar/memory.rb39
-rw-r--r--lib/ohai/plugins/sigar/network.rb168
-rw-r--r--lib/ohai/plugins/sigar/network_route.rb64
-rw-r--r--lib/ohai/plugins/sigar/platform.rb30
-rw-r--r--lib/ohai/plugins/uptime.rb9
-rw-r--r--spec/unit/plugins/hostname_spec.rb55
-rw-r--r--spec/unit/plugins/sigar/network_route_spec.rb148
13 files changed, 16 insertions, 675 deletions
diff --git a/Gemfile b/Gemfile
index 4bcd5f6d..679b580b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,8 +3,6 @@ source "https://rubygems.org"
gemspec
group :development do
- gem "sigar", :platform => "ruby"
-
gem "chefstyle"
gem "overcommit", ">= 0.34.1"
gem "pry-byebug"
diff --git a/lib/ohai/mixin/network_constants.rb b/lib/ohai/mixin/network_constants.rb
index ed53bb8b..d740df95 100644
--- a/lib/ohai/mixin/network_constants.rb
+++ b/lib/ohai/mixin/network_constants.rb
@@ -24,11 +24,6 @@ module Ohai
"inet" => "default",
"inet6" => "default_inet6",
}
-
- # From sigar: include/sigar.h sigar_net_route_t
- SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags,
- :refcnt, :use, :metric, :mtu, :window,
- :irtt, :ifname]
end
end
end
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 0f1b2c22..6b744461 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -76,24 +76,9 @@ Ohai.plugin(:Hostname) do
end
end
- def get_fqdn_from_sigar
- require "sigar"
- sigar = Sigar.new
- sigar.fqdn
- end
-
- def sigar_is_available?
- begin
- require "sigar"
- true
- rescue LoadError
- false
- end
- end
-
collect_data(:hpux, :default) do
machinename from_cmd("hostname")
- fqdn sigar_is_available? ? get_fqdn_from_sigar : resolve_fqdn
+ fqdn resolve_fqdn
collect_hostname
collect_domain
end
diff --git a/lib/ohai/plugins/network_listeners.rb b/lib/ohai/plugins/network_listeners.rb
deleted file mode 100644
index 292378d7..00000000
--- a/lib/ohai/plugins/network_listeners.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2009 VMware, Inc.
-# 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(:NetworkListeners) do
- provides "network/listeners"
-
- depends "network", "counters/network"
-
- collect_data do
- begin
- require "sigar"
- flags = Sigar::NETCONN_TCP | Sigar::NETCONN_SERVER
-
- network Mash.new unless network
- listeners = Mash.new
-
- sigar = Sigar.new
- sigar.net_connection_list(flags).each do |conn|
- port = conn.local_port
- addr = conn.local_address.to_s
- if addr == "0.0.0.0" || addr == "::"
- addr = "*"
- end
- listeners[port] = Mash.new
- listeners[port][:address] = addr
- begin
- pid = sigar.proc_port(conn.type, port)
- # workaround for a failure of proc_state to throw
- # after the first 0 has been supplied to it
- #
- # no longer required when hyperic/sigar#48 is fixed
- throw ArgumentError.new("No such process") if pid == 0
- listeners[port][:pid] = pid
- listeners[port][:name] = sigar.proc_state(pid).name
- rescue
- end
- end
-
- network[:listeners] = Mash.new
- network[:listeners][:tcp] = listeners
- rescue LoadError
- Ohai::Log.debug("Could not load sigar gem. Skipping NetworkListeners plugin")
- end
- end
-end
diff --git a/lib/ohai/plugins/sigar/cpu.rb b/lib/ohai/plugins/sigar/cpu.rb
deleted file mode 100644
index 54f8387c..00000000
--- a/lib/ohai/plugins/sigar/cpu.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# 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(:CPU) do
- provides "cpu"
-
- collect_data(:hpux, :default) do
- require "sigar"
-
- sigar = Sigar.new
-
- cpuinfo = Mash.new
- ix = 0
-
- sigar.cpu_info_list.each do |info|
- current_cpu = ix.to_s
- ix += 1
- cpuinfo[current_cpu] = Mash.new
- cpuinfo[current_cpu]["vendor_id"] = info.vendor
- cpuinfo[current_cpu]["model"] = info.model
- cpuinfo[current_cpu]["mhz"] = info.mhz.to_s
- cpuinfo[current_cpu]["cache_size"] = info.cache_size.to_s
- cpuinfo[:total] = info.total_cores
- cpuinfo[:real] = info.total_sockets
- end
-
- cpu cpuinfo
- end
-end
diff --git a/lib/ohai/plugins/sigar/filesystem.rb b/lib/ohai/plugins/sigar/filesystem.rb
deleted file mode 100644
index 234fc16f..00000000
--- a/lib/ohai/plugins/sigar/filesystem.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# 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(:Filesystem) do
- provides "filesystem"
-
- collect_data(:hpux, :default) do
- require "sigar"
- sigar = Sigar.new
-
- fs = Mash.new
-
- sigar.file_system_list.each do |fsys|
- filesystem = fsys.dev_name
- fs[filesystem] = Mash.new
- fs[filesystem][:mount] = fsys.dir_name
- fs[filesystem][:fs_type] = fsys.sys_type_name
- fs[filesystem][:mount_options] = fsys.options
- begin
- usage = sigar.file_system_usage(fsys.dir_name)
- fs[filesystem][:kb_size] = (usage.total / 1024).to_s
- fs[filesystem][:kb_used] = ((usage.total - usage.free) / 1024).to_s
- fs[filesystem][:kb_available] = (usage.free / 1024).to_s
- fs[filesystem][:percent_used] = (usage.use_percent * 100).to_s + "%"
- rescue SystemExit => e
- raise
- rescue Exception => e
- #e.g. floppy or cdrom drive
- end
- end
-
- # Set the filesystem data
- filesystem fs
- end
-end
diff --git a/lib/ohai/plugins/sigar/memory.rb b/lib/ohai/plugins/sigar/memory.rb
deleted file mode 100644
index 78f55199..00000000
--- a/lib/ohai/plugins/sigar/memory.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# 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(:Memory) do
- provides "memory"
-
- collect_data(:hpux, :default) do
- require "sigar"
- sigar = Sigar.new
-
- memory Mash.new
- memory[:swap] = Mash.new
-
- mem = sigar.mem
- swap = sigar.swap
-
- memory[:total] = (mem.total / 1024).to_s + "kB"
- memory[:free] = (mem.free / 1024).to_s + "kB"
- memory[:used] = (mem.used / 1024).to_s + "kB"
- memory[:swap][:total] = (swap.total / 1024).to_s + "kB"
- memory[:swap][:free] = (swap.free / 1024).to_s + "kB"
- memory[:swap][:used] = (swap.used / 1024).to_s + "kB"
- end
-end
diff --git a/lib/ohai/plugins/sigar/network.rb b/lib/ohai/plugins/sigar/network.rb
deleted file mode 100644
index 68ce3add..00000000
--- a/lib/ohai/plugins/sigar/network.rb
+++ /dev/null
@@ -1,168 +0,0 @@
-#
-# Author:: Matthew Kent (<mkent@magoazul.com>)
-# Copyright:: Copyright (c) 2009 Matthew Kent
-# 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 "ohai/mixin/network_constants"
-
-Ohai.plugin(:Network) do
- include Ohai::Mixin::NetworkConstants
-
- provides "network", "network/interfaces"
- provides "counters/network", "counters/network/interfaces"
-
- def sigar_encaps_lookup(encap)
- return "Loopback" if encap.eql?("Local Loopback")
- return "PPP" if encap.eql?("Point-to-Point Protocol")
- return "SLIP" if encap.eql?("Serial Line IP")
- return "VJSLIP" if encap.eql?("VJ Serial Line IP")
- return "IPIP" if encap.eql?("IPIP Tunnel")
- return "6to4" if encap.eql?("IPv6-in-IPv4")
- encap
- end
-
- def fetch_interfaces(sigar)
- iface = Mash.new
- net_counters = Mash.new
-
- sigar.net_interface_list.each do |cint|
- iface[cint] = Mash.new
-
- if cint =~ /^(\w+)(\d+.*)/
- iface[cint][:type] = $1
- iface[cint][:number] = $2
- end
-
- ifconfig = sigar.net_interface_config(cint)
- iface[cint][:encapsulation] = sigar_encaps_lookup(ifconfig.type)
-
- iface[cint][:addresses] = Mash.new
- # Backwards compat: loopback has no hwaddr
- if (ifconfig.flags & Sigar::IFF_LOOPBACK) == 0
- iface[cint][:addresses][ifconfig.hwaddr] = { "family" => "lladdr" }
- end
- if ifconfig.address != "0.0.0.0"
- iface[cint][:addresses][ifconfig.address] = { "family" => "inet" }
- # Backwards compat: no broadcast on tunnel or loopback dev
- if ((ifconfig.flags & Sigar::IFF_POINTOPOINT) == 0) &&
- ((ifconfig.flags & Sigar::IFF_LOOPBACK) == 0)
- iface[cint][:addresses][ifconfig.address]["broadcast"] = ifconfig.broadcast
- end
- iface[cint][:addresses][ifconfig.address]["netmask"] = ifconfig.netmask
- end
-
- if ifconfig.prefix6_length != 0
- iface[cint][:addresses][ifconfig.address6] = { "family" => "inet6" }
- iface[cint][:addresses][ifconfig.address6]["prefixlen"] = ifconfig.prefix6_length.to_s
- iface[cint][:addresses][ifconfig.address6]["scope"] = Sigar.net_scope_to_s(ifconfig.scope6)
- end
-
- iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(" ")
- iface[cint][:mtu] = ifconfig.mtu.to_s
- iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s
-
- net_counters[cint] = Mash.new unless net_counters[cint]
- if !cint.include?(":")
- ifstat = sigar.net_interface_stat(cint)
- net_counters[cint][:rx] = { "packets" => ifstat.rx_packets.to_s, "errors" => ifstat.rx_errors.to_s,
- "drop" => ifstat.rx_dropped.to_s, "overrun" => ifstat.rx_overruns.to_s,
- "frame" => ifstat.rx_frame.to_s, "bytes" => ifstat.rx_bytes.to_s }
- net_counters[cint][:tx] = { "packets" => ifstat.tx_packets.to_s, "errors" => ifstat.tx_errors.to_s,
- "drop" => ifstat.tx_dropped.to_s, "overrun" => ifstat.tx_overruns.to_s,
- "carrier" => ifstat.tx_carrier.to_s, "collisions" => ifstat.tx_collisions.to_s,
- "bytes" => ifstat.tx_bytes.to_s }
- end
- end
-
- begin
- sigar.arp_list.each do |arp|
- next unless iface[arp.ifname] # this should never happen
- iface[arp.ifname][:arp] = Mash.new unless iface[arp.ifname][:arp]
- iface[arp.ifname][:arp][arp.address] = arp.hwaddr
- end
- rescue
- #64-bit AIX for example requires 64-bit caller
- end
-
- [iface, net_counters]
- end
-
- # sigar-only, from network_route plugin
- def flags(flags)
- f = ""
- if (flags & Sigar::RTF_UP) != 0
- f += "U"
- end
- if (flags & Sigar::RTF_GATEWAY) != 0
- f += "G"
- end
- if (flags & Sigar::RTF_HOST) != 0
- f += "H"
- end
- f
- end
-
- collect_data(:hpux) do
- require "sigar"
- sigar = Sigar.new
-
- network Mash.new unless network
- network[:interfaces] = Mash.new unless network[:interfaces]
- counters Mash.new unless counters
- counters[:network] = Mash.new unless counters[:network]
-
- ninfo = sigar.net_info
- network[:default_interface] = ninfo.default_gateway_interface
- network[:default_gateway] = ninfo.default_gateway
-
- iface, net_counters = fetch_interfaces(sigar)
- counters[:network][:interfaces] = net_counters
- network["interfaces"] = iface
- end
-
- collect_data(:default) do
- require "sigar"
- sigar = Sigar.new
-
- network Mash.new unless network
- network[:interfaces] = Mash.new unless network[:interfaces]
- counters Mash.new unless counters
- counters[:network] = Mash.new unless counters[:network]
-
- ninfo = sigar.net_info
- network[:default_interface] = ninfo.default_gateway_interface
- network[:default_gateway] = ninfo.default_gateway
-
- iface, net_counters = fetch_interfaces(sigar)
- counters[:network][:interfaces] = net_counters
- network[:interfaces] = iface
-
- sigar.net_route_list.each do |route|
- next unless network[:interfaces][route.ifname] # this
- # should never happen
- network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
- route_data = {}
- Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m|
- if m == :flags
- route_data[m] = flags(route.send(m))
- else
- route_data[m] = route.send(m)
- end
- end
- network[:interfaces][route.ifname][:route][route.destination] = route_data
- end
- end
-end
diff --git a/lib/ohai/plugins/sigar/network_route.rb b/lib/ohai/plugins/sigar/network_route.rb
deleted file mode 100644
index d41c1524..00000000
--- a/lib/ohai/plugins/sigar/network_route.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# Author:: Toomas Pelberg (<toomas.pelberg@playtech.com>)
-# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
-# 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 "ohai/mixin/network_constants"
-
-Ohai.plugin(:NetworkRoutes) do
- begin
- require "sigar"
-
- include Ohai::Mixin::NetworkConstants
-
- provides "network/interfaces/adapters/route"
- depends "network/interfaces"
-
- def flags(flags)
- f = ""
- if (flags & Sigar::RTF_UP) != 0
- f += "U"
- end
- if (flags & Sigar::RTF_GATEWAY) != 0
- f += "G"
- end
- if (flags & Sigar::RTF_HOST) != 0
- f += "H"
- end
- f
- end
-
- collect_data(:default) do
- sigar = Sigar.new
-
- sigar.net_route_list.each do |route|
- next unless network[:interfaces][route.ifname] # this should never happen
- network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
- route_data = {}
- Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m|
- if m == :flags
- route_data[m] = flags(route.send(m))
- else
- route_data[m] = route.send(m)
- end
- end
- network[:interfaces][route.ifname][:route][route.destination] = route_data
- end
- end
- rescue LoadError
- Ohai::Log.debug("Could not load sigar gem. Skipping NetworkRoutes plugin")
- end
-end
diff --git a/lib/ohai/plugins/sigar/platform.rb b/lib/ohai/plugins/sigar/platform.rb
deleted file mode 100644
index 454851da..00000000
--- a/lib/ohai/plugins/sigar/platform.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Author:: Doug MacEachern <dougm@vmware.com>
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# 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(:Platform) do
- provides "platform", "platform_version", "platform_family"
-
- collect_data(:hpux) do
- require "sigar"
- sys = Sigar.new.sys_info
-
- platform sys.name.downcase
- platform_version sys.version
- platform_family platform
- end
-end
diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb
index e5866fa3..bc7d412c 100644
--- a/lib/ohai/plugins/uptime.rb
+++ b/lib/ohai/plugins/uptime.rb
@@ -43,15 +43,6 @@ Ohai.plugin(:Uptime) do
return [nil, nil]
end
- collect_data(:hpux, :default) do
- require "sigar"
-
- sigar = Sigar.new
- uptime = sigar.uptime.uptime
- uptime_seconds uptime.to_i * 1000
- uptime seconds_to_human(uptime.to_i)
- end
-
collect_data(:darwin) do
data = collect_uptime("/usr/sbin/sysctl")
uptime_seconds data.first
diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb
index e0f7672d..ed2d4d0a 100644
--- a/spec/unit/plugins/hostname_spec.rb
+++ b/spec/unit/plugins/hostname_spec.rb
@@ -25,50 +25,25 @@ describe Ohai::System, "hostname plugin" do
allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.local", ""))
end
- context "when sigar is not installed" do
- before(:each) do
- allow(@plugin).to receive(:sigar_is_available?).and_return(false)
- expect(@plugin).not_to receive(:get_fqdn_from_sigar)
- allow(@plugin).to receive(:resolve_fqdn).and_return("katie.bethell")
- end
- it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local")
-
- it "should use #resolve_fqdn to find the fqdn" do
- @plugin.run
- expect(@plugin[:fqdn]).to eq("katie.bethell")
- end
-
- it "should set the domain to everything after the first dot of the fqdn" do
- @plugin.run
- expect(@plugin[:domain]).to eq("bethell")
- end
-
- it "should set the [short] hostname to everything before the first dot of the fqdn" do
- @plugin.run
- expect(@plugin[:hostname]).to eq("katie")
- end
+ context "default behavior"
+ before(:each) do
+ allow(@plugin).to receive(:resolve_fqdn).and_return("katie.bethell")
end
+ it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local")
- context "when sigar is installed" do
- before(:each) do
- allow(@plugin).to receive(:sigar_is_available?).and_return(true)
- allow(@plugin).to receive(:get_fqdn_from_sigar).and_return("katie.bethell")
- end
- it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local")
- it "should set the fqdn to the returned value from sigar" do
- @plugin.run
- expect(@plugin[:fqdn]).to eq("katie.bethell")
- end
+ it "should use #resolve_fqdn to find the fqdn" do
+ @plugin.run
+ expect(@plugin[:fqdn]).to eq("katie.bethell")
+ end
- it "should set the domain to everything after the first dot of the fqdn" do
- @plugin.run
- expect(@plugin[:domain]).to eq("bethell")
- end
+ it "should set the domain to everything after the first dot of the fqdn" do
+ @plugin.run
+ expect(@plugin[:domain]).to eq("bethell")
+ end
- it "should set the [short] hostname to everything before the first dot of the fqdn" do
- @plugin.run
- expect(@plugin[:hostname]).to eq("katie")
- end
+ it "should set the [short] hostname to everything before the first dot of the fqdn" do
+ @plugin.run
+ expect(@plugin[:hostname]).to eq("katie")
end
context "when a system has a bare hostname without a FQDN" do
diff --git a/spec/unit/plugins/sigar/network_route_spec.rb b/spec/unit/plugins/sigar/network_route_spec.rb
deleted file mode 100644
index b3b2ec4d..00000000
--- a/spec/unit/plugins/sigar/network_route_spec.rb
+++ /dev/null
@@ -1,148 +0,0 @@
-#
-# Author:: Toomas Pelberg (<toomas.pelberg@playtech.com>)
-# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
-# 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 File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
-
-sigar_available = begin
- require "sigar"
- true
-rescue LoadError
- false
-end
-
-require "ohai"
-
-describe Ohai::System, "Sigar network route plugin" do
-
- if sigar_available
-
- before(:each) do
- @ohai = Ohai::System.new
- @plugin = get_plugin("sigar/network", @ohai)
- allow(@plugin).to receive(:collect_os).and_return(:sigar)
- @sigar = double("Sigar")
- @net_info_conf = {
- :default_gateway => "192.168.1.254",
- :default_gateway_interface => "eth0",
- :primary_dns => "192.168.1.254",
- :secondary_dns => "8.8.8.8",
- :host_name => "localhost",
- }
- net_info = double("Sigar::NetInfo")
- @net_info_conf.each_pair do |k, v|
- allow(net_info).to receive(k).and_return(v)
- end
- @net_route_conf = {
- :destination => "192.168.1.0",
- :gateway => "0.0.0.0",
- :mask => "255.255.255.0",
- :flags => 1,
- :refcnt => 0,
- :use => 0,
- :metric => 0,
- :mtu => 0,
- :window => 0,
- :irtt => 0,
- :ifname => "eth0",
- }
- net_route = double("Sigar::NetRoute")
- @net_route_conf.each_pair do |k, v|
- allow(net_route).to receive(k).and_return(v)
- end
- @net_interface_conf = {
- :flags => 2115,
- :destination => "192.168.1.1",
- :mtu => 1500,
- :type => "Ethernet",
- :hwaddr => "00:11:22:33:44:55:66",
- :address => "192.168.1.1",
- :broadcast => "192.168.1.255",
- :netmask => "255.255.255.0",
- :address6 => nil,
- :tx_queue_len => 1000,
- :prefix6_length => 0,
- }
- net_conf = double("Sigar::NetConf")
- @net_interface_conf.each_pair do |k, v|
- allow(net_conf).to receive(k).and_return(v)
- end
- @net_interface_stat = {
- :rx_bytes => 1369035618,
- :rx_dropped => 0,
- :rx_errors => 0,
- :rx_frame => 0,
- :rx_overruns => 0,
- :rx_packets => 7271669,
- :speed => -1,
- :tx_bytes => 3482843666,
- :tx_carrier => 0,
- :tx_collisions => 0,
- :tx_dropped => 0,
- :tx_errors => 0,
- :tx_overruns => 0,
- :tx_packets => 4392794,
- }
- net_stat = double("Sigar::NetStat")
- @net_interface_stat.each_pair do |k, v|
- allow(net_stat).to receive(k).and_return(v)
- end
- @net_arp_conf = {
- :address => "192.168.1.5",
- :flags => 2,
- :hwaddr => "00:15:62:96:01:D0",
- :ifname => "eth0",
- :type => "ether",
- }
- net_arp = double("Sigar::NetArp")
- @net_arp_conf.each_pair do |k, v|
- allow(net_arp).to receive(k).and_return(v)
- end
- allow(@sigar).to receive(:fqdn).and_return("localhost.localdomain")
- expect(@sigar).to receive(:net_info).once.times.and_return(net_info)
- expect(@sigar).to receive(:net_interface_list).once.and_return(["eth0"])
- expect(@sigar).to receive(:net_interface_config).with("eth0").and_return(net_conf)
- expect(@sigar).to receive(:net_interface_stat).with("eth0").and_return(net_stat)
- expect(@sigar).to receive(:arp_list).once.and_return([net_arp])
-
- # Since we double net_route_list here, flags never gets called
- expect(@sigar).to receive(:net_route_list).once.and_return([net_route])
- expect(Sigar).to receive(:new).once.and_return(@sigar)
-
- @plugin.run
- end
-
- it "should set the routes" do
- expect(@plugin[:network][:interfaces][:eth0]).to have_key(:route)
- end
-
- it "should set the route details" do
- @net_route_conf.each_pair do |k, v|
- # Work around the above doubleing of net_route_list skipping the call to flags()
- if k == :flags
- v = "U"
- @plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v
- end
- expect(@plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"]).to have_key(k)
- expect(@plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"][k]).to eql(v)
- end
- end
-
- else
- pending "Sigar not available, skipping sigar tests"
- end
-end