summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-18 23:45:30 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-05-18 23:45:30 +0000
commit6f83d4daab56385df9a1625cf8ffc64b6a8958f7 (patch)
tree96f5d3eb98f0e61396e02256b2071170fb65c88e
parent7d1f7606c38ad7b32651e8bc98e2258feda99294 (diff)
downloadpuppet-6f83d4daab56385df9a1625cf8ffc64b6a8958f7.tar.gz
puppet-6f83d4daab56385df9a1625cf8ffc64b6a8958f7.tar.xz
puppet-6f83d4daab56385df9a1625cf8ffc64b6a8958f7.zip
Fixing #501 -- there is now a splay option, disabled by default and when running under --test
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2528 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--CHANGELOG4
-rwxr-xr-xbin/puppetd1
-rw-r--r--lib/puppet/configuration.rb8
-rw-r--r--lib/puppet/network/client/master.rb17
-rwxr-xr-xtest/network/client/master.rb32
5 files changed, 61 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 2a40a10fc..e6d0b0292 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+ Added a splay option (#501). It's disabled when running under
+ --test in puppetd. The value is random but cached. It defaults
+ to the runinterval but can be tuned with --splaylimit
+
Changing the notify type so that it always uses
the loglevel.
diff --git a/bin/puppetd b/bin/puppetd
index 02b064147..e9380adb9 100755
--- a/bin/puppetd
+++ b/bin/puppetd
@@ -218,6 +218,7 @@ begin
# Enable all of the most common test options.
Puppet.config.handlearg("--ignorecache")
Puppet.config.handlearg("--no-usecacheonfailure")
+ Puppet.config.handlearg("--no-splay")
options[:onetime] = true
options[:waitforcert] = 0
unless Puppet::Util::Log.level == :debug
diff --git a/lib/puppet/configuration.rb b/lib/puppet/configuration.rb
index 3b90916c6..d1526e2be 100644
--- a/lib/puppet/configuration.rb
+++ b/lib/puppet/configuration.rb
@@ -400,7 +400,13 @@ module Puppet
:dynamicfacts => ["memorysize,memoryfree,swapsize,swapfree",
"Facts that are dynamic; these facts will be ignored when deciding whether
changed facts should result in a recompile. Multiple facts should be
- comma-separated."]
+ comma-separated."],
+ :splaylimit => ["$runinterval",
+ "The maximum time to delay before runs. Defaults to being the same as the
+ run interval."],
+ :splay => [false,
+ "Whether to sleep for a pseudo-random (but consistent) amount of time before
+ a run."]
)
self.setdefaults(:puppetd,
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index 7eb009b2d..2b9490539 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -293,6 +293,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
# The code that actually runs the configuration.
def run(tags = nil, ignoreschedules = false)
got_lock = false
+ splay
Puppet::Util.sync(:puppetrun).synchronize(Sync::EX) do
if !lockfile.lock
Puppet.notice "Lock file %s exists; skipping configuration run" %
@@ -663,6 +664,22 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
@lockfile
end
+
+ # Sleep when splay is enabled; else just return.
+ def splay
+ return unless Puppet[:splay]
+
+ limit = Integer(Puppet[:splaylimit])
+
+ # Pick a splay time and then cache it.
+ unless time = Puppet::Util::Storage.cache(:configuration)[:splay_time]
+ time = rand(limit)
+ Puppet::Util::Storage.cache(:configuration)[:splay_time] = time
+ end
+
+ Puppet.info "Sleeping for %s seconds (splay is enabled)" % time
+ sleep(time)
+ end
end
# $Id$
diff --git a/test/network/client/master.rb b/test/network/client/master.rb
index 1e14d9ce2..edd91cf30 100755
--- a/test/network/client/master.rb
+++ b/test/network/client/master.rb
@@ -3,6 +3,7 @@
$:.unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppettest'
+require 'mocha'
class TestMasterClient < Test::Unit::TestCase
include PuppetTest::ServerTest
@@ -674,6 +675,37 @@ end
newfacts.delete("memorysize")
assert(! client.send(:facts_changed?, newfacts), "Dynamic facts resulted in a false positive")
end
+
+ def test_splay
+ client = mkclient
+
+ # Make sure we default to no splay
+ client.expects(:sleep).never
+
+ assert_nothing_raised("Failed to call splay") do
+ client.send(:splay)
+ end
+
+ # Now set it to true and make sure we get the right value
+ client = mkclient
+ client.expects(:sleep)
+
+ Puppet[:splay] = true
+ assert_nothing_raised("Failed to call sleep when splay is true") do
+ client.send(:splay)
+ end
+
+ time = Puppet::Util::Storage.cache(:configuration)[:splay_time]
+ assert(time, "Splay time was not cached")
+
+ # Now try it again
+ client = mkclient
+ client.expects(:sleep).with(time)
+
+ assert_nothing_raised("Failed to call sleep when splay is true with a cached value") do
+ client.send(:splay)
+ end
+ end
end
# $Id$