From ac58e274c409b69073e304a8355bbe4ccb37350a Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 24 Jul 2009 00:27:44 -0700 Subject: Configuration version information is now in logs The log instances have file, line, and config version information, although it's not currently printed. It's available in the reports, and you can strip it out with your own processors. Signed-off-by: Luke Kanies --- lib/puppet/type.rb | 5 +++++ lib/puppet/util/log.rb | 7 ++++++- spec/unit/type.rb | 13 +++++++++++++ spec/unit/util/log.rb | 29 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 098d83254..33b4e92da 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -594,6 +594,11 @@ class Type end end + def version + return 0 unless catalog + catalog.version + end + # Meta-parameter methods: These methods deal with the results # of specifying metaparameters diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 94b0bcffa..6edc7f482 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -475,7 +475,7 @@ class Puppet::Util::Log @levels.include?(level) end - attr_accessor :level, :message, :time, :remote + attr_accessor :level, :message, :time, :remote, :file, :line, :version attr_reader :source def initialize(args) @@ -522,6 +522,11 @@ class Puppet::Util::Log if source.respond_to?(:tags) source.tags.each { |t| tag(t) } end + + [:file, :line, :version].each do |param| + next unless source.respond_to?(param) + send(param.to_s + "=", source.send(param)) + end end def to_report diff --git a/spec/unit/type.rb b/spec/unit/type.rb index 2bcac7aec..b179677f9 100755 --- a/spec/unit/type.rb +++ b/spec/unit/type.rb @@ -72,6 +72,19 @@ describe Puppet::Type do Puppet::Type.type(:mount).new(:name => "foo").should respond_to(:exported?) end + it "should consider its version to be its catalog version" do + resource = Puppet::Type.type(:mount).new(:name => "foo") + catalog = Puppet::Resource::Catalog.new + catalog.version = 50 + catalog.add_resource resource + + resource.version.should == 50 + end + + it "should consider its version to be zero if it has no catalog" do + Puppet::Type.type(:mount).new(:name => "foo").version.should == 0 + end + describe "when choosing a default provider" do it "should choose the provider with the highest specificity" do # Make a fake type diff --git a/spec/unit/util/log.rb b/spec/unit/util/log.rb index b996f17a0..9d1b4108e 100755 --- a/spec/unit/util/log.rb +++ b/spec/unit/util/log.rb @@ -111,5 +111,34 @@ describe Puppet::Util::Log do report.should be_include(log.source) report.should be_include(log.time.to_s) end + + describe "when setting the source" do + it "should tag itself with any tags the source has" do + source = Puppet::Type.type(:file).new :path => "/foo/bar" + log = Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => source) + source.tags.each do |tag| + log.tags.should be_include(tag) + end + end + + it "should copy over any file and line information" do + source = Puppet::Type.type(:file).new :path => "/foo/bar" + source.file = "/my/file" + source.line = 50 + log = Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => source) + log.file.should == "/my/file" + log.line.should == 50 + end + + it "should copy over any version information" do + catalog = Puppet::Resource::Catalog.new + catalog.version = 25 + source = Puppet::Type.type(:file).new :path => "/foo/bar" + catalog.add_resource source + + log = Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => source) + log.version.should == 25 + end + end end end -- cgit