summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-04-15 16:51:43 -0700
committerPete Higgins <pete@peterhiggins.org>2020-04-15 16:51:50 -0700
commite40757d0abb994cc31990092c42ddd2bb2879741 (patch)
tree36121cdceafe882a0f75549554a0b7a96133dd43
parent3c48e7a622150125f00345b03256efbd9efeacf7 (diff)
downloadohai-e40757d0abb994cc31990092c42ddd2bb2879741.tar.gz
Rename some keys from their Windows versions to Unix equivalents.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/ohai/plugins/windows/dmi.rb10
-rw-r--r--spec/unit/plugins/windows/dmi_spec.rb36
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/ohai/plugins/windows/dmi.rb b/lib/ohai/plugins/windows/dmi.rb
index 64bc9c71..db19b6d4 100644
--- a/lib/ohai/plugins/windows/dmi.rb
+++ b/lib/ohai/plugins/windows/dmi.rb
@@ -38,6 +38,12 @@ Ohai.plugin(:DMI) do
# https://rubular.com/r/FBNtXod4wkZGAG
SPLIT_REGEX = /[A-Z][a-z0-9]+|[A-Z]{2,}(?=[A-Z][a-z0-9])|[A-Z]{2,}/.freeze
+ WINDOWS_TO_UNIX_KEYS = [
+ %w{vendor manufacturer},
+ %w{identifying_number serial_number},
+ %w{name family},
+ ].freeze
+
collect_data(:windows) do
require "ohai/common/dmi"
require "wmi-lite/wmi"
@@ -79,6 +85,10 @@ Ohai.plugin(:DMI) do
dmi.each_value do |records|
records[:all_records] = records.delete(:_all_records)
+
+ WINDOWS_TO_UNIX_KEYS.each do |windows_key, unix_key|
+ records[unix_key] = records.delete(windows_key) if records.has_key?(windows_key)
+ end
end
end
end
diff --git a/spec/unit/plugins/windows/dmi_spec.rb b/spec/unit/plugins/windows/dmi_spec.rb
index 77ffd003..451850d9 100644
--- a/spec/unit/plugins/windows/dmi_spec.rb
+++ b/spec/unit/plugins/windows/dmi_spec.rb
@@ -131,4 +131,40 @@ describe Ohai::System, "DMI", :windows_only do
end
end
end
+
+ context "with information that should be made to match other platforms" do
+ RENAMED_KEYS = [
+ %w{Vendor vendor manufacturer aaa},
+ %w{IdentifyingNumber identifying_number serial_number bbb},
+ %w{Name name family ccc},
+ ].freeze
+
+ before do
+ properties = RENAMED_KEYS.map { |name, _, _, _| double(name: name) }
+ wmi_ole_object = double properties_: properties
+
+ RENAMED_KEYS.each do |name, _, _, value|
+ allow(wmi_ole_object).to receive(:invoke).with(name).and_return(value)
+ end
+
+ wmi_object = WmiLite::Wmi::Instance.new(wmi_ole_object)
+ expect_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with("Win32_SystemEnclosure").and_return([wmi_object])
+
+ plugin.run
+ end
+
+ RENAMED_KEYS.each do |name, transformed_name, renamed_name, value|
+ it "adds #{name} to :all_records" do
+ expect(plugin[:dmi][:chassis][:all_records].first[name]).to eq(value)
+ end
+
+ it "adds #{renamed_name} to the root" do
+ expect(plugin[:dmi][:chassis][renamed_name]).to eq(value)
+ end
+
+ it "does not add #{transformed_name} to the root" do
+ expect(plugin[:dmi][:chassis]).not_to have_key(transformed_name)
+ end
+ end
+ end
end