From 3f070c118b1ae2f3c76172d320ff04e92618a9b3 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 16 Jun 2009 11:03:46 -0500 Subject: Using the logging utilities to clean up module warnings This just makes it easier to add context to warnings and other logs from the module. Signed-off-by: Luke Kanies --- lib/puppet/module.rb | 13 ++++++++++++- spec/unit/module.rb | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index 38ff2bf55..3a6f04d15 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -1,5 +1,8 @@ +require 'puppet/util/logging' + # Support for modules class Puppet::Module + include Puppet::Util::Logging TEMPLATES = "templates" FILES = "files" @@ -118,6 +121,14 @@ class Puppet::Module subpath("plugins") end + def to_s + result = "Module %s" % name + if path + result += "(%s)" % path + end + result + end + private def find_init_manifest @@ -133,7 +144,7 @@ class Puppet::Module def backward_compatible_plugins_dir if dir = File.join(path, "plugins") and FileTest.exist?(dir) - Puppet.warning "Module %s uses the deprecated 'plugins' directory for ruby extensions; please move to 'lib'" % name + warning "using the deprecated 'plugins' directory for ruby extensions; please move to 'lib'" return dir else return File.join(path, "lib") diff --git a/spec/unit/module.rb b/spec/unit/module.rb index 9839d4092..29883dc26 100755 --- a/spec/unit/module.rb +++ b/spec/unit/module.rb @@ -29,6 +29,20 @@ describe Puppet::Module do Puppet::Module.find(nil, "myenv").should be_nil end + it "should provide support for logging" do + Puppet::Module.ancestors.should be_include(Puppet::Util::Logging) + end + + it "should be able to be converted to a string" do + Puppet::Module.new("foo").to_s.should == "Module foo" + end + + it "should add the path to its string form if the module is found" do + mod = Puppet::Module.new("foo") + mod.stubs(:path).returns "/a" + mod.to_s.should == "Module foo(/a)" + end + it "should require a name at initialization" do lambda { Puppet::Module.new }.should raise_error(ArgumentError) end @@ -152,7 +166,7 @@ describe Puppet::Module do mod.stubs(:path).returns "/a/foo" FileTest.expects(:exist?).with("/a/foo/plugins").returns true - Puppet.expects(:warning) + mod.expects(:warning) mod.plugin_directory.should == "/a/foo/plugins" end -- cgit