diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-07 23:56:47 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-07 23:56:47 -0700 |
commit | 62dbae53f89e8d9597081c7b7c0a20b419e4737a (patch) | |
tree | ebec66cb5b51a8ce4be451dc9bcfa13b43fe2a54 | |
parent | a5fc3643105754f5b81f56a787553548537c529c (diff) | |
download | puppet-62dbae53f89e8d9597081c7b7c0a20b419e4737a.tar.gz puppet-62dbae53f89e8d9597081c7b7c0a20b419e4737a.tar.xz puppet-62dbae53f89e8d9597081c7b7c0a20b419e4737a.zip |
Fix for #2807 Puppet settings available as variables
This is Luke's patch plus a change to fix a test that it broke. It creates
a new sub-scope off the top scope, called "settings" and adds each of the
environment's settings to it as variables, thus satisfying the ticket while
taking us one step further from being able to implement futures. *sigh*
-rw-r--r-- | lib/puppet/parser/compiler.rb | 22 | ||||
-rwxr-xr-x | spec/unit/parser/compiler_spec.rb | 1 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index 4357a3a34..0a9d0804f 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -97,6 +97,7 @@ class Puppet::Parser::Compiler def compile # Set the client's parameters into the top scope. set_node_parameters() + create_settings_scope evaluate_main() @@ -447,7 +448,7 @@ class Puppet::Parser::Compiler @catalog.version = known_resource_types.version # Create our initial scope and a resource that will evaluate main. - @topscope = Puppet::Parser::Scope.new(:compiler => self, :source => 'implicit') + @topscope = Puppet::Parser::Scope.new(:compiler => self) @main_stage_resource = Puppet::Parser::Resource.new("stage", :main, :scope => @topscope) @catalog.add_resource(@main_stage_resource) @@ -470,6 +471,25 @@ class Puppet::Parser::Compiler catalog.server_version = node.parameters["serverversion"] end + def create_settings_scope + unless settings_type = environment.known_resource_types.hostclass("settings") + settings_type = Puppet::Resource::Type.new :hostclass, "settings" + environment.known_resource_types.add(settings_type) + end + + settings_resource = Puppet::Parser::Resource.new("class", "settings", :scope => @topscope) + settings_type.evaluate_code(settings_resource) + + @catalog.add_resource(settings_resource) + + scope = @topscope.class_scope(settings_type) + + Puppet.settings.each do |name, setting| + next if name.to_s == "name" + scope.setvar name.to_s, environment[name] + end + end + # Return an array of all of the unevaluated resources. These will be definitions, # which need to get evaluated into native resources. def unevaluated_resources diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb index 67bfc3749..31dc196ef 100755 --- a/spec/unit/parser/compiler_spec.rb +++ b/spec/unit/parser/compiler_spec.rb @@ -704,6 +704,7 @@ describe Puppet::Parser::Compiler do scope = stub 'scope', :source => "mysource" @compiler.topscope.expects(:class_scope).with(node_class).returns(scope) node_resource.stubs(:evaluate) + @compiler.stubs :create_settings_scope @compiler.compile |