lib/ohai/plugins/shard.rb in ohai-15.8.0 vs lib/ohai/plugins/shard.rb in ohai-15.9.1

- old
+ new

@@ -20,14 +20,16 @@ depends "hostname", "dmi", "machine_id", "machinename", "fips", "hardware", "kernel" provides "shard_seed" def get_dmi_property(dmi, thing) %w{system base_board chassis}.each do |section| - unless dmi[section][thing].strip.empty? + if dmi[section] && dmi[section][thing] && !dmi[section][thing].strip.empty? return dmi[section][thing] end end + Ohai::Log.error("shard_seed: Failed to get dmi property #{thing}: is dmidecode installed?") + raise "Failed to generate shard_seed" end def default_sources case collect_os when "linux", "darwin", "windows" @@ -75,15 +77,20 @@ machinename else yield(src) end end + if data.empty? + Ohai::Log.error("shard_seed: Unable to generate seed! Either ensure 'dmidecode' is installed, or use 'Ohai.config[:plugin][:shard_seed][:sources]' to set different sources.") + raise "Failed to generate shard_seed" + end shard_seed digest_algorithm.hexdigest(data)[0...7].to_i(16) end collect_data do create_seed do |src| + Ohai::Log.error("shard_seed: No such source #{src}") raise "No such shard_seed source: #{src}" end end collect_data(:windows) do @@ -97,10 +104,11 @@ when :os_serial kernel["os_info"]["serial_number"] when :uuid wmi.first_of("Win32_ComputerSystemProduct")["UUID"] else + Ohai::Log.error("shard_seed: No such source #{src}") raise "No such shard_seed source: #{src}" end end end @@ -110,10 +118,11 @@ when :serial hardware["serial_number"] when :uuid hardware["platform_UUID"] else + Ohai::Log.error("shard_seed: No such source #{src}") raise "No such shard_seed source: #{src}" end end end @@ -123,9 +132,10 @@ when :serial get_dmi_property(dmi, :serial_number) when :uuid get_dmi_property(dmi, :uuid) else + Ohai::Log.error("shard_seed: No such source #{src}") raise "No such shard_seed source: #{src}" end end end end