[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

Markus Roberts Markus at reality.com
Wed Jul 14 10:36:50 UTC 2010


The following commit has been merged in the upstream branch:
commit 62dbae53f89e8d9597081c7b7c0a20b419e4737a
Author: Markus Roberts <Markus at reality.com>
Date:   Wed Jul 7 23:56:47 2010 -0700

    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*

diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 4357a3a..0a9d080 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 67bfc37..31dc196 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
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list