From 2b57e065d2220be4f172ae429190bd116ddbdaf1 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Thu, 22 Oct 2009 20:09:27 +0200 Subject: Fix #2691 - Collection AR request should not include params if querying with tags f9516d introduced a change in the way the user tags are persisted to the database: user tags are now treated as regular tags (they are stored to the tags table). Thus this commit changed the AR collector request to also look at the tags tables when collecting. Unfortunately this added a performance regression since tag request were still importing the resources parameters tables and AR was issuing a large request which was returning all the resource parameters joined with the tags. This commit fixes the AR request to join to the needed table, instead of doing an include. Including (ie eager loading) parameter values was not working for resource parameters anyway since at least 0.24 because searching by parameter add a constraint to the joins and only the searched parameter was returned instead of all parameter for a given exported resource. So on a performance standpoint this new code should be as fast 0.24 was. Signed-off-by: Brice Figureau --- lib/puppet/parser/collector.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index a7f81b4e7..a6763c419 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -102,18 +102,24 @@ class Puppet::Parser::Collector raise Puppet::DevError, "Cannot collect resources for a nil host" unless @scope.host host = Puppet::Rails::Host.find_by_name(@scope.host) - query = {:include => {:param_values => :param_name}} - search = "(exported=? AND restype=?)" values = [true, @type] search += " AND (%s)" % @equery if @equery - # this is a small performance optimisation - # the tag mechanism involves 3 more joins, which are - # needed only if we query on tags. - if search =~ /puppet_tags/ - query[:include][:puppet_tags] = :resource_tags + # note: + # we're not eagerly including any relations here because + # it can creates so much objects we'll throw out later. + # We used to eagerly include param_names/values but the way + # the search filter is built ruined those efforts and we + # were eagerly loading only the searched parameter and not + # the other ones. + query = {} + case search + when /puppet_tags/ + query = {:joins => {:resource_tags => :puppet_tag}} + when /param_name/ + query = {:joins => {:param_values => :param_name}} end # We're going to collect objects from rails, but we don't want any @@ -139,7 +145,7 @@ class Puppet::Parser::Collector # and such, we'll need to vary the conditions, but this works with no # attributes, anyway. time = Puppet::Util.thinmark do - Puppet::Rails::Resource.find(:all, @type, true, query).each do |obj| + Puppet::Rails::Resource.find(:all, query).each do |obj| if resource = exported_resource(obj) count += 1 resources << resource -- cgit From d383ab897937a7e7e5fcf2929a63241e894f7616 Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Thu, 15 Oct 2009 19:07:22 -0400 Subject: Use notice() in the versioncmp() docs Use of notify() is an error, so replace it with notice, which is a function. Alternately, notify { msg => '2.6-1 is > than 2.4.5' } could be used. Signed-off-by: Todd Zullinger --- lib/puppet/parser/functions/versioncmp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/functions/versioncmp.rb b/lib/puppet/parser/functions/versioncmp.rb index bdf539127..9435655a7 100644 --- a/lib/puppet/parser/functions/versioncmp.rb +++ b/lib/puppet/parser/functions/versioncmp.rb @@ -18,7 +18,7 @@ This functions returns a number:: Example:: if versioncmp('2.6-1', '2.4.5') > 0 { - notify('2.6-1 is > than 2.4.5') + notice('2.6-1 is > than 2.4.5') } ") do |args| -- cgit From 73d04c6b15e1b626cd7dea1f963a5ca02a810137 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 26 Oct 2009 00:43:29 -0700 Subject: Bug #2534 Raise error if property appears twice This patch changes Puppet::Parser::Resource to check if it has been passed two Puppet::Parser::Resource::Param objects with the same name. Signed-off-by: Jesse Wolfe --- lib/puppet/parser/resource.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index b8aaf2715..651ed4224 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -139,6 +139,12 @@ class Puppet::Parser::Resource if params = options[:params] options.delete(:params) params.each do |param| + # Don't set the same parameter twice + if @params[param.name] + self.fail Puppet::ParseError, "Duplicate parameter '%s' for on %s" % + [param.name, self.to_s] + end + set_parameter(param) end end -- cgit From 09fb3f707dfce31a11eda2f35bd77e65c911c15f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 26 Oct 2009 20:39:41 -0700 Subject: Fixing #2752 - "require" loads "include" Signed-off-by: Luke Kanies --- lib/puppet/parser/functions/require.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb index 3a2032d7f..d72169af5 100644 --- a/lib/puppet/parser/functions/require.rb +++ b/lib/puppet/parser/functions/require.rb @@ -27,7 +27,10 @@ Note that this function only works with clients 0.25 and later, and it will fail if used with earlier clients. ") do |vals| - send(:function_include, vals) + # Verify that the 'include' function is loaded + method = Puppet::Parser::Functions.function(:include) + + send(method, vals) if resource.metaparam_compatibility_mode? warning "The 'require' function is only compatible with clients at 0.25 and above; including class but not adding dependency" else -- cgit From b1c57e9c15b1b7f079dc99dfc79e57fe3e5682e0 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Wed, 4 Nov 2009 17:36:43 -0800 Subject: Al Hoang's patch for #2781, removing obsolete when/: syntax This is just Al's patch with removal of trailing ";"s. Signed-off-by: Markus Roberts --- lib/puppet/parser/ast/boolean_operator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/ast/boolean_operator.rb b/lib/puppet/parser/ast/boolean_operator.rb index 160e0e69e..89725d73b 100644 --- a/lib/puppet/parser/ast/boolean_operator.rb +++ b/lib/puppet/parser/ast/boolean_operator.rb @@ -20,14 +20,14 @@ class Puppet::Parser::AST # return result # lazy evaluate right operand case @operator - when "and"; + when "and" if Puppet::Parser::Scope.true?(lval) rval = @rval.safeevaluate(scope) Puppet::Parser::Scope.true?(rval) else # false and false == false false end - when "or"; + when "or" if Puppet::Parser::Scope.true?(lval) true else -- cgit From 38ec9fcc5f3965942a74c8d7b7dfd1cf1796c0df Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Tue, 10 Nov 2009 18:19:59 +0100 Subject: Fix #2796 - Fix puppetdoc rdoc selector parsing This patch fix this bug by adding more to_s methods to ast member so that puppetdoc can just to_s the AST to reconstruct the original puppet code. Of course this is not perfect, but should work most of the time. Signed-off-by: Brice Figureau --- lib/puppet/parser/ast/leaf.rb | 4 ++++ lib/puppet/parser/ast/resourceparam.rb | 4 ++++ lib/puppet/parser/ast/selector.rb | 4 ++++ 3 files changed, 12 insertions(+) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index 153120a34..b73c781e1 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -150,6 +150,10 @@ class Puppet::Parser::AST return scope.lookupvar(@value) end end + + def to_s + "\$#{value}" + end end class Regex < AST::Leaf diff --git a/lib/puppet/parser/ast/resourceparam.rb b/lib/puppet/parser/ast/resourceparam.rb index c552a7ee5..e6d9df17f 100644 --- a/lib/puppet/parser/ast/resourceparam.rb +++ b/lib/puppet/parser/ast/resourceparam.rb @@ -18,5 +18,9 @@ class Puppet::Parser::AST :add => self.add ) end + + def to_s + "#{@param} => #{@value.to_s}" + end end end diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb index 1b05f57f0..84bc2a74a 100644 --- a/lib/puppet/parser/ast/selector.rb +++ b/lib/puppet/parser/ast/selector.rb @@ -41,5 +41,9 @@ class Puppet::Parser::AST ensure scope.unset_ephemeral_var end + + def to_s + param.to_s + " ? { " + values.collect { |v| v.to_s }.join(', ') + " }" + end end end -- cgit From e2c675edb5aecb5af6399ac53f9a85ed8214b8e9 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 13 Nov 2009 14:35:34 +1100 Subject: Updated generate function documentation to make it clear it runs on the master --- lib/puppet/parser/functions/generate.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/functions/generate.rb b/lib/puppet/parser/functions/generate.rb index 1be9016ed..18fe883b4 100644 --- a/lib/puppet/parser/functions/generate.rb +++ b/lib/puppet/parser/functions/generate.rb @@ -1,7 +1,7 @@ # Runs an external command and returns the results Puppet::Parser::Functions::newfunction(:generate, :type => :rvalue, - :doc => "Calls an external command and returns the results of the - command. Any arguments are passed to the external command as + :doc => "Calls an external command on the Puppet master and returns + the results of the command. Any arguments are passed to the external command as arguments. If the generator does not exit with return code of 0, the generator is considered to have failed and a parse error is thrown. Generators can only have file separators, alphanumerics, dashes, -- cgit From bd5dc649ad55fc4724cafad99852b825adfde182 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Thu, 12 Nov 2009 23:30:13 -0800 Subject: Possible workaround for #2824 (MRI GC bug) This is a moderately ugly workaround for the MRI garbage collection bug (see the ticket for details). I explored several other potential solutions (notably, monkey patching the routines that trigger the bug) but none of them were satisfactory. Monkey patching sub, gsub, sub!, gsub!, etc., for example, either changes the scoping of $~, $1, etc. in a way that could potentially subtly change the meaning of programs or (if you are clever) faithfully reproduces the behaviour of MRI--including the memory leak. I decided to go with the standardized and somewhat obnoxious never- used optional argument as it was easy to automatically insert and should be even easier to automatically find and remove if a better fix is developed. It also should be obtrusive enough to escape accidental removal in refactoring. --- lib/puppet/parser/ast/leaf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index b73c781e1..c8ac6f7e3 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -101,7 +101,7 @@ class Puppet::Parser::AST end end - def to_classname + def to_classname(dummy_argument=:work_arround_for_ruby_GC_bug) to_s.downcase.gsub(/[^-\w:.]/,'').sub(/^\.+/,'') end -- cgit