diff --git a/lib/rspec-puppet-facts.rb b/lib/rspec-puppet-facts.rb index 2a37e1e1..a9622d63 100644 --- a/lib/rspec-puppet-facts.rb +++ b/lib/rspec-puppet-facts.rb @@ -2,6 +2,7 @@ require 'facter' require 'facterdb' require 'json' +require 'rspec-puppet-facts/legacy_facts' # The purpose of this module is to simplify the Puppet # module's RSpec tests by looping through all supported @@ -171,6 +172,7 @@ def on_supported_os_implementation(opts = {}) os = "#{facts[:operatingsystem].downcase}-#{operatingsystemmajrelease}-#{facts[:hardwaremodel]}" next unless os.start_with? RspecPuppetFacts.spec_facts_os_filter if RspecPuppetFacts.spec_facts_os_filter facts.merge! RspecPuppetFacts.common_facts + facts.delete_if { |fact, _value| RspecPuppetFacts::LegacyFacts.legacy_fact?(fact) } if RSpec.configuration.prune_legacy_facts os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts) end diff --git a/lib/rspec-puppet-facts/legacy_facts.rb b/lib/rspec-puppet-facts/legacy_facts.rb new file mode 100644 index 00000000..afa0c185 --- /dev/null +++ b/lib/rspec-puppet-facts/legacy_facts.rb @@ -0,0 +1,130 @@ +module RspecPuppetFacts + # This module contains lists of all legacy facts + module LegacyFacts + # Used to determine if a fact is a legacy fact or not + # + # @return [Boolean] Is the fact a legacy fact + # @param [Symbol] fact Fact name + def self.legacy_fact?(fact) + legacy_facts.include?(fact) or fact.to_s.match(Regexp.union(legacy_fact_regexes)) + end + + # @api private + def self.legacy_fact_regexes + [ + /\Ablockdevice_(?.+)_model\Z/, + /\Ablockdevice_(?.+)_size\Z/, + /\Ablockdevice_(?.+)_vendor\Z/, + /\Aipaddress6_(?.+)\Z/, + /\Aipaddress_(?.+)\Z/, + /\Amacaddress_(?.+)\Z/, + /\Amtu_(?.+)\Z/, + /\Anetmask6_(?.+)\Z/, + /\Anetmask_(?.+)\Z/, + /\Anetwork6_(?.+)\Z/, + /\Anetwork_(?.+)\Z/, + /\Ascope6_(?.+)\Z/, + /\Aldom_(?.+)\Z/, + /\Aprocessor\d+\Z/, + /\Asp_(?.+)\Z/, + /\Assh(?.+)key\Z/, + /\Asshfp_(?.+)\Z/, + /\Azone_(?.+)_brand\Z/, + /\Azone_(?.+)_id\Z/, + /\Azone_(?.+)_iptype\Z/, + /\Azone_(?.+)_name\Z/, + /\Azone_(?.+)_path\Z/, + /\Azone_(?.+)_status\Z/, + /\Azone_(?.+)_uuid\Z/ + ] + end + + # @api private + def self.legacy_facts + %i[ + architecture + augeasversion + blockdevices + bios_release_date + bios_vendor + bios_version + boardassettag + boardmanufacturer + boardproductname + boardserialnumber + chassisassettag + chassistype + dhcp_servers + domain + fqdn + gid + hardwareisa + hardwaremodel + hostname + id + interfaces + ipaddress + ipaddress6 + lsbdistcodename + lsbdistdescription + lsbdistid + lsbdistrelease + lsbmajdistrelease + lsbminordistrelease + lsbrelease + macaddress + macosx_buildversion + macosx_productname + macosx_productversion + macosx_productversion_major + macosx_productversion_minor + macosx_productversion_patch + manufacturer + memoryfree + memoryfree_mb + memorysize + memorysize_mb + netmask + netmask6 + network + network6 + operatingsystem + operatingsystemmajrelease + operatingsystemrelease + osfamily + physicalprocessorcount + processorcount + productname + rubyplatform + rubysitedir + rubyversion + scope6 + selinux + selinux_config_mode + selinux_config_policy + selinux_current_mode + selinux_enforced + selinux_policyversion + serialnumber + swapencrypted + swapfree + swapfree_mb + swapsize + swapsize_mb + windows_edition_id + windows_installation_type + windows_product_name + windows_release_id + system32 + uptime + uptime_days + uptime_hours + uptime_seconds + uuid + xendomains + zonename + zones + ] + end + end +end