summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/file_serving/configuration.rb13
-rw-r--r--lib/puppet/file_serving/mount.rb25
-rw-r--r--lib/puppet/indirector/indirection.rb22
-rw-r--r--lib/puppet/network/http_pool.rb32
-rw-r--r--lib/puppet/ssl/certificate_authority.rb9
-rw-r--r--lib/puppet/util/cacher.rb18
-rwxr-xr-xspec/integration/file_serving/configuration.rb4
-rwxr-xr-xspec/integration/indirector/rest.rb8
-rwxr-xr-xspec/integration/network/server/webrick.rb5
-rwxr-xr-xspec/integration/node/catalog.rb2
-rwxr-xr-xspec/integration/node/facts.rb6
-rwxr-xr-xspec/integration/ssl/certificate_authority.rb5
-rwxr-xr-xspec/integration/ssl/certificate_request.rb4
-rwxr-xr-xspec/integration/ssl/certificate_revocation_list.rb5
-rwxr-xr-xspec/integration/ssl/host.rb7
-rwxr-xr-xspec/integration/transaction/report.rb2
-rw-r--r--spec/shared_behaviours/file_server_terminus.rb2
-rwxr-xr-xspec/unit/file_serving/configuration.rb6
-rwxr-xr-xspec/unit/file_serving/mount.rb8
-rwxr-xr-xspec/unit/indirector/indirection.rb26
-rwxr-xr-xspec/unit/network/http_pool.rb19
-rwxr-xr-xspec/unit/node.rb2
-rwxr-xr-xspec/unit/node/catalog.rb5
-rwxr-xr-xspec/unit/node/facts.rb8
-rwxr-xr-xspec/unit/transaction/report.rb2
-rwxr-xr-xspec/unit/util/cacher.rb24
26 files changed, 109 insertions, 160 deletions
diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb
index ccf0957d1..9c38aaa19 100644
--- a/lib/puppet/file_serving/configuration.rb
+++ b/lib/puppet/file_serving/configuration.rb
@@ -5,25 +5,20 @@
require 'puppet'
require 'puppet/file_serving'
require 'puppet/file_serving/mount'
+require 'puppet/util/cacher'
class Puppet::FileServing::Configuration
require 'puppet/file_serving/configuration/parser'
+ extend Puppet::Util::Cacher
+
@config_fileuration = nil
Mount = Puppet::FileServing::Mount
- # Remove our singleton instance.
- def self.clear_cache
- @config_fileuration = nil
- end
-
# Create our singleton configuration.
def self.create
- unless @config_fileuration
- @config_fileuration = new()
- end
- @config_fileuration
+ attr_cache(:configuration) { new() }
end
private_class_method :new
diff --git a/lib/puppet/file_serving/mount.rb b/lib/puppet/file_serving/mount.rb
index 8e5bd03e8..c52cedbfb 100644
--- a/lib/puppet/file_serving/mount.rb
+++ b/lib/puppet/file_serving/mount.rb
@@ -4,6 +4,7 @@
require 'puppet/network/authstore'
require 'puppet/util/logging'
+require 'puppet/util/cacher'
require 'puppet/file_serving'
require 'puppet/file_serving/metadata'
require 'puppet/file_serving/content'
@@ -12,12 +13,16 @@ require 'puppet/file_serving/content'
# or content objects.
class Puppet::FileServing::Mount < Puppet::Network::AuthStore
include Puppet::Util::Logging
+ extend Puppet::Util::Cacher
- @@localmap = nil
-
- # Clear the cache. This is only ever used for testing.
- def self.clear_cache
- @@localmap = nil
+ def self.localmap
+ attr_cache(:localmap) {
+ { "h" => Facter.value("hostname"),
+ "H" => [Facter.value("hostname"),
+ Facter.value("domain")].join("."),
+ "d" => Facter.value("domain")
+ }
+ }
end
attr_reader :name
@@ -173,14 +178,6 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Cache this manufactured map, since if it's used it's likely
# to get used a lot.
def localmap
- unless @@localmap
- @@localmap = {
- "h" => Facter.value("hostname"),
- "H" => [Facter.value("hostname"),
- Facter.value("domain")].join("."),
- "d" => Facter.value("domain")
- }
- end
- @@localmap
+ self.class.localmap
end
end
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 05464f8c9..c70259304 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -1,20 +1,17 @@
require 'puppet/util/docs'
require 'puppet/indirector/envelope'
require 'puppet/indirector/request'
+require 'puppet/util/cacher'
# The class that connects functional classes with their different collection
# back-ends. Each indirection has a set of associated terminus classes,
# each of which is a subclass of Puppet::Indirector::Terminus.
class Puppet::Indirector::Indirection
+ include Puppet::Util::Cacher
include Puppet::Util::Docs
@@indirections = []
- # Clear all cached termini from all indirections.
- def self.clear_cache
- @@indirections.each { |ind| ind.clear_cache }
- end
-
# Find an indirection by name. This is provided so that Terminus classes
# can specifically hook up with the indirections they are associated with.
def self.instance(name)
@@ -54,13 +51,6 @@ class Puppet::Indirector::Indirection
@cache_class = class_name
end
- # Clear our cached list of termini, and reset the cache name
- # so it's looked up again.
- # This is only used for testing.
- def clear_cache
- @termini.clear
- end
-
# This is only used for testing.
def delete
@@indirections.delete(self) if @@indirections.include?(self)
@@ -104,7 +94,6 @@ class Puppet::Indirector::Indirection
@model = model
@name = name
- @termini = {}
@cache_class = nil
@terminus_class = nil
@@ -138,7 +127,7 @@ class Puppet::Indirector::Indirection
raise Puppet::DevError, "No terminus specified for %s; cannot redirect" % self.name
end
- return @termini[terminus_name] ||= make_terminus(terminus_name)
+ return termini[terminus_name] ||= make_terminus(terminus_name)
end
# This can be used to select the terminus class.
@@ -299,4 +288,9 @@ class Puppet::Indirector::Indirection
end
return klass.new
end
+
+ # Use cached termini.
+ def termini
+ attr_cache(:termini) { Hash.new }
+ end
end
diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb
index cf17a8380..78a35cc15 100644
--- a/lib/puppet/network/http_pool.rb
+++ b/lib/puppet/network/http_pool.rb
@@ -1,10 +1,13 @@
require 'puppet/ssl/host'
require 'net/https'
+require 'puppet/util/cacher'
module Puppet::Network; end
# Manage Net::HTTP instances for keep-alive.
module Puppet::Network::HttpPool
+ extend Puppet::Util::Cacher
+
# 2008/03/23
# LAK:WARNING: Enabling this has a high propability of
# causing corrupt files and who knows what else. See #1010.
@@ -17,23 +20,15 @@ module Puppet::Network::HttpPool
# Create an ssl host instance for getting certificate
# information.
def self.ssl_host
- unless defined?(@ssl_host) and @ssl_host
- @ssl_host = Puppet::SSL::Host.new
- end
- @ssl_host
+ attr_cache(:ssl_host) { Puppet::SSL::Host.new }
end
- @http_cache = {}
-
# Clear our http cache, closing all connections.
def self.clear_http_instances
- @http_cache.each do |name, connection|
+ http_cache.each do |name, connection|
connection.finish if connection.started?
end
- @http_cache.clear
- @cert = nil
- @key = nil
- @ssl_host = nil
+ Puppet::Util::Cacher.invalidate
end
# Make sure we set the driver up when we read the cert in.
@@ -69,11 +64,11 @@ module Puppet::Network::HttpPool
# Return our cached instance if we've got a cache, as long as we're not
# resetting the instance.
if keep_alive?
- return @http_cache[key] if ! reset and @http_cache[key]
+ return http_cache[key] if ! reset and http_cache[key]
# Clean up old connections if we have them.
- if http = @http_cache[key]
- @http_cache.delete(key)
+ if http = http_cache[key]
+ http_cache.delete(key)
http.finish if http.started?
end
end
@@ -103,8 +98,15 @@ module Puppet::Network::HttpPool
cert_setup(http)
- @http_cache[key] = http if keep_alive?
+ http_cache[key] = http if keep_alive?
return http
end
+
+ private
+
+ def self.http_cache
+ # Default to an empty hash.
+ attr_cache(:http) { Hash.new }
+ end
end
diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb
index cd5d79f0a..6947af11c 100644
--- a/lib/puppet/ssl/certificate_authority.rb
+++ b/lib/puppet/ssl/certificate_authority.rb
@@ -1,5 +1,6 @@
require 'puppet/ssl/host'
require 'puppet/ssl/certificate_request'
+require 'puppet/util/cacher'
# The class that knows how to sign certificates. It creates
# a 'special' SSL::Host whose name is 'ca', thus indicating
@@ -16,6 +17,8 @@ class Puppet::SSL::CertificateAuthority
require 'puppet/ssl/certificate_authority/interface'
+ extend Puppet::Util::Cacher
+
def self.ca?
return false unless Puppet[:ca]
return false unless Puppet[:name] == "puppetmasterd"
@@ -27,11 +30,7 @@ class Puppet::SSL::CertificateAuthority
def self.instance
return nil unless ca?
- unless defined?(@instance) and @instance
- @instance = new
- end
-
- @instance
+ attr_cache(:instance) { new }
end
attr_reader :name, :host
diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb
index fbab9ab42..7b352c72a 100644
--- a/lib/puppet/util/cacher.rb
+++ b/lib/puppet/util/cacher.rb
@@ -26,7 +26,7 @@ module Puppet::Util::Cacher
def cached_attr(name, &block)
define_method(name) do
- cache(name, &block)
+ attr_cache(name, &block)
end
end
end
@@ -34,7 +34,7 @@ module Puppet::Util::Cacher
module InstanceMethods
private
- def cache(name, &block)
+ def attr_cache(name, &block)
unless defined?(@cacher_caches) and @cacher_caches
@cacher_caches = Cache.new
end
@@ -44,24 +44,26 @@ module Puppet::Util::Cacher
end
class Cache
- attr_reader :timestamp, :caches
+ attr_accessor :caches, :timestamp
def initialize
- @timestamp = Time.now
@caches = {}
end
def value(name)
raise ArgumentError, "You must provide a block when using the cache" unless block_given?
- @caches.clear unless Puppet::Util::Cacher.valid?(@timestamp)
+ if timestamp.nil? or ! Puppet::Util::Cacher.valid?(timestamp)
+ caches.clear
+ self.timestamp = Time.now
+ end
# Use 'include?' here rather than testing for truth, so we
# can cache false values.
- unless @caches.include?(name)
- @caches[name] = yield
+ unless caches.include?(name)
+ caches[name] = yield
end
- @caches[name]
+ caches[name]
end
end
end
diff --git a/spec/integration/file_serving/configuration.rb b/spec/integration/file_serving/configuration.rb
index 6975594a8..cb5a23d3b 100755
--- a/spec/integration/file_serving/configuration.rb
+++ b/spec/integration/file_serving/configuration.rb
@@ -10,7 +10,7 @@ require 'puppet/file_serving/configuration'
describe Puppet::FileServing::Configuration, " when finding files with Puppet::FileServing::Mount" do
before do
# Just in case it already exists.
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
@mount = Puppet::FileServing::Mount.new("mymount")
FileTest.stubs(:exists?).with("/my/path").returns(true)
@@ -38,6 +38,6 @@ describe Puppet::FileServing::Configuration, " when finding files with Puppet::F
end
after do
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb
index 2db3b31fd..1a9671265 100755
--- a/spec/integration/indirector/rest.rb
+++ b/spec/integration/indirector/rest.rb
@@ -57,6 +57,8 @@ describe Puppet::Indirector::REST do
describe "when using webrick" do
before :each do
+ Puppet::Util::Cacher.invalidate
+
Puppet[:servertype] = 'webrick'
Puppet[:server] = '127.0.0.1'
Puppet[:certname] = '127.0.0.1'
@@ -73,11 +75,7 @@ describe Puppet::Indirector::REST do
@server.unlisten
@tmpfile.delete
Puppet.settings.clear
-
- # This is necessary so the terminus instances don't lie around.
- Puppet::SSL::Key.indirection.clear_cache
- Puppet::SSL::Certificate.indirection.clear_cache
- Puppet::SSL::CertificateRequest.indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
describe "when finding a model instance over REST" do
diff --git a/spec/integration/network/server/webrick.rb b/spec/integration/network/server/webrick.rb
index f2b55ef92..0e66ee955 100755
--- a/spec/integration/network/server/webrick.rb
+++ b/spec/integration/network/server/webrick.rb
@@ -30,10 +30,7 @@ describe Puppet::Network::Server do
system("rm -rf %s" % @dir)
- # This is necessary so the terminus instances don't lie around.
- Puppet::SSL::Key.indirection.clear_cache
- Puppet::SSL::Certificate.indirection.clear_cache
- Puppet::SSL::CertificateRequest.indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
describe "before listening" do
diff --git a/spec/integration/node/catalog.rb b/spec/integration/node/catalog.rb
index ca14c2ea8..b0e651511 100755
--- a/spec/integration/node/catalog.rb
+++ b/spec/integration/node/catalog.rb
@@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Node::Catalog do
describe "when using the indirector" do
- after { Puppet::Node::Catalog.indirection.clear_cache }
+ after { Puppet::Util::Cacher.invalidate }
it "should be able to delegate to the :yaml terminus" do
Puppet::Node::Catalog.indirection.stubs(:terminus_class).returns :yaml
diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb
index c2f876578..cef3d79d4 100755
--- a/spec/integration/node/facts.rb
+++ b/spec/integration/node/facts.rb
@@ -7,13 +7,15 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Node::Facts do
describe "when using the indirector" do
- after { Puppet::Node::Facts.indirection.clear_cache }
+ after { Puppet::Util::Cacher.invalidate }
it "should expire any cached node instances when it is saved" do
Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml
+
+ Puppet::Node::Facts.indirection.terminus(:yaml).should equal(Puppet::Node::Facts.indirection.terminus(:yaml))
terminus = Puppet::Node::Facts.indirection.terminus(:yaml)
+ terminus.stubs :save
- terminus.expects(:save)
Puppet::Node.expects(:expire).with("me")
facts = Puppet::Node::Facts.new("me")
diff --git a/spec/integration/ssl/certificate_authority.rb b/spec/integration/ssl/certificate_authority.rb
index 28f880ede..d838bc586 100755
--- a/spec/integration/ssl/certificate_authority.rb
+++ b/spec/integration/ssl/certificate_authority.rb
@@ -28,10 +28,7 @@ describe Puppet::SSL::CertificateAuthority do
system("rm -rf %s" % @dir)
Puppet.settings.clear
- # This is necessary so the terminus instances don't lie around.
- Puppet::SSL::Key.indirection.clear_cache
- Puppet::SSL::Certificate.indirection.clear_cache
- Puppet::SSL::CertificateRequest.indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
}
diff --git a/spec/integration/ssl/certificate_request.rb b/spec/integration/ssl/certificate_request.rb
index 01b1f4a29..f428718e7 100755
--- a/spec/integration/ssl/certificate_request.rb
+++ b/spec/integration/ssl/certificate_request.rb
@@ -16,8 +16,6 @@ describe Puppet::SSL::CertificateRequest do
file.delete
Puppet.settings.clear
- # This is necessary so the terminus instances don't lie around.
- Puppet::SSL::CertificateRequest.indirection.clear_cache
Puppet.settings[:confdir] = @dir
Puppet.settings[:vardir] = @dir
@@ -32,7 +30,7 @@ describe Puppet::SSL::CertificateRequest do
Puppet.settings.clear
# This is necessary so the terminus instances don't lie around.
- Puppet::SSL::CertificateRequest.indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
it "should be able to generate CSRs" do
diff --git a/spec/integration/ssl/certificate_revocation_list.rb b/spec/integration/ssl/certificate_revocation_list.rb
index 74e45b239..246654816 100755
--- a/spec/integration/ssl/certificate_revocation_list.rb
+++ b/spec/integration/ssl/certificate_revocation_list.rb
@@ -28,10 +28,7 @@ describe Puppet::SSL::CertificateRevocationList do
Puppet.settings.clear
# This is necessary so the terminus instances don't lie around.
- Puppet::SSL::Key.indirection.clear_cache
- Puppet::SSL::Certificate.indirection.clear_cache
- Puppet::SSL::CertificateRequest.indirection.clear_cache
- Puppet::SSL::CertificateRevocationList.indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
}
it "should be able to read in written out CRLs with no revoked certificates" do
diff --git a/spec/integration/ssl/host.rb b/spec/integration/ssl/host.rb
index d4834c341..65f10cef3 100755
--- a/spec/integration/ssl/host.rb
+++ b/spec/integration/ssl/host.rb
@@ -29,12 +29,7 @@ describe Puppet::SSL::Host do
system("rm -rf %s" % @dir)
Puppet.settings.clear
-
- # This is necessary so the terminus instances don't lie around.
- Puppet::SSL::Key.indirection.clear_cache
- Puppet::SSL::Certificate.indirection.clear_cache
- Puppet::SSL::CertificateRevocationList.indirection.clear_cache
- Puppet::SSL::CertificateRequest.indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
}
it "should be considered a CA host if its name is equal to 'ca'" do
diff --git a/spec/integration/transaction/report.rb b/spec/integration/transaction/report.rb
index 48e59f203..6bbd5eb10 100755
--- a/spec/integration/transaction/report.rb
+++ b/spec/integration/transaction/report.rb
@@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Transaction::Report do
describe "when using the indirector" do
- after { Puppet::Transaction::Report.indirection.clear_cache }
+ after { Puppet::Util::Cacher.invalidate }
it "should be able to delegate to the :processor terminus" do
Puppet::Transaction::Report.indirection.stubs(:terminus_class).returns :processor
diff --git a/spec/shared_behaviours/file_server_terminus.rb b/spec/shared_behaviours/file_server_terminus.rb
index de08f29fc..883db58f5 100644
--- a/spec/shared_behaviours/file_server_terminus.rb
+++ b/spec/shared_behaviours/file_server_terminus.rb
@@ -7,7 +7,7 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do
# This only works if the shared behaviour is included before
# the 'before' block in the including context.
before do
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true)
FileTest.stubs(:exists?).with("/my/mount/path").returns(true)
FileTest.stubs(:directory?).with("/my/mount/path").returns(true)
diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb
index a0710e20d..d51fa70b2 100755
--- a/spec/unit/file_serving/configuration.rb
+++ b/spec/unit/file_serving/configuration.rb
@@ -15,12 +15,12 @@ describe Puppet::FileServing::Configuration do
it "should have a method for removing the current configuration instance" do
old = Puppet::FileServing::Configuration.create
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
Puppet::FileServing::Configuration.create.should_not equal(old)
end
after do
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
@@ -32,7 +32,7 @@ describe Puppet::FileServing::Configuration do
end
after :each do
- Puppet::FileServing::Configuration.clear_cache
+ Puppet::Util::Cacher.invalidate
end
describe Puppet::FileServing::Configuration, " when initializing" do
diff --git a/spec/unit/file_serving/mount.rb b/spec/unit/file_serving/mount.rb
index ebe058301..6f491e3b2 100755
--- a/spec/unit/file_serving/mount.rb
+++ b/spec/unit/file_serving/mount.rb
@@ -12,9 +12,9 @@ end
describe Puppet::FileServing::Mount do
it "should provide a method for clearing its cached host information" do
- Puppet::FileServing::Mount.new("whatever").send(:localmap)
- Puppet::FileServing::Mount.clear_cache
- Puppet::FileServing::Mount.send(:class_variable_get, "@@localmap").should be_nil
+ old = Puppet::FileServing::Mount.localmap
+ Puppet::Util::Cacher.invalidate
+ Puppet::FileServing::Mount.localmap.should_not equal(old)
end
end
@@ -106,7 +106,7 @@ describe Puppet::FileServing::Mount, " when finding files" do
end
after do
- Puppet::FileServing::Mount.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index cefd0557e..e4799d3ff 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -87,6 +87,9 @@ describe "Delegation Authorizer", :shared => true do
end
describe Puppet::Indirector::Indirection do
+ after do
+ Puppet::Util::Cacher.invalidate
+ end
describe "when initializing" do
# (LAK) I've no idea how to test this, really.
it "should store a reference to itself before it consumes its options" do
@@ -494,7 +497,7 @@ describe Puppet::Indirector::Indirection do
after :each do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
@@ -615,15 +618,6 @@ describe Puppet::Indirector::Indirection do
@indirection.terminus(:foo).should equal(@terminus)
end
- it "should allow the clearance of cached terminus instances" do
- terminus1 = mock 'terminus1'
- terminus2 = mock 'terminus2'
- @terminus_class.stubs(:new).returns(terminus1, terminus2, ArgumentError)
- @indirection.terminus(:foo).should equal(terminus1)
- @indirection.class.clear_cache
- @indirection.terminus(:foo).should equal(terminus2)
- end
-
# Make sure it caches the terminus.
it "should return the same terminus instance each time for a given name" do
@terminus_class.stubs(:new).returns(@terminus)
@@ -638,7 +632,6 @@ describe Puppet::Indirector::Indirection do
after do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
end
end
@@ -675,7 +668,6 @@ describe Puppet::Indirector::Indirection do
after do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
end
end
@@ -706,15 +698,6 @@ describe Puppet::Indirector::Indirection do
@indirection.cache.should equal(@cache)
@indirection.cache.should equal(@cache)
end
-
- it "should remove the cache terminus when all other terminus instances are cleared" do
- cache2 = mock 'cache2'
- @cache_class.stubs(:new).returns(@cache, cache2)
- @indirection.cache_class = :cache_terminus
- @indirection.cache.should equal(@cache)
- @indirection.clear_cache
- @indirection.cache.should equal(cache2)
- end
end
describe "and saving" do
@@ -725,7 +708,6 @@ describe Puppet::Indirector::Indirection do
after :each do
@indirection.delete
- Puppet::Indirector::Indirection.clear_cache
end
end
end
diff --git a/spec/unit/network/http_pool.rb b/spec/unit/network/http_pool.rb
index 04601769e..dd8bed54c 100755
--- a/spec/unit/network/http_pool.rb
+++ b/spec/unit/network/http_pool.rb
@@ -8,6 +8,7 @@ require 'puppet/network/http_pool'
describe Puppet::Network::HttpPool do
after do
+ Puppet::Util::Cacher.invalidate
Puppet::Network::HttpPool.clear_http_instances
Puppet::Network::HttpPool.instance_variable_set("@ssl_host", nil)
end
@@ -147,24 +148,6 @@ describe Puppet::Network::HttpPool do
end
end
- # We mostly have to do this for testing, since in real life people
- # won't change certs within a single process.
- it "should remove its loaded certificate when clearing the cache" do
- Puppet::Network::HttpPool.instance_variable_set("@cert", :yay)
- Puppet::Network::HttpPool.clear_http_instances
- # Can't use the accessor, because it will read the cert in
- Puppet::Network::HttpPool.instance_variable_get("@cert").should be_nil
- end
-
- # We mostly have to do this for testing, since in real life people
- # won't change certs within a single process.
- it "should remove its loaded key when clearing the cache" do
- Puppet::Network::HttpPool.instance_variable_set("@key", :yay)
- Puppet::Network::HttpPool.clear_http_instances
- # Can't use the accessor, because it will read the cert in
- Puppet::Network::HttpPool.instance_variable_get("@key").should be_nil
- end
-
after do
Puppet::Network::HttpPool.clear_http_instances
end
diff --git a/spec/unit/node.rb b/spec/unit/node.rb
index 348e160cf..08afc5183 100755
--- a/spec/unit/node.rb
+++ b/spec/unit/node.rb
@@ -148,7 +148,7 @@ describe Puppet::Node, " when indirecting" do
end
after do
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb
index f397b8706..59c70b45e 100755
--- a/spec/unit/node/catalog.rb
+++ b/spec/unit/node/catalog.rb
@@ -797,7 +797,7 @@ describe Puppet::Node::Catalog, " when indirecting" do
before do
@indirection = stub 'indirection', :name => :catalog
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
it "should redirect to the indirection for retrieval" do
@@ -811,8 +811,7 @@ describe Puppet::Node::Catalog, " when indirecting" do
end
after do
- mocha_verify
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/node/facts.rb b/spec/unit/node/facts.rb
index 1bfccd32e..69b8e4483 100755
--- a/spec/unit/node/facts.rb
+++ b/spec/unit/node/facts.rb
@@ -10,7 +10,8 @@ describe Puppet::Node::Facts, " when indirecting" do
# We have to clear the cache so that the facts ask for our indirection stub,
# instead of anything that might be cached.
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
+
@facts = Puppet::Node::Facts.new("me", "one" => "two")
end
@@ -29,11 +30,6 @@ describe Puppet::Node::Facts, " when indirecting" do
it "should default to the 'facter' terminus" do
Puppet::Node::Facts.indirection.terminus_class.should == :facter
end
-
- after do
- mocha_verify
- Puppet::Indirector::Indirection.clear_cache
- end
end
describe Puppet::Node::Facts, " when storing and retrieving" do
diff --git a/spec/unit/transaction/report.rb b/spec/unit/transaction/report.rb
index 644f8d709..8d49b16a0 100755
--- a/spec/unit/transaction/report.rb
+++ b/spec/unit/transaction/report.rb
@@ -35,6 +35,6 @@ describe Puppet::Transaction::Report, " when being indirect" do
end
after do
- Puppet::Indirector::Indirection.clear_cache
+ Puppet::Util::Cacher.invalidate
end
end
diff --git a/spec/unit/util/cacher.rb b/spec/unit/util/cacher.rb
index 954de380d..73e449588 100755
--- a/spec/unit/util/cacher.rb
+++ b/spec/unit/util/cacher.rb
@@ -10,7 +10,7 @@ class CacheClassTest
cached_attr(:testing) { Time.now }
def sa_cache
- cache(:ca_cache) { Time.now }
+ attr_cache(:ca_cache) { Time.now }
end
end
@@ -18,7 +18,7 @@ class CacheInstanceTest
extend Puppet::Util::Cacher
def self.sa_cache
- cache(:ca_cache) { Time.now }
+ attr_cache(:ca_cache) { Time.now }
end
end
@@ -29,6 +29,14 @@ describe "a cacher user using cached values", :shared => true do
@object.sa_cache.should equal(now)
end
+ it "should not test for validity if it is creating the value" do
+ # This is only necessary in the class, since it has this value kicking
+ # around.
+ @object.instance_variable_set("@cacher_caches", nil)
+ Puppet::Util::Cacher.expects(:valid?).never
+ @object.sa_cache
+ end
+
it "should not consider cached false values to be missing values" do
Puppet::Util::Cacher.stubs(:valid?).returns true
@@ -51,6 +59,14 @@ describe "a cacher user using cached values", :shared => true do
@object.sa_cache.should_not equal(@object.sa_cache)
end
+
+ it "should still cache values after an invalidation" do
+ # Load the cache
+ @object.sa_cache
+
+ Puppet::Util::Cacher.invalidate
+ @object.sa_cache.should equal(@object.sa_cache)
+ end
end
describe Puppet::Util::Cacher do
@@ -123,7 +139,7 @@ describe Puppet::Util::Cacher do
end
it "should provide a private instance method for caching values" do
- @object.private_methods.should be_include("cache")
+ @object.private_methods.should be_include("attr_cache")
end
end
@@ -134,7 +150,7 @@ describe Puppet::Util::Cacher do
end
it "should provide a private instance method for caching values" do
- CacheInstanceTest.private_methods.should be_include("cache")
+ CacheInstanceTest.private_methods.should be_include("attr_cache")
end
it_should_behave_like "a cacher user using cached values"