From 5528911bd6fd784ed9550ed475f240a64c7a56fb Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Thu, 14 Apr 2011 15:53:51 -0700 Subject: (#7111) Clarify scoping deprecation warning This modifies the deprecation warning to explicitly point out that the specified behavior is deprecated, when it is slated to be removed, along with what the user can do to prepare for its removal. Paired-with: Randall Hansen --- lib/puppet/parser/scope.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 8de9d60b1..99f1c6ee2 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -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 -- cgit From a509821f6c2da0a07bc63af433f6e36061d4f241 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Thu, 14 Apr 2011 15:56:49 -0700 Subject: Cleanup trailing whitespace --- lib/puppet/parser/scope.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 99f1c6ee2..a8bb4418a 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -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]}" : '' -- cgit From b3ab0d94cb592189b3c553512dafe221775a0626 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Fri, 15 Apr 2011 09:52:56 -0700 Subject: (#4655) Allow stage to be set using a default class parameter For example: stage{ pre: before => Stage[main] } class someclass ($stage=pre ) { ... } class { someclass: } This transplants adding the edge from the resource to the stage from the compiler into when the resource is evaluated. This moves adding the stage edges to after when the defaults are copied into the resources, making them available. Paired-with: Jesse Wolfe --- lib/puppet/parser/compiler.rb | 19 ++++++++----------- lib/puppet/parser/resource.rb | 17 ++++++++++++++++- lib/puppet/parser/scope.rb | 4 ++-- 3 files changed, 26 insertions(+), 14 deletions(-) (limited to 'lib/puppet/parser') 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..cd0e8c742 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -62,13 +62,28 @@ 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 + 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..2da54fca5 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) @@ -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 -- cgit From 6981ee5f526e00f46f6b5460662bf09cddf832ef Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Wed, 20 Apr 2011 15:41:52 -0700 Subject: Maint: Fix a #4655 introduced log inconsistency When we moved code from the compiler to parser/resource, we lost a conditional that prevented defined resources from gaining containment edges to stages. Adding a stage to a defined resource was usually harmless, but it violated the invariant of "resources should only have exactly one container as their direct parent", producing a 50% chance of a malformed containment path in log messages. Reviewed-By: Jacob Helwig --- lib/puppet/parser/resource.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index cd0e8c742..3bb5f8601 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -66,6 +66,8 @@ class Puppet::Parser::Resource < Puppet::Resource # 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 -- cgit