summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-02-28 14:24:05 -0800
committerGitHub <noreply@github.com>2018-02-28 14:24:05 -0800
commit1ab10788f561daf401858f34502a7127572c5d40 (patch)
tree238fda1ea99d1cb0d08f5d30f46dd59003038f9a
parent8cdfbfe462ef0850333095f31a6ef1a23dda6b73 (diff)
parent3b182df271ecaacbdaf70a3c36b026f4102d3af5 (diff)
downloadohai-1ab10788f561daf401858f34502a7127572c5d40.tar.gz
Merge pull request #1147 from chef/tidy_up
Expand what we blacklist from the kernel/network plugins on Windows
-rw-r--r--lib/ohai/plugins/kernel.rb21
-rw-r--r--lib/ohai/plugins/windows/network.rb4
-rw-r--r--spec/unit/plugins/windows/kernel_spec.rb5
3 files changed, 27 insertions, 3 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/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb
index ae52d215..9a80ec88 100644
--- a/lib/ohai/plugins/windows/network.rb
+++ b/lib/ohai/plugins/windows/network.rb
@@ -36,7 +36,7 @@ Ohai.plugin(:Network) do
wmi = WmiLite::Wmi.new
data[:addresses] = wmi.instances_of("Win32_NetworkAdapterConfiguration")
- # If we are running on windows nano or anothe roperating system from the future
+ # If we are running on windows nano or another operating system from the future
# that does not populate the deprecated win32_* WMI classes, then we should
# grab data from the newer MSFT_* classes
return msft_adapter_data if data[:addresses].count == 0
@@ -81,6 +81,8 @@ Ohai.plugin(:Network) do
i = adapter["index"] || adapter["InterfaceIndex"]
iface_instance[i] = Mash.new
adapter.wmi_ole_object.properties_.each do |p|
+ # skip wmi class name fields which make no sense in ohai
+ next if %w{creation_class_name system_creation_class_name}.include?(p.name.wmi_underscore)
iface_instance[i][p.name.wmi_underscore.to_sym] = adapter[p.name.downcase]
end
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