summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppetlabs.com>2011-04-21 14:37:50 -0700
committerJosh Cooper <josh@puppetlabs.com>2011-04-21 14:37:50 -0700
commit01f610bb223b435dc52f491260af3ea002930102 (patch)
tree93565136d5ef2b4156fdd64476792e441bcfbb4e /lib/puppet/parser
parentac428b9557e2da251e4b51e48de844833ca0aa2a (diff)
parentfc66e98b84b9a16728af054485883334a5887cca (diff)
downloadpuppet-01f610bb223b435dc52f491260af3ea002930102.tar.gz
puppet-01f610bb223b435dc52f491260af3ea002930102.tar.xz
puppet-01f610bb223b435dc52f491260af3ea002930102.zip
Merge branch 'next'
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/compiler.rb19
-rw-r--r--lib/puppet/parser/resource.rb19
-rw-r--r--lib/puppet/parser/scope.rb10
3 files changed, 31 insertions, 17 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index a891f1a11..613fcae74 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -56,23 +56,20 @@ class Puppet::Parser::Compiler
# Note that this will fail if the resource is not unique.
@catalog.add_resource(resource)
+ if resource.type.to_s.downcase != "class" && resource[:stage]
+ raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage"
+ end
- # Add our container edge. If we're a class, then we get treated specially - we can
- # control the stage that the class is applied in. Otherwise, we just
- # get added to our parent container.
+ # Stages should not be inside of classes. They are always a
+ # top-level container, regardless of where they appear in the
+ # manifest.
return if resource.type.to_s.downcase == "stage"
+ # This adds a resource to the class it lexically appears in in the
+ # manifest.
if resource.type.to_s.downcase != "class"
- raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage" if resource[:stage]
return @catalog.add_edge(scope.resource, resource)
end
-
- unless stage = @catalog.resource(:stage, resource[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main)
- raise ArgumentError, "Could not find stage #{resource[:stage] || :main} specified by #{resource}"
- end
-
- resource[:stage] ||= stage.title unless stage.title == :main
- @catalog.add_edge(stage, resource)
end
# Do we use nodes found in the code, vs. the external node sources?
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index ace01bb4b..3bb5f8601 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -62,13 +62,30 @@ class Puppet::Parser::Resource < Puppet::Resource
scope.environment
end
+ # Process the stage metaparameter for a class. A containment edge
+ # is drawn from the class to the stage. The stage for containment
+ # defaults to main, if none is specified.
+ def add_edge_to_stage
+ return unless self.type.to_s.downcase == "class"
+
+ unless stage = catalog.resource(:stage, self[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main)
+ raise ArgumentError, "Could not find stage #{self[:stage] || :main} specified by #{self}"
+ end
+
+ self[:stage] ||= stage.title unless stage.title == :main
+ catalog.add_edge(stage, self)
+ end
+
# Retrieve the associated definition and evaluate it.
def evaluate
return if evaluated?
@evaluated = true
if klass = resource_type and ! builtin_type?
finish
- return klass.evaluate_code(self)
+ evaluated_code = klass.evaluate_code(self)
+ add_edge_to_stage
+
+ return evaluated_code
elsif builtin?
devfail "Cannot evaluate a builtin type (#{type})"
else
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 8de9d60b1..ed67cd141 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -101,7 +101,7 @@ class Puppet::Parser::Scope
# Remove this when rebasing
def environment
- compiler.environment
+ compiler ? compiler.environment : nil
end
def find_hostclass(name)
@@ -222,12 +222,12 @@ class Puppet::Parser::Scope
private :qualified_scope
- # Look up a variable. The simplest value search we do.
+ # Look up a variable. The simplest value search we do.
def lookupvar(name, options = {})
table = ephemeral?(name) ? @ephemeral.last : @symtable
# If the variable is qualified, then find the specified scope and look the variable up there instead.
if name =~ /^(.*)::(.+)$/
- begin
+ begin
qualified_scope($1).lookupvar($2,options)
rescue RuntimeError => e
location = (options[:file] && options[:line]) ? " at #{options[:file]}:#{options[:line]}" : ''
@@ -238,7 +238,7 @@ class Puppet::Parser::Scope
# We can't use "if table[name]" here because the value might be false
if options[:dynamic] and self != compiler.topscope
location = (options[:file] && options[:line]) ? " at #{options[:file]}:#{options[:line]}" : ''
- Puppet.deprecation_warning "Dynamic lookup of $#{name}#{location} will not be supported in future versions. Use a fully-qualified variable name or parameterized classes."
+ Puppet.deprecation_warning "Dynamic lookup of $#{name}#{location} is deprecated. Support will be removed in Puppet 2.8. Use a fully-qualified variable name (e.g., $classname::variable) or parameterized classes."
end
table[name]
elsif parent
@@ -443,6 +443,6 @@ class Puppet::Parser::Scope
def extend_with_functions_module
extend Puppet::Parser::Functions.environment_module(Puppet::Node::Environment.root)
- extend Puppet::Parser::Functions.environment_module(compiler ? environment : nil)
+ extend Puppet::Parser::Functions.environment_module(environment)
end
end