diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-08-19 10:06:27 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-08-19 10:06:27 -0700 |
commit | 719e49d00afc282c2f2d4e0fe20c6e7c39ccc5da (patch) | |
tree | e5d8002c2e1cc9652381dc9d613093458b0a1c92 | |
parent | e756f15f1034757cce5123c7fa9c77ff6627e313 (diff) | |
download | ohai-719e49d00afc282c2f2d4e0fe20c6e7c39ccc5da.tar.gz |
more chefstyle autocorrects after the engine upgrade
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/ohai/common/dmi.rb | 16 | ||||
-rw-r--r-- | lib/ohai/mixin/command.rb | 4 | ||||
-rw-r--r-- | lib/ohai/plugins/solaris2/filesystem.rb | 12 | ||||
-rw-r--r-- | lib/ohai/runner.rb | 4 | ||||
-rw-r--r-- | lib/ohai/system.rb | 4 | ||||
-rw-r--r-- | spec/unit/dsl/plugin_spec.rb | 44 | ||||
-rw-r--r-- | spec/unit/mixin/ec2_metadata_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/mixin/softlayer_metadata_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugin_config_spec.rb | 12 | ||||
-rw-r--r-- | spec/unit/plugins/aix/cpu_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/azure_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/digital_ocean_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/init_package_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/ip_scopes_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/plugins/linux/network_spec.rb | 180 | ||||
-rw-r--r-- | spec/unit/plugins/ruby_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/runner_spec.rb | 128 |
17 files changed, 238 insertions, 200 deletions
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb index 918a0cea..3bd4da39 100644 --- a/lib/ohai/common/dmi.rb +++ b/lib/ohai/common/dmi.rb @@ -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/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/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/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/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 2b762740..5cafedc8 100644 --- a/spec/unit/plugins/aix/cpu_spec.rb +++ b/spec/unit/plugins/aix/cpu_spec.rb @@ -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/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/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 3134bb94..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) @@ -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/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 2e5ce266..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,20 +319,20 @@ describe Ohai::Runner, "run_plugin" do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, true) - klass_a = Ohai.plugin(:A) { + klass_a = Ohai.plugin(:A) do provides("A") depends("B", "C") collect_data {} - } - klass_b = Ohai.plugin(:B) { + end + klass_b = Ohai.plugin(:B) do provides("B") depends("C") collect_data {} - } - klass_c = Ohai.plugin(:C) { + end + klass_c = Ohai.plugin(:C) do provides("C") collect_data {} - } + end @plugins = [] [klass_a, klass_b, klass_c].each do |klass| @@ -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| |