summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-23 15:52:20 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:41 -0600
commitf78a5653ae1c0fe3931c4102ce32f640c80db158 (patch)
tree4537c1e326d6a2141b245477bdd8c4a0ce7fa007
parent54344591fde1a280f38032731e0ccb19521f6611 (diff)
Only caching saved resources when the main save works
This way you don't have data cached that couldn't be saved to the main repository. Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/indirector/indirection.rb3
-rwxr-xr-xspec/unit/indirector/indirection.rb12
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 4ca19cb27..c560bb5b7 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -244,9 +244,10 @@ class Puppet::Indirector::Indirection
request = request(:save, instance, *args)
terminus = prepare(request)
+ terminus.save(request)
+
# If caching is enabled, save our document there
cache.save(request) if cache?
- terminus.save(request)
end
private
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index 6fdb2ba57..71dc4d24f 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -359,7 +359,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
@@ -373,6 +373,16 @@ describe Puppet::Indirector::Indirection do
@terminus.stubs(:save)
@indirection.save(@instance)
end
+
+ it "should not save to the cache if the normal save fails" do
+ request = stub 'request', :instance => @instance, :node => nil
+
+ @indirection.expects(:request).returns request
+
+ @cache.expects(:save).never
+ @terminus.expects(:save).raises "eh"
+ lambda { @indirection.save(@instance) }.should raise_error
+ end
end
end