Skip to content

Commit de99364

Browse files
committed
Update validate_data_hash to return modified hash
Puppet::Pops::Lookup::ModuleDataProvider#validate_data_hash is a method that is supposed to prune a data hash of any keys that are not prefixed with a given module's name. However prior to this commit it incorrectly took the data hash, cloned it, operated on the clone, then returned the unchanged original hash. This commit updates validate_data_hash to instead return the modified hash, and updates the warning message generated when a key is pruned to include the key.
1 parent fb44fd9 commit de99364

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Diff for: lib/puppet/pops/lookup/module_data_provider.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ def validate_data_hash(data_hash)
5151
next memo if k == LOOKUP_OPTIONS || k.start_with?(module_prefix)
5252

5353
msg = "#{yield} must use keys qualified with the name of the module"
54-
memo = memo.clone if memo.equal?(data_hash)
5554
memo.delete(k)
56-
Puppet.warning("Module '#{module_name}': #{msg}")
55+
Puppet.warning("Module '#{module_name}': #{msg}; got #{k}")
5756
memo
5857
end
5958
data_hash

Diff for: spec/unit/functions/lookup_fixture_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def compile_and_get_notifications(code)
377377
expect { compiler.compile }.to raise_error(Puppet::ParseError, /did not find a value for the name 'bad_data::b'/)
378378
end
379379
warnings = logs.select { |log| log.level == :warning }.map { |log| log.message }
380-
expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module")
380+
expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module; got b")
381381
end
382382

383383
it 'will succeed finding prefixed keys even when a key in the function provided module data is not prefixed' do
@@ -391,7 +391,7 @@ def compile_and_get_notifications(code)
391391
expect(resources).to include('module_c')
392392
end
393393
warnings = logs.select { |log| log.level == :warning }.map { |log| log.message }
394-
expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module")
394+
expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module; got b")
395395
end
396396

397397
it 'will resolve global, environment, and module correctly' do
@@ -422,8 +422,8 @@ def compile_and_get_notifications(code)
422422
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
423423
compiler.compile
424424
end
425-
warnings = logs.select { |log| log.level == :warning }.map { |log| log.message }
426-
expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module")
425+
warnings = logs.filter_map { |log| log.message if log.level == :warning }
426+
expect(warnings).to include("Module 'bad_data': Value returned from deprecated API function 'bad_data::data' must use keys qualified with the name of the module; got b")
427427
end
428428

429429
it 'a warning will be logged when key in the hiera provided module data is not prefixed' do
@@ -432,8 +432,8 @@ def compile_and_get_notifications(code)
432432
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
433433
compiler.compile
434434
end
435-
warnings = logs.select { |log| log.level == :warning }.map { |log| log.message }
436-
expect(warnings).to include("Module 'hieraprovider': Value returned from data_hash function 'json_data', when using location '#{environmentpath}/production/modules/hieraprovider/data/first.json', must use keys qualified with the name of the module")
435+
warnings = logs.filter_map { |log| log.message if log.level == :warning }
436+
expect(warnings).to include("Module 'hieraprovider': Value returned from data_hash function 'json_data', when using location '#{environmentpath}/production/modules/hieraprovider/data/first.json', must use keys qualified with the name of the module; got test::param_b")
437437
end
438438
end
439439

Diff for: spec/unit/pops/lookup/lookup_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Lookup
2828
a: a (from global)
2929
d: d (from global)
3030
mod::e: mod::e (from global)
31+
other::y: should be removed
3132
YAML
3233
}
3334
}

0 commit comments

Comments
 (0)