[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:30:54 UTC 2010


The following commit has been merged in the upstream branch:
commit e838bccaee658847e1b2dac5b7e2191a8148202c
Author: Luke Kanies <luke at madstop.com>
Date:   Sat Nov 7 17:46:19 2009 -0600

    Solidifying the RAL/Event integration.
    
    This has two changes:
    
    * Clarifies how we get the property and resource
      name (we pass the instance, the event converts to a
      string)
    * Logs at the resource's loglevel when there's no error
    
    These are related, because the event creator (resource) was
    passing in a string rather than an instance.
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb
index 285a205..8ba19ff 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 ad8ea62..b96f6d1 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 41e1f51..b962149 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 2512c72..d17a56d 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 f447324..03674cb 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 eba5c3d..af3dbc4 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 07470b2..6a837b5 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 be456a8..9e6469c 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

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list