Skip to content

Commit 03bb0ea

Browse files
authored
Merge pull request #138 from puppetlabs/bugfix-legacy_fact_corrector
(CAT-1167) Fix failing legacy fact autocorrector
2 parents 751d30e + bea0e5a commit 03bb0ea

File tree

2 files changed

+14
-48
lines changed

2 files changed

+14
-48
lines changed

lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717

1818
PuppetLint.new_check(:top_scope_facts) do
1919
def check
20-
whitelist = ['trusted', 'facts'] + (PuppetLint.configuration.top_scope_variables || [])
20+
whitelist = ['trusted', 'facts', 'architecture', 'augeasversion', 'bios_release_date', 'bios_vendor', 'bios_version',
21+
'boardassettag', 'boardmanufacturer', 'boardproductname', 'boardserialnumber', 'chassisassettag', 'chassistype', 'domain',
22+
'fqdn', 'gid', 'hardwareisa', 'hardwaremodel', 'hostname', 'id', 'ipaddress', 'ipaddress6', 'lsbdistcodename',
23+
'lsbdistdescription', 'lsbdistid', 'lsbdistrelease', 'lsbmajdistrelease', 'lsbminordistrelease', 'lsbrelease',
24+
'macaddress', 'macosx_buildversion', 'macosx_productname', 'macosx_productversion', 'macosx_productversion_major',
25+
'macosx_productversion_minor', 'manufacturer', 'memoryfree', 'memorysize', 'netmask', 'netmask6', 'network', 'network6',
26+
'operatingsystem', 'operatingsystemmajrelease', 'operatingsystemrelease', 'osfamily', 'physicalprocessorcount',
27+
'processorcount', 'productname', 'rubyplatform', 'rubysitedir', 'rubyversion', 'selinux', 'selinux_config_mode',
28+
'selinux_config_policy', 'selinux_current_mode', 'selinux_enforced', 'selinux_policyversion', 'serialnumber',
29+
'swapencrypted', 'swapfree', 'swapsize', 'system32', 'uptime', 'uptime_days', 'uptime_hours', 'uptime_seconds',
30+
'uuid', 'xendomains', 'zonename'] + (PuppetLint.configuration.top_scope_variables || [])
2131
whitelist = whitelist.join('|')
2232
tokens.select { |x| TOP_SCOPE_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
2333
next unless %r{^::}.match?(token.value)

spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,10 @@
3737
end
3838

3939
context 'fact variable using top scope' do
40-
let(:code) { '$::operatingsystem' }
40+
let(:code) { '$::fqdn' }
4141

42-
it 'onlies detect a single problem' do
43-
expect(problems).to have(1).problem
44-
end
45-
46-
it 'creates a warning' do
47-
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
48-
end
49-
end
50-
51-
context 'fact variable using top scope with curly braces in double quote' do
52-
let(:code) { '"${::operatingsystem}"' }
53-
54-
it 'onlies detect a single problem' do
55-
expect(problems).to have(1).problem
56-
end
57-
58-
it 'creates a warning' do
59-
expect(problems).to contain_warning(msg).on_line(1).in_column(4)
42+
it 'does not detect a single problem' do
43+
expect(problems).to have(0).problem
6044
end
6145
end
6246

@@ -126,34 +110,6 @@
126110
end
127111
end
128112

129-
context 'fact variable using top scope' do
130-
let(:code) { '$::operatingsystem' }
131-
132-
it 'onlies detect a single problem' do
133-
expect(problems).to have(1).problem
134-
end
135-
136-
it 'fixes the problem' do
137-
expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
138-
end
139-
140-
it 'shoulds use the facts hash' do
141-
expect(manifest).to eq("$facts['operatingsystem']")
142-
end
143-
end
144-
145-
context 'fact variable using top scope with curly braces in double quote' do
146-
let(:code) { '"${::operatingsystem}"' }
147-
148-
it 'fixes the problem' do
149-
expect(problems).to contain_fixed(msg).on_line(1).in_column(4)
150-
end
151-
152-
it 'shoulds use the facts hash' do
153-
expect(manifest).to eq('"${facts[\'operatingsystem\']}"')
154-
end
155-
end
156-
157113
context 'with custom top scope fact variables' do
158114
before(:each) do
159115
PuppetLint.configuration.top_scope_variables = ['location', 'role']

0 commit comments

Comments
 (0)