diff options
-rw-r--r-- | lib/puppet/parameter.rb | 2 | ||||
-rw-r--r-- | lib/puppet/property.rb | 6 | ||||
-rw-r--r-- | lib/puppet/transaction/event.rb | 12 | ||||
-rw-r--r-- | lib/puppet/type.rb | 6 | ||||
-rwxr-xr-x | spec/unit/parameter.rb | 4 | ||||
-rwxr-xr-x | spec/unit/property.rb | 6 | ||||
-rwxr-xr-x | spec/unit/transaction/event.rb | 9 | ||||
-rwxr-xr-x | spec/unit/type.rb | 5 |
8 files changed, 40 insertions, 10 deletions
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index 285a205da..8ba19ff7c 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -331,6 +331,6 @@ class Puppet::Parameter end def to_s - s = "Parameter(%s)" % self.name + name.to_s end end diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb index ad8ea623f..b96f6d120 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, :source_description => path + resource.event :name => event_name, :desired_value => should, :property => self, :source_description => path end attr_reader :shadow @@ -323,10 +323,6 @@ class Puppet::Property < Puppet::Parameter set(should) end - def to_s - return "#{resource.name}(#{name})" - end - # Verify that the passed value is valid. # If the developer uses a 'validate' hook, this method will get overridden. def unsafe_validate(value) diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index 41e1f5130..b962149cf 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -11,6 +11,7 @@ class Puppet::Transaction::Event attr_accessor *ATTRIBUTES attr_writer :tags attr_accessor :time + attr_reader :default_log_level EVENT_STATUSES = %w{noop success failure} @@ -26,11 +27,14 @@ class Puppet::Transaction::Event end def resource=(res) + if res.respond_to?(:[]) and level = res[:loglevel] + @default_log_level = level + end @resource = res.to_s end def send_log - super(status == "failure" ? :err : :notice, message) + super(log_level, message) end def status=(value) @@ -44,6 +48,12 @@ class Puppet::Transaction::Event private + # If it's a failure, use 'err', else use either the resource's log level (if available) + # or 'notice'. + def log_level + status == "failure" ? :err : (@default_log_level || :notice) + end + # Used by the Logging module def log_source source_description || property || resource diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 2512c72d3..d17a56d67 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -487,7 +487,7 @@ class Type # Create a transaction event. Called by Transaction or by # a property. def event(options = {}) - Puppet::Transaction::Event.new({:resource => ref, :file => file, :line => line, :tags => tags, :version => version}.merge(options)) + Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => tags, :version => version}.merge(options)) end # Let the catalog determine whether a given cached value is @@ -549,6 +549,10 @@ class Type @parameters[name.to_sym] end + def parameters + @parameters.dup + end + # Is the named property defined? def propertydefined?(name) unless name.is_a? Symbol diff --git a/spec/unit/parameter.rb b/spec/unit/parameter.rb index f4473248a..03674cb88 100755 --- a/spec/unit/parameter.rb +++ b/spec/unit/parameter.rb @@ -22,6 +22,10 @@ describe Puppet::Parameter do @class.value_collection.should be_instance_of(Puppet::Parameter::ValueCollection) end + it "should return its name as a string when converted to a string" do + @parameter.to_s.should == @parameter.name.to_s + end + it "should be able to use cached attributes" do Puppet::Parameter.ancestors.should be_include(Puppet::Util::Cacher) end diff --git a/spec/unit/property.rb b/spec/unit/property.rb index eba5c3d83..af3dbc408 100755 --- a/spec/unit/property.rb +++ b/spec/unit/property.rb @@ -15,6 +15,10 @@ describe Puppet::Property do @property = @class.new :resource => @resource end + it "should return its name as a string when converted to a string" do + @property.to_s.should == @property.name.to_s + end + it "should be able to look up the modified name for a given value" do @class.newvalue(:foo) @class.value_name("foo").should == :foo @@ -129,7 +133,7 @@ describe Puppet::Property do end it "should have the property's name" do - @instance.event.property.should == @instance.name + @instance.event.property.should == @instance.name.to_s end it "should have the 'should' value set" do diff --git a/spec/unit/transaction/event.rb b/spec/unit/transaction/event.rb index 07470b2b9..6a837b50f 100755 --- a/spec/unit/transaction/event.rb +++ b/spec/unit/transaction/event.rb @@ -51,7 +51,14 @@ describe Puppet::Transaction::Event do Puppet::Util::Log.stubs(:new) end - it "should set the level to 'notice' if the event status is 'success'" do + it "should set the level to the resources's log level if the event status is 'success' and a resource is available" do + resource = stub 'resource' + resource.expects(:[]).with(:loglevel).returns :myloglevel + Puppet::Util::Log.expects(:create).with { |args| args[:level] == :myloglevel } + Puppet::Transaction::Event.new(:status => "success", :resource => resource).send_log + end + + it "should set the level to 'notice' if the event status is 'success' and no resource is available" do Puppet::Util::Log.expects(:new).with { |args| args[:level] == :notice } Puppet::Transaction::Event.new(:status => "success").send_log end diff --git a/spec/unit/type.rb b/spec/unit/type.rb index be456a88b..9e6469c0f 100755 --- a/spec/unit/type.rb +++ b/spec/unit/type.rb @@ -111,6 +111,11 @@ describe Puppet::Type do @resource.event.resource.should == "Mount[foo]" end + it "should have the resource's log level as the default log level" do + @resource[:loglevel] = :warning + @resource.event.default_log_level.should == :warning + end + {:file => "/my/file", :line => 50, :tags => %{foo bar}, :version => 50}.each do |attr, value| it "should set the #{attr}" do @resource.stubs(attr).returns value |