diff --git a/lib/facter/facts/linux/dmi/product/version.rb b/lib/facter/facts/linux/dmi/product/version.rb new file mode 100644 index 0000000000..c8a71a80a1 --- /dev/null +++ b/lib/facter/facts/linux/dmi/product/version.rb @@ -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 diff --git a/lib/facter/framework/core/file_loader.rb b/lib/facter/framework/core/file_loader.rb index 92bbc7c73f..8aa07a1fec 100644 --- a/lib/facter/framework/core/file_loader.rb +++ b/lib/facter/framework/core/file_loader.rb @@ -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' diff --git a/lib/facter/resolvers/dmi.rb b/lib/facter/resolvers/dmi.rb index bbe8f259bf..da12403b8a 100644 --- a/lib/facter/resolvers/dmi.rb +++ b/lib/facter/resolvers/dmi.rb @@ -22,6 +22,7 @@ class << self # :product_serial # :product_name # :product_uuid + # :product_version private @@ -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) diff --git a/spec/facter/resolvers/dmi_spec.rb b/spec/facter/resolvers/dmi_spec.rb index 135f6e0e32..bfca944d02 100644 --- a/spec/facter/resolvers/dmi_spec.rb +++ b/spec/facter/resolvers/dmi_spec.rb @@ -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' }