summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2010-06-23 16:33:45 -0700
committerJames Turnbull <james@lovedthanlost.net>2010-06-27 03:50:50 +1000
commitdb39b7c0848f8931989cbe21ff202552c0ae78c1 (patch)
treefe49157c45e6fd5e5666821920cac60b8a961fe4 /lib
parent428683917e4819e294f65511932eb1c9067d8cb8 (diff)
downloadpuppet-db39b7c0848f8931989cbe21ff202552c0ae78c1.tar.gz
puppet-db39b7c0848f8931989cbe21ff202552c0ae78c1.tar.xz
puppet-db39b7c0848f8931989cbe21ff202552c0ae78c1.zip
[#4026] When --use_cached_catalog is specified on a puppetd run actully use the cache
Running puppetd with --use_cached_catalog you would see messages like: info: Not using expired catalog for mattmac.local from cache notice: Using cached catalog Both Puppet::Util::Cacher, which extends catalogs, and Puppet::Indirector::Envelope, which extends all Indirection objects including catalogs, have their own cache expiring mechanisms. The Envelope mechanism was declining to use cached catalogs without taking into account what the --use_cached_catalog options said. This patch fixes so it uses the cached catalog and just logs: debug: Using cached catalog for mattmac.local This commit also renames a method that makes requests from request to instantiate request, and gets rid of the extender hook on Cacher since it was only being used on one test and probably shouldn't be used in general. Reviewed by: Nick Lewis
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/configurer.rb1
-rw-r--r--lib/puppet/indirector/indirection.rb20
-rw-r--r--lib/puppet/resource/catalog.rb5
-rw-r--r--lib/puppet/util/cacher.rb9
4 files changed, 15 insertions, 20 deletions
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 6aeac7486..551d99684 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -194,7 +194,6 @@ class Puppet::Configurer
@duration = thinmark do
result = Puppet::Resource::Catalog.find(Puppet[:certname], fact_options.merge(:ignore_terminus => true))
end
- Puppet.notice "Using cached catalog"
result
rescue => detail
puts detail.backtrace if Puppet[:trace]
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 7c3183396..97fd03ad4 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -116,7 +116,7 @@ class Puppet::Indirector::Indirection
end
# Set up our request object.
- def request(method, key, arguments = nil)
+ def instantiate_request(method, key, arguments = nil)
Puppet::Indirector::Request.new(self.name, method, key, arguments)
end
@@ -169,24 +169,24 @@ class Puppet::Indirector::Indirection
# remove it, we expire it and write it back out to disk. This way people
# can still use the expired object if they want.
def expire(key, *args)
- request = request(:expire, key, *args)
+ request = instantiate_request(:expire, key, *args)
return nil unless cache?
- return nil unless instance = cache.find(request(:find, key, *args))
+ return nil unless instance = cache.find(instantiate_request(:find, key, *args))
Puppet.info "Expiring the %s cache of %s" % [self.name, instance.name]
# Set an expiration date in the past
instance.expiration = Time.now - 60
- cache.save(request(:save, instance, *args))
+ cache.save(instantiate_request(:save, instance, *args))
end
# Search for an instance in the appropriate terminus, caching the
# results if caching is configured..
def find(key, *args)
- request = request(:find, key, *args)
+ request = instantiate_request(:find, key, *args)
terminus = prepare(request)
begin
@@ -203,7 +203,7 @@ class Puppet::Indirector::Indirection
result.expiration ||= self.expiration
if cache? and request.use_cache?
Puppet.info "Caching %s for %s" % [self.name, request.key]
- cache.save request(:save, result, *args)
+ cache.save instantiate_request(:save, result, *args)
end
return terminus.respond_to?(:filter) ? terminus.filter(result) : result
@@ -226,12 +226,12 @@ class Puppet::Indirector::Indirection
# Remove something via the terminus.
def destroy(key, *args)
- request = request(:destroy, key, *args)
+ request = instantiate_request(:destroy, key, *args)
terminus = prepare(request)
result = terminus.destroy(request)
- if cache? and cached = cache.find(request(:find, key, *args))
+ if cache? and cached = cache.find(instantiate_request(:find, key, *args))
# Reuse the existing request, since it's equivalent.
cache.destroy(request)
end
@@ -241,7 +241,7 @@ class Puppet::Indirector::Indirection
# Search for more than one instance. Should always return an array.
def search(key, *args)
- request = request(:search, key, *args)
+ request = instantiate_request(:search, key, *args)
terminus = prepare(request)
if result = terminus.search(request)
@@ -256,7 +256,7 @@ class Puppet::Indirector::Indirection
# Save the instance in the appropriate terminus. This method is
# normally an instance method on the indirected class.
def save(instance, *args)
- request = request(:save, instance, *args)
+ request = instantiate_request(:save, instance, *args)
terminus = prepare(request)
result = terminus.save(request)
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 6f589083c..a0a871126 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -49,6 +49,11 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
# Some metadata to help us compile and generally respond to the current state.
attr_accessor :client_version, :server_version
+ def expired?
+ return false if Puppet[:use_cached_catalog]
+ super
+ end
+
# Add classes to our class list.
def add_class(*classes)
classes.each do |klass|
diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb
index 28786ab53..3c9d24db9 100644
--- a/lib/puppet/util/cacher.rb
+++ b/lib/puppet/util/cacher.rb
@@ -18,15 +18,6 @@ module Puppet::Util::Cacher
extend Expirer
- # Our module has been extended in a class; we can only add the Instance methods,
- # which become *class* methods in the class.
- def self.extended(other)
- class << other
- extend ClassMethods
- include InstanceMethods
- end
- end
-
# Our module has been included in a class, which means the class gets the class methods
# and all of its instances get the instance methods.
def self.included(other)