summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-11-07 17:30:45 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit977595bd712bfa25c176abb3983bc81df665ea7b (patch)
tree1ae2ca7ed9c71ddbc8e7b378a6457282a8042ccd /lib
parent5776fe4e33b5bb3399a2e72d76faeffb2bba1f4e (diff)
downloadpuppet-977595bd712bfa25c176abb3983bc81df665ea7b.tar.gz
puppet-977595bd712bfa25c176abb3983bc81df665ea7b.tar.xz
puppet-977595bd712bfa25c176abb3983bc81df665ea7b.zip
Refactoring the Change/Event/Property interface
This gives all logging responsibility to the event, which can now produce logs identical to those produced directly by the property. At this point, the events are entirely supersets of the logs.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/property.rb2
-rw-r--r--lib/puppet/transaction/change.rb9
-rw-r--r--lib/puppet/transaction/event.rb25
3 files changed, 30 insertions, 6 deletions
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index 9d50dcf6a..ad8ea623f 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -157,7 +157,7 @@ class Puppet::Property < Puppet::Parameter
# Return a modified form of the resource event.
def event
- resource.event :name => event_name, :desired_value => should, :property => name
+ resource.event :name => event_name, :desired_value => should, :property => name, :source_description => path
end
attr_reader :shadow
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb
index 49569d6e3..f8e2a7a82 100644
--- a/lib/puppet/transaction/change.rb
+++ b/lib/puppet/transaction/change.rb
@@ -40,8 +40,9 @@ class Puppet::Transaction::Change
property.sync
result = event()
- result.log = property.notice property.change_to_s(is, should)
+ result.message = property.change_to_s(is, should)
result.status = "success"
+ result.send_log
result
rescue => detail
puts detail.backtrace if Puppet[:trace]
@@ -50,7 +51,8 @@ class Puppet::Transaction::Change
is = property.is_to_s(is)
should = property.should_to_s(should)
- result.log = property.err "change from #{is} to #{should} failed: #{detail}"
+ result.message = "change from #{is} to #{should} failed: #{detail}"
+ result.send_log
result
end
@@ -80,8 +82,9 @@ class Puppet::Transaction::Change
def noop_event
result = event
- result.log = property.log "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)"
+ result.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)"
result.status = "noop"
+ result.send_log
return result
end
end
diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb
index abd5c8041..41e1f5130 100644
--- a/lib/puppet/transaction/event.rb
+++ b/lib/puppet/transaction/event.rb
@@ -1,11 +1,13 @@
require 'puppet/transaction'
require 'puppet/util/tagging'
+require 'puppet/util/logging'
# A simple struct for storing what happens on the system.
class Puppet::Transaction::Event
include Puppet::Util::Tagging
+ include Puppet::Util::Logging
- ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :log, :node, :version, :file, :line]
+ ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :message, :node, :version, :file, :line, :source_description]
attr_accessor *ATTRIBUTES
attr_writer :tags
attr_accessor :time
@@ -19,12 +21,31 @@ class Puppet::Transaction::Event
@time = Time.now
end
+ def property=(prop)
+ @property = prop.to_s
+ end
+
+ def resource=(res)
+ @resource = res.to_s
+ end
+
+ def send_log
+ super(status == "failure" ? :err : :notice, message)
+ end
+
def status=(value)
raise ArgumentError, "Event status can only be #{EVENT_STATUSES.join(', ')}" unless EVENT_STATUSES.include?(value)
@status = value
end
def to_s
- log
+ message
+ end
+
+ private
+
+ # Used by the Logging module
+ def log_source
+ source_description || property || resource
end
end