diff options
author | Markus Roberts <Markus@reality.com> | 2010-02-09 15:17:53 -0800 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-02-09 15:17:53 -0800 |
commit | 27322e5460130b854835aef56ab7076bab83a00b (patch) | |
tree | b69501ce3c7fd616880f60999ad38304a40abba2 /lib | |
parent | 70c71c58c1dd038d033d5fdd3fecc8f15b11fd52 (diff) | |
parent | 71653a74d91b1e6e9845b4a41249861319c0d6b0 (diff) | |
download | puppet-27322e5460130b854835aef56ab7076bab83a00b.tar.gz puppet-27322e5460130b854835aef56ab7076bab83a00b.tar.xz puppet-27322e5460130b854835aef56ab7076bab83a00b.zip |
Merge branch '0.25.x'
Conflicts:
lib/puppet/agent.rb
lib/puppet/application/puppet.rb
lib/puppet/configurer.rb
man/man5/puppet.conf.5
spec/integration/defaults.rb
spec/unit/configurer.rb
Diffstat (limited to 'lib')
25 files changed, 113 insertions, 31 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index cd34cdf5e..a78853a10 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -24,7 +24,7 @@ require 'puppet/util/suidmanager' # it's also a place to find top-level commands like 'debug' module Puppet - PUPPETVERSION = '0.25.3' + PUPPETVERSION = '0.25.4' def Puppet.version return PUPPETVERSION diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb index 09607372f..f712bbdd5 100644 --- a/lib/puppet/agent.rb +++ b/lib/puppet/agent.rb @@ -52,6 +52,8 @@ class Puppet::Agent with_client do |client| begin sync.synchronize { lock { result = client.run(*args) } } + rescue SystemExit,NoMemoryError + raise rescue Exception => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not run %s: %s" % [client_class, detail] @@ -124,6 +126,8 @@ class Puppet::Agent def with_client begin @client = client_class.new + rescue SystemExit,NoMemoryError + raise rescue Exception => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not create instance of %s: %s" % [client_class, detail] diff --git a/lib/puppet/application/puppet.rb b/lib/puppet/application/puppet.rb index e4baf5d05..2f7946b3d 100644 --- a/lib/puppet/application/puppet.rb +++ b/lib/puppet/application/puppet.rb @@ -1,5 +1,6 @@ require 'puppet' require 'puppet/application' +require 'puppet/configurer' require 'puppet/network/handler' require 'puppet/network/client' @@ -124,9 +125,15 @@ Puppet::Application.new(:puppet) do catalog.retrieval_duration = Time.now - starttime + configurer = Puppet::Configurer.new + configurer.execute_prerun_command + # And apply it transaction = catalog.apply + configurer.execute_postrun_command + + status = 0 if not Puppet[:noop] and options[:detailed_exitcodes] then transaction.generate_report exit(transaction.report.exit_status) @@ -134,9 +141,7 @@ Puppet::Application.new(:puppet) do exit(0) end rescue => detail - if Puppet[:trace] - puts detail.backtrace - end + puts detail.backtrace if Puppet[:trace] if detail.is_a?(XMLRPC::FaultException) $stderr.puts detail.message else diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 350e9c34f..8179d2c4d 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -5,6 +5,8 @@ require 'puppet/network/http_pool' require 'puppet/util' class Puppet::Configurer + class CommandHookError < RuntimeError; end + require 'puppet/configurer/fact_handler' require 'puppet/configurer/plugin_handler' @@ -33,6 +35,19 @@ class Puppet::Configurer Puppet[:puppetdlockfile] end + def clear + @catalog.clear(true) if @catalog + @catalog = nil + end + + def execute_postrun_command + execute_from_setting(:postrun_command) + end + + def execute_prerun_command + execute_from_setting(:prerun_command) + end + # Initialize and load storage def dostorage begin @@ -73,6 +88,8 @@ class Puppet::Configurer download_plugins() download_fact_plugins() + + execute_prerun_command end # Get the remote catalog, yo. Returns nil if no catalog can be found. @@ -91,6 +108,8 @@ class Puppet::Configurer duration = thinmark do result = catalog_class.find(name, fact_options.merge(:ignore_cache => true)) end + rescue SystemExit,NoMemoryError + raise rescue Exception => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not retrieve catalog from remote server: %s" % detail @@ -134,6 +153,8 @@ class Puppet::Configurer def run(options = {}) begin prepare() + rescue SystemExit,NoMemoryError + raise rescue Exception => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Failed to prepare catalog: %s" % detail @@ -165,6 +186,7 @@ class Puppet::Configurer # Now close all of our existing http connections, since there's no # reason to leave them lying open. Puppet::Network::HttpPool.clear_http_instances + execute_postrun_command Puppet::Util::Log.close(report) @@ -198,4 +220,14 @@ class Puppet::Configurer return timeout end + + def execute_from_setting(setting) + return if (command = Puppet[setting]) == "" + + begin + Puppet::Util.execute([command]) + rescue => detail + raise CommandHookError, "Could not run command from #{setting}: #{detail}" + end + end end diff --git a/lib/puppet/configurer/fact_handler.rb b/lib/puppet/configurer/fact_handler.rb index 40e79b6c6..72bd76e1f 100644 --- a/lib/puppet/configurer/fact_handler.rb +++ b/lib/puppet/configurer/fact_handler.rb @@ -17,6 +17,8 @@ module Puppet::Configurer::FactHandler begin reload_facter() Puppet::Node::Facts.find(Puppet[:certname]) + rescue SystemExit,NoMemoryError + raise rescue Exception => detail puts detail.backtrace if Puppet[:trace] raise Puppet::Error, "Could not retrieve local facts: %s" % detail diff --git a/lib/puppet/configurer/plugin_handler.rb b/lib/puppet/configurer/plugin_handler.rb index e934f5877..9e1c113f9 100644 --- a/lib/puppet/configurer/plugin_handler.rb +++ b/lib/puppet/configurer/plugin_handler.rb @@ -19,6 +19,8 @@ module Puppet::Configurer::PluginHandler begin Puppet.info "Loading downloaded plugin %s" % file load file + rescue SystemExit,NoMemoryError + raise rescue Exception => detail Puppet.err "Could not load downloaded file %s: %s" % [file, detail] end diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index ca4b9b8d0..b2e849264 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -159,9 +159,6 @@ module Puppet may need to use a FQDN for the server hostname when using a proxy."], :http_proxy_port => [3128, "The HTTP proxy port to use for outgoing connections"], - :http_enable_post_connection_check => [true, - "Boolean; whether or not puppetd should validate the server - SSL certificate against the request hostname."], :filetimeout => [ 15, "The minimum time to wait (in seconds) between checking for updates in configuration files. This timeout determines how quickly Puppet checks whether @@ -199,7 +196,12 @@ module Puppet reports, allowing you to correlate changes on your hosts to the source version on the server."], :zlib => [true, "Boolean; whether to use the zlib library", - ] + ], + :prerun_command => ["", "A command to run before every agent run. If this command returns a non-zero + return code, the entire Puppet run will fail."], + :postrun_command => ["", "A command to run after every agent run. If this command returns a non-zero + return code, the entire Puppet run will be considered to have failed, even though it might have + performed work during the normal run."] ) hostname = Facter["hostname"].value diff --git a/lib/puppet/file_serving/mount/file.rb b/lib/puppet/file_serving/mount/file.rb index 4309ef79a..e1eaf6052 100644 --- a/lib/puppet/file_serving/mount/file.rb +++ b/lib/puppet/file_serving/mount/file.rb @@ -25,7 +25,7 @@ class Puppet::FileServing::Mount::File < Puppet::FileServing::Mount file = ::File.join(full_path, relative_path) - if ! FileTest.exist?(file) + if !(FileTest.exist?(file) or FileTest.symlink?(file)) Puppet.info("File does not exist or is not accessible: #{file}") return nil end diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb index 6c6cbc6be..b5787ddf6 100644 --- a/lib/puppet/indirector/facts/facter.rb +++ b/lib/puppet/indirector/facts/facter.rb @@ -29,6 +29,8 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code Timeout::timeout(self.timeout) do load file end + rescue SystemExit,NoMemoryError + raise rescue Exception => detail Puppet.warning "Could not load fact file %s: %s" % [fqfile, detail] end diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb index 51bab0e6e..ab3c7ef54 100644 --- a/lib/puppet/indirector/ldap.rb +++ b/lib/puppet/indirector/ldap.rb @@ -40,6 +40,8 @@ class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus found = true yield entry end + rescue SystemExit,NoMemoryError + raise rescue Exception => detail if count == 0 # Try reconnecting to ldap if we get an exception and we haven't yet retried. diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 65bb0f82c..444fbf7e7 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -66,6 +66,8 @@ module Puppet::Network::HTTP::Handler check_authorization(indirection_request) send("do_%s" % indirection_request.method, indirection_request, request, response) + rescue SystemExit,NoMemoryError + raise rescue Exception => e return do_exception(response, e) end diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb index 6de204a80..4789d4704 100644 --- a/lib/puppet/network/http_pool.rb +++ b/lib/puppet/network/http_pool.rb @@ -94,8 +94,6 @@ module Puppet::Network::HttpPool # Use configured timeout (#1176) http.read_timeout = Puppet[:configtimeout] http.open_timeout = Puppet[:configtimeout] - # JJM Configurable fix for #896. - http.enable_post_connection_check = Puppet[:http_enable_post_connection_check] cert_setup(http) diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index ee2c008eb..9faa71c8b 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -144,6 +144,8 @@ module Puppet::Network Puppet.debug "Calling %s.%s" % [namespace, method] begin call("%s.%s" % [namespace, method.to_s],*args) + rescue SystemExit,NoMemoryError + raise rescue Exception => detail retry if self.class.error_handler(detail).execute(self, detail, namespace, method) == :retry end diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index 78be1d79e..7a7d55de1 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -39,6 +39,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do "match" => [ :path, :glob ], "size" => [:comparator, :int], "include" => [:string], + "not_include" => [:string], "==" => [:glob], "!=" => [:glob] } @@ -203,6 +204,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do #Get the values from augeas result = @aug.match(path) || [] + fail("Error trying to match path '#{path}'") if (result == -1) + # Now do the work case verb when "size" @@ -213,6 +216,9 @@ Puppet::Type.type(:augeas).provide(:augeas) do when "include" arg = clause_array.shift return_value = result.include?(arg) + when "not_include" + arg = clause_array.shift + return_value = !result.include?(arg) when "==" begin arg = clause_array.shift @@ -261,6 +267,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do when "get"; return_value = process_get(cmd_array) when "match"; return_value = process_match(cmd_array) end + rescue SystemExit,NoMemoryError + raise rescue Exception => e fail("Error sending command '#{command}' with params #{cmd_array[1..-1].inspect}/#{e.message}") end @@ -322,13 +330,16 @@ Puppet::Type.type(:augeas).provide(:augeas) do case command when "set" debug("sending command '#{command}' with params #{cmd_array.inspect}") - aug.set(cmd_array[0], cmd_array[1]) + rv = aug.set(cmd_array[0], cmd_array[1]) + fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}") if (rv) when "rm", "remove" debug("sending command '#{command}' with params #{cmd_array.inspect}") - aug.rm(cmd_array[0]) + rv = aug.rm(cmd_array[0]) + fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}") if (rv) when "clear" debug("sending command '#{command}' with params #{cmd_array.inspect}") - @aug.clear(cmd_array[0]) + rv = aug.clear(cmd_array[0]) + fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}") if (rv == -1) when "insert", "ins" label = cmd_array[0] where = cmd_array[1] @@ -339,9 +350,12 @@ Puppet::Type.type(:augeas).provide(:augeas) do else fail("Invalid value '#{where}' for where param") end debug("sending command '#{command}' with params #{[label, where, path].inspect}") - aug.insert(path, label, before) + rv = aug.insert(path, label, before) + fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}") if (rv == -1) else fail("Command '#{command}' is not supported") end + rescue SystemExit,NoMemoryError + raise rescue Exception => e fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}") end diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb index 28ef05974..6dee2e515 100755 --- a/lib/puppet/provider/cron/crontab.rb +++ b/lib/puppet/provider/cron/crontab.rb @@ -27,13 +27,18 @@ Puppet::Type.type(:cron).provide(:crontab, text_line :environment, :match => %r{^\w+=} - crontab = record_line :crontab, :fields => %w{special minute hour monthday month weekday command}, - :match => %r{^\s*(?:@(\w+)|(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+))\s+(.+)$}, - :optional => %w{special minute hour weekday month monthday}, :absent => "*" + record_line :freebsd_special, :fields => %w{special command}, + :match => %r{^@(\w+)\s+(.+)$}, :pre_gen => proc { |record| + record[:special] = "@" + record[:special] + } + + crontab = record_line :crontab, :fields => %w{minute hour monthday month weekday command}, + :match => %r{^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$}, + :optional => %w{minute hour weekday month monthday}, :absent => "*" class << crontab def numeric_fields - fields - [:command, :special] + fields - [:command] end # Do some post-processing of the parsed record. Basically just # split the numeric fields on ','. diff --git a/lib/puppet/provider/package/blastwave.rb b/lib/puppet/provider/package/blastwave.rb index cf2c87bfe..9b2bbf6a5 100755 --- a/lib/puppet/provider/package/blastwave.rb +++ b/lib/puppet/provider/package/blastwave.rb @@ -11,7 +11,7 @@ Puppet::Type.type(:package).provide :blastwave, :parent => :sun, :source => :sun commands :pkgget => pkgget def pkgget_with_cat(*args) - withenv(:PAGER => "/usr/bin/cat") { pkgget(*args) } + Puppet::Util::Execution::withenv(:PAGER => "/usr/bin/cat") { pkgget(*args) } end def self.extended(mod) @@ -41,7 +41,7 @@ Puppet::Type.type(:package).provide :blastwave, :parent => :sun, :source => :sun command << hash[:justme] end - output = pkgget_with_cat command + output = Puppet::Util::Execution::withenv(:PAGER => "/usr/bin/cat") { pkgget command } list = output.split("\n").collect do |line| next if line =~ /^#/ diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb index 211b66956..45a9074e6 100755 --- a/lib/puppet/provider/service/redhat.rb +++ b/lib/puppet/provider/service/redhat.rb @@ -1,6 +1,6 @@ # Manage Red Hat services. Start/stop uses /sbin/service and enable/disable uses chkconfig -Puppet::Type.type(:service).provide :redhat, :parent => :init do +Puppet::Type.type(:service).provide :redhat, :parent => :init, :source => :init do desc "Red Hat's (and probably many others) form of ``init``-style service management: Uses ``chkconfig`` for service enabling and disabling. diff --git a/lib/puppet/provider/sshkey/parsed.rb b/lib/puppet/provider/sshkey/parsed.rb index 4673b5731..e84e3e5c5 100755 --- a/lib/puppet/provider/sshkey/parsed.rb +++ b/lib/puppet/provider/sshkey/parsed.rb @@ -21,14 +21,14 @@ Puppet::Type.type(:sshkey).provide(:parsed, :post_parse => proc { |hash| names = hash[:name].split(",", -1) hash[:name] = names.shift - hash[:alias] = names + hash[:host_aliases] = names }, :pre_gen => proc { |hash| - if hash[:alias] - names = [hash[:name], hash[:alias]].flatten + if hash[:host_aliases] + names = [hash[:name], hash[:host_aliases]].flatten - hash[:name] = [hash[:name], hash[:alias]].flatten.join(",") - hash.delete(:alias) + hash[:name] = [hash[:name], hash[:host_aliases]].flatten.join(",") + hash.delete(:host_aliases) end } end diff --git a/lib/puppet/provider/user/user_role_add.rb b/lib/puppet/provider/user/user_role_add.rb index 278893724..aa01f8e52 100644 --- a/lib/puppet/provider/user/user_role_add.rb +++ b/lib/puppet/provider/user/user_role_add.rb @@ -1,6 +1,6 @@ require 'puppet/util/user_attr' -Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd do +Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd, :source => :useradd do desc "User management inherits ``useradd`` and adds logic to manage roles on Solaris using roleadd." diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb index 5de2c5a18..8d44ffe9c 100644 --- a/lib/puppet/ssl/host.rb +++ b/lib/puppet/ssl/host.rb @@ -220,6 +220,8 @@ class Puppet::SSL::Host return if certificate generate return if certificate + rescue SystemExit,NoMemoryError + raise rescue Exception => detail Puppet.err "Could not request certificate: %s" % detail.to_s if time < 1 diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb index b8d08bb81..c2b164ede 100644 --- a/lib/puppet/type/augeas.rb +++ b/lib/puppet/type/augeas.rb @@ -76,6 +76,7 @@ Puppet::Type.newtype(:augeas) do get [AUGEAS_PATH] [COMPARATOR] [STRING] match [MATCH_PATH] size [COMPARATOR] [INT] match [MATCH_PATH] include [STRING] + match [MATCH_PATH] not_include [STRING] match [MATCH_PATH] == [AN_ARRAY] match [MATCH_PATH] != [AN_ARRAY] diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb index b5ccb3fb1..3d7190c27 100755 --- a/lib/puppet/type/tidy.rb +++ b/lib/puppet/type/tidy.rb @@ -139,7 +139,7 @@ Puppet::Type.newtype(:tidy) do end def tidy?(path, stat) - if stat.size > value + if stat.size >= value return true else return false diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index ec2f48c7b..ceaabe46a 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -86,6 +86,8 @@ class Puppet::Util::Autoload name = symbolize(name) loaded name, file return true + rescue SystemExit,NoMemoryError + raise rescue Exception => detail # I have no idea what's going on here, but different versions # of ruby are raising different errors on missing files. @@ -123,6 +125,8 @@ class Puppet::Util::Autoload begin Kernel.require file loaded(name, file) + rescue SystemExit,NoMemoryError + raise rescue Exception => detail if Puppet[:trace] puts detail.backtrace @@ -152,7 +156,7 @@ class Puppet::Util::Autoload end end - def search_directories - [module_directories, Puppet[:libdir], $:].flatten + def search_directories(dummy_argument=:work_arround_for_ruby_GC_bug) + [module_directories, Puppet[:libdir].split(File::PATH_SEPARATOR), $:].flatten end end diff --git a/lib/puppet/util/feature.rb b/lib/puppet/util/feature.rb index add1b2691..6218eabf4 100644 --- a/lib/puppet/util/feature.rb +++ b/lib/puppet/util/feature.rb @@ -83,6 +83,8 @@ class Puppet::Util::Feature begin require lib + rescue SystemExit,NoMemoryError + raise rescue Exception Puppet.debug "Failed to load library '%s' for feature '%s'" % [lib, name] return false diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index 6e438bc73..7ce1ccc1c 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -1,3 +1,4 @@ +Process.maxgroups = 1024 module RDoc def self.caller(skip=nil) in_gem_wrapper = false |