diff options
-rwxr-xr-x | bin/puppetd | 51 | ||||
-rw-r--r-- | lib/puppet/client.rb | 2 | ||||
-rw-r--r-- | lib/puppet/server.rb | 12 | ||||
-rw-r--r-- | lib/puppet/transaction.rb | 7 | ||||
-rwxr-xr-x | test/server/runner.rb | 72 |
5 files changed, 101 insertions, 43 deletions
diff --git a/bin/puppetd b/bin/puppetd index 703bb8a21..4701a9f8b 100755 --- a/bin/puppetd +++ b/bin/puppetd @@ -9,8 +9,8 @@ # = Usage # # puppetd [-D|--daemonize] [-d|--debug] [--disable] [--enable] -# [-h|--help] [--fqdn <host name>] [--listen] -# [-l|--logdest syslog|<file>|console] [-o|--onetime] [-t|--test] +# [-h|--help] [--fqdn <host name>] [-l|--logdest syslog|<file>|console] +# [-o|--onetime] [--serve <handler>] [-t|--test] # [-V|--version] [-v|--verbose] [-w|--waitforcert <seconds>] # # = Description @@ -94,12 +94,6 @@ # help:: # Print this help message # -# listen:: -# Start a local listening server. This allows you to remotely manage -# puppet nodes over XMLRPC. The client will fail to start if the -# authorization config file (defaults to /etc/puppetd/namespaceauth.conf) -# does not exist. -# # logdest:: # Where to send messages. Choose between syslog, the console, and a log file. # Defaults to sending messages to syslog, or the console if debugging or @@ -109,6 +103,13 @@ # Run the configuration once, rather than as a long-running daemon. This is # useful for interactively running puppetd. # +# serve:: +# Start another type of server. By default default, +puppetd+ will start +# a server that allows authenticated and authorized remote nodes to trigger +# the configuration to be pulled down and applied. You can specify +# any other type of service here that does not require configuration, +# e.g., filebucket, ca, or pelement. +# # test:: # Enable the most common options used for testing. These are +onetime+, # +verbose+, and +no-usecacheonfailure+. @@ -169,7 +170,6 @@ options = [ [ "--onetime", "-o", GetoptLong::NO_ARGUMENT ], [ "--test", "-t", GetoptLong::NO_ARGUMENT ], [ "--no-client", GetoptLong::NO_ARGUMENT ], - [ "--listen", GetoptLong::NO_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], [ "--version", "-V", GetoptLong::NO_ARGUMENT ], [ "--waitforcert", "-w", GetoptLong::REQUIRED_ARGUMENT ] @@ -189,9 +189,9 @@ options = { :setdest => false, :enable => false, :disable => false, - :listen => false, :client => true, - :fqdn => nil + :fqdn => nil, + :serve => {} } begin @@ -203,6 +203,10 @@ begin options[:daemonize] = true when "--disable" options[:disable] = true + when "--serve" + if klass = Puppet::Server::Handler.handler(arg) + options[:serve][klass.name] = klass + end when "--enable" options[:enable] = true when "--test" @@ -215,8 +219,6 @@ begin Puppet::Log.newdestination(:console) when "--centrallogging" options[:centrallogs] = true - when "--listen" - options[:listen] = true when "--help" if $haveusage RDoc::usage && exit @@ -348,15 +350,28 @@ unless client.readcert end objects = [] + # This has to go after the certs are dealt with. -if options[:listen] +if Puppet[:listen] unless FileTest.exists?(Puppet[:authconfig]) - $stderr.puts "Will not start with authorization file %s" % Puppet[:authconfig] + $stderr.puts "Will not start without authorization file %s" % + Puppet[:authconfig] exit(14) end - handlers = { - :PElement => {} - } + + handlers = nil + + if options[:serve].empty? + handlers = {:Runner => {}} + else + handlers = options[:serve].inject({}) do |hash, name, klass| + hash[name] = {} + end + end + + handlers.each do |name, hash| + Puppet.info "Starting handler for %s" % name + end args[:Handlers] = handlers args[:Port] = Puppet[:puppetport] diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index f1884ac85..fbc9b5e9e 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -9,11 +9,9 @@ module Puppet # but at least it's better organized for now class Client include Puppet - include SignalObserver include Puppet::Util - # FIXME The cert stuff should only come up with networking, so it # should be in the network client, not the normal client. But if i do # that, it's hard to tell whether the certs have been initialized. diff --git a/lib/puppet/server.rb b/lib/puppet/server.rb index 7bdd21134..62137f8cf 100644 --- a/lib/puppet/server.rb +++ b/lib/puppet/server.rb @@ -27,6 +27,14 @@ module Puppet class Server < WEBrick::HTTPServer include Puppet::Daemon + Puppet.config.setdefaults(:puppetd, + :listen => [false, "Whether puppetd should listen for + connections. If this is true, then by default only the + ``runner`` server is started, which allows remote authorized + and authenticated nodes to connect and trigger ``puppetd`` + runs."] + ) + # Create our config object if necessary. This works even if # there's no configuration file. def authconfig @@ -121,8 +129,9 @@ module Puppet end def self.handler(name) + name = name.to_s.downcase @subclasses.find { |h| - h.name == name + h.name.to_s.downcase == name } end @@ -179,6 +188,7 @@ require 'puppet/server/ca' require 'puppet/server/fileserver' require 'puppet/server/filebucket' require 'puppet/server/pelement' +require 'puppet/server/runner' require 'puppet/server/logger' require 'puppet/client' diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index a451d85d4..f5410d642 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -108,7 +108,10 @@ class Transaction if tags.nil? or tags == "" tags = nil else - tags = tags.split(/\s*,\s*/) + tags = [tags] unless tags.is_a? Array + tags = tags.collect do |tag| + tag.split(/\s*,\s*/) + end.flatten end allevents = @objects.collect { |child| @@ -118,7 +121,7 @@ class Transaction # Perform the actual changes events = apply(child) - # Collect the targets any subscriptions to those events + # Collect the targets of any subscriptions to those events collecttargets(events) else child.debug "Not scheduled" diff --git a/test/server/runner.rb b/test/server/runner.rb index 7f362dc17..19c08e558 100755 --- a/test/server/runner.rb +++ b/test/server/runner.rb @@ -36,11 +36,18 @@ class TestServerRunner < Test::Unit::TestCase end def test_runner + Puppet[:ignoreschedules] = false # Okay, make our manifest file = tempfile() created = tempfile() File.open(file, "w") do |f| - f.puts %{file { "#{created}": ensure => file }} + f.puts %{ + class yayness { + file { "#{created}": ensure => file, schedule => weekly } + } + + include yayness + } end client = mkclient(file) @@ -49,25 +56,50 @@ class TestServerRunner < Test::Unit::TestCase assert_nothing_raised { runner = Puppet::Server::Runner.new } - - assert_nothing_raised { - # Try it without backgrounding - runner.run(nil, nil, false) - } - - assert(FileTest.exists?(created), "File did not get created") - - # Now background it - File.unlink(created) - - assert_nothing_raised { - runner.run(nil, nil, true) - } - - Puppet.join - - assert(FileTest.exists?(created), "File did not get created") - + # First: tags + # Second: ignore schedules true/false + # Third: background true/false + # Fourth: whether file should exist true/false + [ + ["with no backgrounding", + nil, true, false, true], # no backgrounding + ["in the background", + nil, true, true, true], # in the background + ["with a bad tag", + ["coolness"], true, true, false], # a bad tag + ["with another bad tag", + "coolness", true, true, false], # another bad tag + ["with a good tag", + ["coolness", "yayness"], true, true, true], # a good tag + ["with another good tag", + ["yayness"], true, true, true], # another good tag + ["with a third good tag", + "yayness", true, true, true], # another good tag + ["not ignoring schedules", + nil, false, true, false], # do not ignore schedules + ["ignoring schedules", + nil, true, true, true], # ignore schedules + ].each do |msg, tags, ignore, bg, shouldexist| + if FileTest.exists?(created) + File.unlink(created) + end + assert_nothing_raised { + # Try it without backgrounding + runner.run(tags, ignore, bg) + } + + if bg + Puppet.join + end + + if shouldexist + assert(FileTest.exists?(created), "File did not get created " + + msg) + else + assert(!FileTest.exists?(created), "File got created incorrectly " + + msg) + end + end end end |