summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-02-28 10:52:30 -0800
committerTim Smith <tsmith@chef.io>2018-02-28 10:59:18 -0800
commita3de6fdea41ce24c3152404eecdfead041c38da0 (patch)
tree4235a69e661aff7dbc5a34c7b032cdcad04a856f
parent8cdfbfe462ef0850333095f31a6ef1a23dda6b73 (diff)
downloadohai-tidy_up.tar.gz
Expand what we blacklist from the kernel plugintidy_up
We're collecting some super useless data here (wmi class names) and some entirely duplicate data. Lets shave a tiny bit of storage space off the node object and make it easier to reason with. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/kernel.rb21
-rw-r--r--spec/unit/plugins/windows/kernel_spec.rb5
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index 9da36820..4e85bdf4 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -134,6 +134,24 @@ Ohai.plugin(:Kernel) do
end
end
+ # see if a WMI name is blacklisted so we can avoid writing out
+ # useless data to ohai
+ # @param [String] name the wmi name to check
+ # @return [Boolean] is the wmi name blacklisted
+ def blacklisted_wmi_name?(name)
+ [
+ "creation_class_name", # this is just the wmi name
+ "cs_creation_class_name", # this is just the wmi name
+ "oem_logo_bitmap", # this is the entire OEM bitmap file
+ "total_swap_space_size", # already in memory plugin
+ "total_virtual_memory_size", # already in memory plugin
+ "total_virtual_memory_size", # already in memory plugin
+ "free_physical_memory", # already in memory plugin
+ "free_space_in_paging_files", # already in memory plugin
+ "free_virtual_memory", # already in memory plugin
+ ].include?(name)
+ end
+
collect_data(:default) do
kernel init_kernel
end
@@ -241,6 +259,7 @@ Ohai.plugin(:Kernel) do
host = wmi.first_of("Win32_OperatingSystem")
kernel[:os_info] = Mash.new
host.wmi_ole_object.properties_.each do |p|
+ next if blacklisted_wmi_name?(p.name.wmi_underscore)
kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
end
@@ -254,7 +273,7 @@ Ohai.plugin(:Kernel) do
kernel[:cs_info] = Mash.new
host = wmi.first_of("Win32_ComputerSystem")
host.wmi_ole_object.properties_.each do |p|
- next if p.name.wmi_underscore == "oem_logo_bitmap" # big bitmap doesn't need to be in ohai
+ next if blacklisted_wmi_name?(p.name.wmi_underscore)
kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
end
diff --git a/spec/unit/plugins/windows/kernel_spec.rb b/spec/unit/plugins/windows/kernel_spec.rb
index 377034cb..44fe4278 100644
--- a/spec/unit/plugins/windows/kernel_spec.rb
+++ b/spec/unit/plugins/windows/kernel_spec.rb
@@ -49,13 +49,15 @@ describe Ohai::System, "Windows kernel plugin", :windows_only do
system_type = double("WIN32OLE", :name => "SystemType")
pc_system_type = double("WIN32OLE", :name => "PCSystemType")
- cs_properties = [ system_type, pc_system_type ]
+ free_virtual_memory = double("WIN32OLE", :name => "FreeVirtualMemory")
+ cs_properties = [ system_type, pc_system_type, free_virtual_memory]
cs = double("WIN32OLE",
:properties_ => cs_properties)
allow(cs).to receive(:invoke).with(system_type.name).and_return("x64-based PC")
allow(cs).to receive(:invoke).with(pc_system_type.name).and_return(2)
+ allow(cs).to receive(:invoke).with(free_virtual_memory.name).and_return("Why would you want this data here?")
cs_wmi = WmiLite::Wmi::Instance.new(cs)
expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with("Win32_ComputerSystem").and_return(cs_wmi)
@@ -72,5 +74,6 @@ describe Ohai::System, "Windows kernel plugin", :windows_only do
expect(plugin[:kernel][:system_type]).to eq("Mobile")
expect(plugin[:kernel][:product_type]).to eq("Workstation")
expect(plugin[:kernel][:server_core]).to eq(false)
+ expect(plugin[:kernel]).not_to have_key(:free_virtual_memory)
end
end