Skip to content

Commit

Permalink
Merge pull request #789 from chef/chefstyle-0.3.1
Browse files Browse the repository at this point in the history
Update chefstyle to 0.3.1 and fix new offenses.
  • Loading branch information
mcquin committed Apr 1, 2016
2 parents af29132 + 870a18f commit 8f48805
Show file tree
Hide file tree
Showing 39 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gemspec
group :development do
gem "sigar", :platform => "ruby"

gem "chefstyle", "= 0.3.0"
gem "chefstyle", "= 0.3.1"
# gem 'pry-byebug'
# gem 'pry-stack_explorer'
end
2 changes: 1 addition & 1 deletion lib/ohai/common/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module DMI
def id_lookup(id)
begin
id = id.to_i
if (id >= 128) and (id <= 255)
if (id >= 128) && (id <= 255)
id = "oem_data_#{id}"
elsif DMI::IdToDescription.has_key?(id)
id = DMI::IdToDescription[id]
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def self.merge_deprecated_config
private

def self.option_deprecated(option)
<<-EOM.chomp!.gsub("\n", " ")
<<-EOM.chomp!.tr("\n", " ")
Ohai::Config[:#{option}] is set. Ohai::Config[:#{option}] is deprecated and will
be removed in future releases of ohai. Use ohai.#{option} in your configuration
file to configure :#{option} for ohai.
EOM
end

def self.option_might_be_deprecated(option)
option_deprecated(option) + <<-EOM.chomp!.gsub("\n", " ")
option_deprecated(option) + <<-EOM.chomp!.tr("\n", " ")
If your configuration file is used with other applications which configure
:#{option}, and you have not configured Ohai::Config[:#{option}], you may
disregard this warning.
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/dsl/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def []=(key, value)

def each(&block)
@data.each do |key, value|
block.call(key, value)
yield(key, value)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def loaded_v6_plugin(plugin, plugin_file_path, plugin_dir_path)

def load_v7_plugin_class(contents, plugin_path)
plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path)
unless plugin_class.kind_of?(Class) and plugin_class < Ohai::DSL::Plugin
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
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def run_command(args = {})

args[:returns] ||= 0
args[:no_status_check] ||= false
if status.exitstatus != args[:returns] and not args[:no_status_check]
if status.exitstatus != args[:returns] && (not args[:no_status_check])
raise Ohai::Exceptions::Exec, "#{args[:command_string]} returned #{status.exitstatus}, expected #{args[:returns]}"
else
Ohai::Log.debug("Ran #{args[:command_string]} (#{args[:command]}) returned #{status.exitstatus}")
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/ec2_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def fetch_metadata(id = "", api_version = nil)
else
metadata_get(key, api_version)
end
elsif not key.eql?(id) and not key.eql?("/")
elsif (not key.eql?(id)) && (not key.eql?("/"))
name = key[0..-2]
sym = metadata_key(name)
if EC2_ARRAY_DIR.include?(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
#ibm xlc
begin
so = shell_out("xlc -qversion")
if so.exitstatus == 0 or (so.exitstatus >> 8) == 249
if so.exitstatus == 0 || (so.exitstatus >> 8) == 249
description = so.stdout.split($/).first
if description =~ /V(\d+\.\d+)/
c[:xlc] = Mash.new
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
inactive = 0
vm_stat = shell_out("vm_stat").stdout
vm_stat_match = /page size of (\d+) bytes/.match(vm_stat)
page_size = if vm_stat_match and vm_stat_match[1]
page_size = if vm_stat_match && vm_stat_match[1]
vm_stat_match[1].to_i
else
4096
Expand Down
6 changes: 3 additions & 3 deletions lib/ohai/plugins/darwin/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def darwin_encaps_lookup(ifname)

def scope_lookup(scope)
return "Node" if scope.eql?("::1")
return "Link" if scope.match(/^fe80\:/)
return "Site" if scope.match(/^fec0\:/)
return "Link" if scope =~ /^fe80\:/
return "Site" if scope =~ /^fec0\:/
"Global"
end

Expand All @@ -73,7 +73,7 @@ def excluded_setting?(setting)
def locate_interface(ifaces, ifname, mac)
return ifname unless ifaces[ifname].nil?
# oh well, time to go hunting!
return ifname.chop if ifname.match /\*$/
return ifname.chop if ifname =~ /\*$/
ifaces.keys.each do |ifc|
ifaces[ifc][:addresses].keys.each do |addr|
return ifc if addr.eql? mac
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
when /^ProductName:\s+(.+)$/
macname = $1
macname.downcase!
macname.gsub!(" ", "_")
macname.tr!(" ", "_")
platform macname
when /^ProductVersion:\s+(.+)$/
platform_version $1
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/darwin/system_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
SPWWANData
SPAirPortData},
"full" => [
"SPHardwareDataType"
"SPHardwareDataType",
],
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/digital_ocean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def build_address_hash(ip, details)
address_hash = Mash.new({
"ip_address" => ip.address,
"type" => private_address?(ip.address) ? "private" : "public",
},)
})

if ip.ipv4?
address_hash["netmask"] = details[:netmask]
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/erlang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
erlang[:version] = output[5]
erlang[:options] = options.split(",")
erlang[:emulator] = output[2].gsub!(/(\(|\))/, "")
if erlang[:version] and erlang[:options] and erlang[:emulator]
if erlang[:version] && erlang[:options] && erlang[:emulator]
languages[:erlang] = erlang
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/ip_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
interface = network["interfaces"][ifName]
interface["addresses"].each do |address, attrs|
begin
attrs.merge! "ip_scope" => address.to_ip.scope
attrs["ip_scope"] = address.to_ip.scope

if private_addr?(address) && !tunnel_iface?(interface)
privateaddress(address)
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def os_lookup(sys_type)
host = wmi.first_of("Win32_ComputerSystem")
kernel[:cs_info] = Mash.new
cs_info_blacklist = [
"oem_logo_bitmap"
"oem_logo_bitmap",
]
host.wmi_ole_object.properties_.each do |p|
if !cs_info_blacklist.include?(p.name.wmi_underscore)
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/linux/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def link_statistics(iface, net_counters)
net_counters[tmp_int][:tx][:queuelen] = $1
end

if line =~ /vlan id (\d+)/ or line =~ /vlan protocol ([\w\.]+) id (\d+)/
if line =~ /vlan id (\d+)/ || line =~ /vlan protocol ([\w\.]+) id (\d+)/
if $2
tmp_prot = $1
tmp_id = $2
Expand Down Expand Up @@ -463,7 +463,7 @@ def favored_default_route(routes, iface, default_route, family)

default_route = choose_default_route(routes)

if default_route.nil? or default_route.empty?
if default_route.nil? || default_route.empty?
attribute_name = if family[:name] == "inet"
"default_interface"
else
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/mono.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
mono[:version] = output[4]
end
if output.length >= 11
mono[:builddate] = "%s %s %s %s" % [output[6], output[7], output[8], output[11].gsub!(/\)/, "")]
mono[:builddate] = "%s %s %s %s" % [output[6], output[7], output[8], output[11].delete!(")")]
end
languages[:mono] = mono if mono[:version]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def sorted_ips(family = "inet")
Mash[network["interfaces"]].each do |iface, iface_v|
next if iface_v.nil? || !iface_v.has_key?("addresses")
iface_v["addresses"].each do |addr, addr_v|
next if addr_v.nil? or not addr_v.has_key? "family" or addr_v["family"] != family
next if addr_v.nil? || (not addr_v.has_key? "family") || addr_v["family"] != family
ipaddresses << {
:ipaddress => addr_v["prefixlen"] ? IPAddress("#{addr}/#{addr_v["prefixlen"]}") : IPAddress("#{addr}/#{addr_v["netmask"]}"),
:scope => addr_v["scope"].nil? ? nil : addr_v["scope"].downcase,
Expand Down Expand Up @@ -106,7 +106,7 @@ def find_ip(family = "inet")
Ohai::Log.debug("[#{family}] no default interface, picking the first ipaddress")
end

return [ nil, nil ] if r.nil? or r.empty?
return [ nil, nil ] if r.nil? || r.empty?

[ r[:ipaddress].to_s, r[:iface] ]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
WINDOWS_ATTRIBUTE_ALIASES = {
"DisplayVersion" => "version",
"Publisher" => "publisher",
"InstallDate" => "installdate"
"InstallDate" => "installdate",
}

collect_data(:linux) do
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
output = so.stdout.split
python[:version] = output[0]
if output.length >= 6
python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].gsub!(/\)/, "")]
python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].delete!(")")]
end

languages[:python] = python if python[:version] and python[:builddate]
languages[:python] = python if python[:version] && python[:builddate]
end
end
end
2 changes: 1 addition & 1 deletion lib/ohai/plugins/sigar/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def flags(flags)
network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
route_data = {}
Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m|
if(m == :flags)
if m == :flags
route_data[m] = flags(route.send(m))
else
route_data[m] = route.send(m)
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/sigar/network_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def flags(flags)
network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
route_data = {}
Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m|
if(m == :flags)
if m == :flags
route_data[m] = flags(route.send(m))
else
route_data[m] = route.send(m)
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/solaris2/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios
# note that a single key just means dmidecode exited with its version
if (dmi.class.to_s == "Mash") and (dmi.keys.length > 1)
if (dmi.class.to_s == "Mash") && (dmi.keys.length > 1)
Ohai::Log.debug("skipping smbios output, since DMI information has already been provided")
return
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/ssh_host_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def extract_keytype?(content)
if sshd_config
File.open(sshd_config) do |conf|
conf.each_line do |line|
if line.match(/^hostkey\s/i)
if line =~ /^hostkey\s/i
pub_file = "#{line.split[1]}.pub"
content = IO.read(pub_file).split
key_type, key_subtype = extract_keytype?(content)
Expand Down
10 changes: 5 additions & 5 deletions lib/ohai/plugins/windows/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def windows_encaps_lookup(encap)
end

iface_instance.keys.each do |i|
if iface_config[i][:ip_enabled] and iface_instance[i][:net_connection_id]
if iface_config[i][:ip_enabled] && iface_instance[i][:net_connection_id]
cint = sprintf("0x%x", iface_instance[i][:interface_index] ? iface_instance[i][:interface_index] : iface_instance[i][:index] ).downcase
iface[cint] = Mash.new
iface[cint][:configuration] = iface_config[i]
Expand All @@ -76,7 +76,7 @@ def windows_encaps_lookup(encap)
ip = iface[cint][:configuration][:ip_address][i]
_ip = IPAddress("#{ip}/#{iface[cint][:configuration][:ip_subnet][i]}")
iface[cint][:addresses][ip] = Mash.new(
:prefixlen => _ip.prefix,
:prefixlen => _ip.prefix
)
if _ip.ipv6?
# inet6 address
Expand All @@ -96,14 +96,14 @@ def windows_encaps_lookup(encap)
# Apparently you can have more than one mac_address? Odd.
[iface[cint][:configuration][:mac_address]].flatten.each do |mac_addr|
iface[cint][:addresses][mac_addr] = {
"family" => "lladdr"
"family" => "lladdr",
}
end
iface[cint][:mtu] = iface[cint][:configuration][:mtu]
iface[cint][:type] = iface[cint][:instance][:adapter_type]
iface[cint][:arp] = {}
iface[cint][:encapsulation] = windows_encaps_lookup(iface[cint][:instance][:adapter_type])
if iface[cint][:configuration][:default_ip_gateway] != nil and iface[cint][:configuration][:default_ip_gateway].size > 0
if iface[cint][:configuration][:default_ip_gateway] != nil && iface[cint][:configuration][:default_ip_gateway].size > 0
network[:default_gateway] = iface[cint][:configuration][:default_ip_gateway].first
network[:default_interface] = cint
end
Expand All @@ -119,7 +119,7 @@ def windows_encaps_lookup(encap)
end
next unless iface[cint]
if line =~ /^\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-fA-F0-9\:-]+)/
iface[cint][:arp][$1] = $2.gsub("-", ":").downcase
iface[cint][:arp][$1] = $2.tr("-", ":").downcase
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/provides_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def all_plugins(attribute_filter = nil)
private

def normalize_and_validate(attribute)
raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: #{attribute}" if attribute.match(/\/\/+/)
raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': #{attribute}" if attribute.match(/\/$/)
raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: #{attribute}" if attribute =~ /\/\/+/
raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': #{attribute}" if attribute =~ /\/$/

parts = attribute.split("/")
parts.shift if parts.length != 0 && parts[0].length == 0 # attribute begins with a '/'
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def run_plugins(safe = false, attribute_filter = nil)
# Users who are migrating from ohai 6 may give one or more Ohai 6 plugin
# names as the +attribute_filter+. In this case we return early because
# the v7 plugin provides map will not have an entry for this plugin.
if attribute_filter and Array(attribute_filter).all? { |filter_item| have_v6_plugin?(filter_item) }
if attribute_filter && Array(attribute_filter).all? { |filter_item| have_v6_plugin?(filter_item) }
return true
end

Expand Down
2 changes: 1 addition & 1 deletion platform_simulation_specs/common/ohai_plugin_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def subsumes?(source, test, path = [], &block)
if source.is_a?( Hash ) && test.is_a?( Hash )
test.all? { |k, v| subsumes?( source[k], v, path.clone << k, &block ) }
else
block.call( path, source, test ) if block
yield(path, source, test) if block
source == test
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/functional/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
describe "#load_all" do
context "when the plugin path contains backslash characters", :windows_only do
let(:plugin_directory) { Dir.mktmpdir("plugins") }
let(:plugin_path) { plugin_directory.gsub("/", "\\") }
let(:plugin_path) { plugin_directory.tr("/", "\\") }

before(:each) do
Ohai.config[:plugin_path] = plugin_path
Expand Down
14 changes: 7 additions & 7 deletions spec/unit/plugins/digital_ocean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
"eth0" => {
"addresses" => {
"00:D3:AD:B3:3F:00" => {
"family" => "lladdr"
"family" => "lladdr",
},
"1.2.3.4" => {
"netmask" => "255.255.255.0"
"netmask" => "255.255.255.0",
},
"2400:6180:0000:00d0:0000:0000:0009:7001" => {},
}
}
}
},
},
},
}

allow(File).to receive(:exist?).with(hint_path_nix).and_return(true)
Expand Down Expand Up @@ -132,10 +132,10 @@
@plugin[:network][:interfaces][:eth1] = {
"addresses" => {
"10.128.142.89" => {
"netmask" => "255.255.255.0"
"netmask" => "255.255.255.0",
},
"fdf8:f53b:82e4:0000:0000:0000:0000:0053" => {},
}
},
}

@plugin.run
Expand Down
Loading

0 comments on commit 8f48805

Please sign in to comment.