Skip to content

Commit 4986331

Browse files
committed
Prune legacy facts based on rspec-puppet config option
1 parent 0921dff commit 4986331

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

lib/rspec-puppet-facts.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'facter'
33
require 'facterdb'
44
require 'json'
5+
require 'rspec-puppet-facts/legacy_facts'
56

67
# The purpose of this module is to simplify the Puppet
78
# module's RSpec tests by looping through all supported
@@ -171,6 +172,7 @@ def on_supported_os_implementation(opts = {})
171172
os = "#{facts[:operatingsystem].downcase}-#{operatingsystemmajrelease}-#{facts[:hardwaremodel]}"
172173
next unless os.start_with? RspecPuppetFacts.spec_facts_os_filter if RspecPuppetFacts.spec_facts_os_filter
173174
facts.merge! RspecPuppetFacts.common_facts
175+
facts.delete_if { |fact, _value| RspecPuppetFacts::LegacyFacts.legacy_fact?(fact) } if RSpec.configuration.include_legacy_facts == false
174176
os_facts_hash[os] = RspecPuppetFacts.with_custom_facts(os, facts)
175177
end
176178

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
module RspecPuppetFacts
2+
# This module contains lists of all legacy facts
3+
module LegacyFacts
4+
# Used to determine if a fact is a legacy fact or not
5+
#
6+
# @return [Boolean] Is the fact a legacy fact
7+
# @param [Symbol] fact Fact name
8+
def self.legacy_fact?(fact)
9+
legacy_facts.include?(fact) or fact.to_s.match(Regexp.union(legacy_fact_regexes))
10+
end
11+
12+
# @api private
13+
def self.legacy_fact_regexes
14+
[
15+
/\Ablockdevice_(?<devicename>.+)_model\Z/,
16+
/\Ablockdevice_(?<devicename>.+)_size\Z/,
17+
/\Ablockdevice_(?<devicename>.+)_vendor\Z/,
18+
/\Aipaddress6_(?<interface>.+)\Z/,
19+
/\Aipaddress_(?<interface>.+)\Z/,
20+
/\Amacaddress_(?<interface>.+)\Z/,
21+
/\Amtu_(?<interface>.+)\Z/,
22+
/\Anetmask6_(?<interface>.+)\Z/,
23+
/\Anetmask_(?<interface>.+)\Z/,
24+
/\Anetwork6_(?<interface>.+)\Z/,
25+
/\Anetwork_(?<interface>.+)\Z/,
26+
/\Ascope6_(?<interface>.+)\Z/,
27+
/\Aldom_(?<name>.+)\Z/,
28+
/\Aprocessor\d+\Z/,
29+
/\Asp_(?<name>.+)\Z/,
30+
/\Assh(?<algorithm>.+)key\Z/,
31+
/\Asshfp_(?<algorithm>.+)\Z/,
32+
/\Azone_(?<name>.+)_brand\Z/,
33+
/\Azone_(?<name>.+)_id\Z/,
34+
/\Azone_(?<name>.+)_iptype\Z/,
35+
/\Azone_(?<name>.+)_name\Z/,
36+
/\Azone_(?<name>.+)_path\Z/,
37+
/\Azone_(?<name>.+)_status\Z/,
38+
/\Azone_(?<name>.+)_uuid\Z/
39+
]
40+
end
41+
42+
# @api private
43+
def self.legacy_facts
44+
%i[
45+
architecture
46+
augeasversion
47+
blockdevices
48+
bios_release_date
49+
bios_vendor
50+
bios_version
51+
boardassettag
52+
boardmanufacturer
53+
boardproductname
54+
boardserialnumber
55+
chassisassettag
56+
chassistype
57+
dhcp_servers
58+
domain
59+
fqdn
60+
gid
61+
hardwareisa
62+
hardwaremodel
63+
hostname
64+
id
65+
interfaces
66+
ipaddress
67+
ipaddress6
68+
lsbdistcodename
69+
lsbdistdescription
70+
lsbdistid
71+
lsbdistrelease
72+
lsbmajdistrelease
73+
lsbminordistrelease
74+
lsbrelease
75+
macaddress
76+
macosx_buildversion
77+
macosx_productname
78+
macosx_productversion
79+
macosx_productversion_major
80+
macosx_productversion_minor
81+
macosx_productversion_patch
82+
manufacturer
83+
memoryfree
84+
memoryfree_mb
85+
memorysize
86+
memorysize_mb
87+
netmask
88+
netmask6
89+
network
90+
network6
91+
operatingsystem
92+
operatingsystemmajrelease
93+
operatingsystemrelease
94+
osfamily
95+
physicalprocessorcount
96+
processorcount
97+
productname
98+
rubyplatform
99+
rubysitedir
100+
rubyversion
101+
scope6
102+
selinux
103+
selinux_config_mode
104+
selinux_config_policy
105+
selinux_current_mode
106+
selinux_enforced
107+
selinux_policyversion
108+
serialnumber
109+
swapencrypted
110+
swapfree
111+
swapfree_mb
112+
swapsize
113+
swapsize_mb
114+
windows_edition_id
115+
windows_installation_type
116+
windows_product_name
117+
windows_release_id
118+
system32
119+
uptime
120+
uptime_days
121+
uptime_hours
122+
uptime_seconds
123+
uuid
124+
xendomains
125+
zonename
126+
zones
127+
]
128+
end
129+
end
130+
end

0 commit comments

Comments
 (0)