Skip to content

Commit

Permalink
Merge pull request #1210 from chef/sp/1209
Browse files Browse the repository at this point in the history
Add system_enclosure plugin for Windows
  • Loading branch information
tas50 authored Jul 10, 2018
2 parents d1d6592 + 694967e commit aa6bbce
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/ohai/plugins/windows/system_enclosure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Author:: Stuart Preston (<[email protected]>)
# Copyright:: Copyright (c) 2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Ohai.plugin :SystemEnclosure do
provides "system_enclosure"

collect_data(:windows) do
require "wmi-lite/wmi"
system_enclosure Mash.new
wmi = WmiLite::Wmi.new
wmi_object = wmi.first_of("Win32_SystemEnclosure").wmi_ole_object
system_enclosure[:manufacturer] = wmi_object.invoke("manufacturer")
system_enclosure[:serialnumber] = wmi_object.invoke("serialnumber")
end
end
45 changes: 45 additions & 0 deletions spec/unit/plugins/windows/system_enclosure_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Author:: Stuart Preston (<[email protected]>)
# Copyright:: Copyright (c) 2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative "../../../spec_helper.rb"

describe Ohai::System, "System Enclosure", :windows_only do
before do
require "wmi-lite/wmi"
@plugin = get_plugin("windows/system_enclosure")
manufacturer = double("WIN32OLE", name: "manufacturer", value: "My Fake Manufacturer")
serialnumber = double("WIN32OLE", name: "serialnumber", value: "1234123412341234")
property_map = [ manufacturer, serialnumber ]

wmi_ole_object = double( "WIN32OLE", properties_: property_map)
allow(wmi_ole_object).to receive(:invoke).with(manufacturer.name).and_return(manufacturer.value)
allow(wmi_ole_object).to receive(:invoke).with(serialnumber.name).and_return(serialnumber.value)
wmi_object = WmiLite::Wmi::Instance.new(wmi_ole_object)
expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with(("Win32_SystemEnclosure")).and_return(wmi_object)
end

it "should return the manufacturer" do
@plugin.run
expect(@plugin["system_enclosure"]["manufacturer"]).to eql("My Fake Manufacturer")
end

it "should return a serial number" do
@plugin.run
expect(@plugin["system_enclosure"]["serialnumber"]).to eql("1234123412341234")
end
end

0 comments on commit aa6bbce

Please sign in to comment.