From f9516d49a02facb43e2856766b6439673450fdd1 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Wed, 3 Jun 2009 21:10:36 +0200 Subject: Make sure virtual and rails query use tags when tag are searched Up to now, when trying to match with tags: File<<| tag == 'value' |>> in fact we were querying parameters. Hopefully all the user tags are stored in parameters so it was working. But it wasn't possible to search on auto-tags (like class name). This patch makes sure searching by tag is done on tags both on the rails side and the resource side. Signed-off-by: Brice Figureau --- lib/puppet/parser/ast/collexpr.rb | 15 +++++++++++---- lib/puppet/parser/collector.rb | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/ast/collexpr.rb b/lib/puppet/parser/ast/collexpr.rb index 54b003a91..eae2b0e42 100644 --- a/lib/puppet/parser/ast/collexpr.rb +++ b/lib/puppet/parser/ast/collexpr.rb @@ -31,10 +31,14 @@ class CollExpr < AST::Branch when "and"; code1.call(resource) and code2.call(resource) when "or"; code1.call(resource) or code2.call(resource) when "==" - if resource[str1].is_a?(Array) - resource[str1].include?(str2) + if str1 == "tag" + resource.tagged?(str2) else - resource[str1] == str2 + if resource[str1].is_a?(Array) + resource[str1].include?(str2) + else + resource[str1] == str2 + end end when "!="; resource[str1] != str2 end @@ -58,8 +62,11 @@ class CollExpr < AST::Branch if oper == "=" or oper == "!=" # Add the rails association info where necessary - if str1 == "title" + case str1 + when "title" str = "title #{oper} '#{str2}'" + when "tag" + str = "puppet_tags.name #{oper} '#{str2}'" else str = "param_values.value #{oper} '#{str2}' and " + "param_names.name = '#{str1}'" diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index ece420536..5f11a6cea 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -102,7 +102,7 @@ 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}} + query = {:include => {:param_values => :param_name, :puppet_tags => :resource_tags}} search = "(exported=? AND restype=?)" values = [true, @type] -- cgit