Skip to content

Commit e2f3a0c

Browse files
authored
Merge pull request #9038 from tvpartytonight/PUP-11751-interpolation-fix
(PUP-11751) catch :undefined_variable when defaults defined
2 parents 787ce09 + 2e51810 commit e2f3a0c

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
lines changed

acceptance/tests/lookup/config5_interpolation.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
# lookup in a masterless setup.
1111
'server'
1212

13-
# pending_test('unexpected `::roles` returning undefined here, but the test passes when strict=warning')
14-
# Should revisit this in PUP-11751
15-
1613
app_type = File.basename(__FILE__, '.*')
1714
tmp_environment = mk_tmp_environment_with_teardown(master, app_type + '1')
1815
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"

lib/puppet/pops/lookup/interpolation.rb

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ def interpolate_method(method_key)
9090
lookup_invocation.report_found_in_overrides(root_key, ovr[root_key])
9191
else
9292
scope = lookup_invocation.scope
93-
val = scope[root_key]
94-
if val.nil? && !nil_in_scope?(scope, root_key)
95-
defaults = lookup_invocation.default_values
96-
if defaults.include?(root_key)
97-
lookup_invocation.report_found_in_defaults(root_key, defaults[root_key])
98-
else
99-
nil
100-
end
93+
val = nil
94+
if (default_val = lookup_invocation.default_values[root_key])
95+
catch(:undefined_variable) { val = scope[root_key] }
96+
else
97+
val = scope[root_key]
98+
end
99+
if val.nil? && default_val.nil?
100+
nil
101+
elsif val.nil?
102+
lookup_invocation.report_found_in_defaults(root_key, default_val)
101103
else
102104
lookup_invocation.report_found(root_key, val)
103105
end
@@ -125,15 +127,6 @@ def interpolate_method(method_key)
125127
interpolate_method
126128
end
127129

128-
# Because the semantics of Puppet::Parser::Scope#include? differs from Hash#include?
129-
def nil_in_scope?(scope, key)
130-
if scope.is_a?(Hash)
131-
scope.include?(key)
132-
else
133-
scope.exist?(key)
134-
end
135-
end
136-
137130
def get_method_and_data(data, allow_methods)
138131
match = data.match(/^(\w+)\((?:["]([^"]+)["]|[']([^']+)['])\)$/)
139132
if match

spec/unit/functions/lookup_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,6 @@ def uri_test_func(options, context)
24202420
end
24212421

24222422
it 'defaults are used when data is not found in scope interpolations' do
2423-
pending('See PUP-11751')
24242423
expect(lookup('mod_a::interpolate_scope_xd', { 'default_values_hash' => defaults })).to eql('-- value scope_xd (from default) --')
24252424
end
24262425

0 commit comments

Comments
 (0)