diff options
author | Luke Kanies <luke@madstop.com> | 2008-07-15 19:01:12 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-02-06 18:08:39 -0600 |
commit | 2afff60abe430dc1e2660fa82807e131e1dc71aa (patch) | |
tree | c9f65993e46214e9123ae6f79da368d185ba612d | |
parent | 361db45875768727d3c5f310c76850f350e6441f (diff) | |
download | puppet-2afff60abe430dc1e2660fa82807e131e1dc71aa.tar.gz puppet-2afff60abe430dc1e2660fa82807e131e1dc71aa.tar.xz puppet-2afff60abe430dc1e2660fa82807e131e1dc71aa.zip |
Adding support for skipping cached indirection instances.
This will allow the soon-to-be-created Agent class to
skip cached catalogs when desired.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/indirector/indirection.rb | 4 | ||||
-rw-r--r-- | lib/puppet/indirector/request.rb | 13 | ||||
-rwxr-xr-x | spec/unit/indirector/indirection.rb | 9 | ||||
-rwxr-xr-x | spec/unit/indirector/request.rb | 8 |
4 files changed, 29 insertions, 5 deletions
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index d4f8af7f7..4ca19cb27 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -186,7 +186,7 @@ class Puppet::Indirector::Indirection terminus = prepare(request) # See if our instance is in the cache and up to date. - if cache? and cached = cache.find(request) + if cache? and request.use_cache? and cached = cache.find(request) if cached.expired? Puppet.info "Not using expired %s for %s from cache; expired at %s" % [self.name, request.key, cached.expiration] else @@ -198,7 +198,7 @@ class Puppet::Indirector::Indirection # Otherwise, return the result from the terminus, caching if appropriate. if result = terminus.find(request) result.expiration ||= self.expiration - if cache? + if cache? and request.use_cache? Puppet.info "Caching %s for %s" % [self.name, request.key] cache.save request(:save, result, *args) end diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 49cc01aab..4149d0db9 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -4,7 +4,7 @@ require 'puppet/indirector' # Indirection call, and as a a result also handles REST calls. It's somewhat # analogous to an HTTP Request object, except tuned for our Indirector. class Puppet::Indirector::Request - attr_accessor :indirection_name, :key, :method, :options, :instance, :node, :ip, :authenticated + attr_accessor :indirection_name, :key, :method, :options, :instance, :node, :ip, :authenticated, :use_cache attr_accessor :server, :port, :uri, :protocol @@ -48,7 +48,16 @@ class Puppet::Indirector::Request # Look up the indirection based on the name provided. def indirection - Puppet::Indirector::Indirection.instance(@indirection_name) + Puppet::Indirector::Indirection.instance(indirection_name) + end + + # Should we allow use of the cached object? + def use_cache? + if defined?(@use_cache) + ! ! use_cache + else + true + end end # Are we trying to interact with multiple resources, or just one? diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb index 564b2d871..6fdb2ba57 100755 --- a/spec/unit/indirector/indirection.rb +++ b/spec/unit/indirector/indirection.rb @@ -246,7 +246,7 @@ describe Puppet::Indirector::Indirection do describe "when caching is enabled" do before do @indirection.cache_class = :cache_terminus - @cache_class.expects(:new).returns(@cache) + @cache_class.stubs(:new).returns(@cache) @instance.stubs(:expired?).returns false end @@ -258,6 +258,13 @@ describe Puppet::Indirector::Indirection do @indirection.find("/my/key") end + it "should not look in the cache if the request specifies not to use the cache" do + @terminus.expects(:find).returns @instance + @cache.expects(:find).never + + @indirection.find("/my/key", :use_cache => false) + end + it "should use a request to look in the cache for cached objects" do @cache.expects(:find).with { |r| r.method == :find and r.key == "/my/key" }.returns @instance diff --git a/spec/unit/indirector/request.rb b/spec/unit/indirector/request.rb index 18f625946..5203280d8 100755 --- a/spec/unit/indirector/request.rb +++ b/spec/unit/indirector/request.rb @@ -126,6 +126,14 @@ describe Puppet::Indirector::Request do Puppet::Indirector::Request.new(:ind, :method, "http:///stuff").uri.should == "http:///stuff" end end + + it "should allow indication that it should not use a cached instance" do + Puppet::Indirector::Request.new(:ind, :method, :key, :use_cache => false).should_not be_use_cache + end + + it "should default to using cached instances" do + Puppet::Indirector::Request.new(:ind, :method, :key).should be_use_cache + end end it "should look use the Indirection class to return the appropriate indirection" do |