diff options
| -rw-r--r-- | lib/puppet/network/client/master.rb | 24 | ||||
| -rwxr-xr-x | test/network/client/master.rb | 17 |
2 files changed, 32 insertions, 9 deletions
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb index a75410256..7feebd2e6 100644 --- a/lib/puppet/network/client/master.rb +++ b/lib/puppet/network/client/master.rb @@ -105,6 +105,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client def clear @objects.remove(true) Puppet::Type.allclear + mkdefault_objects @objects = nil end @@ -156,12 +157,12 @@ class Puppet::Network::Client::Master < Puppet::Network::Client # Let the daemon run again, freely in the filesystem. Frolick, little # daemon! def enable - Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]).unlock(:anonymous => true) + lockfile.unlock(:anonymous => true) end # Stop the daemon from making any configuration runs. def disable - Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]).lock(:anonymous => true) + lockfile.lock(:anonymous => true) end # Retrieve the config from a remote server. If this fails, then @@ -286,15 +287,13 @@ class Puppet::Network::Client::Master < Puppet::Network::Client # The code that actually runs the configuration. def run(tags = nil, ignoreschedules = false) - lockfile = Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]) - - locked = false + got_lock = false Puppet::Util.sync(:puppetrun).synchronize(Sync::EX) do if !lockfile.lock Puppet.notice "Lock file %s exists; skipping configuration run" % lockfile.lockfile else - @running = true + got_lock = true @configtime = thinmark do self.getconfig end @@ -307,7 +306,6 @@ class Puppet::Network::Client::Master < Puppet::Network::Client self.apply(tags, ignoreschedules) end end - @running = false end lockfile.unlock @@ -320,11 +318,11 @@ class Puppet::Network::Client::Master < Puppet::Network::Client end ensure # Just make sure we remove the lock file if we set it. - lockfile.unlock if locked and lockfile.locked? + lockfile.unlock if got_lock and lockfile.locked? end def running? - @running + lockfile.locked? end # Store the classes in the classfile, but only if we're not local. @@ -626,6 +624,14 @@ class Puppet::Network::Client::Master < Puppet::Network::Client return objects end + + def lockfile + unless defined?(@lockfile) + @lockfile = Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]) + end + + @lockfile + end end # $Id$ diff --git a/test/network/client/master.rb b/test/network/client/master.rb index c9f785580..c53e292c8 100755 --- a/test/network/client/master.rb +++ b/test/network/client/master.rb @@ -605,6 +605,23 @@ end end end + + def test_locking + master = mkclient + + class << master + def getconfig + raise ArgumentError, "Just testing" + end + end + + assert_raise(ArgumentError, "did not fail") do + master.run + end + + assert(! master.send(:lockfile).locked?, + "Master is still locked after failure") + end end # $Id$ |
