Please review pull request #419: Ticket/2.7.x/10064 Add environment to reports opened by (nicklewis)

Description:

Previously the Puppet environment was not included in
the report output. Using the model of how configuration_version
was added to the reports the environment will now also be reported.

Puppet::Transaction::Report now takes three arguments:

  • Kind of report
  • Configuration version
  • Environment

Tests for this have been added and existing tests updated.

  • Opened: Fri Jan 27 23:44:50 UTC 2012
  • Based on: puppetlabs:2.7.x (6f394cb38d8c5602cce3e1224e4a0f74e19370fd)
  • Requested merge: nicklewis:ticket/2.7.x/10064 (25a0a694fd7eedfb1e716308ba355151b035a0ae)

Diff follows:

diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb
index ad31d8d..5413a3d 100644
--- a/lib/puppet/application/inspect.rb
+++ b/lib/puppet/application/inspect.rb
@@ -118,6 +118,7 @@ def run_command
       end
 
       @report.configuration_version = catalog.version
+      @report.environment = Puppet[:environment]
 
       inspect_starttime = Time.now
       @report.add_times("config_retrieval", inspect_starttime - retrieval_starttime)
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 4773637..5df3b7b 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -116,6 +116,7 @@ def retrieve_and_apply_catalog(options, fact_options)
 
     report = options[:report]
     report.configuration_version = catalog.version
+    report.environment = Puppet[:environment]
 
     benchmark(:notice, "Finished catalog run") do
       catalog.apply(options)
diff --git a/lib/puppet/face/catalog.rb b/lib/puppet/face/catalog.rb
index 10b15d2..efd4ee7 100644
--- a/lib/puppet/face/catalog.rb
+++ b/lib/puppet/face/catalog.rb
@@ -66,6 +66,7 @@
 
       report = Puppet::Transaction::Report.new("apply")
       report.configuration_version = catalog.version
+      report.environment = Puppet[:environment]
 
       Puppet::Util::Log.newdestination(report)
 
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 20f7108..6eb72e9 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -235,7 +235,7 @@ def ignore_tags?
   def initialize(catalog, report = nil)
     @catalog = catalog
 
-    @report = report || Puppet::Transaction::Report.new("apply", catalog.version)
+    @report = report || Puppet::Transaction::Report.new("apply", catalog.version, Puppet[:environment])
 
     @event_manager = Puppet::Transaction::EventManager.new(self)
 
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index b661831..b7a0341 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_accessor :configuration_version, :host
+  attr_accessor :configuration_version, :host, :environment
   attr_reader :resource_statuses, :logs, :metrics, :time, :kind, :status
 
   # This is necessary since Marshall doesn't know how to
@@ -68,7 +68,7 @@ def finalize_report
     @status = compute_status(resource_metrics, change_metric)
   end
 
-  def initialize(kind, configuration_version=nil)
+  def initialize(kind, configuration_version=nil, environment=nil)
     @metrics = {}
     @logs = []
     @resource_statuses = {}
@@ -79,6 +79,7 @@ def initialize(kind, configuration_version=nil)
     @report_format = 2
     @puppet_version = Puppet.version
     @configuration_version = configuration_version
+    @environment = environment
     @status = 'failed' # assume failed until the report is finalized
   end
 
diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb
index 91a294d..2e69b35 100755
--- a/spec/unit/transaction/report_spec.rb
+++ b/spec/unit/transaction/report_spec.rb
@@ -29,7 +29,7 @@
   end
 
   it "should take a 'configuration_version' as an argument" do
-    Puppet::Transaction::Report.new("inspect", "some configuration version").configuration_version.should == "some configuration version"
+    Puppet::Transaction::Report.new("inspect", "some configuration version", "some environment").configuration_version.should == "some configuration version"
   end
 
   it "should be able to set configuration_version" do
@@ -38,6 +38,16 @@
     report.configuration_version.should == "some version"
   end
 
+  it "should take 'environment' as an argument" do
+    Puppet::Transaction::Report.new("inspect", "some configuration version", "some environment").environment.should == "some environment"
+  end
+
+  it "should be able to set environment" do
+    report = Puppet::Transaction::Report.new("inspect")
+    report.environment = "some environment"
+    report.environment.should == "some environment"
+  end
+
   it "should not include whits" do
     Puppet::FileBucket::File.indirection.stubs(:save)
 

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to