diff options
author | Thom May <thom@may.lt> | 2018-03-07 09:36:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-07 09:36:21 +0000 |
commit | 5be5fe42f0c6a5bec109e0136e0eb42fc975e202 (patch) | |
tree | 636e072786c5aa143ce3cd964da1548f5b1ea818 | |
parent | 3627eb769d3dd25098cf0cb34a4090c2e2e0b0df (diff) | |
parent | 011db28d6c3026ac41b9c519a87643d70ecf9be5 (diff) | |
download | ohai-5be5fe42f0c6a5bec109e0136e0eb42fc975e202.tar.gz |
Merge pull request #1153 from chef/green_travis
Fix chefstyle issues in ohai
60 files changed, 130 insertions, 133 deletions
diff --git a/.travis.yml b/.travis.yml index cfb46ca3..fcb2f338 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ before_install: - bundle --version - rm -f .bundle/config rvm: - - 2.4.2 + - 2.4.3 - 2.5.0 - ruby-head @@ -25,6 +25,7 @@ matrix: - rvm: ruby-head script: + - bundle exec chefstyle -v - bundle exec chefstyle - bundle exec rake spec - bundle exec ohai diff --git a/lib/ohai/config.rb b/lib/ohai/config.rb index 9c24a7bf..085bcb9b 100644 --- a/lib/ohai/config.rb +++ b/lib/ohai/config.rb @@ -33,7 +33,7 @@ module Ohai default :hints_path, [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ] default :log_level, :auto default :log_location, STDERR - default :plugin, Ohai::PluginConfig.new { |h, k| h[k] = Ohai::PluginConfig.new } + default :plugin, ( Ohai::PluginConfig.new { |h, k| h[k] = Ohai::PluginConfig.new } ) default :plugin_path, [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")), ChefConfig::Config.platform_specific_path("/etc/chef/ohai/plugins") ] default :critical_plugins, [] # causes all optional plugins to be run. diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb index 96867780..f08ba552 100644 --- a/lib/ohai/dsl/plugin.rb +++ b/lib/ohai/dsl/plugin.rb @@ -155,9 +155,9 @@ module Ohai # Will raise a TypeError if we hit a subattribute that is not a # Hash, Mash, or Array. keys = [name] + attrs - attribute = keys[0..-2].inject(@data) do |attrs, key| - attrs[key] ||= Mash.new - attrs[key] + attribute = keys[0..-2].inject(@data) do |atts, key| + atts[key] ||= Mash.new + atts[key] end # Set the subattribute to the value. diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index d4d78811..5b9bb27a 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -138,14 +138,14 @@ module Ohai end def load_v7_plugin_class(contents, plugin_path) - plugin_class = eval(contents, TOPLEVEL_BINDING, 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 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 - rescue SystemExit, Interrupt + rescue SystemExit, Interrupt # rubocop: disable Lint/ShadowedException raise rescue Ohai::Exceptions::InvalidPluginName => e Ohai::Log.warn("Plugin Name Error: <#{plugin_path}>: #{e.message}") diff --git a/lib/ohai/log.rb b/lib/ohai/log.rb index 832bf005..667caf3c 100644 --- a/lib/ohai/log.rb +++ b/lib/ohai/log.rb @@ -25,7 +25,7 @@ module Ohai # this class loading initalization is so that we don't lose early logger # messages when run from the CLI? init(STDERR) - level = :info + level = :info # rubocop:disable Lint/UselessAssignment end end diff --git a/lib/ohai/mixin/azure_metadata.rb b/lib/ohai/mixin/azure_metadata.rb index 115477d2..90304e54 100644 --- a/lib/ohai/mixin/azure_metadata.rb +++ b/lib/ohai/mixin/azure_metadata.rb @@ -28,7 +28,7 @@ module Ohai def http_get(uri) conn = Net::HTTP.start(AZURE_METADATA_ADDR) conn.read_timeout = 6 - conn.get(uri, initheader = { "Metadata" => "true" }) + conn.get(uri, { "Metadata" => "true" }) end def fetch_metadata diff --git a/lib/ohai/mixin/gce_metadata.rb b/lib/ohai/mixin/gce_metadata.rb index 10e78ae2..7457e735 100644 --- a/lib/ohai/mixin/gce_metadata.rb +++ b/lib/ohai/mixin/gce_metadata.rb @@ -28,7 +28,7 @@ module Ohai def http_get(uri) conn = Net::HTTP.start(GCE_METADATA_ADDR) conn.read_timeout = 6 - conn.get(uri, initheader = { "Metadata-Flavor" => "Google" }) + conn.get(uri, { "Metadata-Flavor" => "Google" }) end def fetch_metadata(id = "") diff --git a/lib/ohai/mixin/http_helper.rb b/lib/ohai/mixin/http_helper.rb index f9c83fa1..c79e6213 100644 --- a/lib/ohai/mixin/http_helper.rb +++ b/lib/ohai/mixin/http_helper.rb @@ -34,7 +34,7 @@ module Ohai begin t.connect_nonblock(saddr) rescue Errno::EINPROGRESS - r, w, e = IO.select(nil, [t], nil, timeout) + _r, w, _e = IO.select(nil, [t], nil, timeout) if !w.nil? connected = true else diff --git a/lib/ohai/mixin/softlayer_metadata.rb b/lib/ohai/mixin/softlayer_metadata.rb index b887fb3d..dfa16ba8 100644 --- a/lib/ohai/mixin/softlayer_metadata.rb +++ b/lib/ohai/mixin/softlayer_metadata.rb @@ -25,7 +25,7 @@ module ::Ohai::Mixin::SoftlayerMetadata SOFTLAYER_API_QUERY_URL = "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata" unless defined?(SOFTLAYER_API_QUERY_URL) def fetch_metadata - metadata = { + { "public_fqdn" => fetch_metadata_item("getFullyQualifiedDomainName.txt"), "local_ipv4" => fetch_metadata_item("getPrimaryBackendIpAddress.txt"), "public_ipv4" => fetch_metadata_item("getPrimaryIpAddress.txt"), diff --git a/lib/ohai/plugins/aix/memory.rb b/lib/ohai/plugins/aix/memory.rb index 40630110..fa90b7ce 100644 --- a/lib/ohai/plugins/aix/memory.rb +++ b/lib/ohai/plugins/aix/memory.rb @@ -25,7 +25,7 @@ Ohai.plugin(:Memory) do memory[:swap] = Mash.new meminfo = shell_out("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'").stdout - total_in_mb, u, free_in_mb = meminfo.split + total_in_mb, _u, free_in_mb = meminfo.split memory[:total] = "#{total_in_mb.to_i * 1024}kB" memory[:free] = "#{free_in_mb.to_i * 1024}kB" diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb index 292b45c6..561523ff 100644 --- a/lib/ohai/plugins/aix/network.rb +++ b/lib/ohai/plugins/aix/network.rb @@ -114,8 +114,8 @@ Ohai.plugin(:Network) do # Query macaddress e_so = shell_out("entstat -d #{interface} | grep \"Hardware Address\"") iface[interface][:addresses] = Mash.new unless iface[interface][:addresses] - e_so.stdout.lines.each do |line| - if line =~ /Hardware Address: (\S+)/ + e_so.stdout.lines.each do |l| + if l =~ /Hardware Address: (\S+)/ iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" } macaddress $1.upcase unless shell_out("uname -W").stdout.to_i > 0 end diff --git a/lib/ohai/plugins/aix/virtualization.rb b/lib/ohai/plugins/aix/virtualization.rb index 9271323a..d79fc252 100644 --- a/lib/ohai/plugins/aix/virtualization.rb +++ b/lib/ohai/plugins/aix/virtualization.rb @@ -140,7 +140,7 @@ Ohai.plugin(:Virtualization) do breadcrumb.each do |node| evalstr << "[\'#{node}\']" end - wpars[wpar_name][breadcrumb[-1]] = eval evalstr + wpars[wpar_name][breadcrumb[-1]] = eval evalstr # rubocop: disable Security/Eval end end virtualization[:wpars] = wpars unless wpars.empty? diff --git a/lib/ohai/plugins/darwin/hardware.rb b/lib/ohai/plugins/darwin/hardware.rb index c9c4bab0..d6689f7c 100644 --- a/lib/ohai/plugins/darwin/hardware.rb +++ b/lib/ohai/plugins/darwin/hardware.rb @@ -23,7 +23,7 @@ Ohai.plugin(:Hardware) do sp_cmd = "system_profiler #{datatype} -xml" # Hardware queries sp_std = shell_out(sp_cmd) - sp_hash = Plist.parse_xml(sp_std.stdout) + Plist.parse_xml(sp_std.stdout) end collect_data(:darwin) do diff --git a/lib/ohai/plugins/darwin/network.rb b/lib/ohai/plugins/darwin/network.rb index 780b1da7..5bf1398c 100644 --- a/lib/ohai/plugins/darwin/network.rb +++ b/lib/ohai/plugins/darwin/network.rb @@ -74,8 +74,8 @@ Ohai.plugin(:Network) do return ifname unless ifaces[ifname].nil? # oh well, time to go hunting! return ifname.chop if ifname =~ /\*$/ - ifaces.keys.each do |ifc| - ifaces[ifc][:addresses].keys.each do |addr| + ifaces.each_key do |ifc| + ifaces[ifc][:addresses].each_key do |addr| return ifc if addr.eql? mac end end diff --git a/lib/ohai/plugins/darwin/system_profiler.rb b/lib/ohai/plugins/darwin/system_profiler.rb index 20798cc4..6fe375c1 100644 --- a/lib/ohai/plugins/darwin/system_profiler.rb +++ b/lib/ohai/plugins/darwin/system_profiler.rb @@ -64,7 +64,7 @@ SPAirPortData}, end end - system_profile items.sort_by { |h| h["_dataType"] } + system_profile ( items.sort_by { |h| h["_dataType"] } ) # rubocop: disable Lint/ParenthesesAsGroupedExpression rescue LoadError => e Ohai::Log.debug("Can't load gem: #{e})") end diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb index ed7ae9f2..3ff982cf 100644 --- a/lib/ohai/plugins/dmi.rb +++ b/lib/ohai/plugins/dmi.rb @@ -60,21 +60,21 @@ Ohai.plugin(:DMI) do next if blank_line.match(line) line = line.encode(line.encoding, :universal_newline => true) - if dmidecode_version = dmidecode_version_line.match(line) + if ( dmidecode_version = dmidecode_version_line.match(line) ) dmi[:dmidecode_version] = dmidecode_version[1] - elsif smbios_version = smbios_version_line.match(line) + elsif ( smbios_version = smbios_version_line.match(line) ) dmi[:smbios_version] = smbios_version[1] - elsif structures = structures_line.match(line) + elsif ( structures = structures_line.match(line) ) dmi[:structures] = Mash.new dmi[:structures][:count] = structures[1] dmi[:structures][:size] = structures[2] - elsif table_location = table_location_line.match(line) + elsif ( table_location = table_location_line.match(line) ) dmi[:table_location] = table_location[1] - elsif handle = handle_line.match(line) + elsif ( handle = handle_line.match(line) ) # Don't overcapture for now (OHAI-260) unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i) dmi_record = nil @@ -91,14 +91,14 @@ Ohai.plugin(:DMI) do dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = handle[2] field = nil - elsif type = type_line.match(line) + elsif ( type = type_line.match(line) ) if dmi_record .nil? Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1] - elsif data = data_line.match(line) + elsif ( data = data_line.match(line) ) if dmi_record .nil? Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next @@ -106,7 +106,7 @@ Ohai.plugin(:DMI) do dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] field = data[1] - elsif extended_data = extended_data_line.match(line) + elsif ( extended_data = extended_data_line.match(line) ) if dmi_record .nil? Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}") next diff --git a/lib/ohai/plugins/eucalyptus.rb b/lib/ohai/plugins/eucalyptus.rb index 8c5b4c21..35e7aae4 100644 --- a/lib/ohai/plugins/eucalyptus.rb +++ b/lib/ohai/plugins/eucalyptus.rb @@ -40,7 +40,7 @@ Ohai.plugin(:Eucalyptus) do # detect if the mac address starts with d0:0d def has_euca_mac? - network[:interfaces].values.each do |iface| + network[:interfaces].each_value do |iface| mac = get_mac_address(iface[:addresses]) if mac =~ /^[dD]0:0[dD]:/ Ohai::Log.debug("Plugin Eucalyptus: has_euca_mac? == true (#{mac})") diff --git a/lib/ohai/plugins/init_package.rb b/lib/ohai/plugins/init_package.rb index 1bf54ce1..e3162cf0 100644 --- a/lib/ohai/plugins/init_package.rb +++ b/lib/ohai/plugins/init_package.rb @@ -20,6 +20,6 @@ Ohai.plugin(:InitPackage) do provides "init_package" collect_data(:linux) do - init_package File.exists?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : "init" + init_package File.exist?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : "init" end end diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb index 4e85bdf4..95d38d4d 100644 --- a/lib/ohai/plugins/kernel.rb +++ b/lib/ohai/plugins/kernel.rb @@ -238,7 +238,7 @@ Ohai.plugin(:Kernel) do # 6 1180000 4623 1 1 specfs (filesystem for specfs) module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/ so.stdout.lines do |line| - if mod = module_description.match(line) + if ( mod = module_description.match(line) ) modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5] } end end diff --git a/lib/ohai/plugins/linode.rb b/lib/ohai/plugins/linode.rb index c096f228..fcf8e4b1 100644 --- a/lib/ohai/plugins/linode.rb +++ b/lib/ohai/plugins/linode.rb @@ -24,7 +24,7 @@ Ohai.plugin(:Linode) do # # Returns true or false def has_linode_kernel? - if kernel_data = kernel + if ( kernel_data = kernel ) kernel_data[:release].split("-").last =~ /linode/ end end @@ -43,7 +43,7 @@ Ohai.plugin(:Linode) do # # Alters linode mash with new interface based on name parameter def get_ip_address(name, eth) - if eth_iface = network[:interfaces][eth] + if ( eth_iface = network[:interfaces][eth] ) eth_iface[:addresses].each do |key, info| linode[name] = key if info["family"] == "inet" end diff --git a/lib/ohai/plugins/linux/block_device.rb b/lib/ohai/plugins/linux/block_device.rb index 709d03e4..e0133189 100644 --- a/lib/ohai/plugins/linux/block_device.rb +++ b/lib/ohai/plugins/linux/block_device.rb @@ -20,23 +20,23 @@ Ohai.plugin(:BlockDevice) do provides "block_device" collect_data(:linux) do - if File.exists?("/sys/block") + if File.exist?("/sys/block") block = Mash.new Dir["/sys/block/*"].each do |block_device_dir| dir = File.basename(block_device_dir) block[dir] = Mash.new %w{size removable}.each do |check| - if File.exists?("/sys/block/#{dir}/#{check}") + if File.exist?("/sys/block/#{dir}/#{check}") File.open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip } end end %w{model rev state timeout vendor queue_depth}.each do |check| - if File.exists?("/sys/block/#{dir}/device/#{check}") + if File.exist?("/sys/block/#{dir}/device/#{check}") File.open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip } end end %w{rotational physical_block_size logical_block_size}.each do |check| - if File.exists?("/sys/block/#{dir}/queue/#{check}") + if File.exist?("/sys/block/#{dir}/queue/#{check}") File.open("/sys/block/#{dir}/queue/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip } end end diff --git a/lib/ohai/plugins/linux/filesystem.rb b/lib/ohai/plugins/linux/filesystem.rb index d25108f6..4ed8ede0 100644 --- a/lib/ohai/plugins/linux/filesystem.rb +++ b/lib/ohai/plugins/linux/filesystem.rb @@ -196,10 +196,10 @@ Ohai.plugin(:Filesystem) do keys_to_update << key end - keys_to_update.each do |key| + keys_to_update.each do |k| [:fs_type, :uuid, :label].each do |subkey| if parsed[subkey] && !parsed[subkey].empty? - fs[key][subkey] = parsed[subkey] + fs[k][subkey] = parsed[subkey] end end end diff --git a/lib/ohai/plugins/linux/lsb.rb b/lib/ohai/plugins/linux/lsb.rb index 018ef1ec..cee56f29 100644 --- a/lib/ohai/plugins/linux/lsb.rb +++ b/lib/ohai/plugins/linux/lsb.rb @@ -22,7 +22,7 @@ Ohai.plugin(:LSB) do collect_data(:linux) do lsb Mash.new - if File.exists?("/usr/bin/lsb_release") + if File.exist?("/usr/bin/lsb_release") # From package redhat-lsb on Fedora/Redhat, lsb-release on Debian/Ubuntu so = shell_out("lsb_release -a") so.stdout.lines do |line| @@ -39,7 +39,7 @@ Ohai.plugin(:LSB) do lsb[:id] = line end end - elsif File.exists?("/etc/lsb-release") + elsif File.exist?("/etc/lsb-release") # Old, non-standard Debian support File.open("/etc/lsb-release").each do |line| case line diff --git a/lib/ohai/plugins/linux/lspci.rb b/lib/ohai/plugins/linux/lspci.rb index fa03747e..d9413a21 100644 --- a/lib/ohai/plugins/linux/lspci.rb +++ b/lib/ohai/plugins/linux/lspci.rb @@ -51,7 +51,7 @@ Ohai.plugin(:Lspci) do next if dev.nil? case dev[0] when "Device" # There are two different Device tags - if tmp = dev[1].match(/(#{hh}:#{hh}.#{h})/) + if ( tmp = dev[1].match(/(#{hh}:#{hh}.#{h})/) ) # We have a device id d_id = tmp[0] # From now on we will need this id devices[d_id] = Mash.new diff --git a/lib/ohai/plugins/linux/machineid.rb b/lib/ohai/plugins/linux/machineid.rb index b946c418..56b22227 100644 --- a/lib/ohai/plugins/linux/machineid.rb +++ b/lib/ohai/plugins/linux/machineid.rb @@ -22,10 +22,10 @@ Ohai.plugin(:Machineid) do collect_data(:linux) do mid = nil - if File.exists?("/etc/machine-id") - mid = File.read("/etc/machine-id").chomp - elsif File.exists?("/var/lib/dbus/machine-id") - mid = File.read("/var/lib/dbus/machine-id").chomp + if ::File.exist?("/etc/machine-id") + mid = ::File.read("/etc/machine-id").chomp + elsif ::File.exist?("/var/lib/dbus/machine-id") + mid = ::File.read("/var/lib/dbus/machine-id").chomp end if mid diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb index f232ecae..3a53bf53 100644 --- a/lib/ohai/plugins/network.rb +++ b/lib/ohai/plugins/network.rb @@ -120,7 +120,7 @@ Ohai.plugin(:NetworkAddresses) do # ipaddress: IPAddress # iface: String def network_contains_address(address_to_match, ipaddress, iface) - if peer = network["interfaces"][iface]["addresses"][ipaddress.to_s][:peer] + if ( peer = network["interfaces"][iface]["addresses"][ipaddress.to_s][:peer] ) IPAddress(peer) == IPAddress(address_to_match) else ipaddress.include? IPAddress(address_to_match) diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb index 91945141..e169818a 100644 --- a/lib/ohai/plugins/packages.rb +++ b/lib/ohai/plugins/packages.rb @@ -165,7 +165,7 @@ Ohai.plugin(:Packages) do chunked_lines = so.stdout.lines.map(&:strip).chunk do |line| !line.empty? || nil end - chunked_lines.each do |_, lines| + chunked_lines.each do |_, lines| # rubocop: disable Performance/HashEachMethods package = {} lines.each do |line| key, value = line.split(":", 2) diff --git a/lib/ohai/plugins/ruby.rb b/lib/ohai/plugins/ruby.rb index 8a036031..8020c328 100644 --- a/lib/ohai/plugins/ruby.rb +++ b/lib/ohai/plugins/ruby.rb @@ -47,7 +47,7 @@ Ohai.plugin(:Ruby) do # Create a query string from above hash env_string = "" - values.keys.each do |v| + values.each_key do |v| env_string << "#{v}=\#{#{values[v]}}," end @@ -67,7 +67,7 @@ Ohai.plugin(:Ruby) do run_ruby("require 'rubygems'; puts ::Gem.default_exec_format % 'gem'"), "gem", ].map { |bin| ::File.join(bin_dir, bin) } - gem_binary = gem_binaries.find { |bin| ::File.exists? bin } + gem_binary = gem_binaries.find { |bin| ::File.exist? bin } if gem_binary languages[:ruby][:gems_dir] = run_ruby "puts %x{#{ruby_bin} #{gem_binary} env gemdir}.chomp!" languages[:ruby][:gem_bin] = gem_binary diff --git a/lib/ohai/plugins/solaris2/cpu.rb b/lib/ohai/plugins/solaris2/cpu.rb index 52b8941e..39dccc42 100644 --- a/lib/ohai/plugins/solaris2/cpu.rb +++ b/lib/ohai/plugins/solaris2/cpu.rb @@ -31,7 +31,7 @@ Ohai.plugin(:CPU) do cpucores = Array.new cpusockets = Array.new processor_info.each_with_index do |processor, i| - desc, instance, record, keyvalue = processor.split(":") + _desc, instance, _record, keyvalue = processor.split(":") cpu[instance] ||= Mash.new if currentcpu != instance cpu["total"] += 1 diff --git a/lib/ohai/plugins/solaris2/dmi.rb b/lib/ohai/plugins/solaris2/dmi.rb index d2aa35a4..793fb5f1 100644 --- a/lib/ohai/plugins/solaris2/dmi.rb +++ b/lib/ohai/plugins/solaris2/dmi.rb @@ -121,7 +121,7 @@ Ohai.plugin(:DMI) do Ohai::Log.debug("Plugin DMI: converted characters from line:\n#{raw_line}") end - if header_information = header_information_line.match(line) + if ( header_information = header_information_line.match(line) ) dmi_record = {} # look up SMB ID @@ -151,7 +151,7 @@ Ohai.plugin(:DMI) do dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = header_information[4] field = nil - elsif data = data_key_value_line.match(line) + elsif ( data = data_key_value_line.match(line) ) if dmi_record.nil? Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next @@ -159,7 +159,7 @@ Ohai.plugin(:DMI) do dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] field = data[1] - elsif data = data_key_only_line.match(line) + elsif ( data = data_key_only_line.match(line) ) if dmi_record.nil? Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next @@ -167,7 +167,7 @@ Ohai.plugin(:DMI) do dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = "" field = data[1] - elsif extended_data = extended_data_line.match(line) + elsif ( extended_data = extended_data_line.match(line) ) if dmi_record.nil? Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}") next diff --git a/lib/ohai/plugins/solaris2/network.rb b/lib/ohai/plugins/solaris2/network.rb index 93231bac..65c041bb 100644 --- a/lib/ohai/plugins/solaris2/network.rb +++ b/lib/ohai/plugins/solaris2/network.rb @@ -74,7 +74,7 @@ Ohai.plugin(:Network) do end def arpname_to_ifname(iface, arpname) - iface.keys.each do |ifn| + iface.each_key do |ifn| return ifn if ifn.split(":")[0].eql?(arpname) end @@ -146,17 +146,17 @@ Ohai.plugin(:Network) do end end - iface.keys.each do |ifn| + iface.each_key do |ifn| iaddr = nil if iface[ifn][:encapsulation].eql?("Ethernet") - iface[ifn][:addresses].keys.each do |addr| + iface[ifn][:addresses].each_key do |addr| if iface[ifn][:addresses][addr]["family"].eql?("inet") iaddr = addr break end end if iface[ifn][:arp] - iface[ifn][:arp].keys.each do |addr| + iface[ifn][:arp].each_key do |addr| if addr.eql?(iaddr) iface[ifn][:addresses][iface[ifn][:arp][iaddr]] = { "family" => "lladdr" } break diff --git a/lib/ohai/plugins/solaris2/platform.rb b/lib/ohai/plugins/solaris2/platform.rb index 9aa88fb9..90cd0338 100644 --- a/lib/ohai/plugins/solaris2/platform.rb +++ b/lib/ohai/plugins/solaris2/platform.rb @@ -20,7 +20,7 @@ Ohai.plugin(:Platform) do provides "platform", "platform_version", "platform_build", "platform_family" collect_data(:solaris2) do - if File.exists?("/sbin/uname") + if File.exist?("/sbin/uname") uname_exec = "/sbin/uname" else uname_exec = "uname" @@ -37,7 +37,7 @@ Ohai.plugin(:Platform) do end File.open("/etc/release") do |file| - while line = file.gets + while ( line = file.gets ) case line when /^.*(SmartOS).*$/ platform "smartos" diff --git a/lib/ohai/plugins/ssh_host_key.rb b/lib/ohai/plugins/ssh_host_key.rb index 44b9b44c..78c67f5f 100644 --- a/lib/ohai/plugins/ssh_host_key.rb +++ b/lib/ohai/plugins/ssh_host_key.rb @@ -38,9 +38,9 @@ Ohai.plugin(:SSHHostKey) do collect_data do keys[:ssh] = Mash.new - sshd_config = if File.exists?("/etc/ssh/sshd_config") + sshd_config = if File.exist?("/etc/ssh/sshd_config") "/etc/ssh/sshd_config" - elsif File.exists?("/etc/sshd_config") + elsif File.exist?("/etc/sshd_config") # Darwin "/etc/sshd_config" else @@ -62,21 +62,21 @@ Ohai.plugin(:SSHHostKey) do end end - if keys[:ssh][:host_dsa_public].nil? && File.exists?("/etc/ssh/ssh_host_dsa_key.pub") + if keys[:ssh][:host_dsa_public].nil? && File.exist?("/etc/ssh/ssh_host_dsa_key.pub") keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1] end - if keys[:ssh][:host_rsa_public].nil? && File.exists?("/etc/ssh/ssh_host_rsa_key.pub") + if keys[:ssh][:host_rsa_public].nil? && File.exist?("/etc/ssh/ssh_host_rsa_key.pub") keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1] end - if keys[:ssh][:host_ecdsa_public].nil? && File.exists?("/etc/ssh/ssh_host_ecdsa_key.pub") + if keys[:ssh][:host_ecdsa_public].nil? && File.exist?("/etc/ssh/ssh_host_ecdsa_key.pub") content = IO.read("/etc/ssh/ssh_host_ecdsa_key.pub") keys[:ssh][:host_ecdsa_public] = content.split[1] keys[:ssh][:host_ecdsa_type] = content.split[0] end - if keys[:ssh][:host_ed25519_public].nil? && File.exists?("/etc/ssh/ssh_host_ed25519_key.pub") + if keys[:ssh][:host_ed25519_public].nil? && File.exist?("/etc/ssh/ssh_host_ed25519_key.pub") keys[:ssh][:host_ed25519_public] = IO.read("/etc/ssh/ssh_host_ed25519_key.pub").split[1] end end diff --git a/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb index 9a80ec88..ddfdc74d 100644 --- a/lib/ohai/plugins/windows/network.rb +++ b/lib/ohai/plugins/windows/network.rb @@ -87,7 +87,7 @@ Ohai.plugin(:Network) do end end - iface_instance.keys.each do |i| + iface_instance.each_key do |i| if iface_instance[i][:name] && iface_config[i] && iface_config[i][:ip_address][0] cint = sprintf("0x%x", (iface_instance[i][:interface_index] || iface_instance[i][:index]) ).downcase iface[cint] = Mash.new diff --git a/lib/ohai/plugins/zpools.rb b/lib/ohai/plugins/zpools.rb index 7e518663..5a216f76 100644 --- a/lib/ohai/plugins/zpools.rb +++ b/lib/ohai/plugins/zpools.rb @@ -51,7 +51,7 @@ Ohai.plugin(:Zpools) do pools = gather_pool_info # Grab individual health for devices in the zpools - pools.keys.each do |pool| + pools.each_key do |pool| pools[pool][:devices] = Mash.new # Run "zpool status" as non-root user (adm) so that diff --git a/lib/ohai/provides_map.rb b/lib/ohai/provides_map.rb index f9ba0518..0aba1939 100644 --- a/lib/ohai/provides_map.rb +++ b/lib/ohai/provides_map.rb @@ -171,7 +171,7 @@ module Ohai # map, it will find all of the plugins that have at least one provided # attribute. def collect_plugins_in(provides_map, collected) - provides_map.keys.each do |plugin| + provides_map.each_key do |plugin| if plugin.eql?("_plugins") collected.concat(provides_map[plugin]) else diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb index 6f623d38..c482dc9c 100644 --- a/lib/ohai/runner.rb +++ b/lib/ohai/runner.rb @@ -47,7 +47,7 @@ module Ohai else raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}" end - rescue Ohai::Exceptions::Error + rescue Ohai::Exceptions::Error # rubocop: disable Lint/ShadowedException raise rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code raise diff --git a/lib/ohai/util/win32/group_helper.rb b/lib/ohai/util/win32/group_helper.rb index 68134d4f..3c254b49 100644 --- a/lib/ohai/util/win32/group_helper.rb +++ b/lib/ohai/util/win32/group_helper.rb @@ -29,8 +29,6 @@ module Ohai BUILTIN_ADMINISTRATORS_SID = "S-1-5-32-544" def self.windows_root_group_name - administrators_group_name_result = nil - administrators_sid_result = FFI::MemoryPointer.new(:pointer) convert_result = Win32.convert_string_sid_to_sid(BUILTIN_ADMINISTRATORS_SID, administrators_sid_result) last_win32_error = Win32.get_last_error diff --git a/spec/functional/plugins/root_group_spec.rb b/spec/functional/plugins/root_group_spec.rb index 153f0c09..6bf05f2f 100644 --- a/spec/functional/plugins/root_group_spec.rb +++ b/spec/functional/plugins/root_group_spec.rb @@ -24,9 +24,9 @@ describe Ohai::System, "root_group plugin" do let(:plugin) { get_plugin("root_group") } describe "windows platform", :windows_only do - let (:wmi) { wmi = WmiLite::Wmi.new } + let(:wmi) { WmiLite::Wmi.new } - it 'should return the system\'s administrators (root) group' do + it "should return the system's administrators (root) group" do # Notethat the Win32_Group WMI provider can be slow if your # system is domain-joined and has hundreds of thousands of # groups in Active Directory -- not a typical test scenario, but diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb index 5000b112..c0ee6cf5 100644 --- a/spec/unit/dsl/plugin_spec.rb +++ b/spec/unit/dsl/plugin_spec.rb @@ -435,13 +435,13 @@ describe Ohai::DSL::Plugin::VersionVII do end it "collects attributes across multiple plugin files" do - plugin = Ohai.plugin(:Test) { provides("one") } + plugin = Ohai.plugin(:Test) { provides("one") } # rubocop: disable Lint/UselessAssignment plugin = Ohai.plugin(:Test) { provides("two", "three") } expect(plugin.provides_attrs).to eql(%w{one two three}) end it "collects unique attributes" do - plugin = Ohai.plugin(:Test) { provides("one") } + plugin = Ohai.plugin(:Test) { provides("one") } # rubocop: disable Lint/UselessAssignment plugin = Ohai.plugin(:Test) { provides("one", "two") } expect(plugin.provides_attrs).to eql(%w{one two}) end @@ -468,13 +468,13 @@ describe Ohai::DSL::Plugin::VersionVII do end it "collects dependencies across multiple plugin files" do - plugin = Ohai.plugin(:Test) { depends("one") } + plugin = Ohai.plugin(:Test) { depends("one") } # rubocop: disable Lint/UselessAssignment plugin = Ohai.plugin(:Test) { depends("two", "three") } expect(plugin.depends_attrs).to eql(%w{one two three}) end it "collects unique attributes" do - plugin = Ohai.plugin(:Test) { depends("one") } + plugin = Ohai.plugin(:Test) { depends("one") } # rubocop: disable Lint/UselessAssignment plugin = Ohai.plugin(:Test) { depends("one", "two") } expect(plugin.depends_attrs).to eql(%w{one two}) end diff --git a/spec/unit/mixin/azure_metadata_spec.rb b/spec/unit/mixin/azure_metadata_spec.rb index e7414120..8d0f9443 100644 --- a/spec/unit/mixin/azure_metadata_spec.rb +++ b/spec/unit/mixin/azure_metadata_spec.rb @@ -31,7 +31,7 @@ describe Ohai::Mixin::AzureMetadata do allow(http_mock).to receive(:read_timeout=) allow(Net::HTTP).to receive(:start).with("169.254.169.254").and_return(http_mock) - expect(http_mock).to receive(:get).with("http://www.chef.io", initheader = { "Metadata" => "true" }) + expect(http_mock).to receive(:get).with("http://www.chef.io", { "Metadata" => "true" }) mixin.http_get("http://www.chef.io") end end diff --git a/spec/unit/plugins/aix/network_spec.rb b/spec/unit/plugins/aix/network_spec.rb index 5890c6d1..c3f675eb 100644 --- a/spec/unit/plugins/aix/network_spec.rb +++ b/spec/unit/plugins/aix/network_spec.rb @@ -113,7 +113,7 @@ ARP_AN @plugin.run end - it 'for \'macaddress\'' do + it "for 'macaddress'" do expect(@plugin[:macaddress]).to eq("BE:42:80:00:B0:05") end end diff --git a/spec/unit/plugins/aix/virtualization_spec.rb b/spec/unit/plugins/aix/virtualization_spec.rb index 37c9c595..6e8fda7c 100644 --- a/spec/unit/plugins/aix/virtualization_spec.rb +++ b/spec/unit/plugins/aix/virtualization_spec.rb @@ -272,12 +272,12 @@ LSWPAR_L end context "when collecting WPAR info" do - it 'finds the WPAR\'s hostname correctly' do + it "finds the WPAR's hostname correctly" do expect(wpar1[:hostname]).to eq("applejack-pony-541ba3.ponyville.com") expect(wpar2[:hostname]).to eq("fluttershy-pony-5c969f.ponyville.com") end - it 'finds the WPAR\'s IP correctly' do + it "finds the WPAR's IP correctly" do expect(wpar1[:address]).to eq("192.168.0.231") expect(wpar2[:address]).to eq("192.168.0.18") end @@ -289,7 +289,7 @@ LSWPAR_L end end - context 'when WPARs don\'t exist on the LPAR' do + context "when WPARs don't exist on the LPAR" do before do allow(plugin).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, "", nil)) plugin.run diff --git a/spec/unit/plugins/darwin/filesystem_spec.rb b/spec/unit/plugins/darwin/filesystem_spec.rb index 87b0f620..63889dc0 100644 --- a/spec/unit/plugins/darwin/filesystem_spec.rb +++ b/spec/unit/plugins/darwin/filesystem_spec.rb @@ -19,7 +19,7 @@ require_relative "../../../spec_helper.rb" describe Ohai::System, "darwin filesystem plugin" do - let (:plugin) { get_plugin("darwin/filesystem") } + let(:plugin) { get_plugin("darwin/filesystem") } before(:each) do allow(plugin).to receive(:collect_os).and_return(:darwin) diff --git a/spec/unit/plugins/darwin/hardware_spec.rb b/spec/unit/plugins/darwin/hardware_spec.rb index f8c8e1d5..5c456f19 100644 --- a/spec/unit/plugins/darwin/hardware_spec.rb +++ b/spec/unit/plugins/darwin/hardware_spec.rb @@ -20,7 +20,7 @@ require_relative "../../../spec_helper.rb" require_relative "hardware_system_profiler_output.rb" describe Ohai::System, "Darwin hardware plugin", :unix_only do - let (:plugin) { get_plugin("darwin/hardware") } + let(:plugin) { get_plugin("darwin/hardware") } before(:each) do allow(plugin).to receive(:collect_os).and_return(:darwin) # Make sure it always runs correct commands and mock the data as it calls them diff --git a/spec/unit/plugins/haskell_spec.rb b/spec/unit/plugins/haskell_spec.rb index a20b125e..e68aaf76 100644 --- a/spec/unit/plugins/haskell_spec.rb +++ b/spec/unit/plugins/haskell_spec.rb @@ -19,7 +19,7 @@ require_relative "../../spec_helper.rb" describe Ohai::System, "plugin haskell" do let(:plugin) do - plugin = get_plugin("haskell").tap do |plugin| + get_plugin("haskell").tap do |plugin| plugin[:languages] = Mash.new end end diff --git a/spec/unit/plugins/init_package_spec.rb b/spec/unit/plugins/init_package_spec.rb index 7966963d..58966307 100644 --- a/spec/unit/plugins/init_package_spec.rb +++ b/spec/unit/plugins/init_package_spec.rb @@ -31,7 +31,7 @@ describe Ohai::System, "Init package" do let(:proc_1_file) { double(proc_1_file_path, :gets => proc1_content) } before(:each) do - allow(File).to receive(:exists?).with(proc_1_file_path).and_return(proc1_exists) + allow(File).to receive(:exist?).with(proc_1_file_path).and_return(proc1_exists) allow(File).to receive(:open).with(proc_1_file_path).and_return(proc_1_file) end diff --git a/spec/unit/plugins/linux/block_device_spec.rb b/spec/unit/plugins/linux/block_device_spec.rb index bbad8b59..57d2929f 100644 --- a/spec/unit/plugins/linux/block_device_spec.rb +++ b/spec/unit/plugins/linux/block_device_spec.rb @@ -45,7 +45,7 @@ describe Ohai::System, "Linux Block Device Plugin" do @plugin = get_plugin("linux/block_device") allow(@plugin).to receive(:collect_os).and_return(:linux) - allow(File).to receive(:exists?).with("/sys/block").and_return(true) + allow(File).to receive(:exist?).with("/sys/block").and_return(true) allow(Dir).to receive(:[]).with("/sys/block/*") do DISKS.collect { |disk, _files| "/sys/block/#{disk}" } end @@ -55,7 +55,7 @@ describe Ohai::System, "Linux Block Device Plugin" do allow(File).to receive(:open).with(Regexp.new("#{disk}.*#{check}")).and_yield(file_double(value)) end - allow(File).to receive(:exists?).with(Regexp.new(disk)) do |arg| + allow(File).to receive(:exist?).with(Regexp.new(disk)) do |arg| filepath = arg.split("/") checks[filepath.last].nil? ? false : true end diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb index 3f9b4336..6b29bd7d 100644 --- a/spec/unit/plugins/linux/filesystem_spec.rb +++ b/spec/unit/plugins/linux/filesystem_spec.rb @@ -19,7 +19,7 @@ require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux filesystem plugin" do - let (:plugin) { get_plugin("linux/filesystem") } + let(:plugin) { get_plugin("linux/filesystem") } before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) diff --git a/spec/unit/plugins/linux/lsb_spec.rb b/spec/unit/plugins/linux/lsb_spec.rb index ab976d4b..b5ab74a4 100644 --- a/spec/unit/plugins/linux/lsb_spec.rb +++ b/spec/unit/plugins/linux/lsb_spec.rb @@ -35,8 +35,8 @@ describe Ohai::System, "Linux lsb plugin" do and_yield("DISTRIB_CODENAME=hardy"). and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"') allow(File).to receive(:open).with("/etc/lsb-release").and_return(@double_file) - allow(File).to receive(:exists?).with("/usr/bin/lsb_release").and_return(false) - allow(File).to receive(:exists?).with("/etc/lsb-release").and_return(true) + allow(File).to receive(:exist?).with("/usr/bin/lsb_release").and_return(false) + allow(File).to receive(:exist?).with("/etc/lsb-release").and_return(true) end it "should set lsb[:id]" do @@ -62,7 +62,7 @@ describe Ohai::System, "Linux lsb plugin" do describe "on systems with /usr/bin/lsb_release" do before(:each) do - allow(File).to receive(:exists?).with("/usr/bin/lsb_release").and_return(true) + allow(File).to receive(:exist?).with("/usr/bin/lsb_release").and_return(true) @stdin = double("STDIN", { :close => true }) @pid = 10 @@ -140,8 +140,8 @@ LSB_RELEASE end it "should not set any lsb values if /etc/lsb-release or /usr/bin/lsb_release do not exist " do - allow(File).to receive(:exists?).with("/etc/lsb-release").and_return(false) - allow(File).to receive(:exists?).with("/usr/bin/lsb_release").and_return(false) + allow(File).to receive(:exist?).with("/etc/lsb-release").and_return(false) + allow(File).to receive(:exist?).with("/usr/bin/lsb_release").and_return(false) expect(@plugin.attribute?(:lsb)).to be(false) end end diff --git a/spec/unit/plugins/linux/lspci_spec.rb b/spec/unit/plugins/linux/lspci_spec.rb index 074068bb..9948e2f8 100644 --- a/spec/unit/plugins/linux/lspci_spec.rb +++ b/spec/unit/plugins/linux/lspci_spec.rb @@ -19,7 +19,7 @@ require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux lspci plugin" do - let (:plugin) { get_plugin("linux/lspci") } + let(:plugin) { get_plugin("linux/lspci") } before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) @stdout = <<LSPCI diff --git a/spec/unit/plugins/linux/machineid_spec.rb b/spec/unit/plugins/linux/machineid_spec.rb index 6e0243bc..3c601ac2 100644 --- a/spec/unit/plugins/linux/machineid_spec.rb +++ b/spec/unit/plugins/linux/machineid_spec.rb @@ -28,8 +28,8 @@ describe Ohai::System, "Machine id plugin" do it "should read /etc/machine-id if available" do machine_id = "6f702523e2fc7499eb1dc68e5314dacf" - allow(File).to receive(:exists?).with("/etc/machine-id").and_return(true) - allow(File).to receive(:read).with("/etc/machine-id").and_return(machine_id) + allow(::File).to receive(:exist?).with("/etc/machine-id").and_return(true) + allow(::File).to receive(:read).with("/etc/machine-id").and_return(machine_id) plugin.run expect(plugin[:machine_id]).to eq(machine_id) end @@ -37,9 +37,9 @@ describe Ohai::System, "Machine id plugin" do it "should read /var/lib/dbus/machine-id if available" do machine_id = "6f702523e2fc7499eb1dc68e5314dacf" - allow(File).to receive(:exists?).with("/etc/machine-id").and_return(false) - allow(File).to receive(:exists?).with("/var/lib/dbus/machine-id").and_return(true) - allow(File).to receive(:read).with("/var/lib/dbus/machine-id").and_return(machine_id) + allow(::File).to receive(:exist?).with("/etc/machine-id").and_return(false) + allow(::File).to receive(:exist?).with("/var/lib/dbus/machine-id").and_return(true) + allow(::File).to receive(:read).with("/var/lib/dbus/machine-id").and_return(machine_id) plugin.run expect(plugin[:machine_id]).to eq(machine_id) end diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb index 99c1ec34..e14839fb 100644 --- a/spec/unit/plugins/network_spec.rb +++ b/spec/unit/plugins/network_spec.rb @@ -475,8 +475,8 @@ describe Ohai::System, "Network Plugin" do @plugin["network"]["default_interface"] = nil @plugin["network"]["default_inet6_gateway"] = nil @plugin["network"]["default_inet6_interface"] = nil - @plugin["network"]["interfaces"].each do |i, iv| - iv["addresses"].delete_if { |k, kv| %w{inet inet6}.include? kv["family"] } + @plugin["network"]["interfaces"].each_value do |val| + val["addresses"].delete_if { |k, kv| %w{inet inet6}.include? kv["family"] } end end @@ -660,7 +660,7 @@ describe Ohai::System, "Network Plugin" do @plugin["network"]["default_inet6_gateway"] = nil @plugin["network"]["default_inet6_interface"] = nil # just changing scopes to lInK for eth0 addresses - @plugin["network"]["interfaces"]["eth0"]["addresses"].each { |k, v| v[:scope] = "lInK" if %w{inet inet6}.include? v["family"] } + @plugin["network"]["interfaces"]["eth0"]["addresses"].each_value { |v| v[:scope] = "lInK" if %w{inet inet6}.include? v["family"] } end it_populates_ipaddress_attributes @@ -781,8 +781,8 @@ describe Ohai::System, "Network Plugin" do before do @plugin["network"]["default_gateway"] = nil @plugin["network"]["default_interface"] = nil - @plugin["network"]["interfaces"].each do |i, iv| - iv["addresses"].delete_if { |k, kv| kv["family"] == "inet" } + @plugin["network"]["interfaces"].each_value do |val| + val["addresses"].delete_if { |k, kv| kv["family"] == "inet" } end end @@ -928,9 +928,9 @@ describe Ohai::System, "Network Plugin" do before do @plugin["network"]["default_gateway"] = nil @plugin["network"]["default_interface"] = nil - @plugin["network"]["interfaces"].each do |i, iv| - if iv.has_key? "addresses" - iv["addresses"].delete_if { |k, kv| kv["family"] == "inet" } + @plugin["network"]["interfaces"].each_value do |val| + if val.has_key? "addresses" + val["addresses"].delete_if { |k, kv| kv["family"] == "inet" } end end @plugin["ip6address"] = "3ffe:8888:9999::1" @@ -1013,9 +1013,9 @@ describe Ohai::System, "Network Plugin" do before do @plugin["network"]["default_gateway"] = nil @plugin["network"]["default_interface"] = nil - @plugin["network"]["interfaces"].each do |i, iv| - if iv.has_key? "addresses" - iv["addresses"].delete_if { |k, kv| kv["family"] == "inet" } + @plugin["network"]["interfaces"].each_value do |val| + if val.has_key? "addresses" + val["addresses"].delete_if { |k, kv| kv["family"] == "inet" } end end @plugin["macaddress"] = "00:AA:BB:CC:DD:EE" diff --git a/spec/unit/plugins/ruby_spec.rb b/spec/unit/plugins/ruby_spec.rb index b0404132..4fa62fef 100644 --- a/spec/unit/plugins/ruby_spec.rb +++ b/spec/unit/plugins/ruby_spec.rb @@ -49,7 +49,7 @@ describe Ohai::System, "plugin ruby" do :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}" - end.find { |bin| ::File.exists? bin }, + end.find { |bin| ::File.exist? bin }, :ruby_bin => ruby_bin, }.each do |attribute, value| it "should have #{attribute} set to #{value.inspect}" do diff --git a/spec/unit/plugins/rust_spec.rb b/spec/unit/plugins/rust_spec.rb index e8ffdc6e..8046d0ee 100644 --- a/spec/unit/plugins/rust_spec.rb +++ b/spec/unit/plugins/rust_spec.rb @@ -18,7 +18,7 @@ require_relative "../../spec_helper.rb" describe Ohai::System, "plugin rust" do let(:stdout) { "rustc 1.0.0-nightly (29bd9a06e 2015-01-20 23:03:09 +0000)" } - let (:plugin) do + let(:plugin) do plugin = get_plugin("rust") plugin[:languages] = Mash.new allow(plugin).to receive(:shell_out).with("rustc --version").and_return(mock_shell_out(0, stdout, "")) diff --git a/spec/unit/plugins/scala_spec.rb b/spec/unit/plugins/scala_spec.rb index 18e8de69..76656c98 100644 --- a/spec/unit/plugins/scala_spec.rb +++ b/spec/unit/plugins/scala_spec.rb @@ -20,7 +20,7 @@ require_relative "../../spec_helper.rb" describe Ohai::System, "plugin scala" do let(:plugin) do - plugin = get_plugin("scala").tap do |plugin| + get_plugin("scala").tap do |plugin| plugin[:languages] = Mash.new end end diff --git a/spec/unit/plugins/solaris2/cpu_spec.rb b/spec/unit/plugins/solaris2/cpu_spec.rb index 86b6b028..c6991f0d 100644 --- a/spec/unit/plugins/solaris2/cpu_spec.rb +++ b/spec/unit/plugins/solaris2/cpu_spec.rb @@ -455,15 +455,15 @@ END end it "should get the number of threads per core" do - expect(@plugin["cpu"]["corethreads"]).to eql (2) + expect(@plugin["cpu"]["corethreads"]).to eql(2) end it "should get the total number of online cores" do - expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql (8) + expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql(8) end it "should get the total number of offline cores" do - expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql (8) + expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql(8) end describe "per-cpu information" do diff --git a/spec/unit/plugins/solaris2/platform_spec.rb b/spec/unit/plugins/solaris2/platform_spec.rb index f2394609..13b4120c 100644 --- a/spec/unit/plugins/solaris2/platform_spec.rb +++ b/spec/unit/plugins/solaris2/platform_spec.rb @@ -41,7 +41,7 @@ Origin# = 1 NumCPU = 16 UNAME_X - allow(File).to receive(:exists?).with("/sbin/uname").and_return(true) + allow(File).to receive(:exist?).with("/sbin/uname").and_return(true) allow(@plugin).to receive(:shell_out).with("/sbin/uname -X").and_return(mock_shell_out(0, @uname_x, "")) @release = StringIO.new(" SmartOS 20120130T201844Z x86_64\n") @@ -81,7 +81,7 @@ Origin# = 1 NumCPU = 1 UNAME_X - allow(File).to receive(:exists?).with("/sbin/uname").and_return(true) + allow(File).to receive(:exist?).with("/sbin/uname").and_return(true) allow(@plugin).to receive(:shell_out).with("/sbin/uname -X").and_return(mock_shell_out(0, @uname_x, "")) @release = StringIO.new(" Oracle Solaris 11.1 X86\n") diff --git a/spec/unit/plugins/ssh_host_keys_spec.rb b/spec/unit/plugins/ssh_host_keys_spec.rb index cf8de1ac..b2ddb663 100644 --- a/spec/unit/plugins/ssh_host_keys_spec.rb +++ b/spec/unit/plugins/ssh_host_keys_spec.rb @@ -24,13 +24,13 @@ describe Ohai::System, "ssh_host_key plugin" do @plugin = get_plugin("ssh_host_key") @plugin[:keys] = Mash.new - allow(File).to receive(:exists?).with("/etc/ssh/sshd_config").and_return(true) + allow(File).to receive(:exist?).with("/etc/ssh/sshd_config").and_return(true) allow(File).to receive(:open).with("/etc/ssh/sshd_config").and_yield(sshd_config_file) - allow(File).to receive(:exists?).and_return(true) - allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(true) - allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(true) - allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(true) - allow(File).to receive(:exists?).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(true) + allow(File).to receive(:exist?).and_return(true) + allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_dsa_key.pub").and_return(true) + allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_rsa_key.pub").and_return(true) + allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(true) + allow(File).to receive(:exist?).with("/etc/ssh/ssh_host_ed25519_key.pub").and_return(true) # Ensure we can still use IO.read io_read = IO.method(:read) @@ -104,8 +104,8 @@ EOS nil end before do - allow(File).to receive(:exists?).with("/etc/ssh/sshd_config").and_return(false) - allow(File).to receive(:exists?).with("/etc/sshd_config").and_return(false) + allow(File).to receive(:exist?).with("/etc/ssh/sshd_config").and_return(false) + allow(File).to receive(:exist?).with("/etc/sshd_config").and_return(false) end it_behaves_like "loads keys" diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index 64baf51c..5e079c10 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -224,7 +224,7 @@ describe Ohai::Runner, "run_plugin" do context "when there are no edges in the cycle (A->A)" do let(:plugin_class) do - klass1 = Ohai.plugin(:Thing) do + Ohai.plugin(:Thing) do provides("thing") depends("thing") collect_data do @@ -236,8 +236,6 @@ describe Ohai::Runner, "run_plugin" do it "ignores the cycle" do @ohai.provides_map.set_providers_for(plugin, ["thing"]) - - expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other" runner.run_plugin(plugin) # should not raise end @@ -245,7 +243,7 @@ describe Ohai::Runner, "run_plugin" do context "when there is one edge in the cycle (A->B and B->A)" do before(:each) do - klass1 = Ohai.plugin(:Thing) do + klass1 = Ohai.plugin(:Thing) do # rubocop disable Lint/UselessAssignment provides("thing") depends("other") collect_data do |