diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-14 06:07:31 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-14 06:07:31 +0000 |
| commit | 8003320eaa5eb4e4084e3463282e8b1226411ae4 (patch) | |
| tree | 24ef1aaf1cbda23216705705f9e6965492eb6a84 /test | |
| parent | 4910301a2f077abf4440e3ef044207de3732a631 (diff) | |
Applying metrics patch from #659 by thijs
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2579 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rwxr-xr-x | test/util/metrics.rb | 109 |
1 files changed, 53 insertions, 56 deletions
diff --git a/test/util/metrics.rb b/test/util/metrics.rb index c4e375e7b..fd997df17 100755 --- a/test/util/metrics.rb +++ b/test/util/metrics.rb @@ -7,75 +7,72 @@ require 'puppet/util/metric' require 'puppettest' require 'puppet/type' -if Puppet.features.rrd? - class TestMetric < Test::Unit::TestCase - include PuppetTest +class TestMetric < PuppetTest::TestCase + confine "Missing RRDtool library" => Puppet.features.rrd? + include PuppetTest - def gendata - totalmax = 1000 - changemax = 1000 - eventmax = 10 - maxdiff = 10 + def gendata + totalmax = 1000 + changemax = 1000 + eventmax = 10 + maxdiff = 10 - types = [Puppet.type(:file), Puppet.type(:package), Puppet.type(:package)] - data = [:total, :managed, :outofsync, :changed, :totalchanges] - events = [:file_changed, :package_installed, :service_started] + types = [Puppet.type(:file), Puppet.type(:package), Puppet.type(:package)] + data = [:total, :managed, :outofsync, :changed, :totalchanges] + events = [:file_changed, :package_installed, :service_started] - # if this is the first set of data points... - typedata = Hash.new { |typehash,type| - typehash[type] = Hash.new(0) - } - eventdata = Hash.new(0) - typedata = {} - typedata[:total] = rand(totalmax) - typedata[:managed] = rand(typedata[:total]) - typedata[:outofsync] = rand(typedata[:managed]) - typedata[:changed] = rand(typedata[:outofsync]) - typedata[:totalchanges] = rand(changemax) + # if this is the first set of data points... + typedata = Hash.new { |typehash,type| + typehash[type] = Hash.new(0) + } + eventdata = Hash.new(0) + typedata = {} + typedata[:total] = rand(totalmax) + typedata[:managed] = rand(typedata[:total]) + typedata[:outofsync] = rand(typedata[:managed]) + typedata[:changed] = rand(typedata[:outofsync]) + typedata[:totalchanges] = rand(changemax) - events.each { |event| - eventdata[event] = rand(eventmax) - } + events.each { |event| + eventdata[event] = rand(eventmax) + } - return {:typedata => typedata, :eventdata => eventdata} - end + return {:typedata => typedata, :eventdata => eventdata} + end - def rundata(report, time) - assert_nothing_raised { - gendata.each do |name, data| - report.newmetric(name, data) - end - report.metrics.each { |n, m| m.store(time) } - } - end + def rundata(report, time) + assert_nothing_raised { + gendata.each do |name, data| + report.newmetric(name, data) + end + report.metrics.each { |n, m| m.store(time) } + } + end - def setup - super - Puppet[:rrdgraph] = true - end + def setup + super + Puppet[:rrdgraph] = true + end - def test_fakedata - report = Puppet::Transaction::Report.new - time = Time.now.to_i - start = time - 10.times { - rundata(report, time) - time += 300 - } + def test_fakedata + report = Puppet::Transaction::Report.new + time = Time.now.to_i + start = time + 10.times { rundata(report, time) + time += 300 + } + rundata(report, time) - report.metrics.each do |n, m| m.graph end + report.metrics.each do |n, m| m.graph end - File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of| - of.puts "<html><body>" - report.metrics.each { |name, metric| - of.puts "<img src=%s.png><br>" % metric.name - } + File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of| + of.puts "<html><body>" + report.metrics.each { |name, metric| + of.puts "<img src=%s.png><br>" % metric.name } - end + } end -else - $stderr.puts "Missing RRD library -- skipping metric tests" end # $Id$ |
