summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-18 03:43:48 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-18 03:43:48 +0000
commitd77d6d4f9ec20c830c4e9ed34c8e2f1197386f4c (patch)
tree45586ffa96a086414c8b729757ce3b61fca7534e
parentf1ebef038b12231e876510c7247a82f6367a8d45 (diff)
downloadpuppet-d77d6d4f9ec20c830c4e9ed34c8e2f1197386f4c.tar.gz
puppet-d77d6d4f9ec20c830c4e9ed34c8e2f1197386f4c.tar.xz
puppet-d77d6d4f9ec20c830c4e9ed34c8e2f1197386f4c.zip
Adding prefetch of providers to transactions. Nothing is using it yet. I wrote it for cron jobs, but it is too much work to fix this for cron jobs right now.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1806 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/transaction.rb18
-rwxr-xr-xtest/other/transactions.rb38
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index d19ef59ac..05fbe6914 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -162,6 +162,8 @@ class Transaction
# Start logging.
Puppet::Log.newdestination(@report)
+ prefetch()
+
begin
allevents = @objects.collect { |child|
events = []
@@ -250,6 +252,22 @@ class Transaction
@report = Report.new
end
+ # Prefetch any providers that support it. We don't support prefetching
+ # types, just providers.
+ def prefetch
+ @objects.collect { |obj|
+ if pro = obj.provider
+ pro.class
+ else
+ nil
+ end
+ }.reject { |o| o.nil? }.uniq.each do |klass|
+ if klass.respond_to?(:prefetch)
+ klass.prefetch
+ end
+ end
+ end
+
# Generate a transaction report.
def report
@resourcemetrics[:failed] = @failures.find_all do |name, num|
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index dc654994e..3abc84f1b 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -52,6 +52,44 @@ class TestTransactions < Test::Unit::TestCase
end
end
+ def test_prefetch
+ # Create a type just for testing prefetch
+ name = :prefetchtesting
+ $prefetched = false
+ type = Puppet::Type.newtype(name) do
+ newparam(:name) {}
+ end
+
+ # Now create a provider
+ type.provide(:prefetch) do
+ def self.prefetch
+ $prefetched = true
+ end
+ end
+
+ # Now create an instance
+ inst = type.create :name => "yay"
+
+
+ # Create a transaction
+ trans = Puppet::Transaction.new([inst])
+
+ # Make sure prefetch works
+ assert_nothing_raised do
+ trans.prefetch
+ end
+
+ assert_equal(true, $prefetched, "type prefetch was not called")
+
+ # Now make sure it gets called from within evaluate()
+ $prefetched = false
+ assert_nothing_raised do
+ trans.evaluate
+ end
+
+ assert_equal(true, $prefetched, "evaluate did not call prefetch")
+ end
+
def test_refreshes_generate_events
path = tempfile()
firstpath = tempfile()