diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-14 00:14:56 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-14 00:14:56 +0000 |
| commit | 19942633b69f04c6789ef08a04d434024e1bc334 (patch) | |
| tree | b0890fdaf0a0c4a756ebce9604a516d250bc49f9 | |
| parent | 798b3be4cf1d703cd8559414922b296600db9b47 (diff) | |
| download | puppet-19942633b69f04c6789ef08a04d434024e1bc334.tar.gz puppet-19942633b69f04c6789ef08a04d434024e1bc334.tar.xz puppet-19942633b69f04c6789ef08a04d434024e1bc334.zip | |
Adding --enable/--disable locking for puppetd. You can now disable puppetd from running by creating a lock file, which is useful if you are testing a configuration and want puppetd not to run for a bit.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@908 980ebf18-57e1-0310-9a29-db15c13687c0
| -rwxr-xr-x | bin/puppetd | 34 | ||||
| -rw-r--r-- | lib/puppet/client/master.rb | 35 | ||||
| -rw-r--r-- | test/client/master.rb | 72 |
3 files changed, 139 insertions, 2 deletions
diff --git a/bin/puppetd b/bin/puppetd index b6cb2535a..f61ee69f3 100755 --- a/bin/puppetd +++ b/bin/puppetd @@ -37,9 +37,24 @@ # Send all produced logs to the central puppetmasterd system. This currently # results in a significant slowdown, so it is not recommended. # +# disable:: +# Disable working on the local system. This puts a lock file in place, +# causing +puppetd+ not to work on the system until the lock file is removed. +# This is useful if you are testing a configuration and do not want the central +# configuration to override the local state until everything is tested and +# committed. +# +# +puppetd+ exits after executing this. +# # debug:: # Enable full debugging. # +# enable:: +# Enable working on the local system. This removes any lock file, causing +# +puppetd+ to start managing the local system again. +# +# +puppetd+ exits after executing this. +# # fqdn:: # Set the fully-qualified domain name of the client. This is only used for # certificate purposes, but can be used to override the discovered hostname. @@ -95,7 +110,9 @@ end options = [ [ "--centrallogging", GetoptLong::NO_ARGUMENT ], + [ "--disable", GetoptLong::NO_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "--enable", GetoptLong::NO_ARGUMENT ], [ "--fqdn", "-f", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], @@ -122,11 +139,18 @@ centrallogs = false setdest = false +enable = false +disable = false + begin result.each { |opt,arg| case opt # First check to see if the argument is a valid configuration parameter; # if so, set it. + when "--disable" + disable = true + when "--enable" + enable = true when "--centrallogging" centrallogs = true when "--help" @@ -209,6 +233,16 @@ end Puppet.notice "Starting Puppet client version %s" % [Puppet.version] client = Puppet::Client::MasterClient.new(args) +if enable + client.enable +elsif disable + client.disable +end + +if enable or disable + exit(0) +end + unless client.readcert if waitforcert begin diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb index 9ea24d502..be7f3748d 100644 --- a/lib/puppet/client/master.rb +++ b/lib/puppet/client/master.rb @@ -1,5 +1,10 @@ # The client for interacting with the puppetmaster config server. class Puppet::Client::MasterClient < Puppet::Client + Puppet.setdefaults("puppetd", + [:puppetdlockfile, "$statedir/puppetdlock", + "A lock file to temporarily stop puppetd from doing anything."] + ) + @drivername = :Master def self.facts @@ -79,6 +84,19 @@ class Puppet::Client::MasterClient < Puppet::Client @cachefile end + # Disable running the configuration. + def disable + Puppet.notice "Disabling puppetd" + unless FileTest.exists? File.dirname(Puppet[:puppetdlockfile]) + Puppet.recmkdir(File.dirname(Puppet[:puppetdlockfile])) + end + begin + File.open(Puppet[:puppetdlockfile], "w") { |f| f.puts ""; f.flush } + rescue => detail + raise Puppet::Error, "Could not lock puppetd: %s" % detail + end + end + # Initialize and load storage def dostorage begin @@ -96,6 +114,14 @@ class Puppet::Client::MasterClient < Puppet::Client end end + # Enable running again. + def enable + Puppet.notice "Enabling puppetd" + if FileTest.exists? Puppet[:puppetdlockfile] + File.unlink(Puppet[:puppetdlockfile]) + end + end + # Check whether our configuration is up to date def fresh? unless defined? @configstamp @@ -227,8 +253,13 @@ class Puppet::Client::MasterClient < Puppet::Client # The code that actually runs the configuration. def run - self.getconfig - self.apply + if FileTest.exists? Puppet[:puppetdlockfile] + Puppet.notice "%s exists; skipping configuration run" % + Puppet[:puppetdlockfile] + else + self.getconfig + self.apply + end end def setclasses(ary) diff --git a/test/client/master.rb b/test/client/master.rb new file mode 100644 index 000000000..7ec440cc6 --- /dev/null +++ b/test/client/master.rb @@ -0,0 +1,72 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = "../.." +end + +require 'puppet' +require 'puppet/client' +require 'puppet/server' +require 'test/unit' +require 'puppettest.rb' + +# $Id$ + +class TestMasterClient < Test::Unit::TestCase + include ServerTest + + def mkmaster(file) + master = nil + # create our master + assert_nothing_raised() { + # this is the default server setup + master = Puppet::Server::Master.new( + :File => file, + :UseNodes => false, + :Local => true + ) + } + return master + end + + def mkclient(master) + client = nil + assert_nothing_raised() { + client = Puppet::Client::MasterClient.new( + :Master => master + ) + } + + return client + end + + def test_disable + manifest = mktestmanifest + + master = mkmaster(manifest) + + client = mkclient(master) + + assert(! FileTest.exists?(@createdfile)) + + assert_nothing_raised { + client.disable + } + + assert_nothing_raised { + client.run + } + + assert(! FileTest.exists?(@createdfile), "Disabled client ran") + + assert_nothing_raised { + client.enable + } + + assert_nothing_raised { + client.run + } + + assert(FileTest.exists?(@createdfile), "Enabled client did not run") + end +end |
