From 319822af6d58c3e0c391e86cfd836ec31de43c67 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 11 Feb 2009 14:33:48 -0600 Subject: Fixing #1869 - autoloaded files should never leak exceptions Ruby's exception hierarchy is a bit strange, in that only exceptions that sub RuntimeError are caught by default. This patch explicitly catches the base class, Exception, which means that LoadError, SyntaxError, and any RuntimeErrors will all be caught. This is done for both load() and loadall(); load() uses Kernel.load, but loadall() uses Kernel.require. Signed-off-by: Luke Kanies --- lib/puppet/util/autoload.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index 535d9ef2e..0c80f8b06 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -78,7 +78,7 @@ class Puppet::Util::Autoload name = symbolize(name) loaded name, file return true - rescue LoadError => detail + rescue Exception => detail # I have no idea what's going on here, but different versions # of ruby are raising different errors on missing files. unless detail.to_s =~ /^no such file/i @@ -115,7 +115,7 @@ class Puppet::Util::Autoload begin Kernel.require file loaded(name, file) - rescue => detail + rescue Exception => detail if Puppet[:trace] puts detail.backtrace end -- cgit From f0ac3aef53a08e271a5c243f17785cdb58f1f5ef Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 12 Feb 2009 08:20:43 +1100 Subject: Fixed #1959 - Added column protection for environment schema migration --- lib/puppet/rails/database/003_add_environment_to_host.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/rails/database/003_add_environment_to_host.rb b/lib/puppet/rails/database/003_add_environment_to_host.rb index 4593a06f7..3ed10e946 100644 --- a/lib/puppet/rails/database/003_add_environment_to_host.rb +++ b/lib/puppet/rails/database/003_add_environment_to_host.rb @@ -1,9 +1,13 @@ class AddEnvironmentToHost < ActiveRecord::Migration def self.up - add_column :hosts, :environment, :string + unless ActiveRecord::Base.connection.columns(:hosts).collect {|c| c.name}.include?("environment") + add_column :hosts, :environment, :string + end end def self.down - remove_column :hosts, :environment + if ActiveRecord::Base.connection.columns(:hosts).collect {|c| c.name}.include?("environment") + remove_column :hosts, :environment + end end end -- cgit From af3f3ae93ba1e43ac8231e4cf4e5a1f0ed8f3acb Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 11 Feb 2009 16:49:40 -0600 Subject: Refactoring the XMLRPC::Client error-handling I split it all into smaller, manageable chunks, and used methods for each step, instead of having one huge call. Note that I made all of the tests first, then refactored the code, so I'm confident there's no behavior change. I don't know that this is actually a lot cleaner, but it seems that way to me. I'm open to skipping this, but I think it makes the whole thing a lot cleaner. Signed-off-by: Luke Kanies --- lib/puppet/network/xmlrpc/client.rb | 164 ++++++++++++++++++++++++------------ 1 file changed, 111 insertions(+), 53 deletions(-) (limited to 'lib') diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index 37ace2101..91bb03e1f 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -36,57 +36,7 @@ module Puppet::Network interface.methods.each { |ary| method = ary[0] newclient.send(:define_method,method) { |*args| - Puppet.debug "Calling %s.%s" % [namespace, method] - begin - call("%s.%s" % [namespace, method.to_s],*args) - rescue OpenSSL::SSL::SSLError => detail - if detail.message =~ /bad write retry/ - Puppet.warning "Transient SSL write error; restarting connection and retrying" - self.recycle_connection - retry - end - ["certificate verify failed", "hostname was not match", "hostname not match"].each do |str| - if detail.message.include?(str) - Puppet.warning "Certificate validation failed; consider using the certname configuration option" - end - end - raise XMLRPCClientError, - "Certificates were not trusted: %s" % detail - rescue ::XMLRPC::FaultException => detail - raise XMLRPCClientError, detail.faultString - rescue Errno::ECONNREFUSED => detail - msg = "Could not connect to %s on port %s" % - [@host, @port] - raise XMLRPCClientError, msg - rescue SocketError => detail - Puppet.err "Could not find server %s: %s" % - [@host, detail.to_s] - error = XMLRPCClientError.new( - "Could not find server %s" % @host - ) - error.set_backtrace detail.backtrace - raise error - rescue Errno::EPIPE, EOFError - Puppet.warning "Other end went away; restarting connection and retrying" - self.recycle_connection - retry - rescue Timeout::Error => detail - Puppet.err "Connection timeout calling %s.%s: %s" % - [namespace, method, detail.to_s] - error = XMLRPCClientError.new("Connection Timeout") - error.set_backtrace(detail.backtrace) - raise error - rescue => detail - if detail.message =~ /^Wrong size\. Was \d+, should be \d+$/ - Puppet.warning "XMLRPC returned wrong size. Retrying." - retry - end - Puppet.err "Could not call %s.%s: %s" % - [namespace, method, detail.inspect] - error = XMLRPCClientError.new(detail.to_s) - error.set_backtrace detail.backtrace - raise error - end + make_rpc_call(namespace, method, *args) } } @@ -97,13 +47,117 @@ module Puppet::Network @clients[handler] || self.mkclient(handler) end + class ErrorHandler + def initialize(&block) + metaclass.define_method(:execute, &block) + end + end + + # Use a class variable so all subclasses have access to it. + @@error_handlers = {} + + def self.error_handler(exception) + if handler = @@error_handlers[exception.class] + return handler + else + return @@error_handlers[:default] + end + end + + def self.handle_error(*exceptions, &block) + handler = ErrorHandler.new(&block) + + exceptions.each do |exception| + @@error_handlers[exception] = handler + end + end + + handle_error(OpenSSL::SSL::SSLError) do |client, detail, namespace, method| + if detail.message =~ /bad write retry/ + Puppet.warning "Transient SSL write error; restarting connection and retrying" + client.recycle_connection + return :retry + end + ["certificate verify failed", "hostname was not match", "hostname not match"].each do |str| + if detail.message.include?(str) + Puppet.warning "Certificate validation failed; consider using the certname configuration option" + end + end + raise XMLRPCClientError, "Certificates were not trusted: %s" % detail + end + + handle_error(:default) do |client, detail, namespace, method| + if detail.message.to_s =~ /^Wrong size\. Was \d+, should be \d+$/ + Puppet.warning "XMLRPC returned wrong size. Retrying." + return :retry + end + Puppet.err "Could not call %s.%s: %s" % [namespace, method, detail.inspect] + error = XMLRPCClientError.new(detail.to_s) + error.set_backtrace detail.backtrace + raise error + end + + handle_error(OpenSSL::SSL::SSLError) do |client, detail, namespace, method| + if detail.message =~ /bad write retry/ + Puppet.warning "Transient SSL write error; restarting connection and retrying" + client.recycle_connection + return :retry + end + ["certificate verify failed", "hostname was not match", "hostname not match"].each do |str| + if detail.message.include?(str) + Puppet.warning "Certificate validation failed; consider using the certname configuration option" + end + end + raise XMLRPCClientError, "Certificates were not trusted: %s" % detail + end + + handle_error(::XMLRPC::FaultException) do |client, detail, namespace, method| + raise XMLRPCClientError, detail.faultString + end + + handle_error(Errno::ECONNREFUSED) do |client, detail, namespace, method| + msg = "Could not connect to %s on port %s" % [client.host, client.port] + raise XMLRPCClientError, msg + end + + handle_error(SocketError) do |client, detail, namespace, method| + Puppet.err "Could not find server %s: %s" % [@host, detail.to_s] + error = XMLRPCClientError.new("Could not find server %s" % client.host) + error.set_backtrace detail.backtrace + raise error + end + + handle_error(Errno::EPIPE, EOFError) do |client, detail, namespace, method| + Puppet.warning "Other end went away; restarting connection and retrying" + client.recycle_connection + return :retry + end + + handle_error(Timeout::Error) do |client, detail, namespace, method| + Puppet.err "Connection timeout calling %s.%s: %s" % [namespace, method, detail.to_s] + error = XMLRPCClientError.new("Connection Timeout") + error.set_backtrace(detail.backtrace) + raise error + end + + def make_rpc_call(namespace, method, *args) + Puppet.debug "Calling %s.%s" % [namespace, method] + begin + call("%s.%s" % [namespace, method.to_s],*args) + rescue Exception => detail + retry if self.class.error_handler(detail).execute(self, detail, namespace, method) == :retry + end + end + def http unless @http - @http = Puppet::Network::HttpPool.http_instance(@host, @port, true) + @http = Puppet::Network::HttpPool.http_instance(host, port, true) end @http end + attr_reader :host, :port + def initialize(hash = {}) hash[:Path] ||= "/RPC2" hash[:Server] ||= Puppet[:server] @@ -135,7 +189,11 @@ module Puppet::Network # or we've just downloaded certs and we need to create new http instances # with the certs added. def recycle_connection - @http = Puppet::Network::HttpPool.http_instance(@host, @port, true) # reset the instance + if http.started? + http.finish + end + @http = nil + self.http # force a new one end def start -- cgit From 5e35166f1b7219d470916d1ee7a4e6852afaf1f9 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 11 Feb 2009 16:54:04 -0600 Subject: Fixing #961 - closing the http connection after every xmlrpc call There were apparently some circumstances that resulted in the connection not being closed; this just closes it every time if it's still open after the rpc call is complete. Signed-off-by: Luke Kanies --- lib/puppet/network/xmlrpc/client.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb index 91bb03e1f..678ab6c00 100644 --- a/lib/puppet/network/xmlrpc/client.rb +++ b/lib/puppet/network/xmlrpc/client.rb @@ -128,7 +128,7 @@ module Puppet::Network end handle_error(Errno::EPIPE, EOFError) do |client, detail, namespace, method| - Puppet.warning "Other end went away; restarting connection and retrying" + Puppet.info "Other end went away; restarting connection and retrying" client.recycle_connection return :retry end @@ -147,6 +147,8 @@ module Puppet::Network rescue Exception => detail retry if self.class.error_handler(detail).execute(self, detail, namespace, method) == :retry end + ensure + http.finish if http.started? end def http -- cgit From cc4d6586d420f4beea1eeef85cfe7a28f8e493ac Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Thu, 12 Feb 2009 09:32:01 -0500 Subject: Bug #1948: Added patch by jab to support the correct ins syntax. Updated the test cases as well --- lib/puppet/provider/augeas/augeas.rb | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index 0ffddebb0..fd47da389 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -164,14 +164,34 @@ Puppet::Type.type(:augeas).provide(:augeas) do fail("invalid command #{cmd_array.join[" "]}") if cmd_array.length < 2 command = cmd_array[0] cmd_array.shift() - cmd_array[0]=File.join(context, cmd_array[0]) - debug("sending command '#{command}' with params #{cmd_array.inspect}") begin case command - when "set": aug.set(cmd_array[0], cmd_array[1]) - when "rm", "remove": aug.rm(cmd_array[0]) - when "clear": aug.clear(cmd_array[0]) - when "insert", "ins": aug.insert(cmd_array[0]) + when "set": + cmd_array[0]=File.join(context, cmd_array[0]) + debug("sending command '#{command}' with params #{cmd_array.inspect}") + aug.set(cmd_array[0], cmd_array[1]) + when "rm", "remove": + cmd_array[0]=File.join(context, cmd_array[0]) + debug("sending command '#{command}' with params #{cmd_array.inspect}") + aug.rm(cmd_array[0]) + when "clear": + cmd_array[0]=File.join(context, cmd_array[0]) + debug("sending command '#{command}' with params #{cmd_array.inspect}") + aug.clear(cmd_array[0]) + when "insert", "ins" + if cmd_array.size < 3 + fail("ins requires 3 parameters") + end + label = cmd_array[0] + where = cmd_array[1] + path = File.join(context, cmd_array[2]) + case where + when "before": before = true + when "after": before = false + else fail("Invalid value '#{where}' for where param") + end + debug("sending command '#{command}' with params #{[label, where, path]}") + aug.insert(path, label, before) else fail("Command '#{command}' is not supported") end rescue Exception => e -- cgit From 4e89156b21b287b683c27a4cd691856c4e378a62 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 15 Jan 2009 15:13:28 -0600 Subject: Migrated FileType tests to spec, and fleshed them out a bit. Signed-off-by: Luke Kanies --- lib/puppet/util/filetype.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 60cbc77e7..60380d5f1 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -74,7 +74,7 @@ class Puppet::Util::FileType # Back the file up before replacing it. def backup - bucket.backup(@path) if FileTest.exists?(@path) + bucket.backup(@path) if File.exists?(@path) end # Pick or create a filebucket to use. @@ -92,7 +92,7 @@ class Puppet::Util::FileType newfiletype(:flat) do # Read the file. def read - if File.exists?(@path) + if File.exist?(@path) File.read(@path) else return nil @@ -101,7 +101,7 @@ class Puppet::Util::FileType # Remove the file. def remove - if File.exists?(@path) + if File.exist?(@path) File.unlink(@path) end end -- cgit From 53f15b9208a3271e944c687b8d0e670d422fb832 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 15 Jan 2009 15:42:09 -0600 Subject: Removing the apparently obsolete netinfo filetype. Signed-off-by: Luke Kanies --- lib/puppet/util/filetype.rb | 88 --------------------------------------------- 1 file changed, 88 deletions(-) (limited to 'lib') diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 60380d5f1..137ef0c67 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -250,92 +250,4 @@ class Puppet::Util::FileType output_file.delete end end - - # Treat netinfo tables as a single file, just for simplicity of certain - # types - newfiletype(:netinfo) do - class << self - attr_accessor :format - end - def read - %x{nidump -r /#{@path} /} - end - - # This really only makes sense for cron tabs. - def remove - %x{nireport / /#{@path} name}.split("\n").each do |name| - newname = name.gsub(/\//, '\/').sub(/\s+$/, '') - output = %x{niutil -destroy / '/#{@path}/#{newname}'} - - unless $? == 0 - raise Puppet::Error, "Could not remove %s from %s" % - [name, @path] - end - end - end - - # Convert our table to an array of hashes. This only works for - # handling one table at a time. - def to_array(text = nil) - unless text - text = read - end - - hash = nil - - # Initialize it with the first record - records = [] - text.split("\n").each do |line| - next if line =~ /^[{}]$/ # Skip the wrapping lines - next if line =~ /"name" = \( "#{@path}" \)/ # Skip the table name - next if line =~ /CHILDREN = \(/ # Skip this header - next if line =~ /^ \)/ # and its closer - - # Now we should have nothing but records, wrapped in braces - - case line - when /^\s+\{/: hash = {} - when /^\s+\}/: records << hash - when /\s+"(\w+)" = \( (.+) \)/ - field = $1 - values = $2 - - # Always use an array - hash[field] = [] - - values.split(/, /).each do |value| - if value =~ /^"(.*)"$/ - hash[field] << $1 - else - raise ArgumentError, "Could not match value %s" % value - end - end - else - raise ArgumentError, "Could not match line %s" % line - end - end - - records - end - - def write(text) - text.gsub!(/^#.*\n/,'') - text.gsub!(/^$/,'') - if text == "" or text == "\n" - self.remove - return - end - unless format = self.class.format - raise Puppe::DevError, "You must define the NetInfo format to inport" - end - IO.popen("niload -d #{format} . 1>/dev/null 2>/dev/null", "w") { |p| - p.print text - } - - unless $? == 0 - raise ArgumentError, "Failed to write %s" % @path - end - end - end end - -- cgit From d5a193a594bbc2194dbf1e5264369ebea0e55880 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 15 Jan 2009 15:44:09 -0600 Subject: Fixing #1541 - ParsedFile only backs up files once per transaction This moves responsibility for backups from the filetype to the consumer of the filetype, but only ParsedFile actually uses filetypes. Signed-off-by: Luke Kanies --- lib/puppet/provider/parsedfile.rb | 14 ++++++++++++++ lib/puppet/util/filetype.rb | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index a4c4bc87c..45eae57ff 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -78,8 +78,22 @@ class Puppet::Provider::ParsedFile < Puppet::Provider @modified.reject! { |t| flushed.include?(t) } end + # Make sure our file is backed up, but only back it up once per transaction. + # We cheat and rely on the fact that @records is created on each prefetch. + def self.backup_target(target) + unless defined?(@backup_stats) + @backup_stats = {} + end + return nil if @backup_stats[target] == @records.object_id + + target_object(target).backup + @backup_stats[target] = @records.object_id + end + # Flush all of the records relating to a specific target. def self.flush_target(target) + backup_target(target) + records = target_records(target).reject { |r| r[:ensure] == :absent } diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 137ef0c67..5d4ba1440 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -108,7 +108,6 @@ class Puppet::Util::FileType # Overwrite the file. def write(text) - backup() require "tempfile" tf = Tempfile.new("puppet") tf.print text; tf.flush -- cgit From 4dfa034dc8a569634d8b5672f66158157ddddb28 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 12 Feb 2009 15:32:42 -0600 Subject: Revert "Refixing #1420 - _naginator_name is only used for services" This reverts commit efb5cc50c42bc27aec9409e723e3a717ed58c0a8. Conflicts: CHANGELOG --- lib/puppet/external/nagios/base.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/puppet/external/nagios/base.rb b/lib/puppet/external/nagios/base.rb index d95b808dd..6a0c1831c 100755 --- a/lib/puppet/external/nagios/base.rb +++ b/lib/puppet/external/nagios/base.rb @@ -416,18 +416,20 @@ class Nagios::Base :dependent_service_description, :host_name, :hostgroup_name, :service_description, :inherits_parent, :execution_failure_criteria, :notification_failure_criteria, :dependency_period, - :register, :use + :register, :use, + :_naginator_name - setnamevar :service_description + setnamevar :_naginator_name end newtype :serviceescalation do setparameters :host_name, :hostgroup_name, :service_description, :contacts, :contact_groups, :first_notification, :last_notification, :notification_interval, :escalation_period, :escalation_options, - :register, :use + :register, :use, + :_naginator_name - setnamevar :service_description + setnamevar :_naginator_name end newtype :hostdependency do @@ -435,18 +437,20 @@ class Nagios::Base setparameters :dependent_host_name, :dependent_hostgroup_name, :host_name, :hostgroup_name, :inherits_parent, :execution_failure_criteria, :notification_failure_criteria, :dependency_period, - :register, :use + :register, :use, + :_naginator_name - setnamevar :host_name + setnamevar :_naginator_name end newtype :hostescalation do setparameters :host_name, :hostgroup_name, :contacts, :contact_groups, :first_notification, :last_notification, :notification_interval, :escalation_period, :escalation_options, - :register, :use + :register, :use, + :_naginator_name - setnamevar :host_name + setnamevar :_naginator_name end newtype :hostextinfo do @@ -463,9 +467,10 @@ class Nagios::Base setparameters :host_name, :service_description, :notes, :notes_url, :action_url, :icon_image, :icon_image_alt, - :register, :use + :register, :use, + :_naginator_name - setnamevar :service_description + setnamevar :_naginator_name end end -- cgit From 70ea39af65f7e56ce151c9f9ca444261d0332454 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 12 Feb 2009 16:00:29 -0600 Subject: Adding a post-processor for Nagios names. This is a brutal hack until Puppet correctly supports multiple primary keys. It basically just comments out _naginator_name before writing to disk, and uncomments it when reading. This allows Puppet to use it while Nagios ignores it. Yes, a stupid hack, but it appears to work. Signed-off-by: Luke Kanies --- lib/puppet/provider/naginator.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/naginator.rb b/lib/puppet/provider/naginator.rb index 233d82eb6..5510eb9c8 100644 --- a/lib/puppet/provider/naginator.rb +++ b/lib/puppet/provider/naginator.rb @@ -7,6 +7,7 @@ require 'puppet/external/nagios' # The base class for all Naginator providers. class Puppet::Provider::Naginator < Puppet::Provider::ParsedFile + NAME_STRING = "## --PUPPET_NAME-- (called '_naginator_name' in the manifest)" # Retrieve the associated class from Nagios::Base. def self.nagios_type unless defined?(@nagios_type) and @nagios_type @@ -24,14 +25,14 @@ class Puppet::Provider::Naginator < Puppet::Provider::ParsedFile def self.parse(text) begin - Nagios::Parser.new.parse(text) + Nagios::Parser.new.parse(text.gsub(NAME_STRING, "_naginator_name")) rescue => detail raise Puppet::Error, "Could not parse configuration for %s: %s" % [resource_type.name, detail] end end def self.to_file(records) - header + records.collect { |record| record.to_s }.join("\n") + header + records.collect { |record| record.to_s }.join("\n").gsub("_naginator_name", NAME_STRING) end def self.skip_record?(record) -- cgit From 39a8b28690377339d4c430ebf62cec5ef0ed34b8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 12 Feb 2009 22:58:57 -0600 Subject: Fixing #1964 - Facts get loaded from plugins Applying slightly modified patch. Also added tests. Signed-off-by: Luke Kanies --- lib/puppet/indirector/facts/facter.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb index 6ed89dac1..a026dfe60 100644 --- a/lib/puppet/indirector/facts/facter.rb +++ b/lib/puppet/indirector/facts/facter.rb @@ -24,8 +24,12 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code end def self.loadfacts - # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] - x = Puppet[:factpath].split(":").each do |dir| + # Add any per-module fact directories to the factpath + module_fact_dirs = Puppet[:modulepath].split(":").collect do |d| + Dir.glob("%s/*/plugins/facter" % d) + end.flatten + dirs = module_fact_dirs + Puppet[:factpath].split(":") + x = dirs.each do |dir| loaddir(dir, "fact") end end -- cgit From 2218611f7fa10b59945f65c80b05cbd8ebe137ef Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 13 Feb 2009 17:04:36 +1100 Subject: Updated up2date and service confines to add support for Oracle EL and VM --- lib/puppet/provider/package/up2date.rb | 6 ++++-- lib/puppet/provider/service/redhat.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/package/up2date.rb b/lib/puppet/provider/package/up2date.rb index dde633db4..8a1c22892 100644 --- a/lib/puppet/provider/package/up2date.rb +++ b/lib/puppet/provider/package/up2date.rb @@ -3,9 +3,11 @@ Puppet.type(:package).provide :up2date, :parent => :rpm, :source => :rpm do mechanism." commands :up2date => "/usr/sbin/up2date-nox" - defaultfor :operatingsystem => :redhat, + + defaultfor :operatingsystem => [:redhat, :oel, :ovm] :lsbdistrelease => ["2.1", "3", "4"] - confine :operatingsystem => :redhat + + confine :operatingsystem => [:redhat, :oel, :ovm] # Install a package using 'up2date'. def install diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb index c6c3540f5..031db46c1 100755 --- a/lib/puppet/provider/service/redhat.rb +++ b/lib/puppet/provider/service/redhat.rb @@ -9,7 +9,7 @@ Puppet::Type.type(:service).provide :redhat, :parent => :init do commands :chkconfig => "/sbin/chkconfig", :service => "/sbin/service" - defaultfor :operatingsystem => [:redhat, :fedora, :suse, :centos, :sles] + defaultfor :operatingsystem => [:redhat, :fedora, :suse, :centos, :sles, :oel, :ovm] def self.defpath superclass.defpath -- cgit From 2a855510a3cca7d475c31495ccb502af606528dc Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Fri, 13 Feb 2009 08:21:36 -0500 Subject: Bug 1948: Add logic and testing for the command parsing logic --- lib/puppet/provider/augeas/augeas.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index fd47da389..8d4f6d55a 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -52,7 +52,6 @@ Puppet::Type.type(:augeas).provide(:augeas) do commands.concat(parse_commands(datum)) end end - return commands end @@ -179,18 +178,20 @@ Puppet::Type.type(:augeas).provide(:augeas) do debug("sending command '#{command}' with params #{cmd_array.inspect}") aug.clear(cmd_array[0]) when "insert", "ins" - if cmd_array.size < 3 + + ext_array = cmd_array[1].split(" ") ; + if cmd_array.size < 2 or ext_array.size < 2 fail("ins requires 3 parameters") end label = cmd_array[0] - where = cmd_array[1] - path = File.join(context, cmd_array[2]) + where = ext_array[0] + path = File.join(context, ext_array[1]) case where when "before": before = true when "after": before = false else fail("Invalid value '#{where}' for where param") end - debug("sending command '#{command}' with params #{[label, where, path]}") + debug("sending command '#{command}' with params #{[label, where, path].inspect()}") aug.insert(path, label, before) else fail("Command '#{command}' is not supported") end -- cgit From 336b6458a2264c550adf8e6799162380822e0d97 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sat, 14 Feb 2009 02:10:08 +1100 Subject: Fixed #1830 - Added regsubst function --- lib/puppet/parser/functions/regsubst.rb | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/puppet/parser/functions/regsubst.rb (limited to 'lib') diff --git a/lib/puppet/parser/functions/regsubst.rb b/lib/puppet/parser/functions/regsubst.rb new file mode 100644 index 000000000..067d75c51 --- /dev/null +++ b/lib/puppet/parser/functions/regsubst.rb @@ -0,0 +1,93 @@ +module Puppet::Parser::Functions + newfunction(:regsubst, :type => :rvalue, + :doc => "\ + Perform regexp replacement on a string. + + Parameters (in order): + + :str: + The string to operate on. + + :regexp: + The regular expression matching the string. If you want it + anchored at the start and/or end of the string, you must do + that with ^ and $ yourself. + + :replacement: + Replacement string. Can contain back references to what was + matched using \\0, \\1, and so on. + + :flags: + Optional. String of single letter flags for how the regexp + is interpreted: + + - **E** + Extended regexps + - **I** + Ignore case in regexps + - **M** + Multiline regexps + - **G** + Global replacement; all occurances of the regexp in + the string will be replaced. Without this, only the + first occurance will be replaced. + + :lang: + Optional. How to handle multibyte characters. A + single-character string with the following values: + + - **N** + None + - **E** + EUC + - **S** + SJIS + - **U** + UTF-8 + + **Examples** + + Get the third octet from the node's IP address: :: + + $i3 = regsubst($ipaddress, + '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$', + '\\\\3') + + Put angle brackets around each octet in the node's IP address: :: + + $x = regsubst($ipaddress, '([0-9]+)', '<\\\\1>', 'G') + ") \ + do |args| + flag_mapping = { + "E" => Regexp::EXTENDED, + "I" => Regexp::IGNORECASE, + "M" => Regexp::MULTILINE, + } + if args.length < 3 or args.length > 5 + raise Puppet::ParseError, ("regsub(): wrong number of arguments" + + " (#{args.length}; min 3, max 5)") + end + str, regexp, replacement, flags, lang = args + reflags = 0 + global = false + (flags or "").each_byte do |f| + f = f.chr + if f == "G" + global = true + else + fvalue = flag_mapping[f] + if !fvalue + raise Puppet::ParseError, "regsub(): bad flag `#{f}'" + end + reflags |= fvalue + end + end + re = Regexp.compile(regexp, reflags, lang) + if global + result = str.gsub(re, replacement) + else + result = str.sub(re, replacement) + end + return result + end +end -- cgit From 1bc7404f5e3efa633bb0a5cf10828071cfc4d876 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sat, 14 Feb 2009 02:11:21 +1100 Subject: Fixed #1831 - Added sprintf function --- lib/puppet/parser/functions/sprintf.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/puppet/parser/functions/sprintf.rb (limited to 'lib') diff --git a/lib/puppet/parser/functions/sprintf.rb b/lib/puppet/parser/functions/sprintf.rb new file mode 100644 index 000000000..79744104d --- /dev/null +++ b/lib/puppet/parser/functions/sprintf.rb @@ -0,0 +1,17 @@ +module Puppet::Parser::Functions + newfunction(:sprintf, :type => :rvalue, + :doc => "\ + Perform printf-style formatting of text. + + The first parameter is format string describing how the rest of the + parameters should be formatted. See the documentation for the + ``Kernel::sprintf()`` function in Ruby for all the details. + ") \ + do |args| + if args.length < 1 + raise Puppet::ParseError, 'sprintf() needs at least one argument' + end + fmt = args.shift() + return sprintf(fmt, *args) + end +end -- cgit From 2561c8e252dcf66890513458750bb1329a03beec Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sat, 14 Feb 2009 09:57:49 +1100 Subject: Updated Augeas type code --- lib/puppet/type/augeas.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb index 67b62e886..c89400b5e 100644 --- a/lib/puppet/type/augeas.rb +++ b/lib/puppet/type/augeas.rb @@ -92,10 +92,12 @@ Puppet::Type.newtype(:augeas) do rm [PATH] Removes the node at location PATH remove [PATH] Synonym for rm clear [PATH] Keeps the node at PATH, but removes the value. - ins [PATH] Inserts an empty node at PATH. - insert [PATH] Synonym for ins + ins [LABEL] [WHERE] [PATH] + Inserts an empty node LABEL either [WHERE={before|after}] PATH. + insert [LABEL] [WHERE] [PATH] + Synonym for ins - If the parameter 'context' is set that that value is prepended to PATH" + If the parameter 'context' is set that value is prepended to PATH" munge do |value| provider.parse_commands(value) -- cgit