diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-05-01 21:33:02 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-05-01 21:33:02 -0700 |
commit | e3b4ff8f2f48ae860a0cbf31a2f3e64bbabc2e9c (patch) | |
tree | 45269a32fc773dbdb09726f4b50e35f0ae76cc12 | |
parent | 5ecde4f735f67b661a2985b0ee8591ca5df8694f (diff) | |
download | ohai-e3b4ff8f2f48ae860a0cbf31a2f3e64bbabc2e9c.tar.gz |
Add support for using the OS serial number instead of the BIOS serial number on Windows.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r-- | lib/ohai/plugins/shard.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/shard_spec.rb | 14 |
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/ohai/plugins/shard.rb b/lib/ohai/plugins/shard.rb index 7f6e34d1..9820c9c7 100644 --- a/lib/ohai/plugins/shard.rb +++ b/lib/ohai/plugins/shard.rb @@ -17,7 +17,7 @@ # Ohai.plugin(:ShardSeed) do - depends "hostname", "dmi", "machine_id", "machinename", "fips", "hardware" + depends "hostname", "dmi", "machine_id", "machinename", "fips", "hardware", "kernel" provides "shard_seed" def get_dmi_property(dmi, thing) @@ -94,6 +94,8 @@ Ohai.plugin(:ShardSeed) do case src when :serial wmi.first_of("Win32_BIOS")["SerialNumber"] + when :os_serial + kernel["os_info"]["serial_number"] when :uuid wmi.first_of("Win32_ComputerSystemProduct")["UUID"] else diff --git a/spec/unit/plugins/shard_spec.rb b/spec/unit/plugins/shard_spec.rb index 03fe8282..12158df0 100644 --- a/spec/unit/plugins/shard_spec.rb +++ b/spec/unit/plugins/shard_spec.rb @@ -80,14 +80,22 @@ describe Ohai::System, "shard plugin" do let(:os) { :windows } before do wmi = double("WmiLite::Wmi") - expect(WmiLite::Wmi).to receive(:new).and_return(wmi) - expect(wmi).to receive(:first_of).with("Win32_BIOS").and_return("SerialNumber" => serial) - expect(wmi).to receive(:first_of).with("Win32_ComputerSystemProduct").and_return("UUID" => uuid) + allow(WmiLite::Wmi).to receive(:new).and_return(wmi) + allow(wmi).to receive(:first_of).with("Win32_BIOS").and_return("SerialNumber" => serial) + allow(wmi).to receive(:first_of).with("Win32_ComputerSystemProduct").and_return("UUID" => uuid) + plugin["kernel"] = { "os_info" => { "serial_number" => serial + "0" } } + plugin.data.delete("dmi") # To make sure we aren't using the wrong data. end it "should provide a shard with a default-safe set of sources" do expect(subject).to eq(27767217) end + + it "should allow os_serial source" do + Ohai.config[:plugin][:shard_seed][:sources] = [:machinename, :os_serial, :uuid] + # Different from above. + expect(subject).to eq(178738102) + end end context "with a weird OS" do |