+1 On Thu, Sep 23, 2010 at 5:15 PM, Matt Robinson <[email protected]> wrote:
> The code made assumptions about report structure that weren't valid for > 2.6.x. The change has been verified to work with 0.25.x and 2.6.x > report formats. > > Paired with: Rein Henrichs > > Signed-off-by: Matt Robinson <[email protected]> > --- > lib/puppet/reports/rrdgraph.rb | 2 +- > spec/fixtures/yaml/report0.25.x.yaml | 64 ++++++++ > spec/fixtures/yaml/report2.6.x.yaml | 190 > +++++++++++++++++++++++ > spec/lib/puppet_spec/files.rb | 1 + > spec/spec_helper.rb | 1 + > spec/unit/indirector/node/active_record_spec.rb | 1 - > spec/unit/reports/rrdgraph_spec.rb | 29 ++++ > 7 files changed, 286 insertions(+), 2 deletions(-) > create mode 100644 spec/fixtures/yaml/report0.25.x.yaml > create mode 100644 spec/fixtures/yaml/report2.6.x.yaml > create mode 100644 spec/unit/reports/rrdgraph_spec.rb > > diff --git a/lib/puppet/reports/rrdgraph.rb > b/lib/puppet/reports/rrdgraph.rb > index 2357e23..517fa8f 100644 > --- a/lib/puppet/reports/rrdgraph.rb > +++ b/lib/puppet/reports/rrdgraph.rb > @@ -122,7 +122,7 @@ Puppet::Reports.register_report(:rrdgraph) do > # that means we record the total time, the config time, and that's about > # it. We should probably send each type's time as a separate metric. > def timeclean(metric) > - metric.values = metric.values.find_all { |name, label, value| [:total, > :config_retrieval].include?(name) } > + metric.values = metric.values.find_all { |name, label, value| > ['total', 'config_retrieval'].include?(name.to_s) } > end > end > > diff --git a/spec/fixtures/yaml/report0.25.x.yaml > b/spec/fixtures/yaml/report0.25.x.yaml > new file mode 100644 > index 0000000..ce6a642 > --- /dev/null > +++ b/spec/fixtures/yaml/report0.25.x.yaml > @@ -0,0 +1,64 @@ > +--- !ruby/object:Puppet::Transaction::Report > + host: mattmac.local > + logs: > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym info > + message: Applying configuration version '1285283846' > + source: Puppet > + tags: > + - info > + time: 2010-09-23 16:17:26.977750 -07:00 > + metrics: > + time: !ruby/object:Puppet::Util::Metric > + label: Time > + name: time > + values: > + - - !ruby/sym config_retrieval > + - Config retrieval > + - 0.955046892166138 > + - - !ruby/sym schedule > + - Schedule > + - 0.00123691558837891 > + - - !ruby/sym total > + - Total > + - 0.956486701965332 > + - - !ruby/sym filebucket > + - Filebucket > + - 0.00020289421081543 > + resources: !ruby/object:Puppet::Util::Metric > + label: Resources > + name: resources > + values: > + - - !ruby/sym skipped > + - Skipped > + - 0 > + - - !ruby/sym scheduled > + - Scheduled > + - 7 > + - - !ruby/sym applied > + - Applied > + - 0 > + - - !ruby/sym restarted > + - Restarted > + - 0 > + - - !ruby/sym total > + - Total > + - 10 > + - - !ruby/sym failed_restarts > + - Failed restarts > + - 0 > + - - !ruby/sym out_of_sync > + - Out of sync > + - 0 > + - - !ruby/sym failed > + - Failed > + - 0 > + changes: !ruby/object:Puppet::Util::Metric > + label: Changes > + name: changes > + values: > + - - !ruby/sym total > + - Total > + - 0 > + records: {} > + time: 2010-09-23 16:17:26.987789 -07:00 > \ No newline at end of file > diff --git a/spec/fixtures/yaml/report2.6.x.yaml > b/spec/fixtures/yaml/report2.6.x.yaml > new file mode 100644 > index 0000000..dd4c381 > --- /dev/null > +++ b/spec/fixtures/yaml/report2.6.x.yaml > @@ -0,0 +1,190 @@ > +--- !ruby/object:Puppet::Transaction::Report > + external_times: > + !ruby/sym config_retrieval: 0.170313835144043 > + host: ubuntu1004desktop.localdomain > + logs: > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym debug > + message: Using cached certificate for ca > + source: Puppet > + tags: > + - debug > + time: 2010-09-23 15:44:06.244173 -07:00 > + version: &id001 2.6.1 > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym debug > + message: Using cached certificate for ubuntu1004desktop.localdomain > + source: Puppet > + tags: > + - debug > + time: 2010-09-23 15:44:06.244764 -07:00 > + version: *id001 > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym debug > + message: Using cached certificate_revocation_list for ca > + source: Puppet > + tags: > + - debug > + time: 2010-09-23 15:44:06.245677 -07:00 > + version: *id001 > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym debug > + message: "catalog supports formats: b64_zlib_yaml dot marshal pson > raw yaml; using pson" > + source: Puppet > + tags: > + - debug > + time: 2010-09-23 15:44:06.247069 -07:00 > + version: *id001 > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym info > + message: Caching catalog for ubuntu1004desktop.localdomain > + source: Puppet > + tags: > + - info > + time: 2010-09-23 15:44:06.409109 -07:00 > + version: *id001 > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym debug > + message: Creating default schedules > + source: Puppet > + tags: > + - debug > + time: 2010-09-23 15:44:06.418755 -07:00 > + version: *id001 > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym debug > + message: Loaded state in 0.00 seconds > + source: Puppet > + tags: > + - debug > + time: 2010-09-23 15:44:06.427441 -07:00 > + version: *id001 > + - !ruby/object:Puppet::Util::Log > + level: !ruby/sym info > + message: Applying configuration version '1285281846' > + source: Puppet > + tags: > + - info > + time: 2010-09-23 15:44:06.429532 -07:00 > + version: *id001 > + metrics: > + time: !ruby/object:Puppet::Util::Metric > + label: Time > + name: time > + values: > + - - config_retrieval > + - Config retrieval > + - 0.170313835144043 > + - - schedule > + - Schedule > + - 0.00077 > + - - filebucket > + - Filebucket > + - 0.000166 > + resources: !ruby/object:Puppet::Util::Metric > + label: Resources > + name: resources > + values: > + - - !ruby/sym total > + - Total > + - 7 > + events: !ruby/object:Puppet::Util::Metric > + label: Events > + name: events > + values: > + - - !ruby/sym total > + - Total > + - 0 > + changes: !ruby/object:Puppet::Util::Metric > + label: Changes > + name: changes > + values: > + - - !ruby/sym total > + - Total > + - 0 > + resource_statuses: > + "Schedule[monthly]": !ruby/object:Puppet::Resource::Status > + evaluation_time: 0.000121 > + events: [] > + file: > + line: > + resource: "Schedule[monthly]" > + source_description: "/Schedule[monthly]" > + tags: > + - schedule > + - monthly > + time: 2010-09-23 15:44:06.430577 -07:00 > + version: 1285281846 > + "Filebucket[puppet]": !ruby/object:Puppet::Resource::Status > + evaluation_time: 0.000166 > + events: [] > + file: > + line: > + resource: "Filebucket[puppet]" > + source_description: "/Filebucket[puppet]" > + tags: > + - filebucket > + - puppet > + time: 2010-09-23 15:44:06.430998 -07:00 > + version: 1285281846 > + "Schedule[never]": !ruby/object:Puppet::Resource::Status > + evaluation_time: 0.000119 > + events: [] > + file: > + line: > + resource: "Schedule[never]" > + source_description: "/Schedule[never]" > + tags: > + - schedule > + - never > + time: 2010-09-23 15:44:06.433034 -07:00 > + version: 1285281846 > + "Schedule[weekly]": !ruby/object:Puppet::Resource::Status > + evaluation_time: 0.000118 > + events: [] > + file: > + line: > + resource: "Schedule[weekly]" > + source_description: "/Schedule[weekly]" > + tags: > + - schedule > + - weekly > + time: 2010-09-23 15:44:06.431443 -07:00 > + version: 1285281846 > + "Schedule[puppet]": !ruby/object:Puppet::Resource::Status > + evaluation_time: 0.000129 > + events: [] > + file: > + line: > + resource: "Schedule[puppet]" > + source_description: "/Schedule[puppet]" > + tags: > + - schedule > + - puppet > + time: 2010-09-23 15:44:06.432626 -07:00 > + version: 1285281846 > + "Schedule[daily]": !ruby/object:Puppet::Resource::Status > + evaluation_time: 0.000154 > + events: [] > + file: > + line: > + resource: "Schedule[daily]" > + source_description: "/Schedule[daily]" > + tags: > + - schedule > + - daily > + time: 2010-09-23 15:44:06.430130 -07:00 > + version: 1285281846 > + "Schedule[hourly]": !ruby/object:Puppet::Resource::Status > + evaluation_time: 0.000129 > + events: [] > + file: > + line: > + resource: "Schedule[hourly]" > + source_description: "/Schedule[hourly]" > + tags: > + - schedule > + - hourly > + time: 2010-09-23 15:44:06.432185 -07:00 > + version: 1285281846 > + time: 2010-09-23 15:44:05.894401 -07:00 > \ No newline at end of file > diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb > index cab4a1e..52ed903 100644 > --- a/spec/lib/puppet_spec/files.rb > +++ b/spec/lib/puppet_spec/files.rb > @@ -1,4 +1,5 @@ > require 'fileutils' > +require 'tempfile' > > # A support module for testing files. > module PuppetSpec::Files > diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb > index 2fe0c36..b5b2738 100644 > --- a/spec/spec_helper.rb > +++ b/spec/spec_helper.rb > @@ -20,6 +20,7 @@ module PuppetSpec > FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), > "fixtures") unless defined?(FIXTURE_DIR) > end > > +require 'spec/lib/puppet_spec/files' > require 'monkey_patches/alias_should_to_must' > require 'monkey_patches/add_confine_and_runnable_to_rspec_dsl' > require 'monkey_patches/publicize_methods' > diff --git a/spec/unit/indirector/node/active_record_spec.rb > b/spec/unit/indirector/node/active_record_spec.rb > index 6cc3f51..3540ef7 100755 > --- a/spec/unit/indirector/node/active_record_spec.rb > +++ b/spec/unit/indirector/node/active_record_spec.rb > @@ -3,7 +3,6 @@ > require File.dirname(__FILE__) + '/../../../spec_helper' > > require 'puppet/node' > -require 'spec/lib/puppet_spec/files.rb' > > describe "Puppet::Node::ActiveRecord" do > include PuppetSpec::Files > diff --git a/spec/unit/reports/rrdgraph_spec.rb > b/spec/unit/reports/rrdgraph_spec.rb > new file mode 100644 > index 0000000..06c8e2c > --- /dev/null > +++ b/spec/unit/reports/rrdgraph_spec.rb > @@ -0,0 +1,29 @@ > +#!/usr/bin/env ruby > + > +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? > require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } > + > +require 'puppet/reports' > + > +processor = Puppet::Reports.report(:rrdgraph) > + > +describe processor do > + include PuppetSpec::Files > + before do > + Puppet[:rrddir] = tmpdir('rrdgraph') > + Puppet.settings.use :master > + end > + > + after do > + FileUtils.rm_rf(Puppet[:rrddir]) > + end > + > + it "should not error on 0.25.x report format" do > + report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, > 'yaml/report0.25.x.yaml')).extend processor > + lambda{ report.process }.should_not raise_error > + end > + > + it "should not error on 2.6.x report format" do > + report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, > 'yaml/report2.6.x.yaml')).extend processor > + lambda{ report.process }.should_not raise_error > + end > +end > -- > 1.7.1 > > -- > 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]<puppet-dev%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. > > -- 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.
