Greetings!

Please review the pull request #98: Feature/2.7.x/9051 storeconfig backend should be configurable opened by (daniel-pittman)

Some more information about the pull request:

  • Opened: Thu Sep 08 21:28:12 UTC 2011
  • Based on: puppetlabs:2.7.x (b4ea0862b130293a5521709280e2a758b85d1f39)
  • Requested merge: daniel-pittman:feature/2.7.x/9051-storeconfig-backend-should-be-configurable (a04051a48c249e78543e2cc8b0f7bdf5bc1c1e74)

Description:

When the StoreConfig system was extracted from core to a set of termini, most
of the rules about permitted syntax were pushed down into the same place, to
allow them to also be replaced.

One set of restrictions were missed, the limitation that complex search
criteria (like and, or, or parenthetical expressions) were not permitted, and
remained in our parser.

Now, they live in the terminus, and we enforce them only there. This ensures
that StoreConfigs can be replaced with a back-end that supports complex
collection criteria without other changes to the Puppet core.

Signed-off-by: Daniel Pittman dan...@puppetlabs.com

Thanks!
The Pull Request Bot

Diff follows:

diff --git a/lib/puppet/indirector/resource/active_record.rb b/lib/puppet/indirector/resource/active_record.rb
index c2fd188..12aeaae 100644
--- a/lib/puppet/indirector/resource/active_record.rb
+++ b/lib/puppet/indirector/resource/active_record.rb
@@ -6,6 +6,10 @@ class Puppet::Resource::ActiveRecord < Puppet::Indirector::ActiveRecord
     host   = request.options[:host]
     filter = request.options[:filter]
 
+    if filter and filter[1] =~ /^(and|or)$/i then
+      raise Puppet::Error, "Complex search on StoreConfigs resources is not supported"
+    end
+
     query = build_active_record_query(type, host, filter)
     Puppet::Rails::Resource.find(:all, query)
   end
diff --git a/lib/puppet/parser/ast/collexpr.rb b/lib/puppet/parser/ast/collexpr.rb
index d5bd4e9..6032094 100644
--- a/lib/puppet/parser/ast/collexpr.rb
+++ b/lib/puppet/parser/ast/collexpr.rb
@@ -44,17 +44,7 @@ class CollExpr < AST::Branch
       end
     end
 
-    # Now build up the rails conditions code
-    if self.parens and self.form == :exported
-      Puppet.warning "Parentheses are ignored in Rails searches"
-    end
-
-    if form == :exported and (@oper =~ /^(and|or)$/i) then
-      raise Puppet::ParseError, "Puppet does not currently support collecting exported resources with more than one condition"
-    end
-
     match = [match1, @oper, match2]
-
     return match, code
   end
 
diff --git a/spec/unit/indirector/resource/active_record_spec.rb b/spec/unit/indirector/resource/active_record_spec.rb
index 5785756..d04fe96 100755
--- a/spec/unit/indirector/resource/active_record_spec.rb
+++ b/spec/unit/indirector/resource/active_record_spec.rb
@@ -56,6 +56,15 @@ describe "Puppet::Resource::ActiveRecord", :if => (Puppet.features.rails? and de
       search("exec").should == []
     end
 
+    # Assert that this is a case-insensitive rule, too.
+    %w{and or AND OR And Or anD oR}.each do |op|
+      it "should fail if asked to search with #{op.inspect}" do
+        filter = [%w{tag == foo}, op, %w{title == bar}]
+        expect { search("notify", 'localhost', filter) }.
+          to raise_error Puppet::Error, /not supported/
+      end
+    end
+
     context "with a matching resource" do
       before :each do
         host = Puppet::Rails::Host.create!(:name => 'one.local')
diff --git a/spec/unit/parser/ast/collexpr_spec.rb b/spec/unit/parser/ast/collexpr_spec.rb
index 5629772..8782962 100755
--- a/spec/unit/parser/ast/collexpr_spec.rb
+++ b/spec/unit/parser/ast/collexpr_spec.rb
@@ -59,16 +59,20 @@ describe Puppet::Parser::AST::CollExpr do
       end
     end
 
-    it "should warn if this is an exported collection containing parenthesis (unsupported)" do
-      collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==", :parens => true, :form => :exported)
-      Puppet.expects(:warning)
-      collexpr.evaluate(@scope)
+    it "should work if this is an exported collection containing parenthesis" do
+      collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2,
+                                   :oper => "==", :parens => true, :form => :exported)
+      match, code = collexpr.evaluate(@scope)
+      match.should == ["test1", "==", "test2"]
+      @logs.should be_empty     # no warnings emitted
     end
 
     %w{and or}.each do |op|
-      it "should raise an error if this is an exported collection with #{op} operator (unsupported)" do
-        collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=> op, :form => :exported)
-        lambda { collexpr.evaluate(@scope) }.should raise_error(Puppet::ParseError)
+      it "should parse / eval if this is an exported collection with #{op} operator" do
+        collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2,
+                                     :oper => op, :form => :exported)
+        match, code = collexpr.evaluate(@scope)
+        match.should == ["test1", op, "test2"]
       end
     end
   end

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to