Skip to content

Commit

Permalink
Merge pull request #541 from chef/tm/solaris_dmi
Browse files Browse the repository at this point in the history
make DMI work on solaris
  • Loading branch information
thommay committed May 21, 2015
2 parents 738b853 + a79fb14 commit 8149d66
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/ohai/plugins/solaris2/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
#

Ohai.plugin(:DMI) do
provides "dmi"

collect_data(:solaris2) do
require 'ohai/common/dmi'

# if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios
# note that a single key just means dmidecode exited with its version
if (dmi.class.to_s == 'Mash') and (dmi.keys.length > 1)
Expand Down Expand Up @@ -72,6 +75,9 @@
'SMB_TYPE_MEMCHAN' => 37, # memory channel
'SMB_TYPE_IPMIDEV' => 38, # IPMI device information
'SMB_TYPE_POWERSUP' => 39, # system power supply
'SMB_TYPE_ADDINFO' => 40, # additional information
'SMB_TYPE_OBDEVEXT' => 41, # on-board device extended info
'SMB_TYPE_MCHI' => 42, # mgmt controller host interface
'SMB_TYPE_INACTIVE' => 126, # inactive table entry
'SMB_TYPE_EOT' => 127, # end of table
'SMB_TYPE_OEM_LO' => 128, # start of OEM-specific type range
Expand Down Expand Up @@ -120,11 +126,20 @@

# look up SMB ID
if smb_to_id.has_key?(header_information[3])
dmi_record[:type] = DMI.id_lookup(smb_to_id[header_information[3]])
id = smb_to_id[header_information[3]]

# Don't overcapture for now (OHAI-260)
unless Ohai::Common::DMI::IdToCapture.include?(id)
dmi_record = nil
next
end

dmi_record[:type] = Ohai::Common::DMI.id_lookup(id)

else
dmi_record[:type] = header_information[3].downcase
Ohai::Log.debug("unrecognized header type; falling back to #{dmi_record[:type]}")
Ohai::Log.debug("unrecognized header type; skipping")
dmi_record = nil
next
end

dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type])
Expand Down Expand Up @@ -171,6 +186,6 @@
end
end

DMI.convenience_keys(dmi)
Ohai::Common::DMI.convenience_keys(dmi)
end
end
154 changes: 154 additions & 0 deletions spec/unit/plugins/solaris2/dmi_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#
# Author:: Thom May (<[email protected]>)
# Copyright:: Copyright (c) 2015 Chef Software
# 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 File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')

SOLARIS_DMI_OUT = <<-EOS
ID SIZE TYPE
0 64 SMB_TYPE_BIOS (type 0) (BIOS information)
Vendor: American Megatrends Inc.
Version String: 4701
Release Date: 08/26/2014
Address Segment: 0xf000
ROM Size: 8388608 bytes
Image Size: 65536 bytes
Characteristics: 0x53f8b9c80
SMB_BIOSFL_PCI (PCI is supported)
SMB_BIOSFL_APM (APM is supported)
SMB_BIOSFL_FLASH (BIOS is Flash Upgradeable)
SMB_BIOSFL_SHADOW (BIOS shadowing is allowed)
SMB_BIOSFL_CDBOOT (Boot from CD is supported)
SMB_BIOSFL_SELBOOT (Selectable Boot supported)
SMB_BIOSFL_ROMSOCK (BIOS ROM is socketed)
SMB_BIOSFL_EDD (EDD Spec is supported)
SMB_BIOSFL_525_12M (int 0x13 5.25" 1.2M floppy)
SMB_BIOSFL_35_720K (int 0x13 3.5" 720K floppy)
SMB_BIOSFL_35_288M (int 0x13 3.5" 2.88M floppy)
SMB_BIOSFL_I5_PRINT (int 0x5 print screen svcs)
SMB_BIOSFL_I9_KBD (int 0x9 8042 keyboard svcs)
SMB_BIOSFL_I14_SER (int 0x14 serial svcs)
SMB_BIOSFL_I17_PRINTER (int 0x17 printer svcs)
0x100000000
0x400000000
Characteristics Extension Byte 1: 0x3
SMB_BIOSXB1_ACPI (ACPI is supported)
SMB_BIOSXB1_USBL (USB legacy is supported)
Characteristics Extension Byte 2: 0xd
SMB_BIOSXB2_BBOOT (BIOS Boot Specification supported)
SMB_BIOSXB2_ETCDIST (Enable Targeted Content Distrib.)
SMB_BIOSXB2_UEFI (UEFI Specification supported)
Version Number: 0.0
Embedded Ctlr Firmware Version Number: 0.0
ID SIZE TYPE
1 129 SMB_TYPE_SYSTEM (type 1) (system information)
Manufacturer: System manufacturer
Product: System Product Name
Version: System Version
Serial Number: System Serial Number
UUID: 20b1001e-8c00-0072-5566-10c37b474fc1
Wake-Up Event: 0x6 (power switch)
SKU Number: SKU
Family: To be filled by O.E.M.
ID SIZE TYPE
2 116 SMB_TYPE_BASEBOARD (type 2) (base board)
Manufacturer: ASUSTeK COMPUTER INC.
Product: P9X79 WS
Version: Rev 1.xx
Serial Number: 140525831000250
Asset Tag: To be filled by O.E.M.
Location Tag: To be filled by O.E.M.
Chassis: 3
Flags: 0x9
SMB_BBFL_MOTHERBOARD (board is a motherboard)
SMB_BBFL_REPLACABLE (board is field-replacable)
Board Type: 0xa (motherboard)
ID SIZE TYPE
46 38 SMB_TYPE_OBDEVS (type 10) (on-board devices)
Onboard Ethernet
Onboard Audio
ID SIZE TYPE
3 106 SMB_TYPE_CHASSIS (type 3) (system enclosure or chassis)
Manufacturer: Chassis Manufacture
Version: Chassis Version
Serial Number: Chassis Serial Number
Asset Tag: PCS
OEM Data: 0x0
SKU number: ^E
Lock Present: N
Chassis Type: 0x3 (desktop)
Boot-Up State: 0x3 (safe)
Power Supply State: 0x3 (safe)
Thermal State: 0x3 (safe)
Chassis Height: 0u
Power Cords: 1
Element Records: 0
EOS

describe Ohai::System, "Solaris2.X DMI plugin" do
before(:each) do
@plugin = get_plugin("solaris2/dmi")
allow(@plugin).to receive(:collect_os).and_return("solaris2")
@stdout = SOLARIS_DMI_OUT
allow(@plugin).to receive(:shell_out).with("smbios").and_return(mock_shell_out(0, @stdout, ""))
end

it "should run smbios" do
expect(@plugin).to receive(:shell_out).with("smbios").and_return(mock_shell_out(0, @stdout, ""))
@plugin.run
end

{
bios: {
vendor: "American Megatrends Inc.",
release_date: "08/26/2014"
},
system: {
manufacturer: "System manufacturer",
product: "System Product Name"
},
chassis: {
lock_present: "N",
asset_tag: "PCS"
}
}.each do |id, data|
data.each do |attribute, value|
it "should have [:dmi][:#{id}][:#{attribute}] set" do
@plugin.run
expect(@plugin[:dmi][id][attribute]).to eql(value)
end
end
end

it "should ignore unwanted types" do
@plugin.run
expect(@plugin[:dmi]).not_to have_key(:on_board_devices)
end
end

0 comments on commit 8149d66

Please sign in to comment.