Catalogs always consider resource data to be expired if not mid-transaction.

This way we'll cache when in a transaction, but otherwise always
hit the disk so the data is fresh.  This works because we
really only use resources mid-transaction, but it behaves correctly
if we happen to use a resource outside of a transaction.

Signed-off-by: Luke Kanies <luke@madstop.com>
This commit is contained in:
Luke Kanies 2008-11-14 19:15:37 -06:00
Родитель 8b0843913c
Коммит a8d9976d0a
3 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -183,6 +183,14 @@ class Puppet::Node::Catalog < Puppet::SimpleGraph
resource
end
def expired?(ts)
if applying?
return super
else
return true
end
end
# Make sure we support the requested extraction format.
def extraction_format=(value)
unless respond_to?("extract_to_%s" % value)

Просмотреть файл

@ -615,6 +615,17 @@ describe Puppet::Node::Catalog do
Puppet::Node::Catalog.ancestors.should be_include(Puppet::Util::Cacher::Expirer)
end
it "should always be expired if it's not applying" do
@catalog.expects(:applying?).returns false
@catalog.should be_expired(Time.now)
end
it "should not be expired if it's applying and the timestamp is late enough" do
@catalog.expire
@catalog.expects(:applying?).returns true
@catalog.should_not be_expired(Time.now)
end
describe "when applying" do
it "should create and evaluate a transaction" do
@transaction.expects(:evaluate)

Просмотреть файл

@ -164,13 +164,15 @@ describe Puppet::Type.type(:file) do
@resource.stat.should == "mystat"
end
it "should cache the stat instance if it has a catalog" do
it "should cache the stat instance if it has a catalog and is applying" do
stat = mock 'stat'
File.expects(:lstat).returns stat
catalog = Puppet::Node::Catalog.new
@resource.catalog = catalog
catalog.stubs(:applying?).returns true
@resource.stat.should equal(@resource.stat)
end
end