diff options
-rw-r--r-- | lib/puppet/parser/ast/collexpr.rb | 15 | ||||
-rw-r--r-- | lib/puppet/parser/collector.rb | 2 | ||||
-rwxr-xr-x | spec/unit/parser/ast/collexpr.rb | 21 | ||||
-rwxr-xr-x | spec/unit/parser/collector.rb | 4 |
4 files changed, 35 insertions, 7 deletions
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] diff --git a/spec/unit/parser/ast/collexpr.rb b/spec/unit/parser/ast/collexpr.rb index e45203492..4dfc1e97a 100755 --- a/spec/unit/parser/ast/collexpr.rb +++ b/spec/unit/parser/ast/collexpr.rb @@ -74,6 +74,27 @@ describe Puppet::Parser::AST::CollExpr do end end + describe "when evaluating with tags" do + before :each do + @tag = stub 'tag', :safeevaluate => 'tag' + @value = stub 'value', :safeevaluate => 'value' + + @resource = stub 'resource' + @resource.stubs(:tagged?).with("value").returns(true) + end + + it "should produce a textual representation of the expression" do + collexpr = ast::CollExpr.new(:test1 => @tag, :test2 => @value, :oper=>"==") + result = collexpr.evaluate(@scope) + result[0].should == "puppet_tags.name = 'value'" + end + + it "should inspect resource tags if the query term is on tags" do + collexpr = ast::CollExpr.new(:test1 => @tag, :test2 => @value, :oper => "==") + collexpr.evaluate(@scope)[1].call(@resource).should be_true + end + end + [:exported,:virtual].each do |mode| it "should check for array member equality if resource parameter is an array for == in mode #{mode}" do array = mock 'array', :safeevaluate => "array" diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb index 813fbb8c0..3bca564dc 100755 --- a/spec/unit/parser/collector.rb +++ b/spec/unit/parser/collector.rb @@ -502,10 +502,10 @@ describe Puppet::Parser::Collector, "when building its ActiveRecord query for co @collector.evaluate end - it "should return parameter names and parameter values when querying ActiveRecord" do + it "should return parameter names, parameter values and tags when querying ActiveRecord" do Puppet::Rails::Resource.stubs(:find).with { |*arguments| options = arguments[3] - options[:include] == {:param_values => :param_name} + options[:include] == {:param_values => :param_name, :puppet_tags => :resource_tags} }.returns([]) @collector.evaluate |