Skip to content

Commit

Permalink
Add some comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
  • Loading branch information
phiggins committed Apr 10, 2020
1 parent 06d92ab commit 48c6aa1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/ohai/plugins/windows/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Ohai.plugin(:DMI) do
provides "dmi"

# Map the linux component types to their rough Windows API equivalents
DMI_TO_WIN32OLE = {
chassis: "SystemEnclosure",
processor: "Processor",
Expand All @@ -27,6 +28,13 @@
base_board: "BaseBoard",
}.freeze

# This regex is in 3 parts for the different supported patterns in camel
# case names coming from the Windows API:
# * Typical camelcase, eg Depth, PartNumber, NumberOfPowerCords
# * Acronyms preceding camelcase, eg SMBIOSAssetTag
# * Acronyms that occur at the end of the name, eg SKU, DeviceID
#
# This cannot handle some property names, eg SMBIOSBIOSVersion.
SPLIT_REGEX = /[A-Z][a-z0-9]+|[A-Z]{2,}(?=[A-Z][a-z0-9])|[A-Z]{2,}/.freeze

collect_data(:windows) do
Expand All @@ -36,6 +44,13 @@

dmi Mash.new

# The Windows API returns property names in camel case, eg "SerialNumber",
# while `dmi` returns them as space separated strings, eg "Serial Number".
# `Ohai::Common::DMI.convenience_keys` expects property names in `dmi`'s
# format, so build two parallel hashes with the keys as they come from the
# Windows API and in a faked-out `dmi` version. After the call to
# `Ohai::Common::CMI.convenience_keys` replace the faked-out `dmi`
# collection with the one with the original property names.
DMI_TO_WIN32OLE.each do |dmi_key, ole_key|
wmi_object = wmi.first_of("Win32_#{ole_key}").wmi_ole_object

Expand Down
4 changes: 4 additions & 0 deletions spec/unit/plugins/windows/dmi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
describe Ohai::System, "DMI", :windows_only do
let(:plugin) { get_plugin("windows/dmi") }

# Each test case has 3 elements:
# * The name of the property as it comes from the Windows APIs
# * The transformed snake-case version of the property name
# * A unique dummy value per test case
CASES = [
%w{Depth depth aaa},
%w{PartNumber part_number bbb},
Expand Down

0 comments on commit 48c6aa1

Please sign in to comment.