summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-03 17:32:26 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-03 17:32:26 +0000
commit651640c7c4773be43605e08625301e604547ac5c (patch)
treec1110f0454a4e23bdf3e95f1c131bdc11b6029c9
parentc140037f486ef4f0933e6a4a78b44f1105859b8b (diff)
downloadpuppet-651640c7c4773be43605e08625301e604547ac5c.tar.gz
puppet-651640c7c4773be43605e08625301e604547ac5c.tar.xz
puppet-651640c7c4773be43605e08625301e604547ac5c.zip
Fixing #401. Transactions were trying to trigger every resource, even those that did not respond to the specified callback.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2022 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/transaction.rb3
-rwxr-xr-xtest/other/transactions.rb44
2 files changed, 46 insertions, 1 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index f3d05b5ef..fe86c2595 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -544,7 +544,8 @@ class Transaction
# Set an edge to be triggered when we evaluate its target.
def set_trigger(edge)
- return unless edge.callback
+ return unless method = edge.callback
+ return unless edge.target.respond_to?(method)
if edge.target.respond_to?(:ref)
edge.source.info "Scheduling %s of %s" % [edge.callback, edge.target.ref]
end
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index 4a5fee9a0..d1ea0ef68 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -928,6 +928,50 @@ class TestTransactions < Test::Unit::TestCase
assert(FileTest.exists?(file), "graph for %s was not created" % name)
end
end
+
+ def test_set_target
+ file = Puppet::Type.newfile(:path => tempfile(), :content => "yay")
+ exec1 = Puppet::Type.type(:exec).create :command => "/bin/echo exec1"
+ exec2 = Puppet::Type.type(:exec).create :command => "/bin/echo exec2"
+ trans = Puppet::Transaction.new(newcomp(file, exec1, exec2))
+
+ # First try it with an edge that has no callback
+ edge = Puppet::Relationship.new(file, exec1)
+ assert_nothing_raised { trans.set_trigger(edge) }
+ assert(! trans.targeted?(exec1), "edge with no callback resulted in a target")
+
+ # Now with an edge that has an unsupported callback
+ edge = Puppet::Relationship.new(file, exec1, :callback => :nosuchmethod, :event => :ALL_EVENTS)
+ assert_nothing_raised { trans.set_trigger(edge) }
+ assert(! trans.targeted?(exec1), "edge with invalid callback resulted in a target")
+
+ # Lastly, with an edge with a supported callback
+ edge = Puppet::Relationship.new(file, exec1, :callback => :refresh, :event => :ALL_EVENTS)
+ assert_nothing_raised { trans.set_trigger(edge) }
+ assert(trans.targeted?(exec1), "edge with valid callback did not result in a target")
+ end
+
+ # Testing #401 -- transactions are calling refresh() on classes that don't support it.
+ def test_callback_availability
+ $called = []
+ klass = Puppet::Type.newtype(:norefresh) do
+ newparam(:name, :namevar => true) {}
+ def method_missing(method, *args)
+ $called << method
+ end
+ end
+ cleanup do
+ $called = nil
+ Puppet::Type.rmtype(:norefresh)
+ end
+
+ file = Puppet::Type.newfile :path => tempfile(), :content => "yay"
+ one = klass.create :name => "one", :subscribe => file
+
+ assert_apply(file, one)
+
+ assert(! $called.include?(:refresh), "Called refresh when it wasn't set as a method")
+ end
end
# $Id$