diff options
author | Tim Smith <tsmith@chef.io> | 2017-03-29 00:25:12 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-04-17 10:37:34 -0700 |
commit | 9eaf02147e5780fdc246ceb67f3c603f6dbd8260 (patch) | |
tree | 87d24cdea7ff9a02a11d6ee478cb0e1a88776738 | |
parent | a007742eb897423efbaacc799dc07a8901a77273 (diff) | |
download | ohai-9eaf02147e5780fdc246ceb67f3c603f6dbd8260.tar.gz |
Allow configuring what DMI IDs we whitelist
A lot of people want their OEM / IPMI dmi data. It’s super handy to have.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/common/dmi.rb | 6 | ||||
-rw-r--r-- | spec/unit/plugins/dmi_spec.rb | 35 |
2 files changed, 21 insertions, 20 deletions
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb index 988e1493..f1450619 100644 --- a/lib/ohai/common/dmi.rb +++ b/lib/ohai/common/dmi.rb @@ -72,9 +72,9 @@ module Ohai 127 => "end_of_table_marker", } - # 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. - ID_TO_CAPTURE = [ 0, 1, 2, 3, 4, 6, 11 ] + # list of IDs to collect from config or default to a sane list that prunes + # away some of the less useful IDs + ID_TO_CAPTURE = Ohai.config[:plugin][:dmi][:ids] || [ 0, 1, 2, 3, 4, 6, 11 ] # look up DMI ID def id_lookup(id) diff --git a/spec/unit/plugins/dmi_spec.rb b/spec/unit/plugins/dmi_spec.rb index 9c855a9c..b7fa44d9 100644 --- a/spec/unit/plugins/dmi_spec.rb +++ b/spec/unit/plugins/dmi_spec.rb @@ -101,15 +101,16 @@ Chassis Information EOS describe Ohai::System, "plugin dmi" do + let(:plugin) { get_plugin("dmi") } + let(:stdout) { DMI_OUT } + before(:each) do - @plugin = get_plugin("dmi") - @stdout = DMI_OUT - allow(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, "")) + allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, "")) end - it "should run dmidecode" do - expect(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, "")) - @plugin.run + it "runs dmidecode" do + expect(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, "")) + plugin.run end # Test some simple sample data @@ -128,21 +129,21 @@ describe Ohai::System, "plugin dmi" do }, }.each do |id, data| data.each do |attribute, value| - it "should have [:dmi][:#{id}][:#{attribute}] set" do - @plugin.run - expect(@plugin[:dmi][id][attribute]).to eql(value) + it "attribute [:dmi][:#{id}][:#{attribute}] is set" do + plugin.run + expect(plugin[:dmi][id][attribute]).to eql(value) end - it "should have [:dmi][:#{id}][:#{attribute}] set for windows output" do - @stdout = convert_windows_output(DMI_OUT) - expect(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, "")) - @plugin.run - expect(@plugin[:dmi][id][attribute]).to eql(value) + it "attribute [:dmi][:#{id}][:#{attribute}] set for windows output" do + stdout = convert_windows_output(DMI_OUT) + expect(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, "")) + plugin.run + expect(plugin[:dmi][id][attribute]).to eql(value) end end end - it "should correctly ignore unwanted data" do - @plugin.run - expect(@plugin[:dmi][:base_board]).not_to have_key(:error_correction_type) + it "correctly ignores unwanted data" do + plugin.run + expect(plugin[:dmi][:base_board]).not_to have_key(:error_correction_type) end end |