Skip to content

Commit

Permalink
Merge pull request #2671 from jcpunk/dmi_product_version
Browse files Browse the repository at this point in the history
feat(dmi.product_version) Additional system information
  • Loading branch information
joshcooper authored Feb 1, 2024
2 parents 4080a39 + cd74e2d commit 75771c9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/facter/facts/linux/dmi/product/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Facts
module Linux
module Dmi
module Product
class Version
FACT_NAME = 'dmi.product.version'
ALIASES = 'productversion'

def call_the_resolver
fact_value = Facter::Resolvers::Linux::DmiBios.resolve(:product_version)
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/facter/framework/core/file_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
require_relative '../../facts/linux/dmi/product/name'
require_relative '../../facts/linux/dmi/product/serial_number'
require_relative '../../facts/linux/dmi/product/uuid'
require_relative '../../facts/linux/dmi/product/version'
require_relative '../../facts/linux/ec2_metadata'
require_relative '../../facts/linux/ec2_userdata'
require_relative '../../facts/linux/facterversion'
Expand Down
3 changes: 2 additions & 1 deletion lib/facter/resolvers/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class << self
# :product_serial
# :product_name
# :product_uuid
# :product_version

private

Expand All @@ -32,7 +33,7 @@ def post_resolve(fact_name, _options)
def read_facts(fact_name)
files = %w[bios_date bios_vendor bios_version board_asset_tag board_vendor board_name
board_serial chassis_asset_tag chassis_type sys_vendor product_name
product_serial product_uuid]
product_serial product_uuid product_version]
return unless File.directory?('/sys/class/dmi')

file_content = Facter::Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
Expand Down
9 changes: 9 additions & 0 deletions spec/facter/resolvers/dmi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@
end
end

context 'when product_version file exists' do
let(:file_content) { 'VMware 6' }
let(:file) { 'product_version' }

it 'returns product_version' do
expect(resolver.resolve(:product_version)).to eq(file_content)
end
end

context 'when product_serial file exists' do
let(:file_content) { 'VMware-42 1a 02 ea e6 27 76 b8-a1 23 a7 8a d3 12 ee cf' }
let(:file) { 'product_serial' }
Expand Down

0 comments on commit 75771c9

Please sign in to comment.