diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-07 23:12:33 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-07 23:12:33 +0000 |
commit | b98e65f1fd858a1d0af415554db49a121a76232c (patch) | |
tree | 728f94dd17f88902c6bdf21ff6b17486babb08af | |
parent | f1ffc34c0927840beeb21e1e2d864ce14de5d15e (diff) | |
download | puppet-b98e65f1fd858a1d0af415554db49a121a76232c.tar.gz puppet-b98e65f1fd858a1d0af415554db49a121a76232c.tar.xz puppet-b98e65f1fd858a1d0af415554db49a121a76232c.zip |
There is now full support for configuration files, and the entire system has been modified to expect their new behaviour. I have not yet run the test across all test hosts, though.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@873 980ebf18-57e1-0310-9a29-db15c13687c0
33 files changed, 742 insertions, 545 deletions
diff --git a/bin/puppet b/bin/puppet index d8f7d952e..938877dc3 100755 --- a/bin/puppet +++ b/bin/puppet @@ -8,8 +8,7 @@ # = Usage # # puppet [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] -# [-l|--logfile <file>] [-p|--parse-only] <file> -# [-c|--confdir <configuration directory>] [--vardir <var directory>] +# [-l|--logfile <file>] <file> # # = Description # @@ -19,9 +18,11 @@ # # = Options # -# confdir:: -# The configuration root directory, where +puppetmasterd+ defaults to looking -# for all of its configuration files. Defaults to +/etc/puppet+. +# Note that any configuration parameter that's valid in the configuration file +# is also a valid long argument. For example, 'ssldir' is a valid configuration +# parameter, so you can specify '--ssldir <directory>' as an argument. +# +# See the configuration file for the full list of acceptable parameters. # # debug:: # Enable full debugging. @@ -33,13 +34,6 @@ # Where to send messages. Choose between syslog, the console, and a log file. # Defaults to sending messages to the console. # -# parse-only:: -# Just verify syntax, do not apply anything. -# -# vardir:: -# The variable-size directory, used for storing state. Defaults to -# /var/puppet. -# # verbose:: # Print extra information. # @@ -69,18 +63,19 @@ rescue LoadError $haveusage = false end -result = GetoptLong.new( - [ "--confdir", "-c", GetoptLong::REQUIRED_ARGUMENT ], +options = [ [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], - [ "--noop", "-n", GetoptLong::NO_ARGUMENT ], [ "--use-nodes", GetoptLong::NO_ARGUMENT ], - [ "--parse-only", "-p", GetoptLong::NO_ARGUMENT ], - [ "--vardir", GetoptLong::REQUIRED_ARGUMENT ], [ "--version", "-V", GetoptLong::NO_ARGUMENT ] -) +] + +# Add all of the config parameters as valid options. +Puppet.config.addargs(options) + +result = GetoptLong.new(*options) debug = false verbose = false @@ -92,13 +87,11 @@ master = { :Local => true } -Puppet[:logdest] = :console +Puppet::Log.newdestination(:console) begin result.each { |opt,arg| case opt - when "--confdir" - Puppet[:puppetconf] = arg when "--version" puts "%s" % Puppet.version exit @@ -109,24 +102,20 @@ begin puts "No help available unless you have RDoc::usage installed" exit end - when "--noop" - Puppet[:noop] = true when "--use-nodes" master[:UseNodes] = true when "--verbose" verbose = true - when "--parse-only" - parseonly = true when "--debug" debug = true when "--logdest" begin - Puppet[:logdest] = arg + Puppet::Log.newdestination(arg) rescue => detail $stderr.puts detail.to_s end - when "--vardir" - Puppet[:puppetvar] = arg + else + Puppet.config.handlearg(opt, arg) end } rescue GetoptLong::InvalidOption => detail @@ -138,11 +127,19 @@ rescue GetoptLong::InvalidOption => detail end if debug - Puppet[:loglevel] = :debug + Puppet::Log.level = :debug elsif verbose - Puppet[:loglevel] = :info + Puppet::Log.level = :info +end + +# Now parse the config +if Puppet[:config] and File.exists? Puppet[:config] + Puppet.config.parse(Puppet[:config]) end +Puppet.genconfig +Puppet.genmanifest + master[:File] = ARGV.shift begin diff --git a/bin/puppetca b/bin/puppetca index ec76339f0..c3aedf5fe 100755 --- a/bin/puppetca +++ b/bin/puppetca @@ -9,9 +9,7 @@ # = Usage # # puppetca [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] -# [--cadir <ca directory>] [-g|--generate] [-l|--list] -# [-s|--sign] [--ssldir <cert directory>] -# [-c|--confdir <configuration directory>] +# [-g|--generate] [-l|--list] [-s|--sign] # # = Description # @@ -22,15 +20,14 @@ # # = Options # -# all:: -# Operate on all outstanding requests. Only makes sense with '--sign'. +# Note that any configuration parameter that's valid in the configuration file +# is also a valid long argument. For example, 'ssldir' is a valid configuration +# parameter, so you can specify '--ssldir <directory>' as an argument. # -# cadir:: -# Where to look for the ca directory. Defaults to /etc/puppet/ssl/ca. +# See the configuration file for the full list of acceptable parameters. # -# confdir:: -# The configuration root directory, where +puppetmasterd+ defaults to looking -# for all of its configuration files. Defaults to +/etc/puppet+. +# all:: +# Operate on all outstanding requests. Only makes sense with '--sign'. # # debug:: # Enable full debugging. @@ -49,9 +46,6 @@ # Sign an outstanding certificate request. Unless '--all' is specified, # hosts must be listed after all flags. # -# ssldir:: -# The directory in which to store certificates. Defaults to /etc/puppet/ssl. -# # verbose:: # Enable verbosity. # @@ -82,18 +76,20 @@ rescue LoadError $haveusage = false end -result = GetoptLong.new( +options = [ [ "--all", "-a", GetoptLong::NO_ARGUMENT ], - [ "--cadir", GetoptLong::REQUIRED_ARGUMENT ], - [ "--confdir", "-c", GetoptLong::REQUIRED_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--generate", "-g", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--list", "-l", GetoptLong::NO_ARGUMENT ], [ "--sign", "-s", GetoptLong::NO_ARGUMENT ], - [ "--ssldir", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ] -) +] + +# Add all of the config parameters as valid options. +Puppet.config.addargs(options) + +result = GetoptLong.new(*options) mode = nil all = false @@ -104,12 +100,8 @@ begin case opt when "--all" all = true - when "--cadir" - Puppet[:cadir] = arg - when "--confdir" - Puppet[:puppetconf] = arg when "--debug" - Puppet[:loglevel] = :debug + Puppet::Log.level = :debug when "--generate" generate = arg mode = :generate @@ -124,10 +116,10 @@ begin mode = :list when "--sign" mode = :sign - when "--ssldir" - Puppet[:ssldir] = arg when "--verbose" - Puppet[:loglevel] = :info + Puppet::Log.level = :info + else + Puppet.config.handlearg(opt, arg) end } rescue GetoptLong::InvalidOption => detail @@ -138,7 +130,22 @@ rescue GetoptLong::InvalidOption => detail exit(1) end -ca = Puppet::SSLCertificates::CA.new() +# Now parse the config +if Puppet[:config] and File.exists? Puppet[:config] + Puppet.config.parse(Puppet[:config]) +end + +Puppet.genconfig +Puppet.genmanifest + +Puppet::Util.chuser + +begin + ca = Puppet::SSLCertificates::CA.new() +rescue => detail + puts detail.to_s + exit(23) +end unless mode $stderr.puts "You must specify --list or --sign" diff --git a/bin/puppetd b/bin/puppetd index e575a8405..742786c8b 100755 --- a/bin/puppetd +++ b/bin/puppetd @@ -9,11 +9,8 @@ # = Usage # # puppetd [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] -# [--ssldir <cert directory>] [-l|--logdest <syslog|<file>|console>] -# [--fqdn <host name>] [-p|--port <port>] [-o|--onetime] -# [-s|--server <server>] [-i|--ignoreschedules] -# [-w|--waitforcert <seconds>] [-c|--confdir <configuration directory>] -# [--vardir <var directory>] [--centrallogging] +# [-l|--logdest <syslog|<file>|console>] [--fqdn <host name>] +# [-o|--onetime] [-w|--waitforcert <seconds>] [--centrallogging] # # = Description # @@ -30,14 +27,16 @@ # # = Options # +# Note that any configuration parameter that's valid in the configuration file +# is also a valid long argument. For example, 'server' is a valid configuration +# parameter, so you can specify '--server <servername>' as an argument. +# +# See the configuration file for the full list of acceptable parameters. +# # centrallogging:: # Send all produced logs to the central puppetmasterd system. This currently # results in a significant slowdown, so it is not recommended. # -# confdir:: -# The configuration root directory, where +puppetmasterd+ defaults to looking -# for all of its configuration files. Defaults to +/etc/puppet+. -# # debug:: # Enable full debugging. # @@ -51,34 +50,13 @@ # # logdest:: # Where to send messages. Choose between syslog, the console, and a log file. -# Defaults to sending messages to /var/puppet/log/puppet.log, or the console -# if debugging or verbosity is enabled. -# -# port:: -# The port to which to connect on the remote server. Currently defaults to 8139. +# Defaults to sending messages to syslog, or the console if debugging or +# verbosity is enabled. # # onetime:: # Run the configuration once, rather than as a long-running daemon. This is # useful for interactively running puppetd. # -# schedule:: -# What schedule Puppet itself should run on. This dictates how often the -# entire configuration is retrieved and run. The default is named 'puppet', -# and runs every half hour or so. The schedules themselves are defined in the -# configuration, which means that on startup puppetd will always retrieve -# the configuration and then check to see if it's scheduled to run. -# -# server:: -# The remote server from whom to receive the local configuration. Currently -# must also be the certificate authority. Currently defaults to 'puppet'. -# -# ssldir:: -# Where to store and find certificates. Defaults to /etc/puppet/ssl. -# -# vardir:: -# The variable-size directory, used for storing state. Defaults to -# /var/puppet. -# # verbose:: # Turn on verbose reporting. # @@ -91,7 +69,7 @@ # # = Example # -# puppet -s puppet.domain.com +# puppetd --server puppet.domain.com # # = Author # @@ -99,7 +77,7 @@ # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005, 2006 Reductive Labs, LLC # Licensed under the GNU Public License @@ -115,24 +93,22 @@ rescue LoadError $haveusage = false end -result = GetoptLong.new( +options = [ [ "--centrallogging", GetoptLong::NO_ARGUMENT ], - [ "--confdir", "-c", GetoptLong::REQUIRED_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--fqdn", "-f", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], - [ "--noop", "-n", GetoptLong::NO_ARGUMENT ], [ "--onetime", "-o", GetoptLong::NO_ARGUMENT ], - [ "--port", "-p", GetoptLong::REQUIRED_ARGUMENT ], - [ "--schedule", "-S", GetoptLong::REQUIRED_ARGUMENT ], - [ "--server", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--ssldir", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], [ "--version", "-V", GetoptLong::NO_ARGUMENT ], - [ "--vardir", GetoptLong::REQUIRED_ARGUMENT ], [ "--waitforcert", "-w", GetoptLong::REQUIRED_ARGUMENT ] -) +] + +# Add all of the config parameters as valid options. +Puppet.config.addargs(options) + +result = GetoptLong.new(*options) server = "puppet" fqdn = nil @@ -149,10 +125,10 @@ setdest = 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 "--centrallogging" centrallogs = true - when "--confdir" - Puppet[:puppetconf] = arg when "--help" if $haveusage RDoc::usage && exit @@ -164,44 +140,34 @@ begin puts "%s" % Puppet.version exit when "--verbose" - Puppet[:loglevel] = :info - Puppet[:logdest] = :console + Puppet::Log.level = :info + Puppet::Log.newdestination(:console) setdest = true when "--debug" - Puppet[:loglevel] = :debug - Puppet[:logdest] = :console + Puppet::Log.level = :debug + Puppet::Log.newdestination(:console) setdest = true - when "--noop" - Puppet[:noop] = true - when "--schedule" - # This is late-binding -- it'll only look up the schedule name - # when it needs to run - Puppet[:schedule] = arg - when "--ssldir" - Puppet[:ssldir] = arg when "--fqdn" fqdn = arg - when "--server" - server = arg when "--onetime" onetime = true when "--port" args[:Port] = arg when "--logdest" begin - Puppet[:logdest] = arg + Puppet::Log.newdestination(arg) rescue => detail $stderr.puts detail.to_s end - when "--vardir" - Puppet[:puppetvar] = arg when "--waitforcert" waitforcert = arg.to_i + else + Puppet.config.handlearg(opt, arg) end } rescue GetoptLong::InvalidOption => detail + $stderr.puts detail $stderr.puts "Try '#{$0} --help'" - #$stderr.puts detail # FIXME RDoc::usage doesn't seem to work #if $haveusage # RDoc::usage(1,'usage') @@ -209,17 +175,25 @@ rescue GetoptLong::InvalidOption => detail exit(1) end -if Puppet[:loglevel] == :debug or Puppet[:loglevel] == :info +Puppet.genconfig +Puppet.genmanifest + +# Now parse the config +if Puppet[:config] and File.exists? Puppet[:config] + Puppet.config.parse(Puppet[:config]) +end + +if Puppet::Log.level == :debug or Puppet::Log.level == :info args[:Daemonize] = false else args[:Daemonize] = true end unless setdest - Puppet[:logdest] = :syslog + Puppet::Log.newdestination(:syslog) end -args[:Server] = server +args[:Server] = Puppet[:server] if fqdn args[:FQDN] = fqdn end @@ -230,14 +204,12 @@ if centrallogs if args.include?(:Port) logdest += ":" + args[:Port] end - Puppet[:logdest] = logdest + Puppet::Log.newdestination(logdest) end - Puppet.notice "Starting Puppet client version %s" % [Puppet.version] client = Puppet::Client::MasterClient.new(args) - unless client.readcert if waitforcert begin diff --git a/bin/puppetmasterd b/bin/puppetmasterd index 6dc5a3fa9..e0f7da25f 100755 --- a/bin/puppetmasterd +++ b/bin/puppetmasterd @@ -8,59 +8,32 @@ # = Usage # # puppetmasterd [-h|--help] [-d|--debug] [-v|--verbose] [-V|--version] -# [-l|--logdest <syslog|console|<file>>] [--httplog <file>] -# [-m|--manifest <site manifest>] [--noca] [-p|--port <port>] -# [--parseonly] [-s|--ssldir <cert directory>] -# [-c|--confdir <configuration directory>] [--vardir <var dir>] +# [--noca] [--nobucket] # # = Description # -# This is the standalone puppet execution script; use it to execute -# individual scripts that you write. If you need to execute site-wide -# scripts, use +puppetd+ and +puppetmasterd+. +# This is the puppet central daemon. # # = Options # -# autosign:: -# Enable autosign (which presents a potential security problem). If enabled, -# refers to the autosign configuration file at /etc/puppet/autosign.conf to -# determine which hosts should have their certificates signed. +# Note that any configuration parameter that's valid in the configuration file +# is also a valid long argument. For example, 'ssldir' is a valid configuration +# parameter, so you can specify '--ssldir <directory>' as an argument. # -# confdir:: -# The configuration root directory, where +puppetmasterd+ defaults to looking -# for all of its configuration files. Defaults to +/etc/puppet+. +# See the configuration file for the full list of acceptable parameters. # # debug:: # Enable full debugging. Causes the daemon not to go into the background. # -# fsconfig:: -# Where to find the fileserver configuration file. Defaults to -# /etc/puppet/fileserver.conf. If the fileserver config file exists, -# the puppetmasterd daemon will automatically also become a fileserver. -# -# group:: -# Print this help message. -# -# group:: -# The group to run as. Can be either a name or number. Defaults to 'puppet'. -# # help:: # Print this help message. # -# httplog:: -# Where to send http logs (which are currently separate from Puppet logs). -# Defaults to /var/puppet/log/http.log. -# # logdest:: # Where to send messages. Choose between syslog, the console, and a log file. # Defaults to sending messages to /var/puppet/log/puppet.log, or the console # if debugging or verbosity is enabled. # -# manifest:: -# The central site manifest to use for providing clients with their individual -# configurations. Defaults to /etc/puppet/manifests/site.pp. -# -# noca:: +# nobucket:: # Do not function as a file bucket. # # noca:: @@ -69,23 +42,6 @@ # nonodes:: # Do not use individual node designations; each node will receive the result # of evaluating the entire configuration. -# -# parseonly:: -# Just parse the central manifest to verify it is syntactically correct. -# -# port:: -# The port on which to listen. Defaults to 8139. -# -# ssldir:: -# The directory in which to store certificates. Defaults to /etc/puppet/ssl. -# -# user:: -# The user to run as. Can be either a name or number. Defaults to 'user'. -# -# vardir:: -# The variable-size directory, used for storing state. Defaults to -# /var/puppet. -# # verbose:: # Enable verbosity. Causes the daemon not to go into the background. # @@ -109,27 +65,22 @@ require 'getoptlong' require 'puppet' require 'puppet/server' -result = GetoptLong.new( - [ "--autosign", "-a", GetoptLong::NO_ARGUMENT ], - [ "--confdir", "-c", GetoptLong::REQUIRED_ARGUMENT ], +options = [ [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], - [ "--fsconfig", "-f", GetoptLong::REQUIRED_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--httplog", GetoptLong::NO_ARGUMENT ], [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], - [ "--manifest", "-m", GetoptLong::REQUIRED_ARGUMENT ], [ "--noca", GetoptLong::NO_ARGUMENT ], [ "--nobucket", GetoptLong::NO_ARGUMENT ], [ "--nonodes", GetoptLong::NO_ARGUMENT ], - [ "--parseonly", GetoptLong::NO_ARGUMENT ], - [ "--port", "-p", GetoptLong::REQUIRED_ARGUMENT ], - [ "--ssldir", "-s", GetoptLong::REQUIRED_ARGUMENT ], - [ "--user", "-u", GetoptLong::REQUIRED_ARGUMENT ], - [ "--group", "-g", GetoptLong::REQUIRED_ARGUMENT ], - [ "--vardir", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], [ "--version", "-V", GetoptLong::NO_ARGUMENT ] -) +] +Puppet::Log.newdestination(:syslog) + +# Add all of the config parameters as valid options. +Puppet.config.addargs(options) + +result = GetoptLong.new(*options) $haveusage = true @@ -159,21 +110,10 @@ setdest = false begin result.each { |opt,arg| case opt - when "--autosign" - ca[:autosign] = Puppet[:autosign] - when "--confdir" - Puppet[:puppetconf] = arg when "--debug" - Puppet[:debug] = true - Puppet[:logdest] = :console + Puppet::Log.level = :debug + Puppet::Log.newdestination(:console) setdest = true - when "--fsconfig" - unless FileTest.exists?(arg) - $stderr.puts "File server configuration file %s does not exist" % - arg - exit(23) - end - fs[:Config] = arg when "--help" if $haveusage RDoc::usage && exit @@ -181,45 +121,28 @@ begin puts "No help available unless you have RDoc::usage installed" exit end - when "--httplog" - args[:AccessLog] = arg - when "--manifest" - master[:File] = arg when "--noca" haveca = false when "--nobucket" havebucket = false when "--nonodes" master[:UseNodes] = false - when "--parseonly" - parseonly = true - when "--port" - args[:Port] = arg - when "--ssldir" - Puppet[:ssldir] = arg when "--logdest" begin - Puppet[:logdest] = arg + Puppet::Log.newdestination(arg) setdest = true rescue => detail $stderr.puts detail.to_s end - when "--group" - group = arg - when "--user" - user = arg - when "--vardir" - Puppet[:puppetvar] = arg when "--version" puts "%s" % Puppet.version exit when "--verbose" setdest = true - Puppet[:loglevel] = :info - Puppet[:logdest] = :console + Puppet::Log.level = :info + Puppet::Log.newdestination :console else - $stderr.puts "Invalid option '#{opt}'" - exit(1) + Puppet.config.handlearg(opt, arg) end } rescue GetoptLong::InvalidOption => detail @@ -231,44 +154,21 @@ rescue GetoptLong::InvalidOption => detail #end exit(1) end +ca[:autosign] = Puppet[:autosign] -require 'etc' - -if group - if group =~ /^\d+$/ - group = Integer(group) - else - begin - g = Etc.getgrnam(group) - rescue ArgumentError - $stderr.puts "Could not find group %s" % group - end - group = g.gid - end - unless Process.gid == group - Process.egid = group - Process.gid = group - end +# Now parse the config +if Puppet[:config] and File.exists? Puppet[:config] + Puppet.config.parse(Puppet[:config]) end -if user - if user =~ /^\d+$/ - user = Integer(user) - else - begin - u = Etc.getpwnam(user) - rescue ArgumentError - $stderr.puts "Could not find user %s" % user - end - user = u.uid - end - unless Process.uid == user - Process.euid = user - Process.uid = user - end -end +Puppet.genconfig +Puppet.genmanifest + +require 'etc' + +Puppet::Util.chuser -if Puppet[:loglevel] == :debug or Puppet[:loglevel] == :info or parseonly +if Puppet::Log.level == :debug or Puppet::Log.level == :info or parseonly args[:Daemonize] = false else args[:Daemonize] = true @@ -281,7 +181,7 @@ handlers = { } unless setdest - Puppet[:logdest] = :syslog + Puppet::Log.newdestination(:syslog) end if haveca @@ -292,13 +192,11 @@ end # handlers[:FileBucket] = bucket #end -unless fs.include?(:Config) - if File.exists?(Puppet[:fileserverconfig]) - fs[:Config] = Puppet[:fileserverconfig] - #else - # Puppet.notice "File server config %s does not exist; skipping file serving" % - # Puppet[:fileserverconfig] - end +if File.exists?(Puppet[:fileserverconfig]) + fs[:Config] = Puppet[:fileserverconfig] +#else +# Puppet.notice "File server config %s does not exist; skipping file serving" % +# Puppet[:fileserverconfig] end if fs.include?(:Config) @@ -307,8 +205,6 @@ end args[:Handlers] = handlers -Puppet.notice "Starting Puppet server version %s" % [Puppet.version] - begin # use the default, um, everything #server = Puppet::Server.new(:CA => ca) @@ -318,14 +214,21 @@ rescue => detail exit(1) end -if parseonly +if Puppet[:parseonly] # we would have already exited if the file weren't syntactically correct exit(0) end +if args[:Daemonize] + server.daemonize +end + trap(:INT) { server.shutdown } + +Puppet.notice "Starting Puppet server version %s" % [Puppet.version] + begin server.start rescue => detail diff --git a/ext/module_puppet b/ext/module_puppet index 151fac4c9..388b3a1c1 100755 --- a/ext/module_puppet +++ b/ext/module_puppet @@ -7,9 +7,8 @@ # # = Usage # -# puppet [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] -# [-l|--logfile <file>] [-p|--parse-only] <file> -# [-c|--confdir <configuration directory>] [--vardir <var directory>] +# puppet_module [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] +# [-l|--logdest <file>]<file> # # = Description # @@ -19,9 +18,11 @@ # # = Options # -# confdir:: -# The configuration root directory, where +puppetmasterd+ defaults to looking -# for all of its configuration files. Defaults to +/etc/puppet+. +# Note that any configuration parameter that's valid in the configuration file +# is also a valid long argument. For example, 'ssldir' is a valid configuration +# parameter, so you can specify '--ssldir <directory>' as an argument. +# +# See the configuration file for the full list of acceptable parameters. # # debug:: # Enable full debugging. @@ -29,17 +30,10 @@ # help:: # Print this help message # -# logfile:: +# logdest:: # Where to send messages. Choose between syslog, the console, and a log file. # Defaults to sending messages to the console. # -# parse-only:: -# Just verify syntax, do not apply anything. -# -# vardir:: -# The variable-size directory, used for storing state. Defaults to -# /var/puppet. -# # verbose:: # Print extra information. # @@ -65,18 +59,19 @@ rescue LoadError $haveusage = false end -result = GetoptLong.new( - [ "--confdir", "-c", GetoptLong::REQUIRED_ARGUMENT ], +options = [ [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], - [ "--noop", "-n", GetoptLong::NO_ARGUMENT ], [ "--use-nodes", GetoptLong::NO_ARGUMENT ], - [ "--parse-only", "-p", GetoptLong::NO_ARGUMENT ], - [ "--vardir", GetoptLong::REQUIRED_ARGUMENT ], [ "--version", "-V", GetoptLong::NO_ARGUMENT ] -) +] + +# Add all of the config parameters as valid options. +Puppet.config.addargs(options) + +result = GetoptLong.new(*options) debug = false verbose = false @@ -95,8 +90,6 @@ master = { begin result.each { |opt,arg| case opt - when "--confdir" - Puppet[:puppetconf] = arg when "--version" puts "%s" % Puppet.version exit @@ -107,24 +100,20 @@ begin puts "No help available unless you have RDoc::usage installed" exit end - when "--noop" - Puppet[:noop] = true when "--use-nodes" master[:UseNodes] = true when "--verbose" verbose = true - when "--parse-only" - parseonly = true when "--debug" debug = true when "--logdest" begin - Puppet[:logdest] = arg + Puppet::Log.newdestination arg rescue => detail $stderr.puts detail.to_s end - when "--vardir" - Puppet[:puppetvar] = arg + else + Puppet.config.handlearg(opt, arg) end } rescue GetoptLong::InvalidOption => detail @@ -136,11 +125,21 @@ rescue GetoptLong::InvalidOption => detail end if debug - Puppet[:loglevel] = :debug + Puppet::Log.level = :debug + Puppet::Log.newdestination :console elsif verbose - Puppet[:loglevel] = :info + Puppet::Log.level = :info + Puppet::Log.newdestination :console +end + +# Now parse the config +if Puppet[:config] and File.exists? Puppet[:config] + Puppet.config.parse(Puppet[:config]) end +Puppet.genconfig +Puppet.genmanifest + unless ARGV.length > 0 $stderr.puts "You must pass a script to parse" exit(14) diff --git a/lib/puppet.rb b/lib/puppet.rb index fa3aafb87..f31f1d749 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -102,28 +102,42 @@ module Puppet var = "/var/puppet" end self.setdefaults("puppet", - [:puppetconf, conf, "The main Puppet configuration directory."], - [:puppetvar, var, "Where Puppet stores dynamic and growing data."] + [:confdir, conf, "The main Puppet configuration directory."], + [:vardir, var, "Where Puppet stores dynamic and growing data."] + ) + + # Define the config default. + self.setdefaults(self.name, + [:config, "$confdir/#{self.name}.conf", + "The configuration file for #{self.name}."] ) self.setdefaults("puppet", - [:logdir, "$puppetvar/log", + [:logdir, "$vardir/log", "The Puppet log directory."], - [:bucketdir, "$puppetvar/bucket", + [:bucketdir, "$vardir/bucket", "Where FileBucket files are stored."], - [:statedir, "$puppetvar/state", + [:statedir, "$vardir/state", "The directory where Puppet state is stored. Generally, this directory can be removed without causing harm (although it might result in spurious service restarts)."], - [:rundir, "$puppetvar/run", "Where Puppet PID files are kept."], + [:rundir, "$vardir/run", "Where Puppet PID files are kept."], [:statefile, "$statedir/state.yaml", "Where puppetd and puppetmasterd store state associated with the running configuration. In the case of puppetmasterd, this file reflects the state discovered through interacting with clients."], - [:ssldir, "$puppetconf/ssl", "Where SSL certificates are kept."] + [:ssldir, "$confdir/ssl", "Where SSL certificates are kept."], + [:genconfig, false, + "Whether to just print a configuration to stdout and exit. Only makes + sense when used interactively. Takes into account arguments specified + on the CLI."], + [:genmanifest, false, + "Whether to just print a manifest to stdout and exit. Only makes + sense when used interactively. Takes into account arguments specified + on the CLI."] ) self.setdefaults("puppetmasterd", - [:manifestdir, "$puppetconf/manifests", + [:manifestdir, "$confdir/manifests", "Where puppetmasterd looks for its manifests."], [:manifest, "$manifestdir/site.pp", "The entry-point manifest for puppetmasterd."], @@ -137,15 +151,15 @@ module Puppet ) self.setdefaults("puppetd", - [:localconfig, "$puppetconf/localconfig", + [:localconfig, "$confdir/localconfig", "Where puppetd caches the local configuration. An extension reflecting the cache format is added automatically."], - [:classfile, "$puppetconf/classes.txt", + [:classfile, "$confdir/classes.txt", "The file in which puppetd stores a list of the classes associated with the retrieved configuratiion."], [:puppetdlog, "$logdir/puppetd.log", "The log file for puppetd. This is generally not used."], - [:httplogfile, "$logdir/http.log", "Where the puppetd web server logs."], + [:httplog, "$logdir/http.log", "Where the puppetd web server logs."], [:server, "puppet", "The server to which server puppetd should connect"], [:user, "puppet", "The user puppetmasterd should run as."], @@ -159,41 +173,74 @@ module Puppet "How often puppetd applies the client configuration; in seconds"] ) self.setdefaults("metrics", - [:rrddir, "$puppetvar/rrd", + [:rrddir, "$vardir/rrd", "The directory where RRD database files are stored."], [:rrdgraph, false, "Whether RRD information should be graphed."] ) # configuration parameter access and stuff def self.[](param) - @@config[param] - end - - # configuration parameter access and stuff - def self.[]=(param,value) case param when :debug: - if value - Puppet::Log.level=(:debug) + if Puppet::Log.level == :debug + return true else - Puppet::Log.level=(:notice) + return false end - when :loglevel: - Puppet::Log.level=(value) - when :logdest: - Puppet::Log.newdestination(value) else - @@config[param] = value + return @@config[param] end end + # configuration parameter access and stuff + def self.[]=(param,value) + @@config[param] = value +# case param +# when :debug: +# if value +# Puppet::Log.level=(:debug) +# else +# Puppet::Log.level=(:notice) +# end +# when :loglevel: +# Puppet::Log.level=(value) +# when :logdest: +# Puppet::Log.newdestination(value) +# else +# @@config[param] = value +# end + end + def self.clear @@config.clear end + def self.debug=(value) + if value + Puppet::Log.level=(:debug) + else + Puppet::Log.level=(:notice) + end + end + def self.config @@config end + + def self.genconfig + if Puppet[:genconfig] + puts Puppet.config.to_config + exit(0) + end + end + + def self.genmanifest + if Puppet[:genmanifest] + puts Puppet.config.to_manifest + exit(0) + end + end + # Start our event loop. This blocks, waiting for someone, somewhere, # to generate events of some kind. def self.start @@ -258,11 +305,19 @@ module Puppet tmp.split(File::SEPARATOR).each { |dir| path.push dir if ! FileTest.exist?(File.join(path)) - Dir.mkdir(File.join(path), mode) + begin + Dir.mkdir(File.join(path), mode) + rescue Errno::EACCES => detail + Puppet.err detail.to_s + return false + rescue => detail + Puppet.err "Could not create %s: %s" % [path, detail.to_s] + return false + end elsif FileTest.directory?(File.join(path)) next else FileTest.exist?(File.join(path)) - raise "Cannot create %s: basedir %s is a file" % + raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] end } diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb index 295bf2035..010473dbf 100644 --- a/lib/puppet/config.rb +++ b/lib/puppet/config.rb @@ -5,23 +5,22 @@ class Config # Retrieve a config value def [](param) - param = param.intern unless param.is_a? Symbol + param = convert(param) if @config.include?(param) if @config[param] val = @config[param].value return val end else - nil + raise ArgumentError, "Invalid argument %s" % param end end # Set a config value. This doesn't set the defaults, it sets the value itself. def []=(param, value) - param = param.intern unless param.is_a? Symbol + param = convert(param) unless @config.include?(param) - raise Puppet::Error, "Unknown configuration parameter %s" % param - #@config[param] = newelement(param, value) + raise Puppet::Error, "Unknown configuration parameter %s" % param.inspect end unless @order.include?(param) @order << param @@ -40,6 +39,47 @@ class Config return true end + # Generate the list of valid arguments, in a format that GetoptLong can + # understand, and add them to the passed option list. + def addargs(options) + require 'getoptlong' + # Add all of the config parameters as valid options. + self.each { |param, obj| + if self.boolean?(param) + options << ["--#{param}", GetoptLong::NO_ARGUMENT] + options << ["--no-#{param}", GetoptLong::NO_ARGUMENT] + else + options << ["--#{param}", GetoptLong::REQUIRED_ARGUMENT] + end + } + + return options + end + + # Turn the config into a transaction and apply it + def apply + trans = self.to_transportable + begin + comp = trans.to_type + trans = comp.evaluate + trans.evaluate + comp.remove + rescue => detail + puts detail.backtrace + Puppet.err "Could not configure myself: %s" % detail + end + end + + # Is our parameter a boolean parameter? + def boolean?(param) + param = convert(param) + if @config.include?(param) and @config[param].kind_of? CBoolean + return true + else + return false + end + end + # Remove all set values. def clear @config.each { |name, obj| @@ -47,6 +87,15 @@ class Config } end + def convert(param) + case param + when String: return param.intern + when Symbol: return param + else + raise ArgumentError, "Invalid param type %s" % param.class + end + end + def each @order.each { |name| if @config.include?(name) @@ -75,10 +124,40 @@ class Config # Return an object by name. def element(param) - param = param.intern unless param.is_a? Symbol + param = convert(param) @config[param] end + # Handle a command-line argument. + def handlearg(opt, value = nil) + if value == "true" + value = true + end + if value == "false" + value = false + end + str = opt.sub(/^--/,'') + bool = true + newstr = str.sub(/^no-/, '') + if newstr != str + str = newstr + bool = false + end + if self.valid?(str) + if self.boolean?(str) + self[str] = bool + else + self[str] = value + end + + # Mark that this was set on the cli, so it's not overridden if the config + # gets reread. + @config[str.intern].setbycli = true + else + raise ArgumentError, "Invalid argument %s" % opt + end + end + # Create a new config object def initialize @order = [] @@ -87,6 +166,7 @@ class Config # Return all of the parameters associated with a given section. def params(section) + section = section.intern if section.is_a? String @config.find_all { |name, obj| obj.section == section }.collect { |name, obj| @@ -134,8 +214,13 @@ class Config values[section][var.to_s] = value next end - Puppet.info "%s: Setting %s to '%s'" % [section, var, value] - self[var] = value + + # Don't override set parameters, since the file is parsed + # after cli arguments are handled. + unless @config.include?(var) and @config[var].setbycli + Puppet.debug "%s: Setting %s to '%s'" % [section, var, value] + self[var] = value + end @config[var].section = section metas.each { |meta| @@ -155,6 +240,7 @@ class Config # what kind of element we're creating, but the value itself might be either # a default or a value, so we can't actually assign it. def newelement(param, desc, value) + param = convert(param) mod = nil case value when true, false, "true", "false": @@ -171,9 +257,12 @@ class Config element.extend(mod) end + @order << param + return element end + # Iterate across all of the objects in a given section. def persection(section) self.each { |name, obj| if obj.section == section @@ -221,7 +310,13 @@ class Config } if obj.respond_to? :to_transportable - objects << obj.to_transportable + unless done[:file].include? obj.value + trans = obj.to_transportable + # transportable could return nil + next unless trans + objects << trans + done[:file] << obj.value + end end } @@ -241,6 +336,7 @@ class Config section = section.intern unless section.is_a? Symbol #hash.each { |param, value| defs.each { |param, value, desc| + param = convert(param) if @config.include?(param) and @config[param].default raise Puppet::Error, "Default %s is already defined" % param end @@ -260,11 +356,27 @@ class Config # Convert our list of objects into a configuration file. def to_config - str = "" + str = %{The configuration file for #{Puppet.name}. Note that this file +is likely to have unused configuration parameters in it; any parameter that's +valid anywhere in Puppet can be in any config file, even if it's not used. + +Every section can specify three special parameters: owner, group, and mode. +These parameters affect the required permissions of any files specified after +their specification. Puppet will sometimes use these parameters to check its +own configured state, so they can be used to make Puppet a bit more self-managing. + +Note also that the section names are entirely for human-level organizational +purposes; they don't provide separate namespaces. All parameters are in a +single namespace. + +Generated on #{Time.now}. + +}.gsub(/^/, "# ") + eachsection do |section| str += "[#{section}]\n" persection(section) do |obj| - str += obj.to_s + "\n" + str += obj.to_config + "\n" end end @@ -276,6 +388,7 @@ class Config done = { :owner => [], :group => [], + :file => [] } topbucket = Puppet::TransBucket.new @@ -299,12 +412,23 @@ class Config # Convert to a parseable manifest def to_manifest transport = self.to_transportable - return transport.to_manifest + + manifest = transport.to_manifest + "\n" + eachsection { |section| + manifest += "include #{section}\n" + } + + return manifest + end + + def valid?(param) + param = convert(param) + @config.has_key?(param) end # The base element type. class CElement - attr_accessor :name, :section, :default, :parent, :desc + attr_accessor :name, :section, :default, :parent, :desc, :setbycli # Unset any set value. def clear @@ -314,15 +438,43 @@ class Config # Create the new element. Pretty much just sets the name. def initialize(name, desc, value = nil) @name = name - @desc = desc + @desc = desc.gsub(/^\s*/, '') if value @value = value end end - def to_s - str = @desc.gsub(/^/, " # ") + - "\n %s = %s" % [@name, self.value] + def set? + if defined? @value and ! @value.nil? + return true + else + return false + end + end + + # Convert the object to a config statement. + def to_config + str = @desc.gsub(/^/, "# ") + "\n" + + # Add in a statement about the default. + if defined? @default and @default + str += "# The default value is '%s'.\n" % @default + end + + line = "%s = %s" % [@name, self.value] + + # If the value has not been overridden, then print it out commented + # and unconverted, so it's clear that that's the default and how it + # works. + if defined? @value and ! @value.nil? + line = "%s = %s" % [@name, self.value] + else + line = "# %s = %s" % [@name, @default] + end + + str += line + "\n" + + str.gsub(/^/, " ") end # Retrieves the value, or if it's not set, retrieves the default. @@ -358,12 +510,11 @@ class Config # A file. module CFile - attr_accessor :owner, :group, :mode, :type + attr_accessor :owner, :group, :mode def convert(value) - unless value - return nil - end + return value unless value + return value unless value.is_a? String if value =~ /\$(\w+)/ parent = $1 if pval = @parent[parent] @@ -380,20 +531,33 @@ class Config # Set the type appropriately. Yep, a hack. This supports either naming # the variable 'dir', or adding a slash at the end. def munge(value) - if value.to_s =~ /dir/ - @type = :directory - elsif value =~ /\/$/ + if value.to_s =~ /\/$/ @type = :directory return value.sub(/\/$/, '') - else - @type = :file end return value end + # Return the appropriate type. + def type + value = self.value + if @name.to_s =~ /dir/ + return :directory + elsif value.to_s =~ /\/$/ + return :directory + elsif value.is_a? String + return :file + else + return nil + end + end + + # Convert the object to a TransObject instance. def to_transportable + type = self.type + return nil unless type obj = Puppet::TransObject.new(self.value, "file") - obj[:ensure] = self.type + obj[:ensure] = type [:owner, :group, :mode].each { |var| if value = self.send(var) obj[var] = value @@ -407,6 +571,7 @@ class Config # Make sure any provided variables look up to something. def validate(value) + return true unless value.is_a? String value.scan(/\$(\w+)/) { |name| name = name[0] unless @parent[name] @@ -423,7 +588,8 @@ class Config when true, "true": return true when false, "false": return false else - raise Puppet::Error, "Invalid value %s for %s" % [value, @name] + raise Puppet::Error, "Invalid value '%s' for %s" % + [value.inspect, @name] end end end diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb index 65043a463..672ff1d8b 100644 --- a/lib/puppet/log.rb +++ b/lib/puppet/log.rb @@ -27,14 +27,14 @@ module Puppet :crit => RESET } - @destinations = {:syslog => Syslog.open("puppet")} + #@destinations = {:syslog => Syslog.open("puppet")} + @destinations = {:console => :console} # Reset all logs to basics. Basically just closes all files and undefs # all of the other objects. def Log.close(dest = nil) if dest if @destinations.include?(dest) - Puppet.warning "Closing %s" % dest if @destinations.respond_to?(:close) @destinations[dest].close end diff --git a/lib/puppet/server.rb b/lib/puppet/server.rb index cd73ce885..4fadc3987 100644 --- a/lib/puppet/server.rb +++ b/lib/puppet/server.rb @@ -34,9 +34,6 @@ module Puppet daemonize = hash[:Daemonize] end - if daemonize - self.daemonize - end # FIXME we should have some kind of access control here, using # :RequestHandler hash[:Port] ||= Puppet[:masterport] diff --git a/lib/puppet/server/ca.rb b/lib/puppet/server/ca.rb index 7afd0c82c..a008feb70 100644 --- a/lib/puppet/server/ca.rb +++ b/lib/puppet/server/ca.rb @@ -26,7 +26,7 @@ class Server # we only otherwise know how to handle files unless @autosign =~ /^\// raise Puppet::Error, "Invalid autosign value %s" % - @autosign + @autosign.inspect end unless FileTest.exists?(@autosign) diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb index 27e4d814a..cd8511ad6 100755 --- a/lib/puppet/server/fileserver.rb +++ b/lib/puppet/server/fileserver.rb @@ -9,7 +9,7 @@ class Server attr_accessor :local Puppet.setdefaults("fileserver", - [:fileserverconfig, "$puppetconf/fileserver.conf", + [:fileserverconfig, "$confdir/fileserver.conf", "Where the fileserver configuration is stored."]) #CHECKPARAMS = %w{checksum type mode owner group} diff --git a/lib/puppet/sslcertificates.rb b/lib/puppet/sslcertificates.rb index 0c6322bcf..fef661178 100755 --- a/lib/puppet/sslcertificates.rb +++ b/lib/puppet/sslcertificates.rb @@ -9,36 +9,36 @@ rescue LoadError end module Puppet::SSLCertificates - def self.mkdir(dir) - # this is all a bunch of stupid hackery - unless FileTest.exists?(dir) - comp = Puppet.type(:component).create( - :name => "certdir creation" - ) - path = [''] - - dir.split(File::SEPARATOR).each { |d| - path << d - if FileTest.exists?(File.join(path)) - unless FileTest.directory?(File.join(path)) - raise "%s exists but is not a directory" % File.join(path) - end - else - obj = Puppet::Type.type(:file).create( - :name => File.join(path), - :mode => "750", - :ensure => "directory" - ) - - comp.push obj - end - } - trans = comp.evaluate - trans.evaluate - end - - Puppet::Type.allclear - end +# def self.mkdir(dir) +# # this is all a bunch of stupid hackery +# unless FileTest.exists?(dir) +# comp = Puppet.type(:component).create( +# :name => "certdir creation" +# ) +# path = [''] +# +# dir.split(File::SEPARATOR).each { |d| +# path << d +# if FileTest.exists?(File.join(path)) +# unless FileTest.directory?(File.join(path)) +# raise "%s exists but is not a directory" % File.join(path) +# end +# else +# obj = Puppet::Type.type(:file).create( +# :name => File.join(path), +# :mode => "750", +# :ensure => "directory" +# ) +# +# comp.push obj +# end +# } +# trans = comp.evaluate +# trans.evaluate +# end +# +# Puppet::Type.allclear +# end #def self.mkcert(type, name, days, issuercert, issuername, serial, publickey) def self.mkcert(hash) diff --git a/lib/puppet/sslcertificates/ca.rb b/lib/puppet/sslcertificates/ca.rb index 40b34e1ee..a3cd376fc 100644 --- a/lib/puppet/sslcertificates/ca.rb +++ b/lib/puppet/sslcertificates/ca.rb @@ -2,46 +2,6 @@ class Puppet::SSLCertificates::CA Certificate = Puppet::SSLCertificates::Certificate attr_accessor :keyfile, :file, :config, :dir, :cert -# @@params = [ -# :certdir, -# :publickeydir, -# :privatekeydir, -# :cadir, -# :cakey, -# :cacert, -# :capass, -# :capub, -# :csrdir, -# :signeddir, -# :serial, -# :privatedir, -# :ca_crl_days, -# :ca_days, -# :ca_md, -# :req_bits, -# :keylength, -# :autosign -# ] -# :certdir => [:ssldir, "certs"], -# :publickeydir => [:ssldir, "public_keys"], -# :privatekeydir => [:ssldir, "private_keys"], -# :cadir => [:ssldir, "ca"], -# :cacert => [:cadir, "ca_crt.pem"], -# :cakey => [:cadir, "ca_key.pem"], -# :capub => [:cadir, "ca_pub.pem"], -# :csrdir => [:cadir, "requests"], -# :signeddir => [:cadir, "signed"], -# :capass => [:cadir, "ca.pass"], -# :serial => [:cadir, "serial"], -# :privatedir => [:ssldir, "private"], -# :passfile => [:privatedir, "password"], -# :autosign => [:puppetconf, "autosign.conf"], -# :ca_crl_days => 365, -# :ca_days => 1825, -# :ca_md => "md5", -# :req_bits => 2048, -# :keylength => 1024, - Puppet.setdefaults("ca", [:certdir, "$ssldir/certs", "The certificate directory."], [:publickeydir, "$ssldir/public_keys", "The public key directory."], @@ -51,19 +11,26 @@ class Puppet::SSLCertificates::CA [:cacert, "$cadir/ca_crt.pem", "The CA certificate."], [:cakey, "$cadir/ca_key.pem", "The CA private key."], [:capub, "$cadir/ca_pub.pem", "The CA public key."], + [:caprivatedir, "$cadir/private", + "Where the CA stores private certificate information."], [:csrdir, "$cadir/requests", "Where the CA stores certificate requests"], [:signeddir, "$cadir/signed", "Where the CA stores signed certificates."], - [:capass, "$cadir/ca.pass", - "Where the CA stores the password for the private key; usually not used."], + [:capass, "$caprivatedir/ca.pass", + "Where the CA stores the password for the private key"], [:serial, "$cadir/serial", "Where the serial number for certificates is stored."], + [:privatedir, "$ssldir/private", + "Where the client stores private certificate information."], [:passfile, "$privatedir/password", "Where puppetd stores the password for its private key. Generally unused."], - [:autosign, "$puppetconf/autosign.conf", - "Where to look for the autosigning configuration file."], + [:autosign, "$confdir/autosign.conf", + "Whether to enable autosign. Valid values are true (which autosigns + any key request, and is a very bad idea), false (which never autosigns + any key request), and the path to a file, which uses that configuration + file to determine which keys to sign."], [:ca_days, 1825, "How long a certificate should be valid."], [:ca_md, "md5", "The type of hash used in certificates."], [:req_bits, 2048, "The bit length of the certificates."], @@ -97,30 +64,51 @@ class Puppet::SSLCertificates::CA def initialize(hash = {}) self.setconfig(hash) + if Puppet[:capass] + if FileTest.exists?(Puppet[:capass]) + #puts "Reading %s" % Puppet[:capass] + #system "ls -al %s" % Puppet[:capass] + #File.read Puppet[:capass] + Puppet.info "Getting pass" + @config[:password] = self.getpass + else + # Don't create a password if the cert already exists + unless FileTest.exists?(@config[:cacert]) + Puppet.info "Genning pass" + @config[:password] = self.genpass + end + end + end + self.getcert unless FileTest.exists?(@config[:serial]) File.open(@config[:serial], "w") { |f| f << "%04X" % 1 } end - - if Puppet[:capass] and ! FileTest.exists?(Puppet[:capass]) - self.genpass - end end def genpass pass = "" 20.times { pass += (rand(74) + 48).chr } - unless @config[:capass] - raise "No passfile" + Puppet.recmkdir(File.dirname(@config[:capass])) + begin + File.open(@config[:capass], "w", 0600) { |f| f.print pass } + rescue Errno::EACCES => detail + raise Puppet::Error, detail.to_s end - Puppet::SSLCertificates.mkdir(File.dirname(@config[:capass])) - File.open(@config[:capass], "w", 0600) { |f| f.print pass } return pass end + def getpass + if @config[:capass] and File.readable?(@config[:capass]) + return File.read(@config[:capass]) + else + raise Puppet::Error, "Could not read CA passfile %s" % @config[:capass] + end + end + def getcert if FileTest.exists?(@config[:cacert]) @cert = OpenSSL::X509::Certificate.new( @@ -161,7 +149,7 @@ class Puppet::SSLCertificates::CA cert = Certificate.new( :name => "CAcert", :cert => @config[:cacert], - :encrypt => @config[:passfile], + :encrypt => @config[:capass], :key => @config[:cakey], :selfsign => true, :length => 1825, @@ -187,22 +175,13 @@ class Puppet::SSLCertificates::CA def setconfig(hash) @config = {} Puppet.config.params("ca").each { |param| + param = param.intern if param.is_a? String if hash.include?(param) - begin @config[param] = hash[param] Puppet[param] = hash[param] hash.delete(param) - rescue => detail - puts detail - exit - end else - begin @config[param] = Puppet[param] - rescue => detail - puts detail - exit - end end } @@ -217,10 +196,10 @@ class Puppet::SSLCertificates::CA [:cadir, :csrdir, :signeddir].each { |dir| unless @config[dir] - raise "%s is undefined" % dir + raise Puppet::DevError, "%s is undefined" % dir end unless FileTest.exists?(@config[dir]) - Puppet::SSLCertificates.mkdir(@config[dir]) + Puppet.recmkdir(@config[dir]) end } end @@ -249,6 +228,7 @@ class Puppet::SSLCertificates::CA File.read(@config[:cakey]), @config[:password] ) else + system("ls -al %s" % Puppet[:capass]) cakey = OpenSSL::PKey::RSA.new( File.read(@config[:cakey]) ) diff --git a/lib/puppet/sslcertificates/certificate.rb b/lib/puppet/sslcertificates/certificate.rb index 65ceb44b9..618b7473a 100644 --- a/lib/puppet/sslcertificates/certificate.rb +++ b/lib/puppet/sslcertificates/certificate.rb @@ -54,7 +54,7 @@ class Puppet::SSLCertificates::Certificate def initialize(hash) unless hash.include?(:name) - raise "You must specify the common name for the certificate" + raise Puppet::Error, "You must specify the common name for the certificate" end @name = hash[:name] @@ -72,7 +72,7 @@ class Puppet::SSLCertificates::Certificate @cacertfile ||= File.join(Puppet[:certdir], "ca.pem") unless FileTest.directory?(@dir) - Puppet::SSLCertificates.mkdir(@dir) + Puppet.recmkdir(@dir) end unless @certfile =~ /\.pem$/ @@ -82,14 +82,14 @@ class Puppet::SSLCertificates::Certificate Puppet[:privatekeydir], [@name,"pem"].join(".") ) unless FileTest.directory?(@dir) - Puppet::SSLCertificates.mkdir(@dir) + Puppet.recmkdir(@dir) end [@keyfile].each { |file| dir = File.dirname(file) unless FileTest.directory?(dir) - Puppet::SSLCertificates.mkdir(dir) + Puppet.recmkdir(dir) end } @@ -122,7 +122,7 @@ class Puppet::SSLCertificates::Certificate @password = f.read.chomp } else - raise ":encrypt must be a path to a pass phrase file" + raise Puppet::Error, ":encrypt must be a path to a pass phrase file" end else @password = nil diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb index 128a06a84..b9dedfe9e 100644 --- a/lib/puppet/transportable.rb +++ b/lib/puppet/transportable.rb @@ -62,8 +62,8 @@ module Puppet retobj = nil if type = Puppet::Type.type(self.type) unless retobj = type.create(self) - Puppet.notice "Could not create %s[%s]" % - [self.type, self.name] + #Puppet.notice "Could not create %s[%s]" % + # [self.type, self.name] return nil end #retobj.file = @file @@ -208,7 +208,7 @@ module Puppet # Now just call to_type on them with the container as a parent unless obj = child.to_type(container) # nothing; we assume the method already warned - Puppet.warning "Could not create child %s" % child.name + #Puppet.warning "Could not create child %s" % child.name end } diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 3625299f8..6655606df 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1008,17 +1008,22 @@ class Type < Puppet::Element # Remove an object. The argument determines whether the object's # subscriptions get eliminated, too. - def remove(rmdeps) + def remove(rmdeps = true) @children.each { |child| - child.remove + child.remove(rmdeps) } - self.class.delete(self) if rmdeps Puppet::Event::Subscription.dependencies(self).each { |dep| - self.unsubscribe(dep) + begin + self.unsubscribe(dep) + rescue + # ignore failed unsubscribes + end } end + self.warning "Removing" + self.class.delete(self) if defined? @parent and @parent @parent.delete(self) diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 669e8310a..6e74ca602 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -85,6 +85,53 @@ module Util return retval end + # Change the process to a different user + def self.chuser + if group = Puppet[:group] + if group =~ /^\d+$/ + group = Integer(group) + else + begin + g = Etc.getgrnam(group) + rescue ArgumentError + $stderr.puts "Could not find group %s" % group + end + group = g.gid + end + unless Process.gid == group + begin + Process.egid = group + Process.gid = group + rescue + $stderr.puts "could not change to group %s" % group + exit(74) + end + end + end + + if user = Puppet[:user] + if user =~ /^\d+$/ + user = Integer(user) + else + begin + u = Etc.getpwnam(user) + rescue ArgumentError + $stderr.puts "Could not find user %s" % user + end + user = u.uid + end + unless Process.uid == user + begin + Process.euid = user + Process.uid = user + rescue + $stderr.puts "could not change to user %s" % user + exit(74) + end + end + end + end + # Create a lock file while something is happening def self.lock(*opts) lock = opts[0] + ".lock" diff --git a/test/certmgr/certmgr.rb b/test/certmgr/certmgr.rb index d9f2c4812..8c88fe4d6 100755 --- a/test/certmgr/certmgr.rb +++ b/test/certmgr/certmgr.rb @@ -26,7 +26,6 @@ class TestCertMgr < Test::Unit::TestCase super #@dir = File.join(Puppet[:certdir], "testing") @dir = File.join(@configpath, "certest") - Puppet.notice @dir system("mkdir -p %s" % @dir) end diff --git a/test/executables/puppetbin.rb b/test/executables/puppetbin.rb index 9fb4dbd11..39814769c 100755 --- a/test/executables/puppetbin.rb +++ b/test/executables/puppetbin.rb @@ -30,8 +30,8 @@ class TestPuppetBin < Test::Unit::TestCase cmd += " --debug" end #cmd += " --fqdn %s" % fqdn - cmd += " --confdir %s" % Puppet[:puppetconf] - cmd += " --vardir %s" % Puppet[:puppetvar] + cmd += " --confdir %s" % Puppet[:confdir] + cmd += " --vardir %s" % Puppet[:vardir] cmd += " --logdest %s" % "/dev/null" assert_nothing_raised { diff --git a/test/executables/puppetca.rb b/test/executables/puppetca.rb index b69edb314..67df0a6b6 100755 --- a/test/executables/puppetca.rb +++ b/test/executables/puppetca.rb @@ -23,17 +23,20 @@ class TestPuppetCA < Test::Unit::TestCase return cert end + + def runca(args) + return %x{puppetca --confdir=#{Puppet[:confdir]} --user #{Process.uid} --group #{Process.gid} #{args} 2>&1} + + end def test_signing ca = nil - Puppet[:ssldir] = tempfile() - @@tmpfiles << Puppet[:ssldir] Puppet[:autosign] = false assert_nothing_raised { ca = Puppet::Server::CA.new() } - #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] - #system("find %s" % Puppet[:ssldir]) + #Puppet.warning "SSLDir is %s" % Puppet[:confdir] + #system("find %s" % Puppet[:confdir]) cert = mkcert("host.test.com") resp = nil @@ -43,24 +46,24 @@ class TestPuppetCA < Test::Unit::TestCase resp = ca.getcert(cert.csr.to_pem, "fakename", "127.0.0.1") } assert_equal(["",""], resp) - #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] - #system("find %s" % Puppet[:ssldir]) + #Puppet.warning "SSLDir is %s" % Puppet[:confdir] + #system("find %s" % Puppet[:confdir]) output = nil assert_nothing_raised { - output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]} 2>&1}.chomp.split("\n").reject { |line| line =~ /warning:/ } # stupid ssl.rb + output = runca("--list").chomp.split("\n").reject { |line| line =~ /warning:/ } # stupid ssl.rb } - #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] - #system("find %s" % Puppet[:ssldir]) + #Puppet.warning "SSLDir is %s" % Puppet[:confdir] + #system("find %s" % Puppet[:confdir]) assert_equal($?,0) assert_equal(%w{host.test.com}, output) assert_nothing_raised { - output = %x{puppetca --sign -a --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n") + output = runca("--sign -a").chomp.split("\n") } assert_equal($?,0) - assert_equal([], output) + assert_equal(["Signed host.test.com"], output) assert_nothing_raised { - output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n") + output = runca("--list").chomp.split("\n") } assert_equal($?,0) assert_equal([], output) diff --git a/test/executables/puppetd.rb b/test/executables/puppetd.rb index 90733ed19..1ac53db16 100755 --- a/test/executables/puppetd.rb +++ b/test/executables/puppetd.rb @@ -27,15 +27,14 @@ class TestPuppetDExe < Test::Unit::TestCase cmd += " --verbose" cmd += " --onetime" #cmd += " --fqdn %s" % fqdn - cmd += " --port %s" % @@port - cmd += " --confdir %s" % Puppet[:puppetconf] - cmd += " --vardir %s" % Puppet[:puppetvar] + cmd += " --masterport %s" % @@port + cmd += " --confdir %s" % Puppet[:confdir] + cmd += " --vardir %s" % Puppet[:vardir] cmd += " --server localhost" # and verify our daemon runs assert_nothing_raised { - output = %x{#{cmd}}.chomp - puts output + system cmd } sleep 1 assert($? == 0, "Puppetd exited with code %s" % $?) diff --git a/test/executables/puppetmasterd.rb b/test/executables/puppetmasterd.rb index e1f48c11b..691e27070 100755 --- a/test/executables/puppetmasterd.rb +++ b/test/executables/puppetmasterd.rb @@ -27,7 +27,7 @@ class TestPuppetMasterD < Test::Unit::TestCase def test_normalstart startmasterd - pidfile = File.join(Puppet[:puppetvar], "run", "puppetmasterd.pid") + pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid") assert(FileTest.exists?(pidfile), "PID file does not exist") sleep(1) @@ -92,7 +92,7 @@ class TestPuppetMasterD < Test::Unit::TestCase pid = nil ps = Facter["ps"].value || "ps -ef" %x{#{ps}}.chomp.split(/\n/).each { |line| - if line =~ /puppetmasterd --manifest/ + if line =~ /puppetmasterd.+--manifest/ ary = line.split(" ") pid = ary[1].to_i end diff --git a/test/executables/puppetmodule.rb b/test/executables/puppetmodule.rb index 56173c4b6..fcd85f42c 100755 --- a/test/executables/puppetmodule.rb +++ b/test/executables/puppetmodule.rb @@ -32,8 +32,8 @@ class TestPuppetModule < Test::Unit::TestCase cmd = $module cmd += " --verbose" #cmd += " --fqdn %s" % fqdn - cmd += " --confdir %s" % Puppet[:puppetconf] - cmd += " --vardir %s" % Puppet[:puppetvar] + cmd += " --confdir %s" % Puppet[:confdir] + cmd += " --vardir %s" % Puppet[:vardir] if Puppet[:debug] cmd += " --logdest %s" % "console" cmd += " --debug" diff --git a/test/other/config.rb b/test/other/config.rb index fba50e66e..60cb01ba7 100755 --- a/test/other/config.rb +++ b/test/other/config.rb @@ -78,7 +78,7 @@ class TestConfig < Test::Unit::TestCase c = mkconfig assert_nothing_raised { - c.setdefaults(:testing, [:booltest, "testing", true]) + c.setdefaults(:testing, [:booltest, true, "testing"]) } assert(c[:booltest]) @@ -181,8 +181,8 @@ yay = /a/path attr = value owner = puppet group = puppet - attr2 = /some/dir - attr3 = $attr2/other + attrdir = /some/dir + attr3 = $attrdir/other } file = tempfile() @@ -200,8 +200,8 @@ yay = /a/path assert_nothing_raised { c.setdefaults("section1", [:attr, "a", "one"], - [:attr2, "/another/dir", "two"], - [:attr3, "$attr2/maybe", "boo"] + [:attrdir, "/another/dir", "two"], + [:attr3, "$attrdir/maybe", "boo"] ) } @@ -210,8 +210,8 @@ yay = /a/path } assert_equal("value", c[:attr]) - assert_equal("/some/dir", c[:attr2]) - assert_equal(:directory, c.element(:attr2).type) + assert_equal("/some/dir", c[:attrdir]) + assert_equal(:directory, c.element(:attrdir).type) assert_equal("/some/dir/other", c[:attr3]) elem = nil @@ -239,6 +239,78 @@ yay = /a/path Puppet::Type.allclear check_to_transportable(c) end + + def test_arghandling + c = mkconfig + + assert_nothing_raised { + c.setdefaults("testing", + [:onboolean, true, "An on bool"], + [:offboolean, false, "An off bool"], + [:string, "a string", "A string arg"], + [:file, "/path/to/file", "A file arg"] + ) + } + + data = { + :onboolean => [true, false], + :offboolean => [true, false], + :string => ["one string", "another string"], + :file => %w{/a/file /another/file} + } + data.each { |param, values| + values.each { |val| + opt = nil + arg = nil + if c.boolean?(param) + if val + opt = "--%s" % param + else + opt = "--no-%s" % param + end + else + opt = "--%s" % param + arg = val + end + + assert_nothing_raised("Could not handle arg %s with value %s" % + [opt, val]) { + + c.handlearg(opt, arg) + } + } + } + end + + def test_argadding + c = mkconfig + + assert_nothing_raised { + c.setdefaults("testing", + [:onboolean, true, "An on bool"], + [:offboolean, false, "An off bool"], + [:string, "a string", "A string arg"], + [:file, "/path/to/file", "A file arg"] + ) + } + options = [] + + c.addargs(options) + + c.each { |param, obj| + opt = "--%s" % param + assert(options.find { |ary| + ary[0] == opt + }, "Argument %s was not added" % opt) + + if c.boolean?(param) + o = "--no-%s" % param + assert(options.find { |ary| + ary[0] == o + }, "Boolean off %s was not added" % o) + end + } + end end # $Id$ diff --git a/test/other/log.rb b/test/other/log.rb index 16f458193..ad13b15bf 100644 --- a/test/other/log.rb +++ b/test/other/log.rb @@ -44,8 +44,7 @@ class TestLog < Test::Unit::TestCase def test_logfile fact = nil levels = nil - oldlevel = Puppet[:loglevel] - Puppet[:loglevel] = :debug + Puppet::Log.level = :debug levels = getlevels logfile = tempfile() assert_nothing_raised() { @@ -61,7 +60,6 @@ class TestLog < Test::Unit::TestCase } } assert(count == levels.length) - Puppet[:loglevel] = oldlevel end def test_syslog @@ -80,7 +78,6 @@ class TestLog < Test::Unit::TestCase end def test_consolelog - Puppet[:debug] = true if __FILE__ == $0 fact = nil levels = getlevels assert_nothing_raised() { @@ -103,20 +100,18 @@ class TestLog < Test::Unit::TestCase end def test_output - olddebug = Puppet[:debug] - Puppet[:debug] = false + Puppet.debug = false assert(Puppet.err("This is an error").is_a?(Puppet::Log)) assert(Puppet.debug("This is debugging").nil?) - Puppet[:debug] = true + Puppet.debug = true assert(Puppet.err("This is an error").is_a?(Puppet::Log)) assert(Puppet.debug("This is debugging").is_a?(Puppet::Log)) - Puppet[:debug] = olddebug end def test_creatingdirs dir = tempfile() file = File.join(dir, "logfile") - Puppet[:logdest] = file + Puppet::Log.newdestination file Puppet.info "testing logs" assert(FileTest.directory?(dir)) assert(FileTest.file?(file)) @@ -149,7 +144,7 @@ class TestLog < Test::Unit::TestCase # Verify that we can pass strings that match printf args def test_percentlogs - Puppet[:logdest] = :syslog + Puppet::Log.newdestination :syslog assert_nothing_raised { Puppet::Log.new( diff --git a/test/puppet/conffiles.rb b/test/puppet/conffiles.rb index 49da5fa46..b63886488 100755 --- a/test/puppet/conffiles.rb +++ b/test/puppet/conffiles.rb @@ -76,11 +76,15 @@ class TestConfFiles < Test::Unit::TestCase path = tempfile() sampledata { |data| + config = Puppet::Config.new + data.each { |section, hash| + hash.each { |param, value| + config.setdefaults(section, [param, value, value]) + } + } # Write it out as a config file File.open(path, "w") { |f| f.print data2config(data) } - config = nil assert_nothing_raised { - config = Puppet::Config.new config.parse(path) } diff --git a/test/puppet/defaults.rb b/test/puppet/defaults.rb index 2fbd4fe46..73759ca6b 100755 --- a/test/puppet/defaults.rb +++ b/test/puppet/defaults.rb @@ -12,8 +12,8 @@ require 'test/unit' class TestPuppetDefaults < Test::Unit::TestCase include TestPuppet - @@dirs = %w{rrddir puppetconf puppetvar logdir statedir} - @@files = %w{logfile statefile manifest masterlog} + @@dirs = %w{rrddir confdir vardir logdir statedir} + @@files = %w{statefile manifest masterlog} @@normals = %w{puppetport masterport server} @@booleans = %w{rrdgraph noop} @@ -43,8 +43,8 @@ class TestPuppetDefaults < Test::Unit::TestCase if __FILE__ == $0 def disabled_testContained - confdir = Regexp.new(Puppet[:puppetconf]) - vardir = Regexp.new(Puppet[:puppetvar]) + confdir = Regexp.new(Puppet[:confdir]) + vardir = Regexp.new(Puppet[:vardir]) [@@dirs,@@files].flatten.each { |param| value = Puppet[param] @@ -62,8 +62,8 @@ class TestPuppetDefaults < Test::Unit::TestCase end def testFailOnBogusArgs - [0, "ashoweklj", ";", :thisisafakesymbol].each { |param| - assert_raise(ArgumentError) { Puppet[param] } + [0, "ashoweklj", ";"].each { |param| + assert_raise(ArgumentError, "No error on %s" % param) { Puppet[param] } } end @@ -87,15 +87,15 @@ class TestPuppetDefaults < Test::Unit::TestCase def test_settingdefaults testvals = { - :fakeparam => [:puppetconf, "yaytest"], - :anotherparam => proc { File.join(Puppet[:puppetvar], "goodtest") }, + :fakeparam => "$confdir/yaytest", + :anotherparam => "$vardir/goodtest", :string => "a yay string", :boolean => true } testvals.each { |param, default| assert_nothing_raised { - Puppet.setdefault(param,default) + Puppet.setdefaults("testing", [param, default, "a value"]) } } end diff --git a/test/puppettest.rb b/test/puppettest.rb index 439e5b085..012279d4a 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -31,11 +31,11 @@ module TestPuppet end @configpath = File.join(tmpdir, - self.class.to_s + "configdir" + @@testcount.to_s + self.class.to_s + "configdir" + @@testcount.to_s + "/" ) - Puppet[:puppetconf] = @configpath - Puppet[:puppetvar] = @configpath + Puppet[:confdir] = @configpath + Puppet[:vardir] = @configpath unless File.exists?(@configpath) Dir.mkdir(@configpath) @@ -45,12 +45,12 @@ module TestPuppet @@tmppids = [] if $0 =~ /.+\.rb/ or Puppet[:debug] - Puppet[:logdest] = :console - Puppet[:loglevel] = :debug + Puppet::Log.newdestination :console + Puppet::Log.level = :debug $VERBOSE = 1 else Puppet::Log.close - Puppet[:logdest] = "/dev/null" + Puppet::Log.newdestination "/dev/null" Puppet[:httplog] = "/dev/null" end @@ -288,7 +288,7 @@ module ServerTest # create a simple manifest that just creates a file def mktestmanifest - file = File.join(Puppet[:puppetconf], "%ssite.pp" % (self.class.to_s + "test")) + file = File.join(Puppet[:confdir], "%ssite.pp" % (self.class.to_s + "test")) @createdfile = File.join(tmpdir(), self.class.to_s + "servermanifesttesting") File.open(file, "w") { |f| @@ -383,13 +383,13 @@ module ExeTest manifest = mktestmanifest() args += " --manifest %s" % manifest - args += " --confdir %s" % Puppet[:puppetconf] - args += " --vardir %s" % Puppet[:puppetvar] - args += " --port %s" % @@port + args += " --confdir %s" % Puppet[:confdir] + args += " --vardir %s" % Puppet[:vardir] + args += " --masterport %s" % @@port args += " --user %s" % Process.uid args += " --group %s" % Process.gid args += " --nonodes" - args += " --autosign" + args += " --autosign true" #if Puppet[:debug] # args += " --debug" @@ -411,7 +411,7 @@ module ExeTest def stopmasterd(running = true) ps = Facter["ps"].value || "ps -ef" - pidfile = File.join(Puppet[:puppetvar], "run", "puppetmasterd.pid") + pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid") pid = nil if FileTest.exists?(pidfile) diff --git a/test/server/bucket.rb b/test/server/bucket.rb index ac418484e..d4a2eee37 100644 --- a/test/server/bucket.rb +++ b/test/server/bucket.rb @@ -122,7 +122,7 @@ class TestBucket < Test::Unit::TestCase def setup super - @bucket = File.join(Puppet[:puppetconf], "buckettesting") + @bucket = File.join(Puppet[:confdir], "buckettesting") @@tmpfiles << @bucket end diff --git a/test/server/logger.rb b/test/server/logger.rb index 7872ed172..e0a03417e 100644 --- a/test/server/logger.rb +++ b/test/server/logger.rb @@ -16,7 +16,7 @@ class TestLogger < Test::Unit::TestCase def setup super #Puppet[:debug] = true - Puppet[:logdest] = :console + Puppet::Log.newdestination :console end # Test the log driver manually @@ -92,7 +92,7 @@ class TestLogger < Test::Unit::TestCase clientlog = tempfile() serverlog = tempfile() Puppet.warning "serverlog is %s" % serverlog - Puppet[:logdest] = clientlog + Puppet::Log.newdestination clientlog Puppet::Log.close(:syslog) # For testing @@ -113,7 +113,7 @@ class TestLogger < Test::Unit::TestCase # Start our server serverpid = fork { Puppet::Log.close(clientlog) - Puppet[:logdest] = serverlog + Puppet::Log.newdestination serverlog assert_nothing_raised() { trap(:INT) { logger.shutdown } logger.start @@ -152,7 +152,7 @@ class TestLogger < Test::Unit::TestCase # and now use the normal client action # Set the log destination to be the server - Puppet[:logdest] = "localhost:%s" % @@port + Puppet::Log.newdestination "localhost:%s" % @@port # And now do some logging assert_nothing_raised { diff --git a/test/types/basic.rb b/test/types/basic.rb index 082a8342f..9b01f0447 100644 --- a/test/types/basic.rb +++ b/test/types/basic.rb @@ -19,8 +19,6 @@ class TestBasic < Test::Unit::TestCase @configfile = nil @sleeper = nil - Puppet[:loglevel] = :debug if __FILE__ == $0 - assert_nothing_raised() { @component = Puppet.type(:component).create( :name => "yaytest", diff --git a/test/types/filesources.rb b/test/types/filesources.rb index 3d020d628..a3fb358a6 100755 --- a/test/types/filesources.rb +++ b/test/types/filesources.rb @@ -290,8 +290,8 @@ class TestFileSources < Test::Unit::TestCase end Dir.mkdir(basedir) - Puppet[:puppetconf] = basedir - Puppet[:puppetvar] = basedir + Puppet[:confdir] = basedir + Puppet[:vardir] = basedir Puppet[:autosign] = true tmpname = "yaytesting" @@ -368,8 +368,8 @@ class TestFileSources < Test::Unit::TestCase fileserverconf = mkfileserverconf(mounts) - Puppet[:puppetconf] = basedir - Puppet[:puppetvar] = basedir + Puppet[:confdir] = basedir + Puppet[:vardir] = basedir Puppet[:autosign] = true Puppet[:masterport] = 8762 diff --git a/test/types/filetype.rb b/test/types/filetype.rb index b3ebf15ff..7c5e4583c 100644 --- a/test/types/filetype.rb +++ b/test/types/filetype.rb @@ -12,7 +12,6 @@ require 'test/unit' #class TestFileType < Test::Unit::TestCase class TestFileType def disabled_setup - Puppet[:loglevel] = :debug if __FILE__ == $0 @passwdtype = Puppet.type(:filetype)["passwd"] if @passwdtype.nil? |