summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-02-03 10:36:31 +0000
committerTim Smith <tsmith@chef.io>2017-04-03 18:55:02 -0700
commitdd38f05109a4344f80eb68c4edfc93dec7c3bf4a (patch)
tree3c2199740803c88551dbf1aabc9a794c696c054a
parentd076176a20963dee36de98048b57296b74d3cfbc (diff)
downloadohai-dmi_explosion.tar.gz
Rescue exception in DMI plugindmi_explosion
This gets us non-exploding output on Linux systems now. This was the last plugin. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/dmi.rb158
1 files changed, 81 insertions, 77 deletions
diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb
index d24175eb..ed7ae9f2 100644
--- a/lib/ohai/plugins/dmi.rb
+++ b/lib/ohai/plugins/dmi.rb
@@ -44,86 +44,90 @@ Ohai.plugin(:DMI) do
dmi_record = nil
field = nil
- so = shell_out("dmidecode")
- # ==== EXAMPLE RECORD: ====
- #Handle 0x0000, DMI type 0, 24 bytes
- #BIOS Information
- # Vendor: American Megatrends Inc.
- # Version: 080012
- # ... similar lines trimmed
- # Characteristics:
- # ISA is supported
- # PCI is supported
- # ... similar lines trimmed
- so.stdout.lines do |line|
- next if blank_line.match(line)
- line = line.encode(line.encoding, :universal_newline => true)
-
- if dmidecode_version = dmidecode_version_line.match(line)
- dmi[:dmidecode_version] = dmidecode_version[1]
-
- elsif smbios_version = smbios_version_line.match(line)
- dmi[:smbios_version] = smbios_version[1]
-
- elsif structures = structures_line.match(line)
- dmi[:structures] = Mash.new
- dmi[:structures][:count] = structures[1]
- dmi[:structures][:size] = structures[2]
-
- elsif table_location = table_location_line.match(line)
- dmi[:table_location] = table_location[1]
-
- elsif handle = handle_line.match(line)
- # Don't overcapture for now (OHAI-260)
- unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i)
- dmi_record = nil
- next
- end
-
- dmi_record = { :type => Ohai::Common::DMI.id_lookup(handle[2]) }
-
- dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type])
- dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records)
- dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length
- dmi[dmi_record[:type]][:all_records].push(Mash.new)
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = handle[1]
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = handle[2]
- field = nil
-
- elsif type = type_line.match(line)
- if dmi_record.nil?
- Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
- next
- end
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1]
-
- elsif data = data_line.match(line)
- if dmi_record.nil?
- Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
- next
- end
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
- field = data[1]
+ begin
+ so = shell_out("dmidecode")
+ # ==== EXAMPLE RECORD: ====
+ #Handle 0x0000, DMI type 0, 24 bytes
+ #BIOS Information
+ # Vendor: American Megatrends Inc.
+ # Version: 080012
+ # ... similar lines trimmed
+ # Characteristics:
+ # ISA is supported
+ # PCI is supported
+ # ... similar lines trimmed
+ so.stdout.lines do |line|
+ next if blank_line.match(line)
+ line = line.encode(line.encoding, :universal_newline => true)
+
+ if dmidecode_version = dmidecode_version_line.match(line)
+ dmi[:dmidecode_version] = dmidecode_version[1]
+
+ elsif smbios_version = smbios_version_line.match(line)
+ dmi[:smbios_version] = smbios_version[1]
+
+ elsif structures = structures_line.match(line)
+ dmi[:structures] = Mash.new
+ dmi[:structures][:count] = structures[1]
+ dmi[:structures][:size] = structures[2]
+
+ elsif table_location = table_location_line.match(line)
+ dmi[:table_location] = table_location[1]
+
+ elsif handle = handle_line.match(line)
+ # Don't overcapture for now (OHAI-260)
+ unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i)
+ dmi_record = nil
+ next
+ end
+
+ dmi_record = { :type => Ohai::Common::DMI.id_lookup(handle[2]) }
+
+ dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type])
+ dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records)
+ dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length
+ dmi[dmi_record[:type]][:all_records].push(Mash.new)
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = handle[1]
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = handle[2]
+ field = nil
+
+ elsif type = type_line.match(line)
+ if dmi_record .nil?
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
+ next
+ end
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1]
+
+ elsif data = data_line.match(line)
+ if dmi_record .nil?
+ Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
+ next
+ end
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
+ field = data[1]
+
+ elsif extended_data = extended_data_line.match(line)
+ if dmi_record .nil?
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}")
+ next
+ end
+ if field .nil?
+ Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}")
+ next
+ end
+ # overwrite "raw" value with a new Mash
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == "Mash"
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil
+
+ else
+ Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}")
- elsif extended_data = extended_data_line.match(line)
- if dmi_record.nil?
- Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}")
- next
- end
- if field.nil?
- Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}")
- next
end
- # overwrite "raw" value with a new Mash
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == "Mash"
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil
-
- else
- Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}")
-
end
- end
- Ohai::Common::DMI.convenience_keys(dmi)
+ Ohai::Common::DMI.convenience_keys(dmi)
+ rescue Ohai::Exceptions::Exec
+ Ohai::Log.debug('Plugin DMI: Could not shell_out "dmidecode". Skipping data')
+ end
end
end