From 4f19c27137d6de29ae63bf73115f1e8fefd00b03 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 25 Apr 2017 12:08:46 -0700 Subject: (PE-20308) Pass a literal type and not a string to findresource - `defined_with_params` calls `findresource(reference.to_s)` - `findresource` is https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/parser/compiler.rb#L407 and points to https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L352 - This calls `Puppet::Resource.new` with the type https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource/catalog.rb#L366 - This ends up calling `resource_type` via https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L317-L319 and that ends up declaring the type via the autoloader api at https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/resource.rb#L390 - But why does the autoloader API fail to find it in the current environment? - Okay, so when the autoloader is trying to find the type, it uses the typeloader to look it up in the current environment https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/metatype/manager.rb#L171 - this calls `get_file` and `mark_loaded` https://github.com/puppetlabs/puppet/blob/4.8.1/lib/puppet/util/autoload.rb#L64-L67 Suggested workaround is to pass a literal type instead of a string to `findresource` to fix in stdlib, and also to fix loading/requiring of type in core puppet. This seems to affect more recent versions of puppet, so fallback to original behavior on pre-4.5 --- lib/puppet/parser/functions/defined_with_params.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/defined_with_params.rb') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index 99687ae..f2c6230 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -24,7 +24,25 @@ ENDOFDOC params = {} end ret = false - if resource = findresource(reference.to_s) + + if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + # Workaround for PE-20308 + if reference.is_a?(String) + type_name, title = Puppet::Resource.type_and_title(reference, nil) + type = Puppet::Type.type(type_name) + elsif reference.is_a?(Puppet::Resource) + type = reference.resource_type + title = reference.title + else + raise(ArgumentError, "Reference is not understood: '#{reference.class}'") + end + #end workaround + else + type = reference.to_s + title = nil + end + + if resource = findresource(type, title) matches = params.collect do |key, value| # eql? avoids bugs caused by monkeypatching in puppet resource_is_undef = resource[key].eql?(:undef) || resource[key].nil? -- cgit v1.2.3 From ccabfd3e1f4617a583546efaa4303bc24e53b89c Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 26 Apr 2017 09:18:43 -0700 Subject: (PE-20308) Correct boundary for 4.5 vs 4.6 --- lib/puppet/parser/functions/defined_with_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/defined_with_params.rb') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index f2c6230..7f1fe93 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -25,7 +25,7 @@ ENDOFDOC end ret = false - if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0 # Workaround for PE-20308 if reference.is_a?(String) type_name, title = Puppet::Resource.type_and_title(reference, nil) -- cgit v1.2.3 From 32e5a87bb3b8c1d0fabc1e8c2687e4a750173cb5 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 28 Apr 2017 15:48:56 -0700 Subject: (PE-20308) Also fix defined type strings & references --- lib/puppet/parser/functions/defined_with_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/defined_with_params.rb') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index 7f1fe93..e0d4e37 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -29,7 +29,7 @@ ENDOFDOC # Workaround for PE-20308 if reference.is_a?(String) type_name, title = Puppet::Resource.type_and_title(reference, nil) - type = Puppet::Type.type(type_name) + type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name) elsif reference.is_a?(Puppet::Resource) type = reference.resource_type title = reference.title -- cgit v1.2.3 From 7b8b9f8aff906460dcac5d84ef8f44449b8ce395 Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Wed, 14 Jun 2017 10:34:13 +0200 Subject: (MODULES-5095) Workaround for PUP-7650 This commit adds a simple workaround for the problem described in PUP-7650. The workaround is harmless and can remain in place regardless of if the fix for PUP-7650 is in place or not. --- lib/puppet/parser/functions/defined_with_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/defined_with_params.rb') diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index e0d4e37..c45a9df 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -29,7 +29,7 @@ ENDOFDOC # Workaround for PE-20308 if reference.is_a?(String) type_name, title = Puppet::Resource.type_and_title(reference, nil) - type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name) + type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name.downcase) elsif reference.is_a?(Puppet::Resource) type = reference.resource_type title = reference.title -- cgit v1.2.3