diff options
| author | Luke Kanies <luke@madstop.com> | 2008-05-13 16:00:58 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-05-13 16:00:58 -0500 |
| commit | 6efe4000dda3379e867786a9c2d4ae0f0cdfc3be (patch) | |
| tree | a16fd1ae1f4aab7fe04af88daa78f1be1a2b1f3e /spec | |
| parent | 68d8d0ae0686939d94dae8ccc70e5582187335dc (diff) | |
| download | puppet-6efe4000dda3379e867786a9c2d4ae0f0cdfc3be.tar.gz puppet-6efe4000dda3379e867786a9c2d4ae0f0cdfc3be.tar.xz puppet-6efe4000dda3379e867786a9c2d4ae0f0cdfc3be.zip | |
Using the new Cacher class for handling cached data.
This provides a single, global bit for determining whether
a given piece of cached data is still valid.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/integration/file_serving/configuration.rb | 4 | ||||
| -rwxr-xr-x | spec/integration/indirector/rest.rb | 8 | ||||
| -rwxr-xr-x | spec/integration/network/server/webrick.rb | 5 | ||||
| -rwxr-xr-x | spec/integration/node/catalog.rb | 2 | ||||
| -rwxr-xr-x | spec/integration/node/facts.rb | 6 | ||||
| -rwxr-xr-x | spec/integration/ssl/certificate_authority.rb | 5 | ||||
| -rwxr-xr-x | spec/integration/ssl/certificate_request.rb | 4 | ||||
| -rwxr-xr-x | spec/integration/ssl/certificate_revocation_list.rb | 5 | ||||
| -rwxr-xr-x | spec/integration/ssl/host.rb | 7 | ||||
| -rwxr-xr-x | spec/integration/transaction/report.rb | 2 | ||||
| -rw-r--r-- | spec/shared_behaviours/file_server_terminus.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/file_serving/configuration.rb | 6 | ||||
| -rwxr-xr-x | spec/unit/file_serving/mount.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/indirector/indirection.rb | 26 | ||||
| -rwxr-xr-x | spec/unit/network/http_pool.rb | 19 | ||||
| -rwxr-xr-x | spec/unit/node.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/node/catalog.rb | 5 | ||||
| -rwxr-xr-x | spec/unit/node/facts.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/transaction/report.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/util/cacher.rb | 24 |
20 files changed, 55 insertions, 95 deletions
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" |
