[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35
test branch
puppet-dev at googlegroups.com
Wed Jul 14 10:34:49 UTC 2010
The following commit has been merged in the upstream branch:
commit 50a626daa1bef956ea63c405fddeaeab8a9a0756
Author: Luke Kanies <luke at puppetlabs.com>
Date: Thu Jun 10 19:21:05 2010 -0700
Fixing #1545 - Adding 'caller_module_name' variable
This will produce the name of the module that a given
resource is defined in, rather than the module that
the resource type itself is defined in. For instance:
# in one/manifests/onedef.pp
define one::onedef {
notice "Called $name from $caller_module_name"
}
# in two/manifests/init.pp
class two {
one::onedef { yay: }
}
produces:
Called yay from two
This could obviously be extended to actually build a caller
stack, as frightening as that seems.
Signed-off-by: Luke Kanies <luke at puppetlabs.com>
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 140c8c1..c974aee 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -306,6 +306,12 @@ class Puppet::Parser::Scope
self.nodescope
end
+ def parent_module_name
+ return nil unless @parent
+ return nil unless @parent.source
+ @parent.source.module_name
+ end
+
# Return the list of scopes up to the top scope, ordered with our own first.
# This is used for looking up variables and defaults.
def scope_path
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index 227c544..e13b183 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -214,6 +214,10 @@ class Puppet::Resource::Type
scope.setvar("title", resource.title) unless set.include? :title
scope.setvar("name", resource.name) unless set.include? :name
scope.setvar("module_name", module_name) if module_name and ! set.include? :module_name
+
+ if caller_name = scope.parent_module_name and ! set.include?(:caller_module_name)
+ scope.setvar("caller_module_name", caller_name)
+ end
scope.class_set(self.name,scope) if hostclass?
end
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
index b14b2d3..4f30ff0 100755
--- a/spec/unit/parser/scope.rb
+++ b/spec/unit/parser/scope.rb
@@ -28,6 +28,21 @@ describe Puppet::Parser::Scope do
@scope.class_scope(klass).should == "myscope"
end
+ it "should be able to retrieve its parent module name from the source of its parent type" do
+ @topscope.source = Puppet::Resource::Type.new(:hostclass, :foo)
+ @topscope.source.module_name = "foo"
+
+ @scope.parent_module_name.should == "foo"
+ end
+
+ it "should return a nil parent module name if it has no parent" do
+ @topscope.parent_module_name.should be_nil
+ end
+
+ it "should return a nil parent module name if its parent has no source" do
+ @scope.parent_module_name.should be_nil
+ end
+
# #620 - Nodes and classes should conflict, else classes don't get evaluated
describe "when evaluating nodes and classes with the same name (#620)" do
diff --git a/spec/unit/resource/type.rb b/spec/unit/resource/type.rb
index 59e4623..3d0e824 100755
--- a/spec/unit/resource/type.rb
+++ b/spec/unit/resource/type.rb
@@ -322,6 +322,14 @@ describe Puppet::Resource::Type do
@scope.lookupvar("module_name").should == "mymod"
end
+
+ it "should set its caller module name in the scope if available" do
+ @scope.expects(:parent_module_name).returns "mycaller"
+
+ @type.set_resource_parameters(@resource, @scope)
+
+ @scope.lookupvar("caller_module_name").should == "mycaller"
+ end
end
describe "when describing and managing parent classes" do
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list