[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:33:11 UTC 2010


The following commit has been merged in the upstream branch:
commit ddd40bbc3a90133f223e91d6d4be21aada064a26
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Mon Apr 26 17:01:01 2010 -0700

    Fix for #3690 failing to calculate error codes
    
    This failure was getting caused by what I believe to be a bug in
    Puppet::Configurer where it always generated a new
    Puppet::Transaction::Report, even if one existed in an outer scope.
    In puppetd --test, a different Report was getting queried to generate
    the exit status than the one that was passed to the transaction -- this
    Report had no Metrics and would fail when queried.
    
    This obscured a second bug that Metrics could return nil for values if
    the Transaction had applied an empty Catalog, but Transaction::Report
    assumes that values will always be integers.
    
    It could be argued that an empty Report should be populated with empty
    Metrics before a Transaction is run, which would have prevented
    Report#exit_status from raising an exception ... which would have made
    these bugs much harder to track down. So, I've decided to leave that
    unchanged.
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 0ff87e6..d45c4a7 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -140,7 +140,8 @@ class Puppet::Configurer
             Puppet.err "Failed to prepare catalog: %s" % detail
         end
 
-        report = initialize_report()
+        options[:report] ||= initialize_report()
+        report = options[:report]
         Puppet::Util::Log.newdestination(report)
 
         if catalog = options[:catalog]
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 6aeda09..97c036b 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -133,6 +133,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
         Puppet::Util::Storage.load if host_config?
         transaction = Puppet::Transaction.new(self)
 
+        transaction.report = options[:report] if options[:report]
         transaction.tags = options[:tags] if options[:tags]
         transaction.ignoreschedules = true if options[:ignoreschedules]
 
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index f8ed503..e57fe56 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -16,7 +16,7 @@ class Puppet::Transaction
     attr_accessor :sorted_resources, :configurator
 
     # The report, once generated.
-    attr_reader :report
+    attr_accessor :report
 
     # Routes and stores any events and subscriptions.
     attr_reader :event_manager
diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb
index b713246..8717fe0 100644
--- a/lib/puppet/util/metric.rb
+++ b/lib/puppet/util/metric.rb
@@ -14,7 +14,7 @@ class Puppet::Util::Metric
         if value = @values.find { |v| v[0] == name }
             return value[2]
         else
-            return nil
+            return 0
         end
     end
 
diff --git a/spec/unit/configurer.rb b/spec/unit/configurer.rb
index 94ac452..2bdb63d 100755
--- a/spec/unit/configurer.rb
+++ b/spec/unit/configurer.rb
@@ -86,7 +86,9 @@ describe Puppet::Configurer, "when executing a catalog run" do
         @agent = Puppet::Configurer.new
         @agent.stubs(:prepare)
         @agent.stubs(:facts_for_uploading).returns({})
-        @agent.stubs(:retrieve_catalog).returns Puppet::Resource::Catalog.new
+        @catalog = Puppet::Resource::Catalog.new
+        @catalog.stubs(:apply)
+        @agent.stubs(:retrieve_catalog).returns @catalog
 
         Puppet::Util::Log.stubs(:newdestination)
         Puppet::Util::Log.stubs(:close)
@@ -98,13 +100,29 @@ describe Puppet::Configurer, "when executing a catalog run" do
         @agent.run
     end
 
-    it "should initialize a transaction report" do
+    it "should initialize a transaction report if one is not provided" do
         report = stub 'report'
         @agent.expects(:initialize_report).returns report
 
         @agent.run
     end
 
+    it "should pass the new report to the catalog" do
+        report = stub 'report'
+        @agent.stubs(:initialize_report).returns report
+        @catalog.expects(:apply).with{|options| options[:report] == report}
+
+        @agent.run
+    end
+
+    it "should use the provided report if it was passed one" do
+        report = stub 'report'
+        @agent.expects(:initialize_report).never
+        @catalog.expects(:apply).with{|options| options[:report] == report}
+
+        @agent.run(:report => report)
+    end
+
     it "should set the report as a log destination" do
         report = stub 'report'
         @agent.expects(:initialize_report).returns report
diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb
index 64da12d..a55d6e5 100755
--- a/spec/unit/transaction.rb
+++ b/spec/unit/transaction.rb
@@ -92,6 +92,13 @@ describe Puppet::Transaction do
         @transaction.should_not be_any_failed
     end
 
+    it "should be possible to replace the report object" do
+        report = Puppet::Transaction::Report.new
+        @transaction.report = report
+
+        @transaction.report.should == report
+    end
+
     it "should consider a resource to have failed dependencies if any of its dependencies are failed"
 
     describe "when initializing" do
diff --git a/spec/unit/util/metric.rb b/spec/unit/util/metric.rb
index 3501aac..41ab4cc 100755
--- a/spec/unit/util/metric.rb
+++ b/spec/unit/util/metric.rb
@@ -81,7 +81,7 @@ describe Puppet::Util::Metric do
     end
 
     it "should return nil if the named value cannot be found" do
-        @metric[:foo].should be_nil
+        @metric[:foo].should == 0
     end
 
     # LAK: I'm not taking the time to develop these tests right now.

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list