summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2010-12-16 10:36:55 -0800
committerNick Lewis <nick@puppetlabs.com>2010-12-16 10:36:55 -0800
commit52ca8c78c270b93ce997217900a3d333ad8154cc (patch)
tree56f0e4eb1798d0b8a1f5c37bae8ff2cf34171d85 /lib
parentaf6e08c0a59db951502d0cf8c0ca24f5001e92f1 (diff)
parent167e84d39d5cdd6b628d4d681b918406e7c896e6 (diff)
downloadpuppet-52ca8c78c270b93ce997217900a3d333ad8154cc.tar.gz
puppet-52ca8c78c270b93ce997217900a3d333ad8154cc.tar.xz
puppet-52ca8c78c270b93ce997217900a3d333ad8154cc.zip
Merge branch '2.6.next' into 2.6.x
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application/inspect.rb80
-rw-r--r--lib/puppet/configurer/plugin_handler.rb2
-rw-r--r--lib/puppet/external/pson/pure/generator.rb23
-rw-r--r--lib/puppet/indirector/catalog/active_record.rb2
-rw-r--r--lib/puppet/resource/type_collection.rb1
-rw-r--r--lib/puppet/transaction/change.rb74
-rw-r--r--lib/puppet/transaction/event.rb2
-rw-r--r--lib/puppet/transaction/report.rb5
-rw-r--r--lib/puppet/transaction/resource_harness.rb30
-rw-r--r--lib/puppet/type/file.rb3
-rwxr-xr-xlib/puppet/type/file/ensure.rb2
-rwxr-xr-xlib/puppet/type/file/mode.rb54
-rwxr-xr-xlib/puppet/type/user.rb10
-rw-r--r--lib/puppet/util/log.rb11
14 files changed, 157 insertions, 142 deletions
diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb
new file mode 100644
index 000000000..c28fef326
--- /dev/null
+++ b/lib/puppet/application/inspect.rb
@@ -0,0 +1,80 @@
+require 'puppet/application'
+
+class Puppet::Application::Inspect < Puppet::Application
+
+ should_parse_config
+ run_mode :agent
+
+ option("--debug","-d")
+ option("--verbose","-v")
+
+ option("--logdest LOGDEST", "-l") do |arg|
+ begin
+ Puppet::Util::Log.newdestination(arg)
+ options[:logset] = true
+ rescue => detail
+ $stderr.puts detail.to_s
+ end
+ end
+
+ def setup
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+
+ raise "Inspect requires reporting to be enabled. Set report=true in puppet.conf to enable reporting." unless Puppet[:report]
+
+ @report = Puppet::Transaction::Report.new("inspect")
+
+ Puppet::Util::Log.newdestination(@report)
+ Puppet::Util::Log.newdestination(:console) unless options[:logset]
+
+ trap(:INT) do
+ $stderr.puts "Exiting"
+ exit(1)
+ end
+
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ elsif options[:verbose]
+ Puppet::Util::Log.level = :info
+ end
+
+ Puppet::Transaction::Report.terminus_class = :rest
+ Puppet::Resource::Catalog.terminus_class = :yaml
+ end
+
+ def run_command
+ retrieval_starttime = Time.now
+
+ unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname])
+ raise "Could not find catalog for #{Puppet[:certname]}"
+ end
+
+ retrieval_time = Time.now - retrieval_starttime
+ @report.add_times("config_retrieval", retrieval_time)
+
+ starttime = Time.now
+
+ catalog.to_ral.resources.each do |ral_resource|
+ audited_attributes = ral_resource[:audit]
+ next unless audited_attributes
+
+ audited_resource = ral_resource.to_resource
+
+ status = Puppet::Resource::Status.new(ral_resource)
+ audited_attributes.each do |name|
+ event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}")
+ status.add_event(event)
+ end
+ @report.add_resource_status(status)
+ end
+
+ @report.add_metric(:time, {"config_retrieval" => retrieval_time, "inspect" => Time.now - starttime})
+
+ begin
+ @report.save
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not send report: #{detail}"
+ end
+ end
+end
diff --git a/lib/puppet/configurer/plugin_handler.rb b/lib/puppet/configurer/plugin_handler.rb
index 539441e75..cfc6b5a0b 100644
--- a/lib/puppet/configurer/plugin_handler.rb
+++ b/lib/puppet/configurer/plugin_handler.rb
@@ -19,8 +19,6 @@ module Puppet::Configurer::PluginHandler
begin
Puppet.info "Loading downloaded plugin #{file}"
load file
- rescue SystemExit,NoMemoryError
- raise
rescue Exception => detail
Puppet.err "Could not load downloaded file #{file}: #{detail}"
end
diff --git a/lib/puppet/external/pson/pure/generator.rb b/lib/puppet/external/pson/pure/generator.rb
index 4180be57d..89a0c62e0 100644
--- a/lib/puppet/external/pson/pure/generator.rb
+++ b/lib/puppet/external/pson/pure/generator.rb
@@ -44,34 +44,13 @@ module PSON
string << '' # XXX workaround: avoid buffer sharing
string.force_encoding(Encoding::ASCII_8BIT)
string.gsub!(/["\\\x0-\x1f]/) { MAP[$MATCH] }
- string.gsub!(/(
- (?:
- [\xc2-\xdf][\x80-\xbf] |
- [\xe0-\xef][\x80-\xbf]{2} |
- [\xf0-\xf4][\x80-\xbf]{3}
- )+ |
- [\x80-\xc1\xf5-\xff] # invalid
- )/nx) { |c|
- c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'"
- s = PSON::UTF8toUTF16.iconv(c).unpack('H*')[0]
- s.gsub!(/.{4}/n, '\\\\u\&')
- }
- string.force_encoding(Encoding::UTF_8)
string
rescue Iconv::Failure => e
raise GeneratorError, "Caught #{e.class}: #{e}"
end
else
def utf8_to_pson(string) # :nodoc:
- string.
- gsub(/["\\\x0-\x1f]/n) { MAP[$MATCH] }.
- gsub(/((?:
- [\xc2-\xdf][\x80-\xbf] |
- [\xe0-\xef][\x80-\xbf]{2} |
- [\xf0-\xf4][\x80-\xbf]{3}
- )+)/nx) { |c|
- PSON::UTF8toUTF16.iconv(c).unpack('H*')[0].gsub(/.{4}/n, '\\\\u\&')
- }
+ string.gsub(/["\\\x0-\x1f]/n) { MAP[$MATCH] }
end
end
module_function :utf8_to_pson
diff --git a/lib/puppet/indirector/catalog/active_record.rb b/lib/puppet/indirector/catalog/active_record.rb
index fabb08eb9..f814f4aff 100644
--- a/lib/puppet/indirector/catalog/active_record.rb
+++ b/lib/puppet/indirector/catalog/active_record.rb
@@ -32,7 +32,7 @@ class Puppet::Resource::Catalog::ActiveRecord < Puppet::Indirector::ActiveRecord
if node = Puppet::Node.find(catalog.name)
host.ip = node.parameters["ipaddress"]
- host.environment = node.environment
+ host.environment = node.environment.to_s
end
host.save
diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb
index 63d110395..6a03458b3 100644
--- a/lib/puppet/resource/type_collection.rb
+++ b/lib/puppet/resource/type_collection.rb
@@ -153,7 +153,6 @@ class Puppet::Resource::TypeCollection
end
def perform_initial_import
- return if Puppet.settings[:ignoreimport]
parser = Puppet::Parser::Parser.new(environment)
if code = Puppet.settings.uninterpolated_value(:code, environment.to_s) and code != ""
parser.string = code
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb
index ecc3b5a5f..d57ac1917 100644
--- a/lib/puppet/transaction/change.rb
+++ b/lib/puppet/transaction/change.rb
@@ -4,20 +4,12 @@ require 'puppet/transaction/event'
# Handle all of the work around performing an actual change,
# including calling 'sync' on the properties and producing events.
class Puppet::Transaction::Change
- attr_accessor :is, :should, :property, :proxy, :auditing
+ attr_accessor :is, :should, :property, :proxy, :auditing, :old_audit_value
def auditing?
auditing
end
- # Create our event object.
- def event
- result = property.event
- result.previous_value = is
- result.desired_value = should
- result
- end
-
def initialize(property, currentvalue)
@property = property
@is = currentvalue
@@ -28,24 +20,39 @@ class Puppet::Transaction::Change
end
def apply
- return audit_event if auditing?
- return noop_event if noop?
-
- property.sync
-
- result = event
- result.message = property.change_to_s(is, should)
- result.status = "success"
- result.send_log
- result
+ event = property.event
+ event.previous_value = is
+ event.desired_value = should
+ event.historical_value = old_audit_value
+
+ if auditing? and old_audit_value != is
+ event.message = "audit change: previously recorded value #{property.is_to_s(old_audit_value)} has been changed to #{property.is_to_s(is)}"
+ event.status = "audit"
+ event.audited = true
+ brief_audit_message = " (previously recorded value was #{property.is_to_s(old_audit_value)})"
+ else
+ brief_audit_message = ""
+ end
+
+ if property.insync?(is)
+ # nothing happens
+ elsif noop?
+ event.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)#{brief_audit_message}"
+ event.status = "noop"
+ else
+ property.sync
+ event.message = [ property.change_to_s(is, should), brief_audit_message ].join
+ event.status = "success"
+ end
+ event
rescue => detail
puts detail.backtrace if Puppet[:trace]
- result = event
- result.status = "failure"
+ event.status = "failure"
- result.message = "change from #{property.is_to_s(is)} to #{property.should_to_s(should)} failed: #{detail}"
- result.send_log
- result
+ event.message = "change from #{property.is_to_s(is)} to #{property.should_to_s(should)} failed: #{detail}"
+ event
+ ensure
+ event.send_log
end
# Is our property noop? This is used for generating special events.
@@ -65,23 +72,4 @@ class Puppet::Transaction::Change
def to_s
"change #{@property.change_to_s(@is, @should)}"
end
-
- private
-
- def audit_event
- # This needs to store the appropriate value, and then produce a new event
- result = event
- result.message = "audit change: previously recorded value #{property.should_to_s(should)} has been changed to #{property.is_to_s(is)}"
- result.status = "audit"
- result.send_log
- result
- end
-
- def noop_event
- result = event
- result.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)"
- result.status = "noop"
- result.send_log
- result
- end
end
diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb
index e5e5793da..da5b14727 100644
--- a/lib/puppet/transaction/event.rb
+++ b/lib/puppet/transaction/event.rb
@@ -7,7 +7,7 @@ class Puppet::Transaction::Event
include Puppet::Util::Tagging
include Puppet::Util::Logging
- ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :message, :node, :version, :file, :line, :source_description]
+ ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :node, :version, :file, :line, :source_description, :audited]
attr_accessor *ATTRIBUTES
attr_writer :tags
attr_accessor :time
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index e6d1e0528..75c08fc7a 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -10,7 +10,7 @@ class Puppet::Transaction::Report
indirects :report, :terminus_class => :processor
- attr_reader :resource_statuses, :logs, :metrics, :host, :time
+ attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind
# This is necessary since Marshall doesn't know how to
# dump hash with default proc (see below @records)
@@ -49,13 +49,14 @@ class Puppet::Transaction::Report
calculate_event_metrics
end
- def initialize
+ def initialize(kind = "apply")
@metrics = {}
@logs = []
@resource_statuses = {}
@external_times ||= {}
@host = Puppet[:certname]
@time = Time.now
+ @kind = kind
end
def name
diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb
index 29ec9a539..c978e5545 100644
--- a/lib/puppet/transaction/resource_harness.rb
+++ b/lib/puppet/transaction/resource_harness.rb
@@ -25,12 +25,12 @@ class Puppet::Transaction::ResourceHarness
status.changed = true
end
- # Used mostly for scheduling at this point.
+ # Used mostly for scheduling and auditing at this point.
def cached(resource, name)
Puppet::Util::Storage.cache(resource)[name]
end
- # Used mostly for scheduling at this point.
+ # Used mostly for scheduling and auditing at this point.
def cache(resource, name, value)
Puppet::Util::Storage.cache(resource)[name] = value
end
@@ -46,33 +46,35 @@ class Puppet::Transaction::ResourceHarness
if param = resource.parameter(:ensure)
return [] if absent_and_not_being_created?(current, param)
- return [Puppet::Transaction::Change.new(param, current[:ensure])] unless ensure_is_insync?(current, param)
+ unless ensure_is_insync?(current, param)
+ audited.keys.reject{|name| name == :ensure}.each do |name|
+ resource.parameter(name).notice "audit change: previously recorded value #{audited[name]} has been changed to #{current[param]}"
+ cache(resource, name, current[param])
+ end
+ return [Puppet::Transaction::Change.new(param, current[:ensure])]
+ end
return [] if ensure_should_be_absent?(current, param)
end
- resource.properties.reject { |p| p.name == :ensure }.reject do |param|
- param.should.nil?
- end.reject do |param|
- param_is_insync?(current, param)
+ resource.properties.reject { |param| param.name == :ensure }.select do |param|
+ (audited.include?(param.name) && audited[param.name] != current[param.name]) || (param.should != nil && !param_is_insync?(current, param))
end.collect do |param|
change = Puppet::Transaction::Change.new(param, current[param.name])
change.auditing = true if audited.include?(param.name)
+ change.old_audit_value = audited[param.name]
change
end
end
def copy_audited_parameters(resource, current)
- return [] unless audit = resource[:audit]
+ return {} unless audit = resource[:audit]
audit = Array(audit).collect { |p| p.to_sym }
- audited = []
+ audited = {}
audit.find_all do |param|
- next if resource[param]
-
if value = cached(resource, param)
- resource[param] = value
- audited << param
+ audited[param] = value
else
- resource.debug "Storing newly-audited value #{current[param]} for #{param}"
+ resource.property(param).notice "audit change: newly-recorded recorded value #{current[param]}"
cache(resource, param, current[param])
end
end
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index f35a26408..6523c99a0 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -718,8 +718,9 @@ Puppet::Type.newtype(:file) do
mode = self.should(:mode) # might be nil
umask = mode ? 000 : 022
+ mode_int = mode ? mode.to_i(8) : nil
- content_checksum = Puppet::Util.withumask(umask) { File.open(path, 'w', mode) { |f| write_content(f) } }
+ content_checksum = Puppet::Util.withumask(umask) { File.open(path, 'w', mode_int ) { |f| write_content(f) } }
# And put our new file in place
if use_temporary_file # This is only not true when our file is empty.
diff --git a/lib/puppet/type/file/ensure.rb b/lib/puppet/type/file/ensure.rb
index 967e06aee..4a68551ee 100755
--- a/lib/puppet/type/file/ensure.rb
+++ b/lib/puppet/type/file/ensure.rb
@@ -66,7 +66,7 @@ module Puppet
end
if mode
Puppet::Util.withumask(000) do
- Dir.mkdir(@resource[:path],mode)
+ Dir.mkdir(@resource[:path], mode.to_i(8))
end
else
Dir.mkdir(@resource[:path])
diff --git a/lib/puppet/type/file/mode.rb b/lib/puppet/type/file/mode.rb
index 1ce56c843..2acd8b359 100755
--- a/lib/puppet/type/file/mode.rb
+++ b/lib/puppet/type/file/mode.rb
@@ -25,60 +25,26 @@ module Puppet
@event = :file_changed
- # Our modes are octal, so make sure they print correctly. Other
- # valid values are symbols, basically
- def is_to_s(currentvalue)
- case currentvalue
- when Integer
- return "%o" % currentvalue
- when Symbol
- return currentvalue
- else
- raise Puppet::DevError, "Invalid current value for mode: #{currentvalue.inspect}"
- end
- end
-
- def should_to_s(newvalue = @should)
- case newvalue
- when Integer
- return "%o" % newvalue
- when Symbol
- return newvalue
- else
- raise Puppet::DevError, "Invalid 'should' value for mode: #{newvalue.inspect}"
- end
- end
-
munge do |should|
- # this is pretty hackish, but i need to make sure the number is in
- # octal, yet the number can only be specified as a string right now
- value = should
- if value.is_a?(String)
- unless value =~ /^\d+$/
- raise Puppet::Error, "File modes can only be numbers, not #{value.inspect}"
- end
- # Make sure our number looks like octal.
- unless value =~ /^0/
- value = "0#{value}"
- end
- old = value
- begin
- value = Integer(value)
- rescue ArgumentError => detail
- raise Puppet::DevError, "Could not convert #{old.inspect} to integer"
+ if should.is_a?(String)
+ unless should =~ /^[0-7]+$/
+ raise Puppet::Error, "File modes can only be octal numbers, not #{should.inspect}"
end
+ should.to_i(8).to_s(8)
+ else
+ should.to_s(8)
end
-
- return value
end
# If we're a directory, we need to be executable for all cases
# that are readable. This should probably be selectable, but eh.
def dirmask(value)
if FileTest.directory?(@resource[:path])
+ value = value.to_i(8)
value |= 0100 if value & 0400 != 0
value |= 010 if value & 040 != 0
value |= 01 if value & 04 != 0
+ value = value.to_s(8)
end
value
@@ -101,7 +67,7 @@ module Puppet
unless defined?(@fixed)
@should &&= @should.collect { |s| self.dirmask(s) }
end
- return stat.mode & 007777
+ return (stat.mode & 007777).to_s(8)
else
return :absent
end
@@ -111,7 +77,7 @@ module Puppet
mode = self.should
begin
- File.chmod(mode, @resource[:path])
+ File.chmod(mode.to_i(8), @resource[:path])
rescue => detail
error = Puppet::Error.new("failed to chmod #{@resource[:path]}: #{detail.message}")
error.set_backtrace detail.backtrace
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index c8110bb69..761d5d71b 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -72,6 +72,11 @@ module Puppet
end
end
+ newproperty(:home) do
+ desc "The home directory of the user. The directory must be created
+ separately and is not currently checked for existence."
+ end
+
newproperty(:uid) do
desc "The user ID. Must be specified numerically. For new users
being created, if no user ID is specified then one will be
@@ -138,11 +143,6 @@ module Puppet
desc "A description of the user. Generally is a user's full name."
end
- newproperty(:home) do
- desc "The home directory of the user. The directory must be created
- separately and is not currently checked for existence."
- end
-
newproperty(:shell) do
desc "The user's login shell. The shell must exist and be
executable."
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index 36a765c61..7764dc1d1 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -17,11 +17,12 @@ class Puppet::Util::Log
# Create a new destination type.
def self.newdesttype(name, options = {}, &block)
- dest = genclass(
- name, :parent => Puppet::Util::Log::Destination, :prefix => "Dest",
- :block => block,
- :hash => @desttypes,
-
+ dest = genclass(
+ name,
+ :parent => Puppet::Util::Log::Destination,
+ :prefix => "Dest",
+ :block => block,
+ :hash => @desttypes,
:attributes => options
)
dest.match(dest.name)