summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Rakefile2
-rw-r--r--lib/ohai/common/dmi.rb3
-rw-r--r--lib/ohai/dsl/plugin.rb3
-rw-r--r--lib/ohai/dsl/plugin/versionvii.rb6
-rw-r--r--lib/ohai/hints.rb4
-rw-r--r--lib/ohai/loader.rb7
-rw-r--r--lib/ohai/mash.rb2
-rw-r--r--lib/ohai/mixin/constant_helper.rb1
-rw-r--r--lib/ohai/mixin/ec2_metadata.rb7
-rw-r--r--lib/ohai/mixin/gce_metadata.rb5
-rw-r--r--lib/ohai/plugins/aix/kernel.rb2
-rw-r--r--lib/ohai/plugins/aix/network.rb6
-rw-r--r--lib/ohai/plugins/aix/virtualization.rb4
-rw-r--r--lib/ohai/plugins/azure.rb1
-rw-r--r--lib/ohai/plugins/cloud.rb11
-rw-r--r--lib/ohai/plugins/cpu.rb12
-rw-r--r--lib/ohai/plugins/darwin/network.rb13
-rw-r--r--lib/ohai/plugins/digital_ocean.rb2
-rw-r--r--lib/ohai/plugins/dmi.rb1
-rw-r--r--lib/ohai/plugins/dragonflybsd/memory.rb2
-rw-r--r--lib/ohai/plugins/dragonflybsd/network.rb1
-rw-r--r--lib/ohai/plugins/ec2.rb1
-rw-r--r--lib/ohai/plugins/eucalyptus.rb1
-rw-r--r--lib/ohai/plugins/filesystem.rb14
-rw-r--r--lib/ohai/plugins/freebsd/memory.rb2
-rw-r--r--lib/ohai/plugins/freebsd/network.rb1
-rw-r--r--lib/ohai/plugins/haskell.rb8
-rw-r--r--lib/ohai/plugins/hostname.rb3
-rw-r--r--lib/ohai/plugins/java.rb1
-rw-r--r--lib/ohai/plugins/kernel.rb15
-rw-r--r--lib/ohai/plugins/linode.rb2
-rw-r--r--lib/ohai/plugins/linux/lspci.rb5
-rw-r--r--lib/ohai/plugins/linux/network.rb22
-rw-r--r--lib/ohai/plugins/linux/platform.rb1
-rw-r--r--lib/ohai/plugins/netbsd/memory.rb2
-rw-r--r--lib/ohai/plugins/netbsd/network.rb1
-rw-r--r--lib/ohai/plugins/network.rb2
-rw-r--r--lib/ohai/plugins/openbsd/memory.rb2
-rw-r--r--lib/ohai/plugins/openbsd/network.rb1
-rw-r--r--lib/ohai/plugins/openstack.rb1
-rw-r--r--lib/ohai/plugins/packages.rb1
-rw-r--r--lib/ohai/plugins/rackspace.rb1
-rw-r--r--lib/ohai/plugins/scaleway.rb1
-rw-r--r--lib/ohai/plugins/shard.rb2
-rw-r--r--lib/ohai/plugins/solaris2/network.rb4
-rw-r--r--lib/ohai/plugins/virtualbox.rb8
-rw-r--r--lib/ohai/plugins/windows/network.rb6
-rw-r--r--lib/ohai/provides_map.rb10
-rw-r--r--lib/ohai/runner.rb2
-rw-r--r--lib/ohai/system.rb2
-rw-r--r--lib/ohai/util/win32.rb8
-rw-r--r--spec/functional/application_spec.rb2
-rw-r--r--spec/functional/loader_spec.rb2
-rw-r--r--spec/unit/dsl/plugin_spec.rb30
-rw-r--r--spec/unit/plugin_config_spec.rb6
-rw-r--r--spec/unit/plugins/docker_spec.rb22
-rw-r--r--spec/unit/plugins/ec2_spec.rb6
-rw-r--r--spec/unit/plugins/erlang_spec.rb4
-rw-r--r--spec/unit/plugins/hostname_spec.rb24
-rw-r--r--spec/unit/plugins/linux/filesystem_spec.rb1
-rw-r--r--spec/unit/plugins/linux/lspci_spec.rb3
-rw-r--r--spec/unit/plugins/network_spec.rb5
-rw-r--r--spec/unit/plugins/openstack_spec.rb4
-rw-r--r--spec/unit/plugins/ruby_spec.rb2
-rw-r--r--spec/unit/plugins/scsi_spec.rb3
-rw-r--r--spec/unit/plugins/shard_spec.rb2
-rw-r--r--spec/unit/plugins/windows/filesystem_spec.rb4
-rw-r--r--spec/unit/plugins/windows/kernel_spec.rb4
-rw-r--r--spec/unit/system_spec.rb6
69 files changed, 226 insertions, 129 deletions
diff --git a/Rakefile b/Rakefile
index 83e36d8f..200737d3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -39,4 +39,4 @@ task :console do
IRB.start
end
-task default: [:style, :spec]
+task default: %i{style spec}
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb
index 1c9a80af..c7f8a5e1 100644
--- a/lib/ohai/common/dmi.rb
+++ b/lib/ohai/common/dmi.rb
@@ -119,12 +119,14 @@ module Ohai
in_common = Mash.new
next unless records.class.to_s == "Mash"
next unless records.key?("all_records")
+
records[:all_records].each do |record|
record.each do |field, value|
next if value.class.to_s == "Mash"
next if field.to_s == "application_identifier"
next if field.to_s == "size"
next if field.to_s == "record_id"
+
translated = field.downcase.gsub(/[^a-z0-9]/, "_")
value = value.strip
if in_common.key?(translated)
@@ -136,6 +138,7 @@ module Ohai
end
in_common.each do |field, value|
next if value.nil?
+
dmi[type][field] = value.strip
end
end
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb
index 0abb160d..8f0403ae 100644
--- a/lib/ohai/dsl/plugin.rb
+++ b/lib/ohai/dsl/plugin.rb
@@ -145,6 +145,7 @@ module Ohai
def from(cmd)
_status, stdout, _stderr = run_command(command: cmd)
return "" if stdout.nil? || stdout.empty?
+
stdout.strip
end
@@ -155,6 +156,7 @@ module Ohai
regex_list.flatten.each do |regex|
_status, stdout, _stderr = run_command(command: cmd)
return "" if stdout.nil? || stdout.empty?
+
stdout.chomp!.strip
md = stdout.match(regex)
return md[1]
@@ -210,6 +212,7 @@ module Ohai
unless attrs.nil? || attrs.is_a?(Array) || attrs.is_a?(Hash)
raise TypeError.new("Expected Hash but got #{attrs.class}.")
end
+
attrs[key]
end
rescue NoMethodError
diff --git a/lib/ohai/dsl/plugin/versionvii.rb b/lib/ohai/dsl/plugin/versionvii.rb
index 3a8c904e..605c2b3a 100644
--- a/lib/ohai/dsl/plugin/versionvii.rb
+++ b/lib/ohai/dsl/plugin/versionvii.rb
@@ -145,9 +145,11 @@ module Ohai
def configuration(option, *options)
return nil if plugin_config.nil? || !plugin_config.key?(option)
+
value = plugin_config[option]
options.each do |opt|
return nil unless value.key?(opt)
+
value = value[opt]
end
value
@@ -169,12 +171,12 @@ module Ohai
# ["", "Memory"] => ["Memory"]
# ["", "Network", "", "Listeners"] => ["Network", "Listeners"]
# ["SSH", "Host", "", "Key"] => ["SSH", "Host", "Key"]
- parts.delete_if { |part| part.empty? }
+ parts.delete_if(&:empty?)
# ["DMI"] => :dmi
# ["Memory"] => :memory
# ["Network", "Listeners"] => :network_listeners
# ["SSH", "Host", "Key"] => :ssh_host_key
- snake_case_name = parts.map { |part| part.downcase }.join("_").to_sym
+ snake_case_name = parts.map(&:downcase).join("_").to_sym
# Plugin names in config hashes are auto-vivified, so we check with
# key? to avoid falsely instantiating a configuration hash.
diff --git a/lib/ohai/hints.rb b/lib/ohai/hints.rb
index c1ec22a3..e05b5180 100644
--- a/lib/ohai/hints.rb
+++ b/lib/ohai/hints.rb
@@ -51,14 +51,16 @@ module Ohai
def self.hint?(name)
@hints ||= {}
return @hints[name] if @hints[name]
+
Ohai.config[:hints_path].each do |path|
filename = File.join(path, "#{name}.json")
next unless File.exist?(filename)
+
Ohai::Log.trace("Found hint #{name}.json at #{filename}")
@hints[name] = parse_hint_file(filename)
end
- Ohai::Log.trace("Did not find hint #{name}.json in the hint path(s): #{Ohai.config[:hints_path].join(', ')} ") unless @hints.key?(name)
+ Ohai::Log.trace("Did not find hint #{name}.json in the hint path(s): #{Ohai.config[:hints_path].join(", ")} ") unless @hints.key?(name)
@hints[name]
end
end
diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb
index 733aab57..329a7f5a 100644
--- a/lib/ohai/loader.rb
+++ b/lib/ohai/loader.rb
@@ -83,7 +83,8 @@ module Ohai
# @param plugin_path [String]
def load_plugin(plugin_path)
plugin_class = load_plugin_class(plugin_path)
- return nil unless plugin_class.kind_of?(Class)
+ return nil unless plugin_class.is_a?(Class)
+
if plugin_class < Ohai::DSL::Plugin::VersionVII
load_v7_plugin(plugin_class)
else
@@ -137,9 +138,10 @@ module Ohai
# @return [Ohai::DSL::Plugin::VersionVII] Ohai plugin object
def load_v7_plugin_class(contents, plugin_path)
plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path) # rubocop: disable Security/Eval
- unless plugin_class.kind_of?(Class) && plugin_class < Ohai::DSL::Plugin
+ unless plugin_class.is_a?(Class) && plugin_class < Ohai::DSL::Plugin
raise Ohai::Exceptions::IllegalPluginDefinition, "Plugin file cannot contain any statements after the plugin definition"
end
+
plugin_class.sources << plugin_path
@v7_plugin_classes << plugin_class unless @v7_plugin_classes.include?(plugin_class)
plugin_class
@@ -159,6 +161,7 @@ module Ohai
parts = e.message.split(/<.*>[:[0-9]+]*: syntax error, /)
parts.each do |part|
next if part.length == 0
+
logger.warn("Plugin Syntax Error: <#{plugin_path}>: #{part}")
end
rescue Exception, Errno::ENOENT => e
diff --git a/lib/ohai/mash.rb b/lib/ohai/mash.rb
index f6c25db5..d5a3b4b1 100644
--- a/lib/ohai/mash.rb
+++ b/lib/ohai/mash.rb
@@ -179,7 +179,7 @@ class Mash < Hash
#
# @api private
def convert_key(key)
- key.kind_of?(Symbol) ? key.to_s : key
+ key.is_a?(Symbol) ? key.to_s : key
end
# @param value [Object] The value to convert.
diff --git a/lib/ohai/mixin/constant_helper.rb b/lib/ohai/mixin/constant_helper.rb
index af2f0a52..71a019af 100644
--- a/lib/ohai/mixin/constant_helper.rb
+++ b/lib/ohai/mixin/constant_helper.rb
@@ -34,6 +34,7 @@ module Ohai
if object.respond_to?(:constants)
object.constants.each do |const|
next unless strict_const_defined?(object, const)
+
recursive_remove_constants(object.const_get(const))
object.send(:remove_const, const)
end
diff --git a/lib/ohai/mixin/ec2_metadata.rb b/lib/ohai/mixin/ec2_metadata.rb
index 4a8a655f..fc0b516f 100644
--- a/lib/ohai/mixin/ec2_metadata.rb
+++ b/lib/ohai/mixin/ec2_metadata.rb
@@ -68,6 +68,7 @@ module Ohai
if versions.empty?
raise "Mixin EC2: Unable to determine EC2 metadata version (no supported entries found)"
end
+
versions.last
end
end
@@ -134,7 +135,7 @@ module Ohai
end
def fetch_dir_metadata(id, api_version)
- metadata = Hash.new
+ metadata = {}
retrieved_metadata = metadata_get(id, api_version)
if retrieved_metadata
retrieved_metadata.split("\n").each do |o|
@@ -195,11 +196,11 @@ module Ohai
# ignore "./" and "../"
path.gsub(%r{/\.\.?(?:/|$)}, "/")
.sub(%r{^\.\.?(?:/|$)}, "")
- .sub(%r{^$}, "/")
+ .sub(/^$/, "/")
end
def metadata_key(key)
- key.gsub(/\-|\//, "_")
+ key.gsub(%r{\-|/}, "_")
end
end
diff --git a/lib/ohai/mixin/gce_metadata.rb b/lib/ohai/mixin/gce_metadata.rb
index 56c0fb5f..d763f7ae 100644
--- a/lib/ohai/mixin/gce_metadata.rb
+++ b/lib/ohai/mixin/gce_metadata.rb
@@ -31,8 +31,7 @@ module Ohai
conn.get(uri, {
"Metadata-Flavor" => "Google",
"User-Agent" => "chef-ohai/#{Ohai::VERSION}",
- }
- )
+ })
end
def fetch_metadata(id = "")
@@ -76,7 +75,7 @@ module Ohai
end
def sanitize_key(key)
- key.gsub(/\-|\//, "_")
+ key.gsub(%r{\-|/}, "_")
end
end
end
diff --git a/lib/ohai/plugins/aix/kernel.rb b/lib/ohai/plugins/aix/kernel.rb
index 39f18c5e..0891e203 100644
--- a/lib/ohai/plugins/aix/kernel.rb
+++ b/lib/ohai/plugins/aix/kernel.rb
@@ -37,7 +37,7 @@ Ohai.plugin(:Kernel) do
# 6390000 20000 63a0000 ba8 /usr/lib/drivers/if_en
# f1000000c0318000 20000 f1000000c0320000 17138 /usr/lib/drivers/random
so.stdout.lines do |line|
- if line =~ /\s*([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([a-zA-Z0-9\/\._]+)/
+ if line =~ %r{\s*([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([a-zA-Z0-9/\._]+)}
modules[$5] = { text: { address: $1, size: $2 }, data: { address: $3, size: $4 } }
end
end
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
index 4dfb977b..b7915d7e 100644
--- a/lib/ohai/plugins/aix/network.rb
+++ b/lib/ohai/plugins/aix/network.rb
@@ -77,7 +77,7 @@ Ohai.plugin(:Network) do
iface[interface][:metric] = $1 if lin =~ /metric\s(\S+)/
else
# We have key value pairs.
- if lin =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/
+ if lin =~ %r{inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(/(\d{1,2}))?}
tmp_addr, tmp_prefix = $1, $3
if tmp_prefix.nil?
netmask = hex_to_dec_netmask($1) if lin =~ /netmask\s(\S+)\s/
@@ -96,7 +96,7 @@ Ohai.plugin(:Network) do
if lin =~ /broadcast\s(\S+)\s/
iface[interface][:addresses][tmp_addr][:broadcast] = $1
end
- elsif lin =~ /inet6 ([a-f0-9\:]+)%?([\d]*)\/?(\d*)?/
+ elsif lin =~ %r{inet6 ([a-f0-9\:]+)%?([\d]*)/?(\d*)?}
# TODO do we have more properties on inet6 in aix? broadcast
iface[interface][:addresses] ||= Mash.new
iface[interface][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
@@ -128,7 +128,7 @@ Ohai.plugin(:Network) do
so_n.stdout.lines.each do |line|
if line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/
interface = $6
- iface[interface][:routes] = Array.new unless iface[interface][:routes]
+ iface[interface][:routes] = [] unless iface[interface][:routes]
iface[interface][:routes] << Mash.new( destination: $1, family: family,
via: $2, flags: $3)
end
diff --git a/lib/ohai/plugins/aix/virtualization.rb b/lib/ohai/plugins/aix/virtualization.rb
index 71d8bfc6..9a50adbb 100644
--- a/lib/ohai/plugins/aix/virtualization.rb
+++ b/lib/ohai/plugins/aix/virtualization.rb
@@ -58,6 +58,7 @@ Ohai.plugin(:Virtualization) do
case title
when "network"
next if line =~ /^Interface|^---/
+
splat = line.strip.split
key = splat[0].downcase
value = {
@@ -68,6 +69,7 @@ Ohai.plugin(:Virtualization) do
wpars[wpar_name][title][key] = value
when "user-specified routes"
next if line =~ /^Type|^---/
+
splat = line.strip.split
key = splat[2].downcase
value = {
@@ -77,6 +79,7 @@ Ohai.plugin(:Virtualization) do
wpars[wpar_name][title][key] = value
when "file systems"
next if line =~ /^MountPoint|^---/
+
splat = line.strip.split
key = splat[1].downcase
value = {
@@ -99,6 +102,7 @@ Ohai.plugin(:Virtualization) do
wpars[wpar_name][title]["Privileges"] += privileges.split(",")
when "device exports"
next if line =~ /^Name|^---/
+
splat = line.strip.split
key = splat[0].downcase
value = {
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index d0a12567..5969afb6 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -97,6 +97,7 @@ Ohai.plugin(:Azure) do
endpoint_data = fetch_metadata
return nil if endpoint_data.nil?
+
metadata = initialize_metadata_mash_compute
# blindly add everything in compute to our data structure
diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb
index 5c5ce471..45e5f8c5 100644
--- a/lib/ohai/plugins/cloud.rb
+++ b/lib/ohai/plugins/cloud.rb
@@ -53,14 +53,15 @@ Ohai.plugin(:Cloud) do
def add_ipv4_addr(ip, accessibility)
return if ip.nil? # just skip if ip is nil
+
ipaddr = validate_ip_addr(ip, :ipv4)
case accessibility
when :public
- @cloud[:public_ipv4_addrs] ||= Array.new
+ @cloud[:public_ipv4_addrs] ||= []
@cloud[:public_ipv4_addrs] << ipaddr.to_s
when :private
- @cloud[:local_ipv4_addrs] ||= Array.new
+ @cloud[:local_ipv4_addrs] ||= []
@cloud[:local_ipv4_addrs] << ipaddr.to_s
else
raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private."
@@ -69,15 +70,17 @@ Ohai.plugin(:Cloud) do
def add_ipv6_addr(ip, accessibility)
return if ip.nil? # just skip if ip is nil
+
ipaddr = validate_ip_addr(ip, :ipv6)
raise "ERROR: invalid ipv6 address of '#{ip}' detected. " unless ipaddr.ipv6?
+
case accessibility
when :public
- @cloud[:public_ipv6_addrs] ||= Array.new
+ @cloud[:public_ipv6_addrs] ||= []
@cloud[:public_ipv6_addrs] << ipaddr.to_s
when :private
- @cloud[:local_ipv6_addrs] ||= Array.new
+ @cloud[:local_ipv6_addrs] ||= []
@cloud[:local_ipv6_addrs] << ipaddr.to_s
else
raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private."
diff --git a/lib/ohai/plugins/cpu.rb b/lib/ohai/plugins/cpu.rb
index 88e3a5b7..5375c726 100644
--- a/lib/ohai/plugins/cpu.rb
+++ b/lib/ohai/plugins/cpu.rb
@@ -61,7 +61,7 @@ Ohai.plugin(:CPU) do
cpu_number += 1
when /vendor_id\s+:\s(.+)/
vendor_id = $1
- if vendor_id =~ (/IBM\/S390/)
+ if vendor_id =~ (%r{IBM/S390})
cpuinfo["vendor_id"] = vendor_id
else
cpuinfo[current_cpu]["vendor_id"] = vendor_id
@@ -173,9 +173,9 @@ Ohai.plugin(:CPU) do
cpuinfo["model"] = $3.to_i(16).to_s
cpuinfo["stepping"] = $4
# These _should_ match /AMD Features2?/ lines as well
- when /FreeBSD\/SMP: Multiprocessor System Detected: (\d*) CPUs/
+ when %r{FreeBSD/SMP: Multiprocessor System Detected: (\d*) CPUs}
cpuinfo["total"] = $1.to_i
- when /FreeBSD\/SMP: (\d*) package\(s\) x (\d*) core\(s\)/
+ when %r{FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)}
cpuinfo["real"] = $1.to_i
cpuinfo["cores"] = $1.to_i * $2.to_i
end
@@ -336,8 +336,8 @@ Ohai.plugin(:CPU) do
cpu["cpustates"] = Mash.new
currentcpu = 0
- cpucores = Array.new
- cpusockets = Array.new
+ cpucores = []
+ cpusockets = []
processor_info.each do |processor|
_desc, instance, _record, keyvalue = processor.split(":")
cpu[instance] ||= Mash.new
@@ -406,7 +406,7 @@ Ohai.plugin(:CPU) do
cpu[current_cpu]["model_name"] = processor["name"]
cpu[current_cpu]["description"] = processor["description"]
cpu[current_cpu]["mhz"] = processor["maxclockspeed"].to_s
- cpu[current_cpu]["cache_size"] = "#{processor['l2cachesize']} KB"
+ cpu[current_cpu]["cache_size"] = "#{processor["l2cachesize"]} KB"
end
cpu[:total] = logical_processors
diff --git a/lib/ohai/plugins/darwin/network.rb b/lib/ohai/plugins/darwin/network.rb
index f77107e2..24c6f22d 100644
--- a/lib/ohai/plugins/darwin/network.rb
+++ b/lib/ohai/plugins/darwin/network.rb
@@ -21,14 +21,14 @@ Ohai.plugin(:Network) do
provides "counters/network", "counters/network/interfaces"
def parse_media(media_string)
- media = Hash.new
+ media = {}
line_array = media_string.split(" ")
0.upto(line_array.length - 1) do |i|
unless line_array[i].eql?("none")
if line_array[i + 1] =~ /^\<([a-zA-Z\-\,]+)\>$/
- media[line_array[i]] = Hash.new unless media.key?(line_array[i])
+ media[line_array[i]] = {} unless media.key?(line_array[i])
if media[line_array[i]].key?("options")
$1.split(",").each do |opt|
media[line_array[i]]["options"] << opt unless media[line_array[i]]["options"].include?(opt)
@@ -38,7 +38,7 @@ Ohai.plugin(:Network) do
end
else
if line_array[i].eql?("autoselect")
- media["autoselect"] = Hash.new unless media.key?("autoselect")
+ media["autoselect"] = {} unless media.key?("autoselect")
media["autoselect"]["options"] = []
end
end
@@ -56,6 +56,7 @@ Ohai.plugin(:Network) do
return "IPIP" if ifname.eql?("gif")
return "6to4" if ifname.eql?("stf")
return "dot1q" if ifname.eql?("vlan")
+
"Unknown"
end
@@ -63,6 +64,7 @@ Ohai.plugin(:Network) do
return "Node" if scope.eql?("::1")
return "Link" if scope =~ /^fe80\:/
return "Site" if scope =~ /^fec0\:/
+
"Global"
end
@@ -74,6 +76,7 @@ Ohai.plugin(:Network) do
return ifname unless ifaces[ifname].nil?
# oh well, time to go hunting!
return ifname.chop if ifname =~ /\*$/
+
ifaces.each_key do |ifc|
ifaces[ifc][:addresses].each_key do |addr|
return ifc if addr.eql? mac
@@ -115,7 +118,7 @@ Ohai.plugin(:Network) do
if line =~ /\sflags\=\d+\<((UP|BROADCAST|DEBUG|SMART|SIMPLEX|LOOPBACK|POINTOPOINT|NOTRAILERS|RUNNING|NOARP|PROMISC|ALLMULTI|SLAVE|MASTER|MULTICAST|DYNAMIC|,)+)\>\s/
flags = $1.split(",")
else
- flags = Array.new
+ flags = []
end
iface[cint][:flags] = flags.flatten
if cint =~ /^(\w+)(\d+.*)/
@@ -165,6 +168,7 @@ Ohai.plugin(:Network) do
if line =~ /^\S+ \((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([a-zA-Z0-9\.\:\-]+).*\[(\w+)\]/
# MAC addr really should be normalized to include all the zeroes.
next if iface[$3].nil? # this should never happen
+
iface[$3][:arp] ||= Mash.new
iface[$3][:arp][$1] = $2
end
@@ -189,6 +193,7 @@ Ohai.plugin(:Network) do
line =~ /^([a-zA-Z0-9\.\:\-\*]+)\s+\d+\s+\<[a-zA-Z0-9\#]+\>(\s+)(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/
ifname = locate_interface(iface, $1, $2)
next if iface[ifname].nil? # this shouldn't happen, but just in case
+
net_counters[ifname] ||= Mash.new
net_counters[ifname] = { rx: { bytes: $5, packets: $3, errors: $4, drop: 0, overrun: 0, frame: 0, compressed: 0, multicast: 0 },
tx: { bytes: $8, packets: $6, errors: $7, drop: 0, overrun: 0, collisions: $9, carrier: 0, compressed: 0 },
diff --git a/lib/ohai/plugins/digital_ocean.rb b/lib/ohai/plugins/digital_ocean.rb
index 4ee39e2f..884cc76e 100644
--- a/lib/ohai/plugins/digital_ocean.rb
+++ b/lib/ohai/plugins/digital_ocean.rb
@@ -44,6 +44,7 @@ Ohai.plugin(:DigitalOcean) do
def looks_like_digital_ocean?
return true if hint?("digital_ocean")
return true if has_do_dmi? && can_socket_connect?(Ohai::Mixin::DOMetadata::DO_METADATA_ADDR, 80)
+
false
end
@@ -53,6 +54,7 @@ Ohai.plugin(:DigitalOcean) do
digital_ocean Mash.new
fetch_metadata.each do |k, v|
next if k == "vendor_data" # this may have sensitive data we shouldn't store
+
digital_ocean[k] = v
end
else
diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb
index c8a70b13..2aed6d77 100644
--- a/lib/ohai/plugins/dmi.rb
+++ b/lib/ohai/plugins/dmi.rb
@@ -58,6 +58,7 @@ Ohai.plugin(:DMI) do
# ... similar lines trimmed
so.stdout.lines do |line|
next if blank_line.match(line)
+
line = line.encode(line.encoding, universal_newline: true)
if ( dmidecode_version = dmidecode_version_line.match(line) )
diff --git a/lib/ohai/plugins/dragonflybsd/memory.rb b/lib/ohai/plugins/dragonflybsd/memory.rb
index a4ff7165..28787526 100644
--- a/lib/ohai/plugins/dragonflybsd/memory.rb
+++ b/lib/ohai/plugins/dragonflybsd/memory.rb
@@ -46,7 +46,7 @@ Ohai.plugin(:Memory) do
so.stdout.lines do |line|
# Device 1K-blocks Used Avail Capacity
# /dev/ad0s1b 253648 0 253648 0%
- if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
+ if line =~ %r{^([\d\w/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)}
mdev = $1
memory[:swap][mdev] = Mash.new
memory[:swap][mdev][:total] = $2
diff --git a/lib/ohai/plugins/dragonflybsd/network.rb b/lib/ohai/plugins/dragonflybsd/network.rb
index 75abc09d..401bf73e 100644
--- a/lib/ohai/plugins/dragonflybsd/network.rb
+++ b/lib/ohai/plugins/dragonflybsd/network.rb
@@ -89,6 +89,7 @@ Ohai.plugin(:Network) do
so.stdout.lines do |line|
if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
next unless iface[$3] # this should never happen
+
iface[$3][:arp] ||= Mash.new
iface[$3][:arp][$1] = $2.downcase
end
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb
index bd75588e..8ae0cdb2 100644
--- a/lib/ohai/plugins/ec2.rb
+++ b/lib/ohai/plugins/ec2.rb
@@ -124,6 +124,7 @@ Ohai.plugin(:EC2) do
# to the server.
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
next if k == "iam" && !hint?("iam")
+
ec2[k] = v
end
ec2[:userdata] = fetch_userdata
diff --git a/lib/ohai/plugins/eucalyptus.rb b/lib/ohai/plugins/eucalyptus.rb
index 2b34bf6d..616d523f 100644
--- a/lib/ohai/plugins/eucalyptus.rb
+++ b/lib/ohai/plugins/eucalyptus.rb
@@ -71,6 +71,7 @@ Ohai.plugin(:Eucalyptus) do
# to the server.
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
next if k == "iam" && !hint?("iam")
+
eucalyptus[k] = v
end
eucalyptus[:userdata] = fetch_userdata
diff --git a/lib/ohai/plugins/filesystem.rb b/lib/ohai/plugins/filesystem.rb
index 82649309..32ddb607 100644
--- a/lib/ohai/plugins/filesystem.rb
+++ b/lib/ohai/plugins/filesystem.rb
@@ -68,6 +68,7 @@ Ohai.plugin(:Filesystem) do
view[entry[:device]] ||= Mash.new
entry.each do |key, val|
next if %w{device mount}.include?(key)
+
view[entry[:device]][key] = val
end
view[entry[:device]][:mounts] ||= []
@@ -82,9 +83,11 @@ Ohai.plugin(:Filesystem) do
view = {}
fs.each_value do |entry|
next unless entry[:mount]
+
view[entry[:mount]] ||= Mash.new
entry.each do |key, val|
next if %w{mount device}.include?(key)
+
view[entry[:mount]][key] = val
end
view[entry[:mount]][:devices] ||= []
@@ -146,6 +149,7 @@ Ohai.plugin(:Filesystem) do
unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
raise e
end
+
logger.warn("Plugin Filesystem: #{bin} binary is not available. Some data will not be available.")
end
@@ -218,6 +222,7 @@ Ohai.plugin(:Filesystem) do
so.stdout.each_line do |line|
parsed = parse_line(line, cmdtype)
next if parsed.nil?
+
# lsblk lists each device once, so we need to update all entries
# in the hash that are related to this device
keys_to_update = []
@@ -233,7 +238,7 @@ Ohai.plugin(:Filesystem) do
end
keys_to_update.each do |k|
- [:fs_type, :uuid, :label].each do |subkey|
+ %i{fs_type uuid label}.each do |subkey|
if parsed[subkey] && !parsed[subkey].empty?
fs[k][subkey] = parsed[subkey]
end
@@ -266,6 +271,7 @@ Ohai.plugin(:Filesystem) do
if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/
key = "#{$1},#{$2}"
next if fs.key?(key)
+
fs[key] = Mash.new
fs[key][:device] = $1
fs[key][:mount] = $2
@@ -412,9 +418,11 @@ Ohai.plugin(:Filesystem) do
so = shell_out("df -na")
so.stdout.lines do |line|
next unless line =~ /^(.+?)\s*: (\S+)\s*$/
+
mount = $1
fs.each do |key, fs_attributes|
next unless fs_attributes[:mount] == mount
+
fs[key][:fs_type] = $2
end
end
@@ -425,6 +433,7 @@ Ohai.plugin(:Filesystem) do
so = shell_out("mount")
so.stdout.lines do |line|
next unless line =~ /^(.+?) on (.+?) (.+?) on (.+?)$/
+
key = "#{$2},#{$1}"
fs[key] ||= Mash.new
fs[key][:mount] = $1
@@ -441,6 +450,7 @@ Ohai.plugin(:Filesystem) do
so = shell_out(zfs_get)
so.stdout.lines do |line|
next unless line =~ /^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$/
+
filesystem = $1
property = $2
value = $3
@@ -524,7 +534,7 @@ Ohai.plugin(:Filesystem) do
oldie[key][:mount] = mountpoint
oldie[key][:device] = dev
# an entry starting with 'G' or / (E.G. /tmp or /var)
- when /^\s*(G.*?|\/\w)/
+ when %r{^\s*(G.*?|/\w)}
if fields[0] == "Global"
dev = fields[0] + ":" + fields[1]
else
diff --git a/lib/ohai/plugins/freebsd/memory.rb b/lib/ohai/plugins/freebsd/memory.rb
index fdf32a30..0b0cf327 100644
--- a/lib/ohai/plugins/freebsd/memory.rb
+++ b/lib/ohai/plugins/freebsd/memory.rb
@@ -46,7 +46,7 @@ Ohai.plugin(:Memory) do
so.stdout.lines do |line|
# Device 1K-blocks Used Avail Capacity
# /dev/ad0s1b 253648 0 253648 0%
- if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
+ if line =~ %r{^([\d\w/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)}
mdev = $1
memory[:swap][mdev] = Mash.new
memory[:swap][mdev][:total] = $2
diff --git a/lib/ohai/plugins/freebsd/network.rb b/lib/ohai/plugins/freebsd/network.rb
index cff51bc3..1263086a 100644
--- a/lib/ohai/plugins/freebsd/network.rb
+++ b/lib/ohai/plugins/freebsd/network.rb
@@ -89,6 +89,7 @@ Ohai.plugin(:Network) do
so.stdout.lines do |line|
if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
next unless iface[$3] # this should never happen
+
iface[$3][:arp] ||= Mash.new
iface[$3][:arp][$1] = $2.downcase
end
diff --git a/lib/ohai/plugins/haskell.rb b/lib/ohai/plugins/haskell.rb
index 3d308a9b..50d08b3d 100644
--- a/lib/ohai/plugins/haskell.rb
+++ b/lib/ohai/plugins/haskell.rb
@@ -17,10 +17,10 @@
Ohai.plugin(:Haskell) do
provides "languages/haskell",
- "languages/haskell/ghc",
- "languages/haskell/ghci",
- "languages/haskell/cabal",
- "languages/haskell/stack"
+ "languages/haskell/ghc",
+ "languages/haskell/ghci",
+ "languages/haskell/cabal",
+ "languages/haskell/stack"
depends "languages"
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 911a7d9b..1a624b00 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -115,7 +115,8 @@ Ohai.plugin(:Hostname) do
end
rescue
logger.trace(
- "Plugin Hostname: hostname returned an error, probably no domain set")
+ "Plugin Hostname: hostname returned an error, probably no domain set"
+ )
end
domain collect_domain
end
diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb
index ee931864..1beff3fa 100644
--- a/lib/ohai/plugins/java.rb
+++ b/lib/ohai/plugins/java.rb
@@ -63,6 +63,7 @@ Ohai.plugin(:Java) do
# workaround for this particular annoyance.
def has_real_java?
return true unless on_darwin?
+
shell_out("/usr/libexec/java_home").status.success?
end
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index 204af478..7a1e85e7 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -32,9 +32,9 @@ Ohai.plugin(:Kernel) do
[["uname -s", :name], ["uname -r", :release],
["uname -v", :version], ["uname -m", :machine],
["uname -p", :processor]].each do |cmd, property|
- so = shell_out(cmd)
- kernel[property] = so.stdout.split($/)[0]
- end
+ so = shell_out(cmd)
+ kernel[property] = so.stdout.split($/)[0]
+ end
kernel
end
@@ -71,8 +71,9 @@ Ohai.plugin(:Kernel) do
43, # Storage Server Express Core
44, # Storage Server Standard Core
45, # Storage Server Workgroup Core
- 29 # Web Server Core
+ 29, # Web Server Core
].include?(sku)
+
false
end
@@ -84,6 +85,7 @@ Ohai.plugin(:Kernel) do
def arch_lookup(sys_type)
return "x86_64" if sys_type == "x64-based PC"
return "i386" if sys_type == "X86-based PC"
+
sys_type
end
@@ -94,6 +96,7 @@ Ohai.plugin(:Kernel) do
# @return [String] Workstation or Server
def product_type_decode(type)
return "Workstation" if type == 1
+
"Server"
end
@@ -226,7 +229,7 @@ Ohai.plugin(:Kernel) do
so = shell_out("uname -s")
kernel[:os] = so.stdout.split($/)[0]
- so = File.open("/etc/release") { |file| file.gets }
+ so = File.open("/etc/release", &:gets)
md = /(?<update>\d.*\d)/.match(so)
kernel[:update] = md[:update] if md
@@ -260,6 +263,7 @@ Ohai.plugin(:Kernel) do
kernel[:os_info] = Mash.new
host.wmi_ole_object.properties_.each do |p|
next if blacklisted_wmi_name?(p.name.wmi_underscore)
+
kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
end
@@ -274,6 +278,7 @@ Ohai.plugin(:Kernel) do
host = wmi.first_of("Win32_ComputerSystem")
host.wmi_ole_object.properties_.each do |p|
next if blacklisted_wmi_name?(p.name.wmi_underscore)
+
kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
end
diff --git a/lib/ohai/plugins/linode.rb b/lib/ohai/plugins/linode.rb
index 4a7266cb..64e8a62f 100644
--- a/lib/ohai/plugins/linode.rb
+++ b/lib/ohai/plugins/linode.rb
@@ -57,7 +57,7 @@ Ohai.plugin(:Linode) do
linode Mash.new
get_ip_address(:public_ip, :eth0)
get_ip_address(:private_ip, "eth0:1")
- hint?("linode").each { |k, v| linode[k] = v } if hint?("linode").kind_of?(Hash)
+ hint?("linode").each { |k, v| linode[k] = v } if hint?("linode").is_a?(Hash)
else
logger.trace("Plugin Linode: looks_like_linode? == false")
end
diff --git a/lib/ohai/plugins/linux/lspci.rb b/lib/ohai/plugins/linux/lspci.rb
index 24433647..997544a5 100644
--- a/lib/ohai/plugins/linux/lspci.rb
+++ b/lib/ohai/plugins/linux/lspci.rb
@@ -30,7 +30,7 @@ Ohai.plugin(:Lspci) do
hh = /#{h}#{h}/ # any 2 hex digits
hhhh = /#{h}#{h}#{h}#{h}/ # any 4 hex digits
- d_id = String.new # This identifies our pci devices
+ d_id = "" # This identifies our pci devices
def standard_form(devices, d_id, hhhh, tag, line)
tmp = line.scan(/(.*)\s\[(#{hhhh})\]/)[0]
@@ -39,7 +39,7 @@ Ohai.plugin(:Lspci) do
end
def standard_array(devices, d_id, tag, line)
- if !devices[d_id][tag].kind_of?(Array)
+ if !devices[d_id][tag].is_a?(Array)
devices[d_id][tag] = [line]
else
devices[d_id][tag].push(line)
@@ -49,6 +49,7 @@ Ohai.plugin(:Lspci) do
lspci.stdout.split("\n").each do |line|
dev = line.scan(/^(.*):\s(.*)$/)[0]
next if dev.nil?
+
case dev[0]
when "Device" # There are two different Device tags
if ( tmp = dev[1].match(/(#{hh}:#{hh}.#{h})/) )
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 685b64aa..9852413f 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -30,6 +30,7 @@ Ohai.plugin(:Network) do
return "IPIP" if encap.eql?("IPIP Tunnel")
return "6to4" if encap.eql?("IPv6-in-IPv4")
return "Ethernet" if encap.eql?("ether")
+
encap
end
@@ -120,7 +121,7 @@ Ohai.plugin(:Network) do
end
end
- iface[route_int][:routes] = Array.new unless iface[route_int][:routes]
+ iface[route_int][:routes] = [] unless iface[route_int][:routes]
iface[route_int][:routes] << route_entry
end
end
@@ -149,9 +150,11 @@ Ohai.plugin(:Network) do
# determine layer 1 details for the interface using ethtool
def ethernet_layer_one(iface)
return iface unless ethtool_binary_path
+
keys = %w{ Speed Duplex Port Transceiver Auto-negotiation MDI-X }
iface.each_key do |tmp_int|
next unless iface[tmp_int][:encapsulation] == "Ethernet"
+
so = shell_out("#{ethtool_binary_path} #{tmp_int}")
so.stdout.lines do |line|
line.chomp!
@@ -159,6 +162,7 @@ Ohai.plugin(:Network) do
line.lstrip!
k, v = line.split(": ")
next unless keys.include? k
+
k.downcase!.tr!("-", "_")
if k == "speed"
k = "link_speed" # This is not necessarily the maximum speed the NIC supports
@@ -173,8 +177,10 @@ Ohai.plugin(:Network) do
# determine ring parameters for the interface using ethtool
def ethernet_ring_parameters(iface)
return iface unless ethtool_binary_path
+
iface.each_key do |tmp_int|
next unless iface[tmp_int][:encapsulation] == "Ethernet"
+
so = shell_out("#{ethtool_binary_path} -g #{tmp_int}")
logger.trace("Plugin Network: Parsing ethtool output: #{so.stdout}")
type = nil
@@ -182,6 +188,7 @@ Ohai.plugin(:Network) do
so.stdout.lines.each do |line|
next if line.start_with?("Ring parameters for")
next if line.strip.nil?
+
if line =~ /Pre-set maximums/
type = "max"
next
@@ -192,7 +199,7 @@ Ohai.plugin(:Network) do
end
key, val = line.split(/:\s+/)
if type && val
- ring_key = "#{type}_#{key.downcase.tr(' ', '_')}"
+ ring_key = "#{type}_#{key.downcase.tr(" ", "_")}"
iface[tmp_int]["ring_params"][ring_key] = val.to_i
end
end
@@ -317,7 +324,7 @@ Ohai.plugin(:Network) do
end
def parse_ip_addr_link_line(cint, iface, line)
- if line =~ /link\/(\w+) ([\da-f\:]+) /
+ if line =~ %r{link/(\w+) ([\da-f\:]+) }
iface[cint][:encapsulation] = linux_encaps_lookup($1)
unless $2 == "00:00:00:00:00:00"
iface[cint][:addresses] ||= Mash.new
@@ -327,7 +334,7 @@ Ohai.plugin(:Network) do
end
def parse_ip_addr_inet_line(cint, iface, line)
- if line =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/
+ if line =~ %r{inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(/(\d{1,2}))?}
tmp_addr, tmp_prefix = $1, $3
tmp_prefix ||= "32"
original_int = nil
@@ -364,7 +371,7 @@ Ohai.plugin(:Network) do
end
def parse_ip_addr_inet6_line(cint, iface, line)
- if line =~ /inet6 ([a-f0-9\:]+)\/(\d+) scope (\w+)( .*)?/
+ if line =~ %r{inet6 ([a-f0-9\:]+)/(\d+) scope (\w+)( .*)?}
iface[cint][:addresses] ||= Mash.new
tmp_addr = $1
tags = $4 || ""
@@ -395,11 +402,13 @@ Ohai.plugin(:Network) do
def interface_has_no_addresses_in_family?(iface, family)
return true if iface[:addresses].nil?
+
iface[:addresses].values.all? { |addr| addr["family"] != family }
end
def interface_have_address?(iface, address)
return false if iface[:addresses].nil?
+
iface[:addresses].key?(address)
end
@@ -605,7 +614,7 @@ Ohai.plugin(:Network) do
iface[cint][:addresses][$1] = { "family" => "inet" }
tmp_addr = $1
end
- if line =~ /inet6 addr: ([a-f0-9\:]+)\/(\d+) Scope:(\w+)/
+ if line =~ %r{inet6 addr: ([a-f0-9\:]+)/(\d+) Scope:(\w+)}
iface[cint][:addresses] ||= Mash.new
iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2, "scope" => ($3.eql?("Host") ? "Node" : $3) }
end
@@ -650,6 +659,7 @@ Ohai.plugin(:Network) do
so.stdout.lines do |line|
if line =~ /^\S+ \((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) \[(\w+)\] on ([0-9a-zA-Z\.\:\-]+)/
next unless iface[$4] # this should never happen
+
iface[$4][:arp] ||= Mash.new
iface[$4][:arp][$1] = $2.downcase
end
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 61e9c81c..cc5598fd 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -64,6 +64,7 @@ Ohai.plugin(:Platform) do
#
def read_os_release_info(file)
return nil unless File.exist?(file)
+
File.read(file).split.inject({}) do |map, line|
key, value = line.split("=")
map[key] = value.gsub(/\A"|"\Z/, "") if value
diff --git a/lib/ohai/plugins/netbsd/memory.rb b/lib/ohai/plugins/netbsd/memory.rb
index 02ddcf5c..65cc8699 100644
--- a/lib/ohai/plugins/netbsd/memory.rb
+++ b/lib/ohai/plugins/netbsd/memory.rb
@@ -85,7 +85,7 @@ Ohai.plugin(:Memory) do
so.stdout.lines do |line|
# Device 1024-blocks Used Avail Capacity Priority
# swap_device 1048824 0 1048824 0% 0
- if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
+ if line =~ %r{^([\d\w/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)}
mdev = $1
memory[:swap][mdev] = Mash.new
memory[:swap][mdev][:total] = $2
diff --git a/lib/ohai/plugins/netbsd/network.rb b/lib/ohai/plugins/netbsd/network.rb
index f5e80386..66cb6a20 100644
--- a/lib/ohai/plugins/netbsd/network.rb
+++ b/lib/ohai/plugins/netbsd/network.rb
@@ -89,6 +89,7 @@ Ohai.plugin(:Network) do
so.stdout.lines do |line|
if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
next unless iface[$3] # this should never happen
+
iface[$3][:arp] ||= Mash.new
iface[$3][:arp][$1] = $2.downcase
end
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index 2f5925e1..af50d6d7 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -37,8 +37,10 @@ Ohai.plugin(:NetworkAddresses) do
ipaddresses = []
Mash[network["interfaces"]].each do |iface, iface_v|
next if iface_v.nil? || !iface_v.key?("addresses")
+
iface_v["addresses"].each do |addr, addr_v|
next if addr_v.nil? || (not addr_v.key? "family") || addr_v["family"] != family
+
ipaddresses << {
ipaddress: addr_v["prefixlen"] ? IPAddress("#{addr}/#{addr_v["prefixlen"]}") : IPAddress("#{addr}/#{addr_v["netmask"]}"),
scope: addr_v["scope"].nil? ? nil : addr_v["scope"].downcase,
diff --git a/lib/ohai/plugins/openbsd/memory.rb b/lib/ohai/plugins/openbsd/memory.rb
index 020a3881..ab7de696 100644
--- a/lib/ohai/plugins/openbsd/memory.rb
+++ b/lib/ohai/plugins/openbsd/memory.rb
@@ -85,7 +85,7 @@ Ohai.plugin(:Memory) do
so.stdout.lines do |line|
# Device 1024-blocks Used Avail Capacity Priority
# swap_device 1048824 0 1048824 0% 0
- if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
+ if line =~ %r{^([\d\w/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)}
mdev = $1
memory[:swap][mdev] = Mash.new
memory[:swap][mdev][:total] = $2
diff --git a/lib/ohai/plugins/openbsd/network.rb b/lib/ohai/plugins/openbsd/network.rb
index 9868b2c2..14664860 100644
--- a/lib/ohai/plugins/openbsd/network.rb
+++ b/lib/ohai/plugins/openbsd/network.rb
@@ -89,6 +89,7 @@ Ohai.plugin(:Network) do
so.stdout.lines do |line|
if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
next unless iface[$3] # this should never happen
+
iface[$3][:arp] ||= Mash.new
iface[$3][:arp][$1] = $2.downcase
end
diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb
index cd2731da..2cd86aed 100644
--- a/lib/ohai/plugins/openstack.rb
+++ b/lib/ohai/plugins/openstack.rb
@@ -55,6 +55,7 @@ Ohai.plugin(:Openstack) do
# dreamhost systems have the dhc-user on them
def openstack_provider
return "dreamhost" if get_attribute("etc", "passwd", "dhc-user")
+
"openstack"
end
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index 796efee0..04c19e96 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -92,6 +92,7 @@ Ohai.plugin(:Packages) do
pkg = reg.open(key)
name = pkg["DisplayName"] rescue nil
next if name.nil?
+
package = packages[name] = Mash.new
WINDOWS_ATTRIBUTE_ALIASES.each do |registry_attr, package_attr|
value = pkg[registry_attr] rescue nil
diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb
index ee1174ae..3199723c 100644
--- a/lib/ohai/plugins/rackspace.rb
+++ b/lib/ohai/plugins/rackspace.rb
@@ -49,6 +49,7 @@ Ohai.plugin(:Rackspace) do
# false:: Otherwise
def has_rackspace_manufacturer?
return false unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
+
require "wmi-lite/wmi"
wmi = WmiLite::Wmi.new
if wmi.first_of("Win32_ComputerSystem")["PrimaryOwnerName"] == "Rackspace"
diff --git a/lib/ohai/plugins/scaleway.rb b/lib/ohai/plugins/scaleway.rb
index 2b83acf3..37343f03 100644
--- a/lib/ohai/plugins/scaleway.rb
+++ b/lib/ohai/plugins/scaleway.rb
@@ -39,6 +39,7 @@ Ohai.plugin(:Scaleway) do
def looks_like_scaleway?
return true if hint?("scaleway")
return true if has_scaleway_cmdline? && can_socket_connect?(Ohai::Mixin::ScalewayMetadata::SCALEWAY_METADATA_ADDR, 80)
+
false
end
diff --git a/lib/ohai/plugins/shard.rb b/lib/ohai/plugins/shard.rb
index f286e2a0..80300cfa 100644
--- a/lib/ohai/plugins/shard.rb
+++ b/lib/ohai/plugins/shard.rb
@@ -31,7 +31,7 @@ Ohai.plugin(:ShardSeed) do
def default_sources
case collect_os
when "linux", "darwin", "windows"
- [:machinename, :serial, :uuid]
+ %i{machinename serial uuid}
else
[:machinename]
end
diff --git a/lib/ohai/plugins/solaris2/network.rb b/lib/ohai/plugins/solaris2/network.rb
index 7e7ffc5e..5e890f2b 100644
--- a/lib/ohai/plugins/solaris2/network.rb
+++ b/lib/ohai/plugins/solaris2/network.rb
@@ -70,6 +70,7 @@ Ohai.plugin(:Network) do
return "Ethernet" if ETHERNET_ENCAPS.include?(ifname)
return "Ethernet" if ifname.eql?("net")
return "Loopback" if ifname.eql?("lo")
+
"Unknown"
end
@@ -129,7 +130,7 @@ Ohai.plugin(:Network) do
iface[cint][:addresses] ||= Mash.new
iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf("%2x" * 4) * ".", "broadcast" => $4 }
end
- if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*)\/(\d+)\s*$/
+ if line =~ %r{\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*)/(\d+)\s*$}
iface[cint][:addresses] ||= Mash.new
iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 }
end
@@ -141,6 +142,7 @@ Ohai.plugin(:Network) do
so.stdout.lines do |line|
if line =~ /([0-9a-zA-Z]+)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\w+)?\s+([a-zA-Z0-9\.\:\-]+)/
next unless iface[arpname_to_ifname(iface, $1)] # this should never happen, except on solaris because sun hates you.
+
iface[arpname_to_ifname(iface, $1)][:arp] ||= Mash.new
iface[arpname_to_ifname(iface, $1)][:arp][$2] = $5
end
diff --git a/lib/ohai/plugins/virtualbox.rb b/lib/ohai/plugins/virtualbox.rb
index 34743315..b2549f99 100644
--- a/lib/ohai/plugins/virtualbox.rb
+++ b/lib/ohai/plugins/virtualbox.rb
@@ -87,6 +87,7 @@ Ohai.plugin(:Virtualbox) do
hostfloppies hostonlyifs natnets
}
return nil unless supported_queries.include? query_type
+
results = Mash.new
so_cmd = "VBoxManage list --sorted #{query_type}"
@@ -103,8 +104,9 @@ Ohai.plugin(:Virtualbox) do
# initialize a blank record hash
record = Mash.new
# parse the record block into key/value pairs
- blk.each_line() do |line|
+ blk.each_line do |line|
next unless line.include? ":"
+
# split the line into key/value pair
key, right = line.split(":", 2)
@@ -144,9 +146,9 @@ Ohai.plugin(:Virtualbox) do
virtualbox[:host][:version] = Regexp.last_match(1)
when /VBoxRev, value: (\S*),/
virtualbox[:host][:revision] = Regexp.last_match(1)
- when /GuestAdd\/VersionExt, value: (\S*),/
+ when %r{GuestAdd/VersionExt, value: (\S*),}
virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
- when /GuestAdd\/Revision, value: (\S*),/
+ when %r{GuestAdd/Revision, value: (\S*),}
virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
end
end
diff --git a/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb
index 68e08060..21f0c8c1 100644
--- a/lib/ohai/plugins/windows/network.rb
+++ b/lib/ohai/plugins/windows/network.rb
@@ -22,6 +22,7 @@ Ohai.plugin(:Network) do
def windows_encaps_lookup(encap)
return "Ethernet" if encap.eql?("Ethernet 802.3")
+
encap
end
@@ -40,6 +41,7 @@ Ohai.plugin(:Network) do
# that does not populate the deprecated win32_* WMI classes, then we should
# grab data from the newer MSFT_* classes
return msft_adapter_data if data[:addresses].count == 0
+
data[:adapters] = wmi.instances_of("Win32_NetworkAdapter")
data
end
@@ -84,6 +86,7 @@ Ohai.plugin(:Network) do
#
def prefer_ipv4(addresses)
return nil unless addresses.is_a?(Array)
+
addresses.find { |ip| IPAddress.valid_ipv4?(ip) } ||
addresses.find { |ip| IPAddress.valid_ipv6?(ip) }
end
@@ -99,6 +102,7 @@ Ohai.plugin(:Network) do
#
def favored_default_route_windows(configuration)
return nil unless configuration.is_a?(Hash)
+
config = configuration.dup
config.inject([]) do |arr, (k, v)|
@@ -143,6 +147,7 @@ Ohai.plugin(:Network) do
adapter.wmi_ole_object.properties_.each do |p|
# skip wmi class name fields which make no sense in ohai
next if %w{creation_class_name system_creation_class_name}.include?(p.name.wmi_underscore)
+
iface_instance[i][p.name.wmi_underscore.to_sym] = adapter[p.name.downcase]
end
end
@@ -204,6 +209,7 @@ Ohai.plugin(:Network) do
cint = $2.downcase
end
next unless iface[cint]
+
if line =~ /^\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-fA-F0-9\:-]+)/
iface[cint][:arp][$1] = $2.tr("-", ":").downcase
end
diff --git a/lib/ohai/provides_map.rb b/lib/ohai/provides_map.rb
index d803d298..42a25cd8 100644
--- a/lib/ohai/provides_map.rb
+++ b/lib/ohai/provides_map.rb
@@ -32,7 +32,7 @@ module Ohai
end
def set_providers_for(plugin, provided_attributes)
- unless plugin.kind_of?(Ohai::DSL::Plugin)
+ unless plugin.is_a?(Ohai::DSL::Plugin)
raise ArgumentError, "set_providers_for only accepts Ohai Plugin classes (got: #{plugin})"
end
@@ -55,6 +55,7 @@ module Ohai
attrs = select_subtree(@map, attribute)
raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless attrs
raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: \'#{attribute}\'" unless attrs[:_plugins]
+
plugins += attrs[:_plugins]
end
plugins.uniq
@@ -95,8 +96,10 @@ module Ohai
attributes.each do |attribute|
parts = normalize_and_validate(attribute)
raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless @map[parts[0]]
+
attrs = select_closest_subtree(@map, attribute)
raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: \'#{attribute}\'" unless attrs
+
plugins += attrs[:_plugins]
end
plugins.uniq
@@ -114,8 +117,8 @@ module Ohai
private
def normalize_and_validate(attribute)
- raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: #{attribute}" if attribute =~ /\/\/+/
- raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': #{attribute}" if attribute =~ /\/$/
+ raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: #{attribute}" if attribute =~ %r{//+}
+ raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': #{attribute}" if attribute =~ %r{/$}
parts = attribute.split("/")
parts.shift if parts.length != 0 && parts[0].length == 0 # attribute begins with a '/'
@@ -127,6 +130,7 @@ module Ohai
parts = normalize_and_validate(attribute)
parts.each do |part|
return nil unless subtree[part]
+
subtree = subtree[part]
end
subtree
diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb
index cc776618..0571d935 100644
--- a/lib/ohai/runner.rb
+++ b/lib/ohai/runner.rb
@@ -39,7 +39,7 @@ module Ohai
# will be run even if they have been run before.
def run_plugin(plugin)
elapsed = Benchmark.measure do
- unless plugin.kind_of?(Ohai::DSL::Plugin)
+ unless plugin.is_a?(Ohai::DSL::Plugin)
raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)"
end
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index 5698a844..7d1f56d1 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -160,6 +160,7 @@ module Ohai
data = data[part]
end
raise ArgumentError, "I cannot find an attribute named #{a}!" if data.nil?
+
case data
when Hash, Mash, Array, Integer
json_pretty_print(data)
@@ -184,6 +185,7 @@ module Ohai
# make sure the directory config is an array since it could be a string set in client.rb
Array(Ohai.config[:directory]).each do |dir|
next if Ohai.config[:plugin_path].include?(dir)
+
Ohai.config[:plugin_path] << dir
end
end
diff --git a/lib/ohai/util/win32.rb b/lib/ohai/util/win32.rb
index 5d5ab156..8a62c07a 100644
--- a/lib/ohai/util/win32.rb
+++ b/lib/ohai/util/win32.rb
@@ -28,18 +28,18 @@ module Ohai
ffi_lib "advapi32"
attach_function :lookup_account_sid,
- :LookupAccountSidA, [ :pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer ], :long
+ :LookupAccountSidA, %i{pointer pointer pointer pointer pointer pointer pointer}, :long
attach_function :convert_string_sid_to_sid,
- :ConvertStringSidToSidA, [ :pointer, :pointer ], :long
+ :ConvertStringSidToSidA, %i{pointer pointer}, :long
ffi_lib "kernel32"
attach_function :local_free,
- :LocalFree, [ :pointer ], :long
+ :LocalFree, [ :pointer ], :long
attach_function :get_last_error,
- :GetLastError, [], :long
+ :GetLastError, [], :long
end
end
end
diff --git a/spec/functional/application_spec.rb b/spec/functional/application_spec.rb
index a49aea05..b222e532 100644
--- a/spec/functional/application_spec.rb
+++ b/spec/functional/application_spec.rb
@@ -81,7 +81,7 @@ RSpec.describe "Ohai::Application" do
it "loads the workstation configuration file" do
app.configure_ohai
- expect(Ohai.config[:disabled_plugins]).to eq([ :Foo, :Baz ])
+ expect(Ohai.config[:disabled_plugins]).to eq(%i{Foo Baz})
end
end
diff --git a/spec/functional/loader_spec.rb b/spec/functional/loader_spec.rb
index 033f3271..f1eb2c2f 100644
--- a/spec/functional/loader_spec.rb
+++ b/spec/functional/loader_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe "Ohai::Loader" do
it "loads all the plugins" do
loader.load_all
loaded_plugins = loader.instance_variable_get(:@v7_plugin_classes)
- loaded_plugins_names = loaded_plugins.map { |plugin| plugin.name }
+ loaded_plugins_names = loaded_plugins.map(&:name)
expect(loaded_plugins_names).to eq(["Ohai::NamedPlugin::Foo"])
end
end
diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb
index ff5289ac..5119fed7 100644
--- a/spec/unit/dsl/plugin_spec.rb
+++ b/spec/unit/dsl/plugin_spec.rb
@@ -220,7 +220,7 @@ shared_examples "Ohai::DSL::Plugin" do
it "returns nil" do
expect(
plugin.get_attribute("the_monarch", "henchmen",
- "corky_knightrider")
+ "corky_knightrider")
).to be nil
end
end
@@ -229,9 +229,9 @@ shared_examples "Ohai::DSL::Plugin" do
it "raises a TypeError" do
expect do
plugin.get_attribute("the_monarch", "arch_rival",
- "dr_venture", "since")
+ "dr_venture", "since")
end.to raise_error(TypeError,
- "Expected Hash but got String.")
+ "Expected Hash but got String.")
end
end
end
@@ -254,7 +254,7 @@ shared_examples "Ohai::DSL::Plugin" do
it "returns nil" do
expect(
plugin.get_attribute(:the_monarch, :henchmen,
- :corky_knightrider)
+ :corky_knightrider)
).to be nil
end
end
@@ -263,9 +263,9 @@ shared_examples "Ohai::DSL::Plugin" do
it "raises a TypeError" do
expect do
plugin.get_attribute(:the_monarch, :arch_rival,
- :dr_venture, :since)
+ :dr_venture, :since)
end.to raise_error(TypeError,
- "Expected Hash but got String.")
+ "Expected Hash but got String.")
end
end
end
@@ -327,7 +327,7 @@ shared_examples "Ohai::DSL::Plugin" do
it "returns false" do
expect(
plugin.attribute?("the_monarch", "henchmen",
- "corky_knightrider")
+ "corky_knightrider")
).to be false
end
end
@@ -336,9 +336,9 @@ shared_examples "Ohai::DSL::Plugin" do
it "raises a TypeError" do
expect do
plugin.attribute?("the_monarch", "arch_rival",
- "dr_venture", "since")
+ "dr_venture", "since")
end.to raise_error(TypeError,
- "Expected Hash but got String.")
+ "Expected Hash but got String.")
end
end
end
@@ -360,7 +360,7 @@ shared_examples "Ohai::DSL::Plugin" do
it "returns false" do
expect(
plugin.attribute?(:the_monarch, :henchmen,
- :corky_knightrider)
+ :corky_knightrider)
).to be false
end
end
@@ -369,9 +369,9 @@ shared_examples "Ohai::DSL::Plugin" do
it "raises a TypeError" do
expect do
plugin.attribute?(:the_monarch, :arch_rival,
- :dr_venture, :since)
+ :dr_venture, :since)
end.to raise_error(TypeError,
- "Expected Hash but got String.")
+ "Expected Hash but got String.")
end
end
end
@@ -494,7 +494,7 @@ describe Ohai::DSL::Plugin::VersionVII do
it "saves a list of platforms" do
plugin = Ohai.plugin(:Test) { collect_data(:freebsd, :netbsd, :openbsd) {} }
- [:freebsd, :netbsd, :openbsd].each do |platform|
+ %i{freebsd netbsd openbsd}.each do |platform|
expect(plugin.data_collector).to have_key(platform)
end
end
@@ -505,7 +505,7 @@ describe Ohai::DSL::Plugin::VersionVII do
collect_data(:windows) {}
collect_data(:darwin) {}
end
- [:darwin, :default, :windows].each do |platform|
+ %i{darwin default windows}.each do |platform|
expect(plugin.data_collector).to have_key(platform)
end
end
@@ -513,7 +513,7 @@ describe Ohai::DSL::Plugin::VersionVII do
it "saves platforms across multiple plugins" do
plugin = Ohai.plugin(:Test) { collect_data {} }
plugin = Ohai.plugin(:Test) { collect_data(:aix, :sigar) {} }
- [:aix, :default, :sigar].each do |platform|
+ %i{aix default sigar}.each do |platform|
expect(plugin.data_collector).to have_key(platform)
end
end
diff --git a/spec/unit/plugin_config_spec.rb b/spec/unit/plugin_config_spec.rb
index 45c61c68..96b826a2 100644
--- a/spec/unit/plugin_config_spec.rb
+++ b/spec/unit/plugin_config_spec.rb
@@ -54,7 +54,7 @@ describe "Ohai::PluginConfig" do
let(:value) do
{
bar0: true,
- bar1: [ :baz0, :baz1, :baz2 ],
+ bar1: %i{baz0 baz1 baz2},
bar2: { qux0: true, qux1: false },
}
end
@@ -68,7 +68,7 @@ describe "Ohai::PluginConfig" do
let(:value) do
{
:bar0 => true,
- "bar1" => [ :baz0, :baz1, :baz2 ],
+ "bar1" => %i{baz0 baz1 baz2},
:bar2 => { qux0: true, qux1: false },
}
end
@@ -82,7 +82,7 @@ describe "Ohai::PluginConfig" do
let(:value) do
{
bar0: true,
- bar1: [ :baz0, :baz1, :baz2 ],
+ bar1: %i{baz0 baz1 baz2},
bar2: { :qux0 => true, "qux1" => false },
}
end
diff --git a/spec/unit/plugins/docker_spec.rb b/spec/unit/plugins/docker_spec.rb
index fe7ceb4f..90610426 100644
--- a/spec/unit/plugins/docker_spec.rb
+++ b/spec/unit/plugins/docker_spec.rb
@@ -47,17 +47,17 @@ macvlan
null
overlay},
"Authorization" => nil,
- "Log" => [
- "awslogs",
- "fluentd",
- "gcplogs",
- "gelf",
- "journald",
- "json-file",
- "logentries",
- "splunk",
- "syslog",
- ],
+ "Log" => %w{
+ awslogs
+ fluentd
+ gcplogs
+ gelf
+ journald
+ json-file
+ logentries
+ splunk
+ syslog
+ },
},
"networking" => {
"ipv4_forwarding" => true,
diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb
index b94857e8..bcbaeac3 100644
--- a/spec/unit/plugins/ec2_spec.rb
+++ b/spec/unit/plugins/ec2_spec.rb
@@ -400,7 +400,8 @@ describe Ohai::System, "plugin ec2" do
"skunumber" => nil,
"uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
"vendor" => "Xen",
- "version" => "4.2.amazon" })
+ "version" => "4.2.amazon" }
+ )
end
end
@@ -416,7 +417,8 @@ describe Ohai::System, "plugin ec2" do
"skunumber" => nil,
"uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6",
"vendor" => "Xen",
- "version" => "1.2.3" })
+ "version" => "1.2.3" }
+ )
end
end
diff --git a/spec/unit/plugins/erlang_spec.rb b/spec/unit/plugins/erlang_spec.rb
index f10b8b89..29515b0d 100644
--- a/spec/unit/plugins/erlang_spec.rb
+++ b/spec/unit/plugins/erlang_spec.rb
@@ -27,9 +27,9 @@ describe Ohai::System, "plugin erlang" do
erl_v_output = "Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 7.3\n"
erl_systeminfo_output = "19.1,8.1,2.11"
allow(plugin).to receive(:shell_out).with("erl +V")
- .and_return(mock_shell_out(0, "", erl_v_output))
+ .and_return(mock_shell_out(0, "", erl_v_output))
allow(plugin).to receive(:shell_out).with("erl -eval '{ok, Ver} = file:read_file(filename:join([code:root_dir(), \"releases\", erlang:system_info(otp_release), \"OTP_VERSION\"])), Vsn = binary:bin_to_list(Ver, {0, byte_size(Ver) - 1}), io:format(\"~s,~s,~s\", [Vsn, erlang:system_info(version), erlang:system_info(nif_version)]), halt().' -noshell")
- .and_return(mock_shell_out(0, erl_systeminfo_output, ""))
+ .and_return(mock_shell_out(0, erl_systeminfo_output, ""))
end
it "sets languages[:erlang][:options]" do
diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb
index 97cecf4f..dfc666d1 100644
--- a/spec/unit/plugins/hostname_spec.rb
+++ b/spec/unit/plugins/hostname_spec.rb
@@ -64,9 +64,11 @@ describe Ohai::System, "hostname plugin" do
before(:each) do
allow(@plugin).to receive(:collect_os).and_return(:linux)
allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(
- mock_shell_out(0, "katie", ""))
+ mock_shell_out(0, "katie", "")
+ )
allow(@plugin).to receive(:shell_out).with("hostname --fqdn").and_return(
- mock_shell_out(0, "", ""), mock_shell_out(0, "katie.local", ""))
+ mock_shell_out(0, "", ""), mock_shell_out(0, "katie.local", "")
+ )
end
it "should be called twice" do
@@ -79,9 +81,11 @@ describe Ohai::System, "hostname plugin" do
before(:each) do
allow(@plugin).to receive(:collect_os).and_return(:linux)
allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(
- mock_shell_out(0, "katie", ""))
+ mock_shell_out(0, "katie", "")
+ )
allow(@plugin).to receive(:shell_out).with("hostname --fqdn").and_return(
- mock_shell_out(0, "katie.local", ""))
+ mock_shell_out(0, "katie.local", "")
+ )
end
it "should be not be called twice" do
@@ -109,7 +113,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do
"address1",
"address2",
"address3",
- "address4"
+ "address4",
]
end
@@ -118,7 +122,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do
"local",
[],
23,
- "address"
+ "address",
]
end
@@ -127,7 +131,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do
"local.dx.internal.cloudapp.net",
[],
23,
- "address"
+ "address",
]
end
@@ -136,12 +140,12 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do
allow(WmiLite::Wmi).to receive(:new).and_return(success)
allow(success).to receive(:first_of).with("Win32_ComputerSystem").and_return(host)
allow(Socket).to receive(:gethostname).and_return("local")
- allow(Socket).to receive(:gethostbyname).with(anything()).and_return(info)
+ allow(Socket).to receive(:gethostbyname).with(anything).and_return(info)
end
context "when hostname is not set for the machine" do
it "should return short machine name" do
- allow(Socket).to receive(:gethostbyaddr).with(anything()).and_return(local_hostent)
+ allow(Socket).to receive(:gethostbyaddr).with(anything).and_return(local_hostent)
@plugin.run
expect(@plugin[:fqdn]).to eq("local")
end
@@ -149,7 +153,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do
context "when hostname is set for the machine" do
it "should return the fqdn of the machine" do
- allow(Socket).to receive(:gethostbyaddr).with(anything()).and_return(fqdn_hostent)
+ allow(Socket).to receive(:gethostbyaddr).with(anything).and_return(fqdn_hostent)
@plugin.run
expect(@plugin[:fqdn]).to eq("local.dx.internal.cloudapp.net")
end
diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb
index e3e7b380..a60e5879 100644
--- a/spec/unit/plugins/linux/filesystem_spec.rb
+++ b/spec/unit/plugins/linux/filesystem_spec.rb
@@ -410,6 +410,7 @@ describe Ohai::System, "Linux filesystem plugin" do
allow(@double_file).to receive(:read_nonblock) do
@counter += 1
raise EOFError if @counter == 2
+
@mounts
end
allow(@double_file).to receive(:close)
diff --git a/spec/unit/plugins/linux/lspci_spec.rb b/spec/unit/plugins/linux/lspci_spec.rb
index eaebf895..93cf0205 100644
--- a/spec/unit/plugins/linux/lspci_spec.rb
+++ b/spec/unit/plugins/linux/lspci_spec.rb
@@ -87,7 +87,8 @@ describe Ohai::System, "Linux lspci plugin" do
NUMANode: 0
LSPCI
allow(plugin).to receive(:shell_out).with("lspci -vnnmk").and_return(
- mock_shell_out(0, @stdout, ""))
+ mock_shell_out(0, @stdout, "")
+ )
end
describe "when gathering data from lspci" do
diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb
index 864e581e..da4290c3 100644
--- a/spec/unit/plugins/network_spec.rb
+++ b/spec/unit/plugins/network_spec.rb
@@ -421,8 +421,8 @@ describe Ohai::System, "Network Plugin" do
end
it "warns about this conflict" do
- expect(@plugin.logger).to receive(:trace).with(/\[inet\] no ipaddress\/mask on eth1/).once
- expect(@plugin.logger).to receive(:trace).with(/\[inet6\] no ipaddress\/mask on eth1/).once
+ expect(@plugin.logger).to receive(:trace).with(%r{\[inet\] no ipaddress/mask on eth1}).once
+ expect(@plugin.logger).to receive(:trace).with(%r{\[inet6\] no ipaddress/mask on eth1}).once
allow(@plugin.logger).to receive(:trace)
@plugin.run
end
@@ -822,6 +822,7 @@ describe Ohai::System, "Network Plugin" do
@plugin["network"]["default_interface"] = nil
@plugin["network"]["interfaces"].each do |i, iv|
next if i == "lo"
+
iv["addresses"].delete_if { |k, kv| kv["family"] == "inet" }
end
end
diff --git a/spec/unit/plugins/openstack_spec.rb b/spec/unit/plugins/openstack_spec.rb
index 988feb09..bda21a33 100644
--- a/spec/unit/plugins/openstack_spec.rb
+++ b/spec/unit/plugins/openstack_spec.rb
@@ -114,8 +114,8 @@ describe Ohai::System, "plugin openstack" do
it "overwrite timout by setting" do
allow(plugin).to receive(:can_socket_connect?)
- .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, override_timout)
- .and_return(false)
+ .with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, override_timout)
+ .and_return(false)
allow(plugin).to receive(:hint?).with("openstack").and_return(true)
plugin.run
end
diff --git a/spec/unit/plugins/ruby_spec.rb b/spec/unit/plugins/ruby_spec.rb
index df8c64d9..e402c5dd 100644
--- a/spec/unit/plugins/ruby_spec.rb
+++ b/spec/unit/plugins/ruby_spec.rb
@@ -48,7 +48,7 @@ describe Ohai::System, "plugin ruby" do
host_vendor: ::RbConfig::CONFIG["host_vendor"],
gems_dir: `#{ruby_bin} #{::RbConfig::CONFIG["bindir"]}/gem env gemdir`.chomp,
gem_bin: [ ::Gem.default_exec_format % "gem", "gem" ].map do |bin|
- "#{::RbConfig::CONFIG['bindir']}/#{bin}"
+ "#{::RbConfig::CONFIG["bindir"]}/#{bin}"
end.find { |bin| ::File.exist? bin },
ruby_bin: ruby_bin,
}.each do |attribute, value|
diff --git a/spec/unit/plugins/scsi_spec.rb b/spec/unit/plugins/scsi_spec.rb
index bc2b3a8c..a746fd74 100644
--- a/spec/unit/plugins/scsi_spec.rb
+++ b/spec/unit/plugins/scsi_spec.rb
@@ -31,7 +31,8 @@ describe Ohai::System, "lsscsi plugin" do
[6:2:4:0] disk LSI MR9286CV-8e 3.41 /dev/sdf
LSSCSI
allow(plugin).to receive(:shell_out).with("lsscsi").and_return(
- mock_shell_out(0, @stdout, ""))
+ mock_shell_out(0, @stdout, "")
+ )
plugin.run
end
diff --git a/spec/unit/plugins/shard_spec.rb b/spec/unit/plugins/shard_spec.rb
index 5516b352..8e1657f3 100644
--- a/spec/unit/plugins/shard_spec.rb
+++ b/spec/unit/plugins/shard_spec.rb
@@ -93,7 +93,7 @@ describe Ohai::System, "shard plugin" do
end
it "should allow os_serial source" do
- Ohai.config[:plugin][:shard_seed][:sources] = [:machinename, :os_serial, :uuid]
+ Ohai.config[:plugin][:shard_seed][:sources] = %i{machinename os_serial uuid}
# Different from above.
expect(subject).to eq(178738102)
end
diff --git a/spec/unit/plugins/windows/filesystem_spec.rb b/spec/unit/plugins/windows/filesystem_spec.rb
index eb04c513..e1f33b70 100644
--- a/spec/unit/plugins/windows/filesystem_spec.rb
+++ b/spec/unit/plugins/windows/filesystem_spec.rb
@@ -43,7 +43,7 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
"freespace" => "100000",
"name" => "D:",
# Lets not pass "volumename" for this drive
- }
+ },
]
end
@@ -56,7 +56,7 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
{
"conversionstatus" => 2,
"driveletter" => "D:",
- }
+ },
]
end
diff --git a/spec/unit/plugins/windows/kernel_spec.rb b/spec/unit/plugins/windows/kernel_spec.rb
index 16f5d452..d72c2eaa 100644
--- a/spec/unit/plugins/windows/kernel_spec.rb
+++ b/spec/unit/plugins/windows/kernel_spec.rb
@@ -34,7 +34,7 @@ describe Ohai::System, "Windows kernel plugin", :windows_only do
os_properties = [ caption, version, build_number, csd_version, os_type, product_type, operating_system_sku ]
os = double( "WIN32OLE",
- properties_: os_properties)
+ properties_: os_properties)
allow(os).to receive(:invoke).with(build_number.name).and_return("7601")
allow(os).to receive(:invoke).with(csd_version.name).and_return("Service Pack 1")
@@ -53,7 +53,7 @@ describe Ohai::System, "Windows kernel plugin", :windows_only do
cs_properties = [ system_type, pc_system_type, free_virtual_memory]
cs = double("WIN32OLE",
- properties_: cs_properties)
+ properties_: cs_properties)
allow(cs).to receive(:invoke).with(system_type.name).and_return("x64-based PC")
allow(cs).to receive(:invoke).with(pc_system_type.name).and_return(2)
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index f81c67e0..fc1508e7 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -37,9 +37,9 @@ describe "Ohai::System" do
it "merges provided configuration options into the ohai config context" do
config = {
- disabled_plugins: [ :Foo, :Baz ],
+ disabled_plugins: %i{Foo Baz},
directory: ["/some/extra/plugins"],
- critical_plugins: [ :Foo, :Bar ],
+ critical_plugins: %i{Foo Bar},
}
Ohai::System.new(config)
config.each do |option, value|
@@ -249,7 +249,7 @@ describe "Ohai::System" do
it "should fail when critical plugins fail" do
Ohai.config[:plugin_path] = [ path_to(".") ]
expect { ohai.all_plugins }.to raise_error(Ohai::Exceptions::CriticalPluginFailure,
- "The following Ohai plugins marked as critical failed: [:Fails]. Failing Chef run.")
+ "The following Ohai plugins marked as critical failed: [:Fails]. Failing Chef run.")
end
end