Signed-off-by: Paul Berry <[email protected]>
---
 lib/puppet/transaction/report.rb                |   16 ++++++------
 lib/puppet/util/metric.rb                       |    1 +
 spec/integration/indirector/report/rest_spec.rb |   28 +++++++++-------------
 spec/unit/transaction/report_spec.rb            |   26 ++++++++++----------
 spec/unit/util/metric_spec.rb                   |   14 +++++-----
 5 files changed, 41 insertions(+), 44 deletions(-)

diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 6315973..8e04759 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -44,7 +44,7 @@ class Puppet::Transaction::Report
   end
 
   def compute_status(resource_metrics, change_metric)
-    if (resource_metrics[:failed] || 0) > 0
+    if (resource_metrics["failed"] || 0) > 0
       'failed'
     elsif change_metric > 0
       'changed'
@@ -57,7 +57,7 @@ class Puppet::Transaction::Report
     resource_metrics = add_metric(:resources, calculate_resource_metrics)
     add_metric(:time, calculate_time_metrics)
     change_metric = calculate_change_metric
-    add_metric(:changes, {:total => change_metric})
+    add_metric(:changes, {"total" => change_metric})
     add_metric(:events, calculate_event_metrics)
     @status = compute_status(resource_metrics, change_metric)
   end
@@ -109,8 +109,8 @@ class Puppet::Transaction::Report
   # individual bits represent the presence of different metrics.
   def exit_status
     status = 0
-    status |= 2 if @metrics["changes"][:total] > 0
-    status |= 4 if @metrics["resources"][:failed] > 0
+    status |= 2 if @metrics["changes"]["total"] > 0
+    status |= 4 if @metrics["resources"]["failed"] > 0
     status
   end
 
@@ -126,9 +126,9 @@ class Puppet::Transaction::Report
 
   def calculate_event_metrics
     metrics = Hash.new(0)
-    metrics[:total] = 0
+    metrics["total"] = 0
     resource_statuses.each do |name, status|
-      metrics[:total] += status.events.length
+      metrics["total"] += status.events.length
       status.events.each do |event|
         metrics[event.status] += 1
       end
@@ -139,12 +139,12 @@ class Puppet::Transaction::Report
 
   def calculate_resource_metrics
     metrics = Hash.new(0)
-    metrics[:total] = resource_statuses.length
+    metrics["total"] = resource_statuses.length
 
     resource_statuses.each do |name, status|
 
       Puppet::Resource::Status::STATES.each do |state|
-        metrics[state] += 1 if status.send(state)
+        metrics[state.to_s] += 1 if status.send(state)
       end
     end
 
diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb
index 8f55e7b..09bbb61 100644
--- a/lib/puppet/util/metric.rb
+++ b/lib/puppet/util/metric.rb
@@ -132,6 +132,7 @@ class Puppet::Util::Metric
   end
 
   def newvalue(name,value,label = nil)
+    raise ArgumentError.new("metric name #{name.inspect} is not a string") 
unless name.is_a? String
     label ||= labelize(name)
     @values.push [name,label,value]
   end
diff --git a/spec/integration/indirector/report/rest_spec.rb 
b/spec/integration/indirector/report/rest_spec.rb
index 7fa026b..5b5b2dd 100644
--- a/spec/integration/indirector/report/rest_spec.rb
+++ b/spec/integration/indirector/report/rest_spec.rb
@@ -67,30 +67,26 @@ describe "Report REST Terminus" do
     report = Puppet::Transaction::Report.new("apply")
 
     resourcemetrics = {
-      :total => 12,
-      :out_of_sync => 20,
-      :applied => 45,
-      :skipped => 1,
-      :restarted => 23,
-      :failed_restarts => 1,
-      :scheduled => 10
+      "total" => 12,
+      "out_of_sync" => 20,
+      "applied" => 45,
+      "skipped" => 1,
+      "restarted" => 23,
+      "failed_restarts" => 1,
+      "scheduled" => 10
     }
     report.add_metric(:resources, resourcemetrics)
 
     timemetrics = {
-      :resource1 => 10,
-      :resource2 => 50,
-      :resource3 => 40,
-      :resource4 => 20,
+      "resource1" => 10,
+      "resource2" => 50,
+      "resource3" => 40,
+      "resource4" => 20,
     }
     report.add_metric(:times, timemetrics)
 
 
-          report.add_metric(
-        :changes,
-        
-      :total => 20
-    )
+    report.add_metric(:changes, "total" => 20)
 
     report.save
   end
diff --git a/spec/unit/transaction/report_spec.rb 
b/spec/unit/transaction/report_spec.rb
index 96d464b..766d4f1 100755
--- a/spec/unit/transaction/report_spec.rb
+++ b/spec/unit/transaction/report_spec.rb
@@ -101,22 +101,22 @@ describe Puppet::Transaction::Report do
   describe "when computing exit status" do
     it "should produce 2 if changes are present" do
       report = Puppet::Transaction::Report.new("apply")
-      report.add_metric("changes", {:total => 1})
-      report.add_metric("resources", {:failed => 0})
+      report.add_metric("changes", {"total" => 1})
+      report.add_metric("resources", {"failed" => 0})
       report.exit_status.should == 2
     end
 
     it "should produce 4 if failures are present" do
       report = Puppet::Transaction::Report.new("apply")
-      report.add_metric("changes", {:total => 0})
-      report.add_metric("resources", {:failed => 1})
+      report.add_metric("changes", {"total" => 0})
+      report.add_metric("resources", {"failed" => 1})
       report.exit_status.should == 4
     end
 
     it "should produce 6 if both changes and failures are present" do
       report = Puppet::Transaction::Report.new("apply")
-      report.add_metric("changes", {:total => 1})
-      report.add_metric("resources", {:failed => 1})
+      report.add_metric("changes", {"total" => 1})
+      report.add_metric("resources", {"failed" => 1})
       report.exit_status.should == 6
     end
   end
@@ -162,7 +162,7 @@ describe Puppet::Transaction::Report do
         add_statuses(3)
 
         @report.finalize_report
-        metric(:resources, :total).should == 3
+        metric(:resources, "total").should == 3
       end
 
       Puppet::Resource::Status::STATES.each do |state|
@@ -170,7 +170,7 @@ describe Puppet::Transaction::Report do
           add_statuses(3) { |status| status.send(state.to_s + "=", true) }
 
           @report.finalize_report
-          metric(:resources, state).should == 3
+          metric(:resources, state.to_s).should == 3
         end
       end
 
@@ -185,13 +185,13 @@ describe Puppet::Transaction::Report do
       it "should provide the number of changes from the resource statuses and 
mark the report as 'changed'" do
         add_statuses(3) { |status| 3.times { status << 
Puppet::Transaction::Event.new(:status => 'success') } }
         @report.finalize_report
-        metric(:changes, :total).should == 9
+        metric(:changes, "total").should == 9
         @report.status.should == 'changed'
       end
 
       it "should provide a total even if there are no changes, and mark the 
report as 'unchanged'" do
         @report.finalize_report
-        metric(:changes, :total).should == 0
+        metric(:changes, "total").should == 0
         @report.status.should == 'unchanged'
       end
     end
@@ -234,15 +234,15 @@ describe Puppet::Transaction::Report do
     describe "for events" do
       it "should provide the total number of events" do
         add_statuses(3) do |status|
-          3.times { |i| status.add_event(Puppet::Transaction::Event.new) }
+          3.times { |i| status.add_event(Puppet::Transaction::Event.new 
:status => 'success') }
         end
         @report.finalize_report
-        metric(:events, :total).should == 9
+        metric(:events, "total").should == 9
       end
 
       it "should provide the total even if there are no events" do
         @report.finalize_report
-        metric(:events, :total).should == 0
+        metric(:events, "total").should == 0
       end
 
       Puppet::Transaction::Event::EVENT_STATUSES.each do |status_name|
diff --git a/spec/unit/util/metric_spec.rb b/spec/unit/util/metric_spec.rb
index 72571ee..600b88f 100755
--- a/spec/unit/util/metric_spec.rb
+++ b/spec/unit/util/metric_spec.rb
@@ -59,7 +59,7 @@ describe Puppet::Util::Metric do
   end
 
   it "should support a label for values" do
-    @metric.newvalue(:foo, 10, "label")
+    @metric.newvalue("foo", 10, "label")
     @metric.values[0][1].should == "label"
   end
 
@@ -69,19 +69,19 @@ describe Puppet::Util::Metric do
   end
 
   it "should return its values sorted by label" do
-    @metric.newvalue(:foo, 10, "b")
-    @metric.newvalue(:bar, 10, "a")
+    @metric.newvalue("foo", 10, "b")
+    @metric.newvalue("bar", 10, "a")
 
-    @metric.values.should == [[:bar, "a", 10], [:foo, "b", 10]]
+    @metric.values.should == [["bar", "a", 10], ["foo", "b", 10]]
   end
 
   it "should use an array indexer method to retrieve individual values" do
-    @metric.newvalue(:foo, 10)
-    @metric[:foo].should == 10
+    @metric.newvalue("foo", 10)
+    @metric["foo"].should == 10
   end
 
   it "should return nil if the named value cannot be found" do
-    @metric[:foo].should == 0
+    @metric["foo"].should == 0
   end
 
   # LAK: I'm not taking the time to develop these tests right now.
-- 
1.7.2

-- 
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