diff options
author | Paul Berry <paul@puppetlabs.com> | 2010-12-29 15:33:14 -0800 |
---|---|---|
committer | Paul Berry <paul@puppetlabs.com> | 2010-12-30 11:53:16 -0800 |
commit | 716ee1cd76a2b30c10e715bca3e22896d9c4e36f (patch) | |
tree | e7ea2e94a99dd842abad74c417e9c104bc986dfa | |
parent | 037eac4383ed5a5e9cdde765b607a180209bad1e (diff) | |
download | puppet-716ee1cd76a2b30c10e715bca3e22896d9c4e36f.tar.gz puppet-716ee1cd76a2b30c10e715bca3e22896d9c4e36f.tar.xz puppet-716ee1cd76a2b30c10e715bca3e22896d9c4e36f.zip |
(#5715) Changed the type of metric names to always be strings.
-rw-r--r-- | lib/puppet/transaction/report.rb | 16 | ||||
-rw-r--r-- | lib/puppet/util/metric.rb | 1 | ||||
-rw-r--r-- | spec/integration/indirector/report/rest_spec.rb | 28 | ||||
-rwxr-xr-x | spec/unit/transaction/report_spec.rb | 26 | ||||
-rwxr-xr-x | 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 6315973ba..8e04759ad 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 8f55e7b44..09bbb6137 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 7fa026b73..5b5b2ddd8 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 96d464b7a..766d4f14d 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 72571ee4a..600b88f85 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. |