diff options
| author | Luke Kanies <luke@madstop.com> | 2009-10-29 00:23:05 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 2cbd9e85259ed1742f8a54a7e5b9825d0bb79d5e (patch) | |
| tree | bafbe77d88527b56c3d10a975180a1748fa971da /spec/integration | |
| parent | 6a450c51eedc38b73d79389c19b8d5e5964a9d71 (diff) | |
Switching transactions to callback-based events
Events are now queued as they are created, and
the queues are managed through simple interfaces,
rather than collecting events over time and
responding to them inline.
This drastically simplifies event management,
and will make moving it to a separate system
essentially trivial.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/integration')
| -rwxr-xr-x | spec/integration/transaction.rb | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/spec/integration/transaction.rb b/spec/integration/transaction.rb index 7ab852bd2..1b8b11d48 100755 --- a/spec/integration/transaction.rb +++ b/spec/integration/transaction.rb @@ -2,9 +2,12 @@ require File.dirname(__FILE__) + '/../spec_helper' +require 'puppet_spec/files' require 'puppet/transaction' describe Puppet::Transaction do + include PuppetSpec::Files + it "should not apply generated resources if the parent resource fails" do catalog = Puppet::Resource::Catalog.new resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false @@ -63,4 +66,119 @@ describe Puppet::Transaction do transaction.evaluate end + it "should refresh resources that subscribe to changed resources" do + name = tmpfile("something") + file = Puppet::Type.type(:file).new( + :name => name, + :ensure => "file" + ) + exec = Puppet::Type.type(:exec).new( + :name => "echo true", + :path => "/usr/bin:/bin", + :refreshonly => true, + :subscribe => Puppet::Resource::Reference.new(file.class.name, file.name) + ) + + catalog = Puppet::Resource::Catalog.new + catalog.add_resource file, exec + + exec.expects(:refresh) + + catalog.apply + end + + it "should not refresh resources that only require changed resources" do + name = tmpfile("something") + file = Puppet::Type.type(:file).new( + :name => name, + :ensure => "file" + ) + exec = Puppet::Type.type(:exec).new( + :name => "echo true", + :path => "/usr/bin:/bin", + :refreshonly => true, + :require => Puppet::Resource::Reference.new(file.class.name, file.name) + ) + + + catalog = Puppet::Resource::Catalog.new + catalog.add_resource file + catalog.add_resource exec + + exec.expects(:refresh).never + + trans = catalog.apply + + trans.events.length.should == 1 + end + + it "should cascade events such that multiple refreshes result" do + files = [] + + 4.times { |i| + files << Puppet::Type.type(:file).new( + :name => tmpfile("something"), + :ensure => "file" + ) + } + + fname = tmpfile("something") + exec = Puppet::Type.type(:exec).new( + :name => "touch %s" % fname, + :path => "/usr/bin:/bin", + :refreshonly => true + ) + + exec[:subscribe] = files.collect { |f| + Puppet::Resource::Reference.new(:file, f.name) + } + + catalog = Puppet::Resource::Catalog.new + catalog.add_resource(exec, *files) + + catalog.apply + FileTest.should be_exist(fname) + end + + # Make sure refreshing happens mid-transaction, rather than at the end. + it "should refresh resources as they're encountered rather than all at the end" do + file = tmpfile("something") + + exec1 = Puppet::Type.type(:exec).new( + :title => "one", + :name => "echo one >> %s" % file, + :path => "/usr/bin:/bin" + ) + + exec2 = Puppet::Type.type(:exec).new( + :title => "two", + :name => "echo two >> %s" % file, + :path => "/usr/bin:/bin", + :refreshonly => true, + :subscribe => exec1 + ) + + exec3 = Puppet::Type.type(:exec).new( + :title => "three", + :name => "echo three >> %s" % file, + :path => "/usr/bin:/bin", + :require => exec2 + ) + execs = [exec1, exec2, exec3] + + catalog = Puppet::Resource::Catalog.new + catalog.add_resource(exec1,exec2,exec3) + + trans = Puppet::Transaction.new(catalog) + execs.each { |e| catalog.should be_vertex(e) } + trans.prepare + execs.each { |e| catalog.should be_vertex(e) } + reverse = trans.relationship_graph.reversal + execs.each { |e| reverse.should be_vertex(e) } + + catalog.apply + + FileTest.should be_exist(file) + File.read(file).should == "one\ntwo\nthree\n" + end end |
