diff options
30 files changed, 54 insertions, 56 deletions
diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb index 78a35cc15..4b371abe7 100644 --- a/lib/puppet/network/http_pool.rb +++ b/lib/puppet/network/http_pool.rb @@ -28,7 +28,7 @@ module Puppet::Network::HttpPool http_cache.each do |name, connection| connection.finish if connection.started? end - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end # Make sure we set the driver up when we read the cert in. diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb index 773c02182..139aa3659 100644 --- a/lib/puppet/util/cacher.rb +++ b/lib/puppet/util/cacher.rb @@ -2,11 +2,11 @@ module Puppet::Util::Cacher # It's basically not possible to test that this is set, # but we need to start with a value so that all initial values # start out valid -- that is, everything's valid until the - # first call to 'invalidate'. + # first call to 'expire'. @timestamp = Time.now # Cause all cached values to be considered expired. - def self.invalidate + def self.expire @timestamp = Time.now end @@ -70,6 +70,11 @@ module Puppet::Util::Cacher class Cache attr_accessor :caches, :timestamp + def clear + caches.clear + self.timestamp = Time.now + end + def initialize @caches = {} @timestamp = Time.now @@ -90,8 +95,7 @@ module Puppet::Util::Cacher # clear other cached values, too (if this instance is caching more # than one value). if expired? - caches.clear - self.timestamp = Time.now + clear end # Generate a new value if we don't have one. Use 'include?' here diff --git a/spec/integration/file_serving/configuration.rb b/spec/integration/file_serving/configuration.rb index dfdda402d..06cf3abd9 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::Util::Cacher.invalidate + Puppet::Util::Cacher.expire @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::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end end diff --git a/spec/integration/file_serving/content.rb b/spec/integration/file_serving/content.rb index af0181393..a51b36223 100755 --- a/spec/integration/file_serving/content.rb +++ b/spec/integration/file_serving/content.rb @@ -16,5 +16,5 @@ describe Puppet::FileServing::Content, " when finding files" do @indirection = Puppet::FileServing::Content.indirection end - after { Puppet::Util::Cacher.invalidate } + after { Puppet::Util::Cacher.expire } end diff --git a/spec/integration/file_serving/metadata.rb b/spec/integration/file_serving/metadata.rb index af3e16324..10c884f47 100755 --- a/spec/integration/file_serving/metadata.rb +++ b/spec/integration/file_serving/metadata.rb @@ -16,5 +16,5 @@ describe Puppet::FileServing::Metadata, " when finding files" do @indirection = Puppet::FileServing::Metadata.indirection end - after { Puppet::Util::Cacher.invalidate } + after { Puppet::Util::Cacher.expire } end diff --git a/spec/integration/indirector/certificate/rest.rb b/spec/integration/indirector/certificate/rest.rb index 0f14998d5..113cded4a 100755 --- a/spec/integration/indirector/certificate/rest.rb +++ b/spec/integration/indirector/certificate/rest.rb @@ -21,7 +21,7 @@ describe "Certificate REST Terminus" do Puppet.settings[:masterport] = "34343" Puppet.settings[:http_enable_post_connection_check] = false - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet[:servertype] = 'webrick' Puppet[:server] = '127.0.0.1' diff --git a/spec/integration/indirector/certificate_request/rest.rb b/spec/integration/indirector/certificate_request/rest.rb index decd971dc..24c7e91c7 100755 --- a/spec/integration/indirector/certificate_request/rest.rb +++ b/spec/integration/indirector/certificate_request/rest.rb @@ -8,7 +8,7 @@ require 'puppet/network/http/webrick/rest' describe "Certificate Request REST Terminus" do before do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet[:masterport] = 34343 Puppet[:server] = "localhost" diff --git a/spec/integration/indirector/certificate_revocation_list/rest.rb b/spec/integration/indirector/certificate_revocation_list/rest.rb index 872f4522c..bbe65c6c4 100755 --- a/spec/integration/indirector/certificate_revocation_list/rest.rb +++ b/spec/integration/indirector/certificate_revocation_list/rest.rb @@ -21,7 +21,7 @@ describe "Certificate REST Terminus" do Puppet.settings[:masterport] = "34343" Puppet.settings[:http_enable_post_connection_check] = false - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet[:servertype] = 'webrick' Puppet[:server] = '127.0.0.1' @@ -59,7 +59,7 @@ describe "Certificate REST Terminus" do end after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet.settings.clear @server.unlisten end diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb index 95c2759b9..aafc35c9b 100755 --- a/spec/integration/indirector/rest.rb +++ b/spec/integration/indirector/rest.rb @@ -57,7 +57,7 @@ describe Puppet::Indirector::REST do describe "when using webrick" do before :each do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet[:servertype] = 'webrick' Puppet[:server] = '127.0.0.1' diff --git a/spec/integration/network/server/webrick.rb b/spec/integration/network/server/webrick.rb index e74920782..5cd573141 100755 --- a/spec/integration/network/server/webrick.rb +++ b/spec/integration/network/server/webrick.rb @@ -30,7 +30,7 @@ describe Puppet::Network::Server do system("rm -rf %s" % @dir) - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end describe "before listening" do diff --git a/spec/integration/node/catalog.rb b/spec/integration/node/catalog.rb index 75be9501a..438f92834 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::Util::Cacher.invalidate } + after { Puppet::Util::Cacher.expire } before do # This is so the tests work w/out networking. Facter.stubs(:to_hash).returns({"hostname" => "foo.domain.com"}) diff --git a/spec/integration/node/facts.rb b/spec/integration/node/facts.rb index 5a54a6e49..0a4d21ed6 100755 --- a/spec/integration/node/facts.rb +++ b/spec/integration/node/facts.rb @@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Node::Facts do describe "when using the indirector" do - after { Puppet::Util::Cacher.invalidate } + after { Puppet::Util::Cacher.expire } it "should expire any cached node instances when it is saved" do Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml diff --git a/spec/integration/ssl/certificate_authority.rb b/spec/integration/ssl/certificate_authority.rb index d838bc586..5f963f7f5 100755 --- a/spec/integration/ssl/certificate_authority.rb +++ b/spec/integration/ssl/certificate_authority.rb @@ -28,7 +28,7 @@ describe Puppet::SSL::CertificateAuthority do system("rm -rf %s" % @dir) Puppet.settings.clear - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire 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 f428718e7..f1b2b8460 100755 --- a/spec/integration/ssl/certificate_request.rb +++ b/spec/integration/ssl/certificate_request.rb @@ -30,7 +30,7 @@ describe Puppet::SSL::CertificateRequest do Puppet.settings.clear # This is necessary so the terminus instances don't lie around. - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire 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 246654816..be1a5f4a1 100755 --- a/spec/integration/ssl/certificate_revocation_list.rb +++ b/spec/integration/ssl/certificate_revocation_list.rb @@ -28,7 +28,7 @@ describe Puppet::SSL::CertificateRevocationList do Puppet.settings.clear # This is necessary so the terminus instances don't lie around. - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire } 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 65f10cef3..5b01e9f7e 100755 --- a/spec/integration/ssl/host.rb +++ b/spec/integration/ssl/host.rb @@ -29,7 +29,7 @@ describe Puppet::SSL::Host do system("rm -rf %s" % @dir) Puppet.settings.clear - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire } 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 6bbd5eb10..68533b503 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::Util::Cacher.invalidate } + after { Puppet::Util::Cacher.expire } 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 fc5673a65..13561f09c 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::Util::Cacher.invalidate + Puppet::Util::Cacher.expire FileTest.stubs(:exists?).returns true FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true) diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb index 741e3bc1d..21fdfe3b4 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::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet::FileServing::Configuration.create.should_not equal(old) end after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end end @@ -32,7 +32,7 @@ describe Puppet::FileServing::Configuration do end after :each do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire 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 6f491e3b2..42f5accb9 100755 --- a/spec/unit/file_serving/mount.rb +++ b/spec/unit/file_serving/mount.rb @@ -13,7 +13,7 @@ end describe Puppet::FileServing::Mount do it "should provide a method for clearing its cached host information" do old = Puppet::FileServing::Mount.localmap - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire 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::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end end diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb index 166065ecf..564b2d871 100755 --- a/spec/unit/indirector/indirection.rb +++ b/spec/unit/indirector/indirection.rb @@ -104,7 +104,7 @@ end describe Puppet::Indirector::Indirection do after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end describe "when initializing" do # (LAK) I've no idea how to test this, really. @@ -513,7 +513,7 @@ describe Puppet::Indirector::Indirection do after :each do @indirection.delete - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end end diff --git a/spec/unit/network/http_pool.rb b/spec/unit/network/http_pool.rb index a986292f6..f09e8e4ca 100755 --- a/spec/unit/network/http_pool.rb +++ b/spec/unit/network/http_pool.rb @@ -8,7 +8,7 @@ require 'puppet/network/http_pool' describe Puppet::Network::HttpPool do after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet::Network::HttpPool.clear_http_instances Puppet::Network::HttpPool.instance_variable_set("@ssl_host", nil) end diff --git a/spec/unit/node.rb b/spec/unit/node.rb index df3b7483c..25dad8c67 100755 --- a/spec/unit/node.rb +++ b/spec/unit/node.rb @@ -128,7 +128,7 @@ describe Puppet::Node, "when indirecting" do end after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end end diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb index 63aa2f60c..28d66644a 100755 --- a/spec/unit/node/catalog.rb +++ b/spec/unit/node/catalog.rb @@ -860,7 +860,7 @@ describe Puppet::Node::Catalog, " when indirecting" do before do @indirection = stub 'indirection', :name => :catalog - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end it "should redirect to the indirection for retrieval" do @@ -874,7 +874,7 @@ describe Puppet::Node::Catalog, " when indirecting" do end after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end end diff --git a/spec/unit/node/facts.rb b/spec/unit/node/facts.rb index 69b8e4483..f12e20404 100755 --- a/spec/unit/node/facts.rb +++ b/spec/unit/node/facts.rb @@ -10,7 +10,7 @@ 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::Util::Cacher.invalidate + Puppet::Util::Cacher.expire @facts = Puppet::Node::Facts.new("me", "one" => "two") end diff --git a/spec/unit/ssl/certificate_authority.rb b/spec/unit/ssl/certificate_authority.rb index 2ff324a6a..e007df25b 100755 --- a/spec/unit/ssl/certificate_authority.rb +++ b/spec/unit/ssl/certificate_authority.rb @@ -6,7 +6,7 @@ require 'puppet/ssl/certificate_authority' describe Puppet::SSL::CertificateAuthority do after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire Puppet.settings.clearused end diff --git a/spec/unit/transaction/report.rb b/spec/unit/transaction/report.rb index 8d49b16a0..12765735b 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::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end end diff --git a/spec/unit/util/cacher.rb b/spec/unit/util/cacher.rb index 9d92178d2..08c4c14d5 100755 --- a/spec/unit/util/cacher.rb +++ b/spec/unit/util/cacher.rb @@ -46,51 +46,45 @@ describe "a cacher user using cached values", :shared => true do @object.sa_cache.should equal(@object.sa_cache) end - it "should use the block to generate new values if the cached values are invalid" do + it "should use the block to generate new values if the cached values are expired" do Puppet::Util::Cacher.stubs(:valid?).returns false @object.sa_cache.should_not equal(@object.sa_cache) end - it "should still cache values after an invalidation" do + it "should still cache values after an expiration" do # Load the cache @object.sa_cache - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire @object.sa_cache.should equal(@object.sa_cache) end end describe Puppet::Util::Cacher do before do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end after do - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end - it "should have a method for invalidating caches" do - Puppet::Util::Cacher.should respond_to(:invalidate) + it "should have a method for expiring caches" do + Puppet::Util::Cacher.should respond_to(:expire) end it "should have a method for determining whether a cached value is valid" do Puppet::Util::Cacher.should respond_to(:valid?) end - it "should consider cached values valid if the cached value was created and there was never an invalidation" do - Puppet::Util::Cacher.instance_variable_set("@timestamp", nil) - - Puppet::Util::Cacher.should be_valid(Time.now) - end - - it "should consider cached values valid if the cached value was created since the last invalidation" do - Puppet::Util::Cacher.invalidate + it "should consider cached values valid if the cached value was created since the last expiration" do + Puppet::Util::Cacher.expire Puppet::Util::Cacher.should be_valid(Time.now + 1) end - it "should consider cached values invalid if the cache was invalidated after the cached value was created" do - Puppet::Util::Cacher.invalidate + it "should consider cached values expired if the cache was expired after the cached value was created" do + Puppet::Util::Cacher.expire Puppet::Util::Cacher.should_not be_valid(Time.now - 1) end diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb index 1f4432d00..42295785e 100755 --- a/test/lib/puppettest.rb +++ b/test/lib/puppettest.rb @@ -302,7 +302,7 @@ module PuppetTest Puppet::Util::Storage.clear Puppet.clear Puppet.settings.clear - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire @memoryatend = Puppet::Util.memory diff = @memoryatend - @memoryatstart diff --git a/test/network/handler/master.rb b/test/network/handler/master.rb index 0de38414a..babddec7d 100755 --- a/test/network/handler/master.rb +++ b/test/network/handler/master.rb @@ -18,7 +18,7 @@ class TestMaster < Test::Unit::TestCase def teardown super - Puppet::Util::Cacher.invalidate + Puppet::Util::Cacher.expire end def test_freshness_is_always_now |