diff options
Diffstat (limited to 'lib/puppet/parser/compile.rb')
-rw-r--r-- | lib/puppet/parser/compile.rb | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb index 992b165e5..93ba180a7 100644 --- a/lib/puppet/parser/compile.rb +++ b/lib/puppet/parser/compile.rb @@ -14,7 +14,7 @@ require 'puppet/util/errors' class Puppet::Parser::Compile include Puppet::Util include Puppet::Util::Errors - attr_reader :topscope, :parser, :node, :facts, :collections, :configuration + attr_reader :parser, :node, :facts, :collections, :configuration, :node_scope # Add a collection to the global list. def add_collection(coll) @@ -83,12 +83,12 @@ class Puppet::Parser::Compile return @configuration end - # FIXME There are no tests for this. + # LAK:FIXME There are no tests for this. def delete_collection(coll) @collections.delete(coll) if @collections.include?(coll) end - # FIXME There are no tests for this. + # LAK:FIXME There are no tests for this. def delete_resource(resource) @resource_table.delete(resource.ref) if @resource_table.include?(resource.ref) end @@ -107,14 +107,14 @@ class Puppet::Parser::Compile # Evaluate all of the classes specified by the node. def evaluate_node_classes - evaluate_classes(@node.classes, @topscope) + evaluate_classes(@node.classes, topscope) end # Evaluate each specified class in turn. If there are any classes we can't # find, just tag the configuration and move on. This method really just # creates resource objects that point back to the classes, and then the # resources are themselves evaluated later in the process. - def evaluate_classes(classes, scope) + def evaluate_classes(classes, scope, lazy_evaluate = true) unless scope.source raise Puppet::DevError, "No source for scope passed to evaluate_classes" end @@ -126,6 +126,10 @@ class Puppet::Parser::Compile # of resources. resource = Puppet::Parser::Resource.new(:type => "class", :title => klass.classname, :scope => scope, :source => scope.source) store_resource(scope, resource) + + # If they've disabled lazy evaluation (which the :include function does), + # then evaluate our resource immediately. + resource.evaluate unless lazy_evaluate @configuration.tag(klass.classname) found << name else @@ -138,9 +142,7 @@ class Puppet::Parser::Compile # Return a resource by either its ref or its type and title. def findresource(string, name = nil) - if name - string = "%s[%s]" % [string.capitalize, name] - end + string = "%s[%s]" % [string.capitalize, name] if name @resource_table[string] end @@ -169,7 +171,7 @@ class Puppet::Parser::Compile # using the top scope. Adds an edge between the scope and # its parent to the graph. def newscope(parent, options = {}) - parent ||= @topscope + parent ||= topscope options[:compile] = self options[:parser] ||= self.parser scope = Puppet::Parser::Scope.new(options) @@ -225,6 +227,12 @@ class Puppet::Parser::Compile @configuration.add_edge!(scope.resource, resource) end + # The top scope is usually the top-level scope, but if we're using AST nodes, + # then it is instead the node's scope. + def topscope + node_scope || @topscope + end + private # If ast nodes are enabled, then see if we can find and evaluate one. @@ -237,10 +245,7 @@ class Puppet::Parser::Compile break if astnode = @parser.nodes[name.to_s.downcase] end - unless astnode - astnode = @parser.nodes["default"] - end - unless astnode + unless (astnode ||= @parser.nodes["default"]) raise Puppet::ParseError, "Could not find default node or by name with '%s'" % node.names.join(", ") end @@ -249,6 +254,12 @@ class Puppet::Parser::Compile resource = Puppet::Parser::Resource.new(:type => "node", :title => astnode.classname, :scope => topscope, :source => topscope.source) store_resource(topscope, resource) @configuration.tag(astnode.classname) + + resource.evaluate + + # Now set the node scope appropriately, so that :topscope can + # behave differently. + @node_scope = class_scope(astnode) end # Evaluate our collections and return true if anything returned an object. @@ -258,10 +269,11 @@ class Puppet::Parser::Compile found_something = false exceptwrap do - @collections.each do |collection| - if collection.evaluate - found_something = true - end + # We have to iterate over a dup of the array because + # collections can delete themselves from the list, which + # changes its length and causes some collections to get missed. + @collections.dup.each do |collection| + found_something = true if collection.evaluate end end @@ -314,6 +326,8 @@ class Puppet::Parser::Compile @configuration.add_vertex!(@main_resource) @resource_table["Class[main]"] = @main_resource + + @main_resource.evaluate end # Make sure the entire configuration is evaluated. @@ -404,7 +418,6 @@ class Puppet::Parser::Compile # A graph for maintaining scope relationships. @scope_graph = GRATR::Digraph.new - @scope_graph.add_vertex!(@topscope) # For maintaining the relationship between scopes and their resources. @configuration = Puppet::Node::Configuration.new(@node.name) |