summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-06-20 11:29:39 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-06-20 11:29:39 -0700
commit97eae99ee6518ab5f3be894448b502fd45266fe2 (patch)
tree3527d9ab2a16ce7ef0d28eb3f01f681bd8416722
parentf1eddc9cf42c77b51d3e5150c2b2b3d34197b615 (diff)
downloadohai-97eae99ee6518ab5f3be894448b502fd45266fe2.tar.gz
autofixing cops for 0.5.0
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/ohai/common/dmi.rb24
-rw-r--r--lib/ohai/dsl/plugin.rb14
-rw-r--r--lib/ohai/dsl/plugin/versionvi.rb2
-rw-r--r--lib/ohai/dsl/plugin/versionvii.rb8
-rw-r--r--lib/ohai/mash.rb2
-rw-r--r--lib/ohai/mixin/command.rb6
-rw-r--r--lib/ohai/mixin/dmi_decode.rb2
-rw-r--r--lib/ohai/mixin/os.rb22
-rw-r--r--lib/ohai/mixin/string.rb2
-rw-r--r--lib/ohai/plugins/azure.rb4
-rw-r--r--lib/ohai/plugins/c.rb19
-rw-r--r--lib/ohai/plugins/digital_ocean.rb4
-rw-r--r--lib/ohai/plugins/ec2.rb10
-rw-r--r--lib/ohai/plugins/eucalyptus.rb4
-rw-r--r--lib/ohai/plugins/hostname.rb14
-rw-r--r--lib/ohai/plugins/java.rb40
-rw-r--r--lib/ohai/plugins/kernel.rb2
-rw-r--r--lib/ohai/plugins/linux/filesystem.rb2
-rw-r--r--lib/ohai/plugins/openstack.rb10
-rw-r--r--lib/ohai/plugins/uptime.rb2
-rw-r--r--lib/ohai/util/file_helper.rb4
-rw-r--r--platform_simulation_specs/common/ohai_plugin_common.rb2
22 files changed, 95 insertions, 104 deletions
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb
index dce927ea..988e1493 100644
--- a/lib/ohai/common/dmi.rb
+++ b/lib/ohai/common/dmi.rb
@@ -78,20 +78,18 @@ module Ohai
# look up DMI ID
def id_lookup(id)
- begin
- id = id.to_i
- if (id >= 128) && (id <= 255)
- id = "oem_data_#{id}"
- elsif DMI::ID_TO_DESCRIPTION.has_key?(id)
- id = DMI::ID_TO_DESCRIPTION[id]
- else
- Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
- id = "unknown"
- end
- rescue
- Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
- id
+ id = id.to_i
+ if (id >= 128) && (id <= 255)
+ id = "oem_data_#{id}"
+ elsif DMI::ID_TO_DESCRIPTION.has_key?(id)
+ id = DMI::ID_TO_DESCRIPTION[id]
+ else
+ Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
+ id = "unknown"
end
+ rescue
+ Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
+ id
end
# create simplified convenience access keys for each record type
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb
index 7d7456e1..e3694ac1 100644
--- a/lib/ohai/dsl/plugin.rb
+++ b/lib/ohai/dsl/plugin.rb
@@ -180,14 +180,12 @@ module Ohai
# emulates the old plugin loading behavior
def safe_run
- begin
- self.run
- rescue Ohai::Exceptions::Error => e
- raise e
- rescue => e
- Ohai::Log.debug("Plugin #{self.name} threw #{e.inspect}")
- e.backtrace.each { |line| Ohai::Log.debug( line ) }
- end
+ run
+ rescue Ohai::Exceptions::Error => e
+ raise e
+ rescue => e
+ Ohai::Log.debug("Plugin #{name} threw #{e.inspect}")
+ e.backtrace.each { |line| Ohai::Log.debug( line ) }
end
def method_missing(name, *args)
diff --git a/lib/ohai/dsl/plugin/versionvi.rb b/lib/ohai/dsl/plugin/versionvi.rb
index 704581de..2a96c0fb 100644
--- a/lib/ohai/dsl/plugin/versionvi.rb
+++ b/lib/ohai/dsl/plugin/versionvi.rb
@@ -44,7 +44,7 @@ module Ohai
end
def self.collect_contents(contents)
- define_method(:run_plugin) { self.instance_eval(contents) }
+ define_method(:run_plugin) { instance_eval(contents) }
end
def provides(*paths)
diff --git a/lib/ohai/dsl/plugin/versionvii.rb b/lib/ohai/dsl/plugin/versionvii.rb
index f9c62bd7..cd8dc13c 100644
--- a/lib/ohai/dsl/plugin/versionvii.rb
+++ b/lib/ohai/dsl/plugin/versionvii.rb
@@ -85,11 +85,11 @@ module Ohai
platform = collect_os
if collector.has_key?(platform)
- self.instance_eval(&collector[platform])
+ instance_eval(&collector[platform])
elsif collector.has_key?(:default)
- self.instance_eval(&collector[:default])
+ instance_eval(&collector[:default])
else
- Ohai::Log.debug("Plugin #{self.name}: No data to collect. Skipping...")
+ Ohai::Log.debug("Plugin #{name}: No data to collect. Skipping...")
end
end
@@ -122,7 +122,7 @@ module Ohai
# Memory => ["", "Memory"]
# NetworkListeners => ["", "Network", "", "Listeners"]
# SSHHostKey => ["SSH", "Host", "", "Key"]
- parts = self.name.to_s.split(/([A-Z][a-z]+)/)
+ parts = name.to_s.split(/([A-Z][a-z]+)/)
# ["DMI"] => ["DMI"]
# ["", "Memory"] => ["Memory"]
# ["", "Network", "", "Listeners"] => ["Network", "Listeners"]
diff --git a/lib/ohai/mash.rb b/lib/ohai/mash.rb
index 8dcf4b25..5ea21d76 100644
--- a/lib/ohai/mash.rb
+++ b/lib/ohai/mash.rb
@@ -135,7 +135,7 @@ class Mash < Hash
#
# @return [Mash] A new mash with the hash values merged in.
def merge(hash)
- self.dup.update(hash)
+ dup.update(hash)
end
# @param key<Object>
diff --git a/lib/ohai/mixin/command.rb b/lib/ohai/mixin/command.rb
index 01a00edc..a6105ba0 100644
--- a/lib/ohai/mixin/command.rb
+++ b/lib/ohai/mixin/command.rb
@@ -37,13 +37,13 @@ module Ohai
so = Mixlib::ShellOut.new(cmd, options)
begin
so.run_command
- Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and returned #{so.exitstatus}")
+ Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
so
rescue Errno::ENOENT => e
- Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and failed #{e.inspect}")
+ Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
raise Ohai::Exceptions::Exec, e
rescue Mixlib::ShellOut::CommandTimeout => e
- Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
+ Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
raise Ohai::Exceptions::Exec, e
end
end
diff --git a/lib/ohai/mixin/dmi_decode.rb b/lib/ohai/mixin/dmi_decode.rb
index 64be3371..971911c8 100644
--- a/lib/ohai/mixin/dmi_decode.rb
+++ b/lib/ohai/mixin/dmi_decode.rb
@@ -46,6 +46,6 @@ module ::Ohai::Mixin::DmiDecode
return "veertu"
end
end
- return nil
+ nil
end
end
diff --git a/lib/ohai/mixin/os.rb b/lib/ohai/mixin/os.rb
index 83cdc34e..b8222596 100644
--- a/lib/ohai/mixin/os.rb
+++ b/lib/ohai/mixin/os.rb
@@ -26,32 +26,32 @@ module Ohai
def collect_os
case ::RbConfig::CONFIG["host_os"]
when /aix(.+)$/
- return "aix"
+ "aix"
when /darwin(.+)$/
- return "darwin"
+ "darwin"
when /hpux(.+)$/
- return "hpux"
+ "hpux"
when /linux/
- return "linux"
+ "linux"
when /freebsd(.+)$/
- return "freebsd"
+ "freebsd"
when /openbsd(.+)$/
- return "openbsd"
+ "openbsd"
when /netbsd(.*)$/
- return "netbsd"
+ "netbsd"
when /dragonfly(.*)$/
- return "dragonflybsd"
+ "dragonflybsd"
when /solaris2/
- return "solaris2"
+ "solaris2"
when /mswin|mingw32|windows/
# After long discussion in IRC the "powers that be" have come to a consensus
# that no Windows platform exists that was not based on the
# Windows_NT kernel, so we herby decree that "windows" will refer to all
# platforms built upon the Windows_NT kernel and have access to win32 or win64
# subsystems.
- return "windows"
+ "windows"
else
- return ::RbConfig::CONFIG["host_os"]
+ ::RbConfig::CONFIG["host_os"]
end
end
diff --git a/lib/ohai/mixin/string.rb b/lib/ohai/mixin/string.rb
index 48830a36..a10fab2b 100644
--- a/lib/ohai/mixin/string.rb
+++ b/lib/ohai/mixin/string.rb
@@ -23,7 +23,7 @@ class String
# This should implement the same functionality as underscore method in
# ActiveSupport::CoreExtensions::String::Inflections
def wmi_underscore
- self.gsub(/::/, "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
+ gsub(/::/, "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z\d])([A-Z])/, '\1_\2').tr("-", "_").downcase
end
end
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index 8d984083..7eae3955 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -41,7 +41,7 @@ Ohai.plugin(:Azure) do
def has_waagent?
if File.exist?("/usr/sbin/waagent") || Dir.exist?('C:\WindowsAzure')
Ohai::Log.debug("Plugin Azure: Found waagent used by MS Azure.")
- return true
+ true
end
end
@@ -56,7 +56,7 @@ Ohai.plugin(:Azure) do
end
end
end
- return has_245
+ has_245
end
end
diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb
index 61b20cc6..ced74ced 100644
--- a/lib/ohai/plugins/c.rb
+++ b/lib/ohai/plugins/c.rb
@@ -123,18 +123,17 @@ Ohai.plugin(:C) do
def collect_xlc
# ibm xlc
- begin
- so = shell_out("xlc -qversion")
- if so.exitstatus == 0 || (so.exitstatus >> 8) == 249
- description = so.stdout.split($/).first
- if description =~ /V(\d+\.\d+)/
- @c[:xlc] = Mash.new
- @c[:xlc][:version] = $1
- @c[:xlc][:description] = description.strip
- end
+
+ so = shell_out("xlc -qversion")
+ if so.exitstatus == 0 || (so.exitstatus >> 8) == 249
+ description = so.stdout.split($/).first
+ if description =~ /V(\d+\.\d+)/
+ @c[:xlc] = Mash.new
+ @c[:xlc][:version] = $1
+ @c[:xlc][:description] = description.strip
end
- rescue Ohai::Exceptions::Exec
end
+ rescue Ohai::Exceptions::Exec
end
def collect_sunpro
diff --git a/lib/ohai/plugins/digital_ocean.rb b/lib/ohai/plugins/digital_ocean.rb
index d43f02e3..c1b3f891 100644
--- a/lib/ohai/plugins/digital_ocean.rb
+++ b/lib/ohai/plugins/digital_ocean.rb
@@ -38,13 +38,13 @@ Ohai.plugin(:DigitalOcean) do
# dmi[:bios][:all_records][0][:Vendor] may not exist
end
Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == false")
- return false
+ false
end
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)
- return false
+ false
end
collect_data do
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb
index 1ad6b88a..f0e0f5eb 100644
--- a/lib/ohai/plugins/ec2.rb
+++ b/lib/ohai/plugins/ec2.rb
@@ -43,10 +43,10 @@ Ohai.plugin(:EC2) do
# detect a version of '4.2.amazon'
if get_attribute(:dmi, :bios, :all_records, 0, :Version) =~ /amazon/
Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == true")
- return true
+ true
else
Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == false")
- return false
+ false
end
end
@@ -60,7 +60,7 @@ Ohai.plugin(:EC2) do
end
end
Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == false")
- return false
+ false
end
# looks for the Amazon.com Organization in Windows Kernel data
@@ -69,10 +69,10 @@ Ohai.plugin(:EC2) do
# detect an Organization of 'Amazon.com'
if get_attribute(:kernel, :os_info, :organization) =~ /Amazon/
Ohai::Log.debug("Plugin EC2: has_amazon_org? == true")
- return true
+ true
else
Ohai::Log.debug("Plugin EC2: has_amazon_org? == false")
- return false
+ false
end
end
diff --git a/lib/ohai/plugins/eucalyptus.rb b/lib/ohai/plugins/eucalyptus.rb
index 82ee391d..0481fe29 100644
--- a/lib/ohai/plugins/eucalyptus.rb
+++ b/lib/ohai/plugins/eucalyptus.rb
@@ -62,7 +62,7 @@ Ohai.plugin(:Eucalyptus) do
if looks_like_euca?
Ohai::Log.debug("Plugin Eucalyptus: looks_like_euca? == true")
eucalyptus Mash.new
- self.fetch_metadata.each do |k, v|
+ fetch_metadata.each do |k, v|
# Eucalyptus 3.4+ supports IAM roles and Instance Profiles much like AWS
# https://www.eucalyptus.com/blog/2013/10/15/iam-roles-and-instance-profiles-eucalyptus-34
#
@@ -73,7 +73,7 @@ Ohai.plugin(:Eucalyptus) do
next if k == "iam" && !hint?("iam")
eucalyptus[k] = v
end
- eucalyptus[:userdata] = self.fetch_userdata
+ eucalyptus[:userdata] = fetch_userdata
else
Ohai::Log.debug("Plugin Eucalyptus: looks_like_euca? == false")
false
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index a6ba86c4..0c08c9b1 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -47,14 +47,12 @@ Ohai.plugin(:Hostname) do
# forward and reverse lookup to canonicalize FQDN (hostname -f equivalent)
# this is ipv6-safe, works on ruby 1.8.7+
def resolve_fqdn
- begin
- hostname = from_cmd("hostname")
- addrinfo = Socket.getaddrinfo(hostname, nil).first
- iaddr = IPAddr.new(addrinfo[3])
- Socket.gethostbyaddr(iaddr.hton)[0]
- rescue
- nil
- end
+ hostname = from_cmd("hostname")
+ addrinfo = Socket.getaddrinfo(hostname, nil).first
+ iaddr = IPAddr.new(addrinfo[3])
+ Socket.gethostbyaddr(iaddr.hton)[0]
+ rescue
+ nil
end
def collect_domain
diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb
index c023bfc3..2cec8c64 100644
--- a/lib/ohai/plugins/java.rb
+++ b/lib/ohai/plugins/java.rb
@@ -21,30 +21,28 @@ Ohai.plugin(:Java) do
depends "languages"
def get_java_info
- begin
- so = shell_out("java -mx64m -version")
- # Sample output:
- # java version "1.8.0_60"
- # Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
- # Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
- if so.exitstatus == 0
- java = Mash.new
- so.stderr.split(/\r?\n/).each do |line|
- case line
- when /(?:java|openjdk) version \"([0-9\.\_]+)\"/
- java[:version] = $1
- when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/
- java[:runtime] = { "name" => $1, "build" => $3 }
- when /^(.+ (Client|Server) VM) \(build\s*(.+)\)$/
- java[:hotspot] = { "name" => $1, "build" => $3 }
- end
+ so = shell_out("java -mx64m -version")
+ # Sample output:
+ # java version "1.8.0_60"
+ # Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
+ # Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
+ if so.exitstatus == 0
+ java = Mash.new
+ so.stderr.split(/\r?\n/).each do |line|
+ case line
+ when /(?:java|openjdk) version \"([0-9\.\_]+)\"/
+ java[:version] = $1
+ when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/
+ java[:runtime] = { "name" => $1, "build" => $3 }
+ when /^(.+ (Client|Server) VM) \(build\s*(.+)\)$/
+ java[:hotspot] = { "name" => $1, "build" => $3 }
end
-
- languages[:java] = java unless java.empty?
end
- rescue Ohai::Exceptions::Exec
- Ohai::Log.debug('Plugin Java: Could not shell_out "java -mx64m -version". Skipping plugin')
+
+ languages[:java] = java unless java.empty?
end
+ rescue Ohai::Exceptions::Exec
+ Ohai::Log.debug('Plugin Java: Could not shell_out "java -mx64m -version". Skipping plugin')
end
# On Mac OS X, the development tools include "stubs" for JVM executables that
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index 3441eb73..032be9b9 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -67,7 +67,7 @@ Ohai.plugin(:Kernel) do
return "WIN98" if sys_type.to_s.eql?("17")
return "WINNT" if sys_type.to_s.eql?("18")
return "WINCE" if sys_type.to_s.eql?("19")
- return nil
+ nil
end
collect_data(:default) do
diff --git a/lib/ohai/plugins/linux/filesystem.rb b/lib/ohai/plugins/linux/filesystem.rb
index e7af796c..fd6d9798 100644
--- a/lib/ohai/plugins/linux/filesystem.rb
+++ b/lib/ohai/plugins/linux/filesystem.rb
@@ -55,7 +55,7 @@ Ohai.plugin(:Filesystem) do
end
return f
end
- return nil
+ nil
end
def generate_device_view(fs)
diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb
index aa8ad1a2..c8e6e91b 100644
--- a/lib/ohai/plugins/openstack.rb
+++ b/lib/ohai/plugins/openstack.rb
@@ -32,10 +32,10 @@ Ohai.plugin(:Openstack) do
# detect a manufacturer of OpenStack Foundation
if get_attribute(:dmi, :system, :all_records, 0, :Manufacturer) =~ /OpenStack/
Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == true")
- return true
+ true
else
Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == false")
- return false
+ false
end
end
@@ -43,17 +43,17 @@ Ohai.plugin(:Openstack) do
def openstack_hint?
if hint?("openstack")
Ohai::Log.debug("Plugin Openstack: openstack hint present")
- return true
+ true
else
Ohai::Log.debug("Plugin Openstack: openstack hint not present")
- return false
+ false
end
end
# dreamhost systems have the dhc-user on them
def openstack_provider
return "dreamhost" if get_attribute("etc", "passwd", "dhc-user")
- return "openstack"
+ "openstack"
end
collect_data do
diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb
index f0cfb3c1..01cbab8b 100644
--- a/lib/ohai/plugins/uptime.rb
+++ b/lib/ohai/plugins/uptime.rb
@@ -40,7 +40,7 @@ Ohai.plugin(:Uptime) do
return [usec, seconds_to_human(usec)]
end
end
- return [nil, nil]
+ [nil, nil]
end
collect_data(:darwin) do
diff --git a/lib/ohai/util/file_helper.rb b/lib/ohai/util/file_helper.rb
index eb9a12e9..35f3abb6 100644
--- a/lib/ohai/util/file_helper.rb
+++ b/lib/ohai/util/file_helper.rb
@@ -26,11 +26,11 @@ module Ohai
paths.each do |path|
filename = File.join(path, cmd)
if File.executable?(filename)
- Ohai::Log.debug("Plugin #{self.name}: found #{cmd} at #{filename}")
+ Ohai::Log.debug("Plugin #{name}: found #{cmd} at #{filename}")
return filename
end
end
- Ohai::Log.debug("Plugin #{self.name}: did not find #{cmd}")
+ Ohai::Log.debug("Plugin #{name}: did not find #{cmd}")
false
end
end
diff --git a/platform_simulation_specs/common/ohai_plugin_common.rb b/platform_simulation_specs/common/ohai_plugin_common.rb
index 1e9593ca..7421d92f 100644
--- a/platform_simulation_specs/common/ohai_plugin_common.rb
+++ b/platform_simulation_specs/common/ohai_plugin_common.rb
@@ -70,7 +70,7 @@ module OhaiPluginCommon
@instances << current
end
@methods = [:platform, :arch, :env, :params, :stdout, :stderr, :exit_status]
- @methods.each { |m| self.send(:define_method, m.to_s) { |text| push m.to_sym, text } }
+ @methods.each { |m| send(:define_method, m.to_s) { |text| push m.to_sym, text } }
#Format data into a form the rest of the app expects
def process