diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-22 04:57:25 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-22 04:57:25 +0000 |
commit | 164c18f0ce0c1ebb25b8417f2a820b805e4a9f92 (patch) | |
tree | ec84b5bd4018e797634c8d0e9d9eae76f3ae1548 | |
parent | 98004b283f46794e3f9334ccdd286e1ccc8d065f (diff) | |
download | puppet-164c18f0ce0c1ebb25b8417f2a820b805e4a9f92.tar.gz puppet-164c18f0ce0c1ebb25b8417f2a820b805e4a9f92.tar.xz puppet-164c18f0ce0c1ebb25b8417f2a820b805e4a9f92.zip |
As requested by Christian Warden, triggering an object now results in
an event, which can result in further triggers.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1660 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/transaction.rb | 32 | ||||
-rwxr-xr-x | test/other/events.rb | 2 | ||||
-rw-r--r-- | test/other/transactions.rb | 31 | ||||
-rwxr-xr-x | test/types/exec.rb | 2 |
4 files changed, 53 insertions, 14 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 66d691d97..e95b3fdd9 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -159,7 +159,7 @@ class Transaction begin allevents = @objects.collect { |child| - events = nil + events = [] if (self.ignoretags or tags.nil? or child.tagged?(tags)) if self.ignoreschedules or child.scheduled? @objectmetrics[:scheduled] += 1 @@ -171,9 +171,6 @@ class Transaction # Keep track of how long we spend in each type of object @timemetrics[child.class.name] += seconds - - # Collect the targets of any subscriptions to those events - collecttargets(events) else child.debug "Not scheduled" end @@ -181,8 +178,13 @@ class Transaction child.debug "Not tagged with %s" % tags.join(", ") end - # Now check to see if there are any events for this child - trigger(child) + # Check to see if there are any events for this child + if triggedevents = trigger(child) + events += triggedevents + end + + # Collect the targets of any subscriptions to those events + collecttargets(events) # And return the events for collection events @@ -327,6 +329,7 @@ class Transaction callbacks = Hash.new { |hash, key| hash[key] = [] } sources = Hash.new { |hash, key| hash[key] = [] } + trigged = [] while obj if @targets.include?(obj) callbacks.clear @@ -345,8 +348,9 @@ class Transaction end callbacks.each do |callback, subs| - obj.notice "Triggering '%s' from %s dependencies" % + message = "Triggering '%s' from %s dependencies" % [callback, subs.length] + obj.notice message # At this point, just log failures, don't try to react # to them in any way. begin @@ -363,12 +367,26 @@ class Transaction end end + # And then add an event for it. + trigged << Puppet::Event.new( + :event => :triggered, + :transaction => self, + :source => obj, + :message => message + ) + triggered(obj, callback) end end obj = obj.parent end + + if trigged.empty? + return nil + else + return trigged + end end def triggered(object, method) diff --git a/test/other/events.rb b/test/other/events.rb index ab6270b2b..a8f062b81 100755 --- a/test/other/events.rb +++ b/test/other/events.rb @@ -25,7 +25,7 @@ class TestEvents < Test::Unit::TestCase comp = newcomp("eventtesting", file, exec) - trans = assert_events([:file_created], comp) + trans = assert_events([:file_created, :triggered], comp) assert_equal(1, trans.triggered?(exec, :refresh)) end diff --git a/test/other/transactions.rb b/test/other/transactions.rb index e66151979..381a434c7 100644 --- a/test/other/transactions.rb +++ b/test/other/transactions.rb @@ -48,6 +48,27 @@ class TestTransactions < Test::Unit::TestCase end end + def test_refreshes_generate_events + path = tempfile() + firstpath = tempfile() + secondpath = tempfile() + file = Puppet::Type.newfile(:path => path, :content => "yayness") + first = Puppet::Type.newexec(:title => "first", + :command => "/bin/echo first > #{firstpath}", + :subscribe => [:file, path], + :refreshonly => true + ) + second = Puppet::Type.newexec(:title => "second", + :command => "/bin/echo second > #{secondpath}", + :subscribe => [:exec, "first"], + :refreshonly => true + ) + + assert_apply(file, first, second) + + assert(FileTest.exists?(secondpath), "Refresh did not generate an event") + end + unless %x{groups}.chomp.split(/ /).length > 1 $stderr.puts "You must be a member of more than one group to test transactions" else @@ -221,7 +242,7 @@ class TestTransactions < Test::Unit::TestCase file[:mode] = "755" } - trans = assert_events([:file_changed], component) + trans = assert_events([:file_changed, :triggered], component) assert(FileTest.exists?(execfile), "Execfile does not exist") File.unlink(execfile) @@ -229,7 +250,7 @@ class TestTransactions < Test::Unit::TestCase file[:group] = @groups[1] } - trans = assert_events([:file_changed], component) + trans = assert_events([:file_changed, :triggered], component) assert(FileTest.exists?(execfile), "Execfile does not exist") end @@ -260,7 +281,7 @@ class TestTransactions < Test::Unit::TestCase file[:mode] = "755" } - trans = assert_events([:file_changed, :file_changed], component) + trans = assert_events([:file_changed, :file_changed, :triggered], component) end @@ -348,7 +369,7 @@ class TestTransactions < Test::Unit::TestCase file[:content] = "some content" - assert_events([:file_changed], comp) + assert_events([:file_changed, :triggered], comp) assert(FileTest.exists?(fname), "File did not get recreated") # Now remove it, so it can get created again @@ -366,7 +387,7 @@ class TestTransactions < Test::Unit::TestCase assert(! file.insync?, "Uh, file is in sync?") - assert_events([:file_changed], comp) + assert_events([:file_changed, :triggered], comp) assert(FileTest.exists?(fname), "File did not get recreated") end diff --git a/test/types/exec.rb b/test/types/exec.rb index d51af1736..615dd86cd 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -161,7 +161,7 @@ class TestExec < Test::Unit::TestCase # verify that only the file_changed event was kicked off, not the # command_executed assert_equal( - [:file_changed], + [:file_changed, :triggered], events ) end |