Skip to content

Commit

Permalink
(FACT-2747) Add legacy facts.
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanIrimie committed Aug 19, 2020
1 parent 93b24bd commit bf0d4fe
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
5 changes: 2 additions & 3 deletions lib/facter/facts/aix/disks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/facter/facts/linux/disks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions lib/facter/facts/solaris/disks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions spec/facter/facts/aix/disks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/facter/facts/linux/disks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 29 additions & 4 deletions spec/facter/facts/solaris/disks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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

0 comments on commit bf0d4fe

Please sign in to comment.