summaryrefslogtreecommitdiffstats
path: root/lib/puppet/node
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2010-08-13 15:43:34 -0700
committerPaul Berry <paul@puppetlabs.com>2010-08-13 15:54:26 -0700
commit4da88fb4cd57871f16649d50572240ac3f7420f0 (patch)
tree1b0df4e444bc27f925aac293cf721fa7acee06f7 /lib/puppet/node
parentcaca187dffbd6e628d7eda599c7f2939dd05fafc (diff)
downloadpuppet-4da88fb4cd57871f16649d50572240ac3f7420f0.tar.gz
puppet-4da88fb4cd57871f16649d50572240ac3f7420f0.tar.xz
puppet-4da88fb4cd57871f16649d50572240ac3f7420f0.zip
[#4496]+[#4521]+[#4522] Add structures to the AST to represent type definitions (classes, definitions, and nodes).
Previously, type definitions were not represented directly in the AST. Instead, the parser would instantiate types and insert them into known_resource_types as soon as they were parsed. This made it difficult to distinguish which types had come from the file that was just parsed and which types had been loaded previously, which led to bug 4496. A side-effect of this change is that the user is no longer allowed to define types inside of conditional constructs (such as if/else). This was allowed before but had unexpected semantics (bugs 4521 and 4522). It is still possible, however, to place an "include" statement inside a conditional construct, and have that "include" statement trigger the autoloading of a file that instantiates types.
Diffstat (limited to 'lib/puppet/node')
-rw-r--r--lib/puppet/node/environment.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index ad11a0476..3d55ac1a0 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -81,7 +81,7 @@ class Puppet::Node::Environment
Thread.current[:known_resource_types] ||= synchronize {
if @known_resource_types.nil? or @known_resource_types.stale?
@known_resource_types = Puppet::Resource::TypeCollection.new(self)
- perform_initial_import
+ @known_resource_types.import_ast(perform_initial_import, '')
end
@known_resource_types
}
@@ -146,13 +146,13 @@ class Puppet::Node::Environment
private
def perform_initial_import
- return if Puppet.settings[:ignoreimport]
+ return empty_parse_result if Puppet.settings[:ignoreimport]
parser = Puppet::Parser::Parser.new(self)
if code = Puppet.settings.uninterpolated_value(:code, name.to_s) and code != ""
parser.string = code
else
file = Puppet.settings.value(:manifest, name.to_s)
- return unless File.exist?(file)
+ return empty_parse_result unless File.exist?(file)
parser.file = file
end
parser.parse
@@ -163,5 +163,11 @@ class Puppet::Node::Environment
raise error
end
+ def empty_parse_result
+ # Return an empty toplevel hostclass to use as the result of
+ # perform_initial_import when no file was actually loaded.
+ return Puppet::Parser::AST::Hostclass.new('')
+ end
+
@root = new(:'*root*')
end