diff options
38 files changed, 347 insertions, 307 deletions
@@ -5,7 +5,7 @@ gemspec group :development do gem "sigar", :platform => "ruby" - gem "chefstyle", "= 0.3.1" + gem "chefstyle", "= 0.4.0" gem "overcommit", ">= 0.34.1" gem "pry-byebug" gem "pry-stack_explorer" diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb index 2b5e2ff4..3bd4da39 100644 --- a/lib/ohai/common/dmi.rb +++ b/lib/ohai/common/dmi.rb @@ -24,7 +24,7 @@ module Ohai # all-lowercase, all non-alphanumeric converted to '_' # 128-255 are 'oem_data_[id]' # Everything else is 'unknown' - IdToDescription = { + ID_TO_DESCRIPTION = { 0 => "bios", 1 => "system", 2 => "base_board", @@ -71,7 +71,7 @@ module Ohai # list of IDs to collect, otherwise we generate pages of hashes about cache chip size and whatnot # See OHAI-260. When we can give the user a choice, this will be a default. - IdToCapture = [ 0, 1, 2, 3, 4, 6, 11 ] + ID_TO_CAPTURE = [ 0, 1, 2, 3, 4, 6, 11 ] # look up DMI ID def id_lookup(id) @@ -79,8 +79,8 @@ module Ohai id = id.to_i if (id >= 128) && (id <= 255) id = "oem_data_#{id}" - elsif DMI::IdToDescription.has_key?(id) - id = DMI::IdToDescription[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" @@ -95,12 +95,12 @@ module Ohai # for single occurrences of one type, copy to top level all fields and values # for multiple occurrences of same type, copy to top level all fields and values that are common to all records def convenience_keys(dmi) - dmi.each { |type, records| + dmi.each do |type, records| in_common = Mash.new next unless records.class.to_s == "Mash" next unless records.has_key?("all_records") - records[:all_records].each { |record| - record.each { |field, value| + records[:all_records].each do |record| + record.each do |field, value| next if value.class.to_s == "Mash" next if field.to_s == "application_identifier" next if field.to_s == "size" @@ -112,13 +112,13 @@ module Ohai else in_common[translated] = value end - } - } - in_common.each { |field, value| + end + end + in_common.each do |field, value| next if value == nil dmi[type][field] = value.strip - } - } + end + end end module_function :id_lookup, :convenience_keys diff --git a/lib/ohai/config.rb b/lib/ohai/config.rb index e617ecbb..f7e1f518 100644 --- a/lib/ohai/config.rb +++ b/lib/ohai/config.rb @@ -31,29 +31,28 @@ module Ohai # These methods need to be defined before they are used as config defaults, # otherwise they will get method_missing'd to nil. - private - - def self.default_hints_path - [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ] - end - - def self.default_plugin_path - [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")) ] - end + class << self + def merge_deprecated_config + [ :hints_path, :plugin_path ].each do |option| + if has_key?(option) && send(option) != send("default_#{option}".to_sym) + Ohai::Log.warn(option_deprecated(option)) + end + end - public + ohai.merge!(configuration) + end - # Copy deprecated configuration options into the ohai config context. - def self.merge_deprecated_config - [ :hints_path, :plugin_path ].each do |option| - if has_key?(option) && send(option) != send("default_#{option}".to_sym) - Ohai::Log.warn(option_deprecated(option)) - end + def default_hints_path + [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ] end - ohai.merge!(configuration) + def default_plugin_path + [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")) ] + end end + # Copy deprecated configuration options into the ohai config context. + # Keep "old" config defaults around so anyone calling Ohai::Config[:key] # won't be broken. Also allows users to append to configuration options # (e.g., Ohai::Config[:plugin_path] << some_path) in their config files. @@ -86,8 +85,11 @@ module Ohai # Furthermore, when the top-level config settings are removed we will # need to ensure that Ohai.config[:log_level] can be set by writing # log_level in a configuration file for consistent behavior with chef. - deprecation_warning = [ :log_level, :log_location ].include?(value) ? - option_might_be_deprecated(option) : option_deprecated(option) + deprecation_warning = if [ :log_level, :log_location ].include?(value) + option_might_be_deprecated(option) + else + option_deprecated(option) + end Ohai::Log.warn(deprecation_warning) value end @@ -102,22 +104,22 @@ module Ohai default :plugin_path, Ohai::Config.default_plugin_path end - private - - def self.option_deprecated(option) - <<-EOM.chomp!.tr("\n", " ") + class << self + def option_deprecated(option) + <<-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 + EOM + end - def self.option_might_be_deprecated(option) - option_deprecated(option) + <<-EOM.chomp!.tr("\n", " ") + def option_might_be_deprecated(option) + 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. -EOM + EOM + end end end diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index 72bfb621..0468a6de 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -35,7 +35,7 @@ module Ohai # specified by calling `require_plugin` with a relative path. To manage # this, we track the path and root of each file as we discover them so we # can feed this into the v6 "dependency solver" as we load them. - class PluginFile < Struct.new(:path, :plugin_root) + PluginFile = Struct.new(:path, :plugin_root) do # Finds all the *.rb files under the configured paths in :plugin_path def self.find_all_in(plugin_dir) diff --git a/lib/ohai/mixin/command.rb b/lib/ohai/mixin/command.rb index a17d8917..04a4f63f 100644 --- a/lib/ohai/mixin/command.rb +++ b/lib/ohai/mixin/command.rb @@ -177,7 +177,7 @@ module Ohai $VERBOSE = nil ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) - cid = fork { + cid = fork do Process.setsid pw.last.close @@ -226,7 +226,7 @@ module Ohai end ps.last.close unless ps.last.closed? exit! - } + end ensure $VERBOSE = verbose end diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb index 9fb019ef..bcda1c4a 100644 --- a/lib/ohai/plugins/dmi.rb +++ b/lib/ohai/plugins/dmi.rb @@ -75,7 +75,7 @@ Ohai.plugin(:DMI) do elsif handle = handle_line.match(line) # Don't overcapture for now (OHAI-260) - unless Ohai::Common::DMI::IdToCapture.include?(handle[2].to_i) + unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i) dmi_record = nil next end diff --git a/lib/ohai/plugins/ip_scopes.rb b/lib/ohai/plugins/ip_scopes.rb index 1eb2dea1..4d8d61d8 100644 --- a/lib/ohai/plugins/ip_scopes.rb +++ b/lib/ohai/plugins/ip_scopes.rb @@ -24,10 +24,10 @@ Ohai.plugin(:IpScopes) do begin require "ipaddr_extensions" - network["interfaces"].keys.sort.each do |ifName| - next if network["interfaces"][ifName]["addresses"].nil? + network["interfaces"].keys.sort.each do |if_name| + next if network["interfaces"][if_name]["addresses"].nil? - interface = network["interfaces"][ifName] + interface = network["interfaces"][if_name] interface["addresses"].each do |address, attrs| begin attrs["ip_scope"] = address.to_ip.scope diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index dbe8cd18..98c95245 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -380,7 +380,7 @@ Ohai.plugin(:Network) do end def interface_address_not_link_level?(iface, address) - iface[:addresses][address][:scope].downcase != "link" + !iface[:addresses][address][:scope].casecmp("link").zero? end def interface_valid_for_route?(iface, address, family) diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb index 52612120..282f8e14 100644 --- a/lib/ohai/plugins/rackspace.rb +++ b/lib/ohai/plugins/rackspace.rb @@ -38,7 +38,7 @@ Ohai.plugin(:Rackspace) do def has_rackspace_metadata? so = shell_out("xenstore-read vm-data/provider_data/provider") if so.exitstatus == 0 - so.stdout.strip.downcase == "rackspace" + so.stdout.strip.casecmp("rackspace").zero? end rescue Ohai::Exceptions::Exec false @@ -115,9 +115,9 @@ Ohai.plugin(:Rackspace) do if so.exitstatus == 0 networks = [] so.stdout.split("\n").map { |l| l.split("=").first.strip }.map do |item| - _so = shell_out("xenstore-read vm-data/networking/#{item}") - if _so.exitstatus == 0 - networks.push(FFI_Yajl::Parser.new.parse(_so.stdout)) + so = shell_out("xenstore-read vm-data/networking/#{item}") + if so.exitstatus == 0 + networks.push(FFI_Yajl::Parser.new.parse(so.stdout)) else Ohai::Log.debug("rackspace plugin: Unable to capture custom private networking information for Rackspace cloud") return false diff --git a/lib/ohai/plugins/solaris2/dmi.rb b/lib/ohai/plugins/solaris2/dmi.rb index 93423830..3f98dbfe 100644 --- a/lib/ohai/plugins/solaris2/dmi.rb +++ b/lib/ohai/plugins/solaris2/dmi.rb @@ -129,7 +129,7 @@ Ohai.plugin(:DMI) do id = smb_to_id[header_information[3]] # Don't overcapture for now (OHAI-260) - unless Ohai::Common::DMI::IdToCapture.include?(id) + unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(id) dmi_record = nil next end diff --git a/lib/ohai/plugins/solaris2/filesystem.rb b/lib/ohai/plugins/solaris2/filesystem.rb index 263ae037..9eceac80 100644 --- a/lib/ohai/plugins/solaris2/filesystem.rb +++ b/lib/ohai/plugins/solaris2/filesystem.rb @@ -44,10 +44,10 @@ Ohai.plugin(:Filesystem) do so.stdout.lines do |line| next unless line =~ /^(.+?)\s*: (\S+)\s*$/ mount = $1 - fs.each { |filesystem, fs_attributes| + fs.each do |filesystem, fs_attributes| next unless fs_attributes[:mount] == mount fs[filesystem][:fs_type] = $2 - } + end end # Grab mount information from /bin/mount @@ -82,7 +82,7 @@ Ohai.plugin(:Filesystem) do zfs[filesystem][:sources][$2] = $4.chomp end - zfs.each { |filesystem, attributes| + zfs.each do |filesystem, attributes| fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:fs_type] = "zfs" fs[filesystem][:mount] = attributes[:values][:mountpoint] if attributes[:values].has_key?("mountpoint") @@ -91,14 +91,14 @@ Ohai.plugin(:Filesystem) do # find all zfs parents parents = filesystem.split("/") zfs_parents = [] - (0..parents.length - 1).to_a.each { |parent_indexes| + (0..parents.length - 1).to_a.each do |parent_indexes| next_parent = parents[0..parent_indexes].join("/") zfs_parents.push(next_parent) - } + end zfs_parents.pop fs[filesystem][:zfs_parents] = zfs_parents fs[filesystem][:zfs_zpool] = (zfs_parents.length == 0) - } + end # Set the filesystem data filesystem fs diff --git a/lib/ohai/plugins/solaris2/network.rb b/lib/ohai/plugins/solaris2/network.rb index 858d5183..7a2a47bc 100644 --- a/lib/ohai/plugins/solaris2/network.rb +++ b/lib/ohai/plugins/solaris2/network.rb @@ -170,14 +170,14 @@ Ohai.plugin(:Network) do matches = /interface: (?<name>\S+)\s+index\s+(?<index>\d+)/.match(line) if matches network[:default_interface] = - case - when iface[matches[:name]] - matches[:name] - when int_name = full_interface_name(iface, matches[:name], matches[:index]) - int_name - else - matches[:name] - end + case + when iface[matches[:name]] + matches[:name] + when int_name = full_interface_name(iface, matches[:name], matches[:index]) + int_name + else + matches[:name] + end Ohai::Log.debug("found interface device: #{network[:default_interface]} #{matches[:name]}") end matches = /gateway: (\S+)/.match(line) diff --git a/lib/ohai/plugins/windows/cpu.rb b/lib/ohai/plugins/windows/cpu.rb index 7d07c5f0..ccb29c86 100644 --- a/lib/ohai/plugins/windows/cpu.rb +++ b/lib/ohai/plugins/windows/cpu.rb @@ -54,9 +54,11 @@ Ohai.plugin(:CPU) do cpu[current_cpu]["vendor_id"] = processor["manufacturer"] cpu[current_cpu]["family"] = processor["family"].to_s cpu[current_cpu]["model"] = processor["revision"].to_s - cpu[current_cpu]["stepping"] = processor["stepping"].nil? \ - ? processor["description"].match(/Stepping\s+(\d+)/)[1] \ - : processor["stepping"] + cpu[current_cpu]["stepping"] = if processor["stepping"].nil? + processor["description"].match(/Stepping\s+(\d+)/)[1] + else + processor["stepping"] + end cpu[current_cpu]["physical_id"] = processor["deviceid"] cpu[current_cpu]["model_name"] = processor["description"] cpu[current_cpu]["mhz"] = processor["maxclockspeed"].to_s diff --git a/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb index 79495378..8ae050e6 100644 --- a/lib/ohai/plugins/windows/network.rb +++ b/lib/ohai/plugins/windows/network.rb @@ -74,21 +74,21 @@ Ohai.plugin(:Network) do iface[cint][:addresses] = Mash.new iface[cint][:configuration][:ip_address].each_index do |i| ip = iface[cint][:configuration][:ip_address][i] - _ip = IPAddress("#{ip}/#{iface[cint][:configuration][:ip_subnet][i]}") + ip2 = IPAddress("#{ip}/#{iface[cint][:configuration][:ip_subnet][i]}") iface[cint][:addresses][ip] = Mash.new( - :prefixlen => _ip.prefix + :prefixlen => ip2.prefix ) - if _ip.ipv6? + if ip2.ipv6? # inet6 address iface[cint][:addresses][ip][:family] = "inet6" iface[cint][:addresses][ip][:scope] = "Link" if ip =~ /^fe80/i else # should be an inet4 address - iface[cint][:addresses][ip][:netmask] = _ip.netmask.to_s + iface[cint][:addresses][ip][:netmask] = ip2.netmask.to_s if iface[cint][:configuration][:ip_use_zero_broadcast] - iface[cint][:addresses][ip][:broadcast] = _ip.network.to_s + iface[cint][:addresses][ip][:broadcast] = ip2.network.to_s else - iface[cint][:addresses][ip][:broadcast] = _ip.broadcast.to_s + iface[cint][:addresses][ip][:broadcast] = ip2.broadcast.to_s end iface[cint][:addresses][ip][:family] = "inet" end diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb index 967c96ea..d687c7b3 100644 --- a/lib/ohai/runner.rb +++ b/lib/ohai/runner.rb @@ -76,9 +76,9 @@ module Ohai # Remove the already ran plugins from dependencies if force is not set # Also remove the plugin that we are about to run from dependencies as well. - dependency_providers.delete_if { |dep_plugin| + dependency_providers.delete_if do |dep_plugin| dep_plugin.has_run? || dep_plugin.eql?(next_plugin) - } + end if dependency_providers.empty? @safe_run ? next_plugin.safe_run : next_plugin.run diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index 17642814..c55383ca 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -94,9 +94,9 @@ module Ohai # Then run all the version 7 plugins begin - @provides_map.all_plugins(attribute_filter).each { |plugin| + @provides_map.all_plugins(attribute_filter).each do |plugin| @runner.run_plugin(plugin) - } + end rescue Ohai::Exceptions::AttributeNotFound, Ohai::Exceptions::DependencyCycle => e Ohai::Log.error("Encountered error while running plugins: #{e.inspect}") raise diff --git a/platform_simulation_specs/common/ohai_plugin_common.rb b/platform_simulation_specs/common/ohai_plugin_common.rb index 3e5970c7..a8f8ba8b 100644 --- a/platform_simulation_specs/common/ohai_plugin_common.rb +++ b/platform_simulation_specs/common/ohai_plugin_common.rb @@ -60,8 +60,6 @@ module OhaiPluginCommon def read_output( cmd, path = "#{data_path}" ) #using an anonymous class to minimize scoping issues. @data = Class.new do - @instances - #DSL - make a list of hashes with def push(param, value) @instances ||= [] diff --git a/spec/functional/application_spec.rb b/spec/functional/application_spec.rb index 5c98e6ff..79e8c3ed 100644 --- a/spec/functional/application_spec.rb +++ b/spec/functional/application_spec.rb @@ -35,7 +35,7 @@ RSpec.describe "Ohai::Application" do ARGV.replace(@original_argv) end - describe '#configure_ohai' do + describe "#configure_ohai" do let(:config_content) { "" } let(:config_dir) { Dir.mktmpdir(".chef") } diff --git a/spec/support/integration_helper.rb b/spec/support/integration_helper.rb index ce61b3f1..38554e40 100644 --- a/spec/support/integration_helper.rb +++ b/spec/support/integration_helper.rb @@ -18,7 +18,7 @@ module IntegrationSupport end end - def with_plugin(plugin_path, contents) + def with_plugin(plugin_path, contents) # rubocop:disable Lint/NestedMethodDefinition filename = path_to(plugin_path) dir = File.dirname(filename) FileUtils.mkdir_p(dir) unless dir == "." @@ -27,11 +27,11 @@ module IntegrationSupport end end - def path_to(plugin_path) + def path_to(plugin_path) # rubocop:disable Lint/NestedMethodDefinition File.expand_path(plugin_path, @plugins_directory) end - def self.with_plugin(plugin_path, contents) + def self.with_plugin(plugin_path, contents) # rubocop:disable Lint/NestedMethodDefinition before :each do with_plugin(plugin_path, contents) end diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 0f45786e..e815063f 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -34,7 +34,7 @@ RSpec.describe "Ohai::Application" do ARGV.replace(@original_argv) end - describe '#configure_ohai' do + describe "#configure_ohai" do describe "loading configuration from a file" do let(:config_file) { "/local/workstation/config" } let(:config_loader) { instance_double("ChefConfig::WorkstationConfigLoader") } diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb index 2a35701c..0b3c158a 100644 --- a/spec/unit/dsl/plugin_spec.rb +++ b/spec/unit/dsl/plugin_spec.rb @@ -170,10 +170,10 @@ shared_examples "Ohai::DSL::Plugin" do describe "and an intermediate key is not a hash" do it "raises a TypeError" do - expect { + expect do plugin.get_attribute("the_monarch", "arch_rival", "dr_venture", "since") - }.to raise_error(TypeError, + end.to raise_error(TypeError, "Expected Hash but got String.") end end @@ -204,10 +204,10 @@ shared_examples "Ohai::DSL::Plugin" do describe "and an intermediate key is not a hash" do it "raises a TypeError" do - expect { + expect do plugin.get_attribute(:the_monarch, :arch_rival, :dr_venture, :since) - }.to raise_error(TypeError, + end.to raise_error(TypeError, "Expected Hash but got String.") end end @@ -277,10 +277,10 @@ shared_examples "Ohai::DSL::Plugin" do describe "and an intermediate key is not a hash" do it "raises a TypeError" do - expect { + expect do plugin.attribute?("the_monarch", "arch_rival", "dr_venture", "since") - }.to raise_error(TypeError, + end.to raise_error(TypeError, "Expected Hash but got String.") end end @@ -310,10 +310,10 @@ shared_examples "Ohai::DSL::Plugin" do describe "and an intermediate key is not a hash" do it "raises a TypeError" do - expect { + expect do plugin.attribute?(:the_monarch, :arch_rival, :dr_venture, :since) - }.to raise_error(TypeError, + end.to raise_error(TypeError, "Expected Hash but got String.") end end @@ -369,11 +369,11 @@ describe Ohai::DSL::Plugin::VersionVII do end it "collects from multiple provides statements" do - plugin = Ohai.plugin(:Test) { + plugin = Ohai.plugin(:Test) do provides("one") provides("two", "three") provides("four") - } + end expect(plugin.provides_attrs).to eql(%w{one two three four}) end @@ -402,11 +402,11 @@ describe Ohai::DSL::Plugin::VersionVII do end it "collects from multiple depends statements" do - plugin = Ohai.plugin(:Test) { + plugin = Ohai.plugin(:Test) do depends("one") depends("two", "three") depends("four") - } + end expect(plugin.depends_attrs).to eql(%w{one two three four}) end @@ -442,11 +442,11 @@ describe Ohai::DSL::Plugin::VersionVII do end it "saves multiple collect_data blocks" do - plugin = Ohai.plugin(:Test) { + plugin = Ohai.plugin(:Test) do collect_data {} collect_data(:windows) {} collect_data(:darwin) {} - } + end [:darwin, :default, :windows].each do |platform| expect(plugin.data_collector).to have_key(platform) end @@ -461,21 +461,21 @@ describe Ohai::DSL::Plugin::VersionVII do end it "fails a platform has already been defined in the same plugin" do - expect { - Ohai.plugin(:Test) { + expect do + Ohai.plugin(:Test) do collect_data {} collect_data {} - } - }.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/) + end + end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/) end it "fails if a platform has already been defined in another plugin file" do Ohai.plugin(:Test) { collect_data {} } - expect { - Ohai.plugin(:Test) { + expect do + Ohai.plugin(:Test) do collect_data {} - } - }.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/) + end + end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/) end end diff --git a/spec/unit/mixin/ec2_metadata_spec.rb b/spec/unit/mixin/ec2_metadata_spec.rb index 002b42c2..2bd867d0 100644 --- a/spec/unit/mixin/ec2_metadata_spec.rb +++ b/spec/unit/mixin/ec2_metadata_spec.rb @@ -20,13 +20,13 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") require "ohai/mixin/ec2_metadata" describe Ohai::Mixin::Ec2Metadata do - let(:mixin) { + let(:mixin) do metadata_object = Object.new.extend(Ohai::Mixin::Ec2Metadata) http_client = double("Net::HTTP client") allow(http_client).to receive(:get).and_return(response) allow(metadata_object).to receive(:http_client).and_return(http_client) metadata_object - } + end context "#best_api_version" do context "with a sorted list of metadata versions" do diff --git a/spec/unit/mixin/softlayer_metadata_spec.rb b/spec/unit/mixin/softlayer_metadata_spec.rb index f69ba0b2..a4719685 100644 --- a/spec/unit/mixin/softlayer_metadata_spec.rb +++ b/spec/unit/mixin/softlayer_metadata_spec.rb @@ -22,10 +22,10 @@ require "ohai/mixin/softlayer_metadata" describe ::Ohai::Mixin::SoftlayerMetadata do - let(:mixin) { + let(:mixin) do mixin = Object.new.extend(::Ohai::Mixin::SoftlayerMetadata) mixin - } + end def make_request(item) "/rest/v3.1/SoftLayer_Resource_Metadata/#{item}" diff --git a/spec/unit/plugin_config_spec.rb b/spec/unit/plugin_config_spec.rb index 1391a2a5..5cf9f6d9 100644 --- a/spec/unit/plugin_config_spec.rb +++ b/spec/unit/plugin_config_spec.rb @@ -52,13 +52,13 @@ describe "Ohai::PluginConfig" do describe "when all Hash keys are symbols" do - let(:value) { + let(:value) do { :bar0 => true, :bar1 => [ :baz0, :baz1, :baz2 ], :bar2 => { :qux0 => true, :qux1 => false }, } - } + end include_examples "success" @@ -66,13 +66,13 @@ describe "Ohai::PluginConfig" do describe "when some top-level Hash key is not a symbol" do - let(:value) { + let(:value) do { :bar0 => true, "bar1" => [ :baz0, :baz1, :baz2 ], :bar2 => { :qux0 => true, :qux1 => false }, } - } + end include_examples "failure" @@ -80,13 +80,13 @@ describe "Ohai::PluginConfig" do describe "when some nested Hash key is not a symbol" do - let(:value) { + let(:value) do { :bar0 => true, :bar1 => [ :baz0, :baz1, :baz2 ], :bar2 => { :qux0 => true, "qux1" => false }, } - } + end include_examples "failure" diff --git a/spec/unit/plugins/aix/cpu_spec.rb b/spec/unit/plugins/aix/cpu_spec.rb index d782ced0..5cafedc8 100644 --- a/spec/unit/plugins/aix/cpu_spec.rb +++ b/spec/unit/plugins/aix/cpu_spec.rb @@ -20,12 +20,12 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") describe Ohai::System, "AIX cpu plugin" do before(:each) do - @lsdev_Cc_processor = <<-LSDEV_CC_PROCESSOR + @lsdev_cc_processor = <<-LSDEV_CC_PROCESSOR proc0 Available 00-00 Processor proc4 Defined 00-04 Processor LSDEV_CC_PROCESSOR - @lsattr_El_proc0 = <<-LSATTR_EL + @lsattr_el_proc0 = <<-LSATTR_EL frequency 1654344000 Processor Speed False smt_enabled true Processor SMT enabled False smt_threads 2 Processor SMT threads False @@ -43,8 +43,8 @@ PMCYCLES_M @plugin = get_plugin("aix/cpu") allow(@plugin).to receive(:collect_os).and_return(:aix) - allow(@plugin).to receive(:shell_out).with("lsdev -Cc processor").and_return(mock_shell_out(0, @lsdev_Cc_processor, nil)) - allow(@plugin).to receive(:shell_out).with("lsattr -El proc0").and_return(mock_shell_out(0, @lsattr_El_proc0, nil)) + allow(@plugin).to receive(:shell_out).with("lsdev -Cc processor").and_return(mock_shell_out(0, @lsdev_cc_processor, nil)) + allow(@plugin).to receive(:shell_out).with("lsattr -El proc0").and_return(mock_shell_out(0, @lsattr_el_proc0, nil)) allow(@plugin).to receive(:shell_out).with("pmcycles -m").and_return(mock_shell_out(0, @pmcycles_m, nil)) end @@ -119,9 +119,9 @@ PMCYCLES_M it "doesn't set mhz of a processor it can't see" do # I'm so sorry - expect { + expect do expect(@plugin[:cpu]["0"][:mhz]).to eq(1654) - }.to raise_error(NoMethodError) + end.to raise_error(NoMethodError) end end end diff --git a/spec/unit/plugins/aix/filesystem_spec.rb b/spec/unit/plugins/aix/filesystem_spec.rb index b71e5f81..33d63af7 100644 --- a/spec/unit/plugins/aix/filesystem_spec.rb +++ b/spec/unit/plugins/aix/filesystem_spec.rb @@ -19,7 +19,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") describe Ohai::System, "AIX filesystem plugin" do before(:each) do - @df_Pk_LPAR = <<-DF_PK + @df_pk_lpar = <<-DF_PK Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hd4 2097152 219796 1877356 11% / /dev/hd2 5242880 2416828 2826052 47% /usr @@ -46,7 +46,7 @@ Filesystem 1024-blocks Used Available Capacity Mounted on /dev/fslv12 10485760 272376 10213384 3% /wpars/toolchain-tester-5c969f/var DF_PK - @df_Pk_WPAR = <<-DF_PK + @df_pk_wpar = <<-DF_PK Filesystem 1024-blocks Used Available Capacity Mounted on Global 10485760 130872 10354888 2% / Global 5242880 39572 5203308 1% /home @@ -57,7 +57,7 @@ Global 5242880 2725048 2517832 52% /usr Global 10485760 272376 10213384 3% /var DF_PK - @mount_LPAR = <<-MOUNT + @mount_lpar = <<-MOUNT node mounted mounted over vfs date options -------- --------------- --------------- ------ ------------ --------------- /dev/hd4 / jfs2 Jul 17 13:22 rw,log=/dev/hd8 @@ -71,7 +71,7 @@ DF_PK 192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys MOUNT - @mount_WPAR = <<-MOUNT + @mount_wpar = <<-MOUNT node mounted mounted over vfs date options -------- --------------- --------------- ------ ------------ --------------- Global / jfs2 Nov 23 21:03 rw,log=NULL @@ -91,8 +91,8 @@ MOUNT context "when run within an LPAR" do before do - allow(@plugin).to receive(:shell_out).with("df -Pk").and_return(mock_shell_out(0, @df_Pk_LPAR, nil)) - allow(@plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @mount_LPAR, nil)) + allow(@plugin).to receive(:shell_out).with("df -Pk").and_return(mock_shell_out(0, @df_pk_lpar, nil)) + allow(@plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @mount_lpar, nil)) @plugin.run end @@ -153,8 +153,8 @@ MOUNT context "when run within a WPAR" do before do - allow(@plugin).to receive(:shell_out).with("df -Pk").and_return(mock_shell_out(0, @df_Pk_WPAR, nil)) - allow(@plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @mount_WPAR, nil)) + allow(@plugin).to receive(:shell_out).with("df -Pk").and_return(mock_shell_out(0, @df_pk_wpar, nil)) + allow(@plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @mount_wpar, nil)) @plugin.run end diff --git a/spec/unit/plugins/aix/virtualization_spec.rb b/spec/unit/plugins/aix/virtualization_spec.rb index 3d968e19..4d07f814 100644 --- a/spec/unit/plugins/aix/virtualization_spec.rb +++ b/spec/unit/plugins/aix/virtualization_spec.rb @@ -27,12 +27,12 @@ describe Ohai::System, "AIX virtualization plugin" do allow(p).to receive(:collect_os).and_return(:aix) allow(p).to receive(:shell_out).with("uname -L").and_return(mock_shell_out(0, "29 l273pp027", nil)) allow(p).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "0", nil)) - allow(p).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, @lswpar_L, nil)) + allow(p).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, @lswpar_l, nil)) p end before(:each) do - @lswpar_L = <<-LSWPAR_L + @lswpar_l = <<-LSWPAR_L ================================================================= applejack-541ba3 - Active ================================================================= diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb index dfa4f728..63238114 100644 --- a/spec/unit/plugins/azure_spec.rb +++ b/spec/unit/plugins/azure_spec.rb @@ -21,7 +21,7 @@ require "open-uri" describe Ohai::System, "plugin azure" do let(:plugin) { get_plugin("azure") } - let(:hint) { + let(:hint) do { "public_ip" => "137.135.46.202", "vm_name" => "test-vm", @@ -29,7 +29,7 @@ describe Ohai::System, "plugin azure" do "public_ssh_port" => "22", "public_winrm_port" => "5985", } - } + end shared_examples_for "!azure" do it "does not set the azure attribute" do diff --git a/spec/unit/plugins/darwin/hardware_spec.rb b/spec/unit/plugins/darwin/hardware_spec.rb index 65f3cd4f..de69f3ee 100644 --- a/spec/unit/plugins/darwin/hardware_spec.rb +++ b/spec/unit/plugins/darwin/hardware_spec.rb @@ -27,7 +27,7 @@ describe Ohai::System, "Darwin hardware plugin", :unix_only do allow(plugin).to receive(:shell_out).with( "system_profiler SPHardwareDataType -xml" ).and_return( - mock_shell_out(0, HardwareSystemProfilerOutput::Hardware, "") + mock_shell_out(0, HardwareSystemProfilerOutput::HARDWARE, "") ) allow(plugin).to receive(:shell_out).with( @@ -57,13 +57,13 @@ describe Ohai::System, "Darwin hardware plugin", :unix_only do allow(plugin).to receive(:shell_out).with( "system_profiler SPStorageDataType -xml" ).and_return( - mock_shell_out(0, HardwareSystemProfilerOutput::Storage, "") + mock_shell_out(0, HardwareSystemProfilerOutput::STORAGE, "") ) allow(plugin).to receive(:shell_out).with( "system_profiler SPPowerDataType -xml" ).and_return( - mock_shell_out(0, HardwareSystemProfilerOutput::Power, "") + mock_shell_out(0, HardwareSystemProfilerOutput::POWER, "") ) end diff --git a/spec/unit/plugins/darwin/hardware_system_profiler_output.rb b/spec/unit/plugins/darwin/hardware_system_profiler_output.rb index 086ebec0..d56f2223 100644 --- a/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +++ b/spec/unit/plugins/darwin/hardware_system_profiler_output.rb @@ -1,5 +1,5 @@ module HardwareSystemProfilerOutput - Hardware = <<hardware_output + HARDWARE = <<hardware_output <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> @@ -289,7 +289,7 @@ module HardwareSystemProfilerOutput </plist> hardware_output - Storage = <<storage_output + STORAGE = <<storage_output <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> @@ -600,7 +600,7 @@ hardware_output </plist> storage_output - Power = <<power_output + POWER = <<power_output <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> diff --git a/spec/unit/plugins/digital_ocean_spec.rb b/spec/unit/plugins/digital_ocean_spec.rb index 64374755..45b0109d 100644 --- a/spec/unit/plugins/digital_ocean_spec.rb +++ b/spec/unit/plugins/digital_ocean_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "plugin digital_ocean" do let(:plugin) { get_plugin("digital_ocean") } let(:digitalocean_path) { "/etc/digitalocean" } - let(:hint) { + let(:hint) do { "droplet_id" => 12345678, "name" => "example.com", @@ -33,7 +33,7 @@ describe Ohai::System, "plugin digital_ocean" do "private" => "5.6.7.8", }, } - } + end before do plugin[:network] = { diff --git a/spec/unit/plugins/init_package_spec.rb b/spec/unit/plugins/init_package_spec.rb index 29532c1d..c34fb654 100644 --- a/spec/unit/plugins/init_package_spec.rb +++ b/spec/unit/plugins/init_package_spec.rb @@ -19,11 +19,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) describe Ohai::System, "Init package" do - let(:plugin) { + let(:plugin) do p = get_plugin("init_package") allow(p).to receive(:collect_os).and_return("linux") p - } + end let(:proc1_content) { "init\n" } let(:proc1_exists) { true } diff --git a/spec/unit/plugins/ip_scopes_spec.rb b/spec/unit/plugins/ip_scopes_spec.rb index b0b600d0..4a808949 100644 --- a/spec/unit/plugins/ip_scopes_spec.rb +++ b/spec/unit/plugins/ip_scopes_spec.rb @@ -8,9 +8,10 @@ end describe Ohai::System, "plugin ip_scopes" do let(:plugin) { get_plugin("ip_scopes") } let(:network) { Mash.new(:interfaces => interfaces) } - let(:interfaces) { Hash[ + let(:interfaces) do + Hash[ interface1, { :addresses => addresses1, :type => interface1_type }, - interface2, { :addresses => addresses2, :type => interface2_type }] } + interface2, { :addresses => addresses2, :type => interface2_type }] end let(:interface1) { :eth0 } let(:interface2) { :eth1 } let(:addresses1) { {} } diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index e2037fc3..6e78997f 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -29,7 +29,8 @@ end describe Ohai::System, "Linux Network Plugin" do let(:plugin) { get_plugin("linux/network") } - let(:linux_ifconfig) { <<-EOM + let(:linux_ifconfig) do + <<-EOM eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2 inet addr:10.116.201.76 Bcast:10.116.201.255 Mask:255.255.255.0 inet6 addr: fe80::1031:3dff:fe02:bea2/64 Scope:Link @@ -149,9 +150,10 @@ fwdintf Link encap:Ethernet HWaddr 00:00:00:00:00:0a EOM # Note that ifconfig shows foo:veth0@eth0 but fails to show any address information. # This was not a mistake collecting the output and Apparently ifconfig is broken in this regard. - } + end - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/24 dev eth0 proto kernel 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 @@ -160,26 +162,29 @@ EOM 10.5.4.0/24 \\ nexthop via 10.5.4.1 dev eth0 weight 1\\ nexthop via 10.5.4.2 dev eth0 weight 1 default via 10.116.201.1 dev eth0 EOM - } + end - let(:linux_route_n) { <<-EOM + let(:linux_route_n) do + <<-EOM Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0 EOM - } + end - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 EOM - } + end - let(:linux_ip_addr) { <<-EOM + let(:linux_ip_addr) do + <<-EOM 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo @@ -236,9 +241,10 @@ EOM 13: fwdintf: <MULTICAST,NOARP,UP,LOWER_UP> mtu 1496 qdisc pfifo_fast state UNKNOWN group default qlen 1000 link/ether 00:00:00:00:00:0a brd ff:ff:ff:ff:ff:ff EOM - } + end - let(:linux_ip_link_s_d) { <<-EOM + let(:linux_ip_link_s_d) do + <<-EOM 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 RX: bytes packets errors dropped overrun mcast @@ -295,26 +301,30 @@ EOM TX: bytes packets errors dropped carrier collsns 140 2 0 1 0 0 EOM - } + end - let(:linux_arp_an) { <<-EOM + let(:linux_arp_an) do + <<-EOM ? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0 EOM - } + end - let(:linux_ip_neighbor_show) { <<-EOM + let(:linux_ip_neighbor_show) do + <<-EOM 10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE EOM - } + end - let(:linux_ip_inet6_neighbor_show) { <<-EOM + let(:linux_ip_inet6_neighbor_show) do + <<-EOM 1111:2222:3333:4444::1 dev eth0.11 lladdr 00:1c:0e:12:34:56 router REACHABLE fe80::21c:eff:fe12:3456 dev eth0.11 lladdr 00:1c:0e:30:28:00 router REACHABLE fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE EOM - } + end - let(:linux_ethtool) { <<-EOM + let(:linux_ethtool) do + <<-EOM Settings for eth0: Supported ports: [ FIBRE ] Supported link modes: 1000baseT/Full @@ -337,9 +347,10 @@ Settings for eth0: drv probe link Link detected: yes EOM - } + end - let(:linux_ethtool_g) { <<-EOM + let(:linux_ethtool_g) do + <<-EOM Ring parameters for eth0: Pre-set maximums: RX: 8192 @@ -353,7 +364,7 @@ RX Jumbo: 0 TX: 8192 EOM - } + end before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) @@ -392,7 +403,7 @@ EOM end end - describe '#interface_has_no_addresses_in_family?' do + describe "#interface_has_no_addresses_in_family?" do context "when interface has no addresses" do let(:iface) { {} } @@ -418,7 +429,7 @@ EOM end end - describe '#interface_have_address?' do + describe "#interface_have_address?" do context "when interface has no addresses" do let(:iface) { {} } @@ -444,7 +455,7 @@ EOM end end - describe '#interface_address_not_link_level?' do + describe "#interface_address_not_link_level?" do context "when the address scope is link" do let(:iface) { { addresses: { "1.2.3.4" => { scope: "Link" } } } } @@ -462,7 +473,7 @@ EOM end end - describe '#interface_valid_for_route?' do + describe "#interface_valid_for_route?" do let(:iface) { double("iface") } let(:address) { "1.2.3.4" } let(:family) { "inet" } @@ -508,7 +519,7 @@ EOM end end - describe '#route_is_valid_default_route?' do + describe "#route_is_valid_default_route?" do context "when the route destination is default" do let(:route) { { destination: "default" } } let(:default_route) { double("default_route") } @@ -722,19 +733,21 @@ EOM end describe "with a link level default route" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/24 dev eth0 proto kernel default dev eth0 scope link EOM - } + end - let(:linux_route_n) { <<-EOM + let(:linux_route_n) do + <<-EOM Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0 EOM - } + end before(:each) do plugin.run @@ -750,19 +763,21 @@ EOM end describe "with a subinterface" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 192.168.0.0/24 dev eth0.11 proto kernel src 192.168.0.2 default via 192.168.0.15 dev eth0.11 EOM - } + end - let(:linux_route_n) { <<-EOM + let(:linux_route_n) do + <<-EOM Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.11 0.0.0.0 192.168.0.15 0.0.0.0 UG 0 0 0 eth0.11 EOM - } + end before(:each) do plugin.run @@ -857,12 +872,13 @@ EOM end describe "when there isn't a source field in route entries and no ipv6 default routes" do - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec EOM - } + end before(:each) do plugin.run @@ -882,7 +898,8 @@ EOM end describe "when there's a source field in the default route entry" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/24 dev eth0 proto kernel 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 @@ -890,15 +907,16 @@ EOM 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 default via 10.116.201.1 dev eth0 src 10.116.201.76 EOM - } + end - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 EOM - } + end before(:each) do plugin.run @@ -919,7 +937,8 @@ EOM end describe "when there're several default routes" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 @@ -928,16 +947,17 @@ EOM default via 10.116.201.1 dev eth0 metric 10 default via 10.116.201.254 dev eth0 metric 9 EOM - } + end - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 EOM - } + end before(:each) do plugin.run @@ -960,7 +980,8 @@ EOM end describe "when there're a mixed setup of routes that could be used to set ipaddress" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 @@ -969,16 +990,17 @@ EOM default via 10.116.201.1 dev eth0 metric 10 default via 10.116.201.254 dev eth0 metric 9 src 10.116.201.74 EOM - } + end - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:3333:4444::2 EOM - } + end before(:each) do plugin.run @@ -999,7 +1021,8 @@ EOM end describe "when there's a source field in a local route entry but it isnt in the default route" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 @@ -1007,15 +1030,16 @@ EOM 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 default via 10.116.201.1 dev eth0 EOM - } + end - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 EOM - } + end it "completes the run" do expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/) @@ -1050,11 +1074,12 @@ EOM end context "when then ipv4 interface has the NOARP flag and no ipv6 routes exist" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.118.19.1 dev tun0 proto kernel src 10.118.19.39 default via 172.16.19.1 dev tun0 EOM - } + end let(:linux_ip_route_inet6) { "" } it "completes the run" do @@ -1072,10 +1097,11 @@ EOM end describe "with a link level default route" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM default dev venet0 scope link EOM - } + end before(:each) do plugin.run @@ -1092,10 +1118,11 @@ EOM end describe "with a link level default route to an unaddressed int" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM default dev eth3 scope link EOM - } + end before(:each) do plugin.run @@ -1116,10 +1143,11 @@ EOM end describe "with a link level default route with a source" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM default dev fwdintf scope link src 2.2.2.2 EOM - } + end before(:each) do plugin.run @@ -1140,11 +1168,12 @@ EOM end describe "when not having a global scope ipv6 address" do - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 default via fe80::21c:eff:fe12:3456 dev eth0.153 src fe80::2e0:81ff:fe2b:48e7 metric 1024 EOM - } + end before(:each) do plugin.run end @@ -1161,21 +1190,23 @@ EOM end describe "with no default route" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2 EOM - } + end - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3 EOM - } + end before(:each) do plugin.run @@ -1197,7 +1228,8 @@ EOM describe "with openvz setup" do let(:linux_ip_route) { "default dev venet0 scope link" } - let(:linux_ip_addr) { <<-EOM + let(:linux_ip_addr) do + <<-EOM 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo @@ -1210,7 +1242,7 @@ EOM inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic valid_lft 6128sec preferred_lft 2526sec EOM - } + end # We don't have the corresponding ipv6 data for these tests let(:linux_ip_route_inet6) { "" } let(:linux_ip_inet6_neighbor_show) { "" } @@ -1241,22 +1273,24 @@ EOM end describe "with irrelevant routes (container setups)" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 10.116.201.0/26 dev eth0 proto kernel src 10.116.201.39 10.116.201.0/26 dev if4 proto kernel src 10.116.201.45 10.118.19.0/26 dev eth0 proto kernel src 10.118.19.39 10.118.19.0/26 dev if5 proto kernel src 10.118.19.45 default via 10.116.201.1 dev eth0 src 10.116.201.99 EOM - } + end - let(:linux_ip_route_inet6) { <<-EOM + let(:linux_ip_route_inet6) do + <<-EOM fe80::/64 dev eth0 proto kernel metric 256 fe80::/64 dev eth0.11 proto kernel metric 256 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::FFFF:2 default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 EOM - } + end before(:each) do plugin.run @@ -1284,10 +1318,11 @@ EOM # This should never happen in the real world. describe "when encountering a surprise interface" do - let(:linux_ip_route) { <<-EOM + let(:linux_ip_route) do + <<-EOM 192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1 EOM - } + end it "logs a message and skips previously unseen interfaces in 'ip route show'" do expect(Ohai::Log).to receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once @@ -1297,7 +1332,8 @@ EOM end describe "when running with ip version ss131122" do - let(:linux_ip_link_s_d) { <<-EOM + let(:linux_ip_link_s_d) do + <<-EOM 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN mode DEFAULT group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 RX: bytes packets errors dropped overrun mcast @@ -1330,7 +1366,7 @@ EOM TX: bytes packets errors dropped carrier collsns 691785313 1919690 0 0 0 0 EOM - } + end it "adds the vlan information of an interface" do plugin.run diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index fffa7d51..5bff78e4 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -699,7 +699,7 @@ CISCO_RELEASE end end - describe '#read_os_release_info' do + describe "#read_os_release_info" do let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" } it "returns nil if the file does not exist" do allow(File).to receive(:exist?).with("/etc/test-release").and_return(false) @@ -716,7 +716,7 @@ CISCO_RELEASE end end - describe '#os_release_info' do + describe "#os_release_info" do context "when CISCO_RELEASE_INFO is not populated" do let(:release_info) { { "ID" => "os_id" } } diff --git a/spec/unit/plugins/ruby_spec.rb b/spec/unit/plugins/ruby_spec.rb index c57755f5..9acb35b6 100644 --- a/spec/unit/plugins/ruby_spec.rb +++ b/spec/unit/plugins/ruby_spec.rb @@ -47,8 +47,9 @@ describe Ohai::System, "plugin ruby" do :host_os => ::RbConfig::CONFIG["host_os"], :host_vendor => ::RbConfig::CONFIG["host_vendor"], :gems_dir => `#{ruby_bin} #{::RbConfig::CONFIG["bindir"]}/gem env gemdir`.chomp, - :gem_bin => [ ::Gem.default_exec_format % "gem", "gem" ].map {|bin| "#{::RbConfig::CONFIG['bindir']}/#{bin}" - }.find { |bin| ::File.exists? bin }, + :gem_bin => [ ::Gem.default_exec_format % "gem", "gem" ].map do |bin| + "#{::RbConfig::CONFIG['bindir']}/#{bin}" + end.find { |bin| ::File.exists? bin }, :ruby_bin => ruby_bin, }.each do |attribute, value| it "should have #{attribute} set to #{value.inspect}" do diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index c35ad64d..abbeecd3 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -101,15 +101,15 @@ describe Ohai::Runner, "run_plugin" do end describe "when running a plugin with no dependencies, Ohai::Runner" do - let(:plugin) { - klass = Ohai.plugin(:Test) { + let(:plugin) do + klass = Ohai.plugin(:Test) do provides("thing") - collect_data { + collect_data do thing(Mash.new) - } - } + end + end klass.new(@ohai.data) - } + end it "should run the plugin" do @runner.run_plugin(plugin) @@ -126,13 +126,13 @@ describe Ohai::Runner, "run_plugin" do describe "when running a plugin with one dependency" do describe "when the dependency does not exist" do before(:each) do - klass = Ohai.plugin(:Test) { + klass = Ohai.plugin(:Test) do provides("thing") depends("other_thing") - collect_data { + collect_data do thing(other_thing) - } - } + end + end @plugin = klass.new(@ohai.data) end @@ -148,19 +148,19 @@ describe Ohai::Runner, "run_plugin" do describe "when the dependency has a single provider" do before(:each) do - klass1 = Ohai.plugin(:Thing) { + klass1 = Ohai.plugin(:Thing) do provides("thing") - collect_data { + collect_data do thing("thang") - } - } - klass2 = Ohai.plugin(:Other) { + end + end + klass2 = Ohai.plugin(:Other) do provides("other") depends("thing") - collect_data { + collect_data do other(thing) - } - } + end + end @plugins = [] [klass1, klass2].each do |klass| @@ -181,19 +181,19 @@ describe Ohai::Runner, "run_plugin" do describe "when the dependency has multiple providers" do before(:each) do - klass1 = Ohai.plugin(:Thing) { + klass1 = Ohai.plugin(:Thing) do provides("thing") - collect_data { + collect_data do thing(Mash.new) - } - } - klass2 = Ohai.plugin(:Other) { + end + end + klass2 = Ohai.plugin(:Other) do provides("other") depends("thing") - collect_data { + collect_data do other(thing) - } - } + end + end @plugins = [] [klass1, klass1, klass2].each do |klass| @@ -219,25 +219,25 @@ describe Ohai::Runner, "run_plugin" do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, true) - klass1 = Ohai.plugin(:One) { + klass1 = Ohai.plugin(:One) do provides("one") - collect_data { + collect_data do one(1) - } - } - klass2 = Ohai.plugin(:Two) { + end + end + klass2 = Ohai.plugin(:Two) do provides("two") - collect_data { + collect_data do two(2) - } - } - klass3 = Ohai.plugin(:Three) { + end + end + klass3 = Ohai.plugin(:Three) do provides("three") depends("one", "two") - collect_data { + collect_data do three(3) - } - } + end + end @plugins = [] [klass1, klass2, klass3].each do |klass| @@ -282,20 +282,20 @@ 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) { + klass1 = Ohai.plugin(:Thing) do provides("thing") depends("other") - collect_data { + collect_data do thing(other) - } - } - klass2 = Ohai.plugin(:Other) { + end + end + klass2 = Ohai.plugin(:Other) do provides("other") depends("thing") - collect_data { + collect_data do other(thing) - } - } + end + end @plugins = [] [klass1, klass2].each_with_index do |klass, idx| @@ -319,35 +319,35 @@ describe Ohai::Runner, "run_plugin" do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, true) - klassA = Ohai.plugin(:A) { + klass_a = Ohai.plugin(:A) do provides("A") depends("B", "C") collect_data {} - } - klassB = Ohai.plugin(:B) { + end + klass_b = Ohai.plugin(:B) do provides("B") depends("C") collect_data {} - } - klassC = Ohai.plugin(:C) { + end + klass_c = Ohai.plugin(:C) do provides("C") collect_data {} - } + end @plugins = [] - [klassA, klassB, klassC].each do |klass| + [klass_a, klass_b, klass_c].each do |klass| @plugins << klass.new(@ohai.data) end - @pluginA, @pluginB, @pluginC = @plugins + @plugin_a, @plugin_b, @plugin_c = @plugins end it "should not detect a cycle when B is the first provider returned" do - @ohai.provides_map.set_providers_for(@pluginA, ["A"]) - @ohai.provides_map.set_providers_for(@pluginB, ["B"]) - @ohai.provides_map.set_providers_for(@pluginC, ["C"]) + @ohai.provides_map.set_providers_for(@plugin_a, ["A"]) + @ohai.provides_map.set_providers_for(@plugin_b, ["B"]) + @ohai.provides_map.set_providers_for(@plugin_c, ["C"]) expect(Ohai::Log).not_to receive(:error).with(/DependencyCycleError/) - @runner.run_plugin(@pluginA) + @runner.run_plugin(@plugin_a) @plugins.each do |plugin| expect(plugin.has_run?).to be true @@ -355,12 +355,12 @@ describe Ohai::Runner, "run_plugin" do end it "should not detect a cycle when C is the first provider returned" do - @ohai.provides_map.set_providers_for(@pluginA, ["A"]) - @ohai.provides_map.set_providers_for(@pluginC, ["C"]) - @ohai.provides_map.set_providers_for(@pluginB, ["B"]) + @ohai.provides_map.set_providers_for(@plugin_a, ["A"]) + @ohai.provides_map.set_providers_for(@plugin_c, ["C"]) + @ohai.provides_map.set_providers_for(@plugin_b, ["B"]) expect(Ohai::Log).not_to receive(:error).with(/DependencyCycleError/) - @runner.run_plugin(@pluginA) + @runner.run_plugin(@plugin_a) @plugins.each do |plugin| expect(plugin.has_run?).to be true @@ -414,27 +414,27 @@ describe Ohai::Runner, "#get_cycle" do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, true) - klass1 = Ohai.plugin(:One) { + klass1 = Ohai.plugin(:One) do provides("one") depends("two") - collect_data { + collect_data do one(two) - } - } - klass2 = Ohai.plugin(:Two) { + end + end + klass2 = Ohai.plugin(:Two) do provides("two") depends("one") - collect_data { + collect_data do two(one) - } - } - klass3 = Ohai.plugin(:Three) { + end + end + klass3 = Ohai.plugin(:Three) do provides("three") depends("two") - collect_data { + collect_data do three(two) - } - } + end + end plugins = [] [klass1, klass2, klass3].each_with_index do |klass, idx| diff --git a/spec/unit/util/ip_helper_spec.rb b/spec/unit/util/ip_helper_spec.rb index 766a9636..0532cbc9 100644 --- a/spec/unit/util/ip_helper_spec.rb +++ b/spec/unit/util/ip_helper_spec.rb @@ -78,12 +78,12 @@ describe "Ohai::Util::IpHelper" do allow(ip_helper).to receive(:private_address?) end - it 'should call #private_address?' do + it "should call #private_address?" do expect(ip_helper).to receive(:private_address?) ip_helper.public_address?(address) end - it 'should return the inverse of #private_address?' do + it "should return the inverse of #private_address?" do expect(ip_helper.public_address?(address)).to equal !ip_helper.private_address?(address) end end |