diff options
author | Tim Smith <tsmith@chef.io> | 2018-03-06 10:38:39 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-03-06 10:38:39 -0800 |
commit | 011db28d6c3026ac41b9c519a87643d70ecf9be5 (patch) | |
tree | 636e072786c5aa143ce3cd964da1548f5b1ea818 | |
parent | dfa786b965a649349ef77def4c22af454c33ccb0 (diff) | |
download | ohai-011db28d6c3026ac41b9c519a87643d70ecf9be5.tar.gz |
Resolve the last of the chefstyle warningsgreen_travis
Signed-off-by: Tim Smith <tsmith@chef.io>
45 files changed, 80 insertions, 84 deletions
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/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/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/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/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 292862eb..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 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 b31b8f68..90cd0338 100644 --- a/lib/ohai/plugins/solaris2/platform.rb +++ b/lib/ohai/plugins/solaris2/platform.rb @@ -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/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 28af5ff9..6bf05f2f 100644 --- a/spec/functional/plugins/root_group_spec.rb +++ b/spec/functional/plugins/root_group_spec.rb @@ -24,7 +24,7 @@ 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 # Notethat the Win32_Group WMI provider can be slow if your 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/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/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/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/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/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/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 |