diff --git a/lib/facter/facts/aix/disks.rb b/lib/facter/facts/aix/disks.rb index ea16d1b023..81bc3943b4 100644 --- a/lib/facter/facts/aix/disks.rb +++ b/lib/facter/facts/aix/disks.rb @@ -4,7 +4,7 @@ module Facts module Aix class Disks FACT_NAME = 'disks' - ALIASES = %w[blockdevices blockdevice_.*_model blockdevice_.*_size blockdevice_.*_vendor'].freeze + ALIASES = %w[blockdevices blockdevice_.*_size'].freeze def call_the_resolver facts = [] @@ -24,8 +24,7 @@ def call_the_resolver def add_regex_facts(disks, facts) disks&.each do |disk_name, disk_info| - facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size], :legacy)) - facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size_bytes", disk_info[:size_bytes], :legacy)) + facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes].to_s, :legacy)) end end end diff --git a/lib/facter/facts/linux/disks.rb b/lib/facter/facts/linux/disks.rb index 1457d39182..b9b91faee2 100644 --- a/lib/facter/facts/linux/disks.rb +++ b/lib/facter/facts/linux/disks.rb @@ -25,7 +25,7 @@ def call_the_resolver def add_regex_facts(disks, facts) disks&.each do |disk_name, disk_info| facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_model", disk_info[:model], :legacy)) - facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes], :legacy)) + facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes].to_s, :legacy)) facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_vendor", disk_info[:vendor], :legacy)) end end diff --git a/lib/facter/facts/solaris/disks.rb b/lib/facter/facts/solaris/disks.rb index a4d926d71b..b576587cd6 100644 --- a/lib/facter/facts/solaris/disks.rb +++ b/lib/facter/facts/solaris/disks.rb @@ -4,10 +4,29 @@ module Facts module Solaris class Disks FACT_NAME = 'disks' + %w[blockdevices blockdevice_.*_size blockdevice_.*_vendor'].freeze def call_the_resolver - fact_value = Facter::Resolvers::Solaris::Disks.resolve(:disks) - Facter::ResolvedFact.new(FACT_NAME, fact_value) + facts = [] + disks = Facter::Resolvers::Solaris::Disks.resolve(:disks) + + disks = disks&.empty? ? nil : disks + blockdevices = disks&.keys&.join(',') + + facts.push(Facter::ResolvedFact.new(FACT_NAME, disks)) + facts.push(Facter::ResolvedFact.new('blockdevices', blockdevices, :legacy)) + add_regex_facts(disks, facts) + + facts + end + + private + + def add_regex_facts(disks, facts) + disks&.each do |disk_name, disk_info| + facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_size", disk_info[:size_bytes].to_s, :legacy)) + facts.push(Facter::ResolvedFact.new("blockdevice_#{disk_name}_vendor", disk_info[:vendor], :legacy)) + end end end end diff --git a/spec/facter/facts/aix/disks_spec.rb b/spec/facter/facts/aix/disks_spec.rb index 833d989eb5..837c7ab9f0 100644 --- a/spec/facter/facts/aix/disks_spec.rb +++ b/spec/facter/facts/aix/disks_spec.rb @@ -37,8 +37,7 @@ .and contain_exactly( an_object_having_attributes(name: 'disks', value: expecte_response), an_object_having_attributes(name: 'blockdevices', value: 'hdisk0'), - an_object_having_attributes(name: 'blockdevice_hdisk0_size', value: '20.00 GiB', type: :legacy), - an_object_having_attributes(name: 'blockdevice_hdisk0_size_bytes', value: 21_474_836_480, type: :legacy) + an_object_having_attributes(name: 'blockdevice_hdisk0_size', value: '21474836480', type: :legacy) ) end diff --git a/spec/facter/facts/linux/disks_spec.rb b/spec/facter/facts/linux/disks_spec.rb index 494e79628f..1366f28c58 100644 --- a/spec/facter/facts/linux/disks_spec.rb +++ b/spec/facter/facts/linux/disks_spec.rb @@ -42,7 +42,7 @@ an_object_having_attributes(name: 'disks', value: expecte_response), an_object_having_attributes(name: 'blockdevices', value: 'sda'), an_object_having_attributes(name: 'blockdevice_sda_model', value: 'Virtual disk', type: :legacy), - an_object_having_attributes(name: 'blockdevice_sda_size', value: 21_474_836_480, type: :legacy), + an_object_having_attributes(name: 'blockdevice_sda_size', value: '21474836480', type: :legacy), an_object_having_attributes(name: 'blockdevice_sda_vendor', value: 'VMware', type: :legacy) ) end diff --git a/spec/facter/facts/solaris/disks_spec.rb b/spec/facter/facts/solaris/disks_spec.rb index afbb8205f1..d5c714df90 100644 --- a/spec/facter/facts/solaris/disks_spec.rb +++ b/spec/facter/facts/solaris/disks_spec.rb @@ -4,7 +4,24 @@ describe '#call_the_resolver' do subject(:fact) { Facts::Solaris::Disks.new } - let(:value) do + let(:disks) do + { + 'sd0' => { + product: 'VMware IDE CDR00Revision', + size: '0 bytes', + size_bytes: 0, + vendor: 'NECVMWar' + }, + 'sd1' => { + product: 'Virtual disk Revision', + size: '20.00 GiB', + size_bytes: 21_474_836_480, + vendor: 'VMware' + } + } + end + + let(:expected_response) do { 'sd0' => { 'product' => 'VMware IDE CDR00Revision', @@ -22,7 +39,7 @@ end before do - allow(Facter::Resolvers::Solaris::Disks).to receive(:resolve).with(:disks).and_return(value) + allow(Facter::Resolvers::Solaris::Disks).to receive(:resolve).with(:disks).and_return(disks) end it 'calls Facter::Resolvers::Solaris::Disks' do @@ -31,8 +48,16 @@ end it 'returns disks fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'disks', value: value) + expect(fact.call_the_resolver) + .to be_an_instance_of(Array) + .and contain_exactly( + an_object_having_attributes(name: 'disks', value: expected_response), + an_object_having_attributes(name: 'blockdevices', value: 'sd0,sd1'), + an_object_having_attributes(name: 'blockdevice_sd0_size', value: '0', type: :legacy), + an_object_having_attributes(name: 'blockdevice_sd0_vendor', value: 'NECVMWar', type: :legacy), + an_object_having_attributes(name: 'blockdevice_sd1_size', value: '21474836480', type: :legacy), + an_object_having_attributes(name: 'blockdevice_sd1_vendor', value: 'VMware', type: :legacy) + ) end end end