diff options
-rw-r--r-- | lib/puppet/network/handler/configuration.rb | 6 | ||||
-rw-r--r-- | lib/puppet/network/handler/master.rb | 13 | ||||
-rw-r--r-- | lib/puppet/node/configuration.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/compile.rb | 9 | ||||
-rwxr-xr-x | spec/unit/parser/compile.rb | 20 | ||||
-rwxr-xr-x | test/language/ast.rb | 10 | ||||
-rwxr-xr-x | test/language/compile.rb | 7 | ||||
-rwxr-xr-x | test/language/functions.rb | 16 | ||||
-rwxr-xr-x | test/language/parser.rb | 2 | ||||
-rwxr-xr-x | test/language/scope.rb | 8 | ||||
-rw-r--r-- | test/lib/puppettest/parsertesting.rb | 2 | ||||
-rw-r--r-- | test/lib/puppettest/resourcetesting.rb | 15 |
12 files changed, 53 insertions, 57 deletions
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb index 1dbb16370..05c86f22e 100644 --- a/lib/puppet/network/handler/configuration.rb +++ b/lib/puppet/network/handler/configuration.rb @@ -37,7 +37,9 @@ class Puppet::Network::Handler # Add any external data to the node. add_node_data(node) - return translate(compile(node)) + configuration = compile(node) + + return translate(configuration) end def initialize(options = {}) @@ -214,5 +216,3 @@ class Puppet::Network::Handler end end end - -# $Id$ diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index ace383e9f..18f37ca4a 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -77,7 +77,9 @@ class Puppet::Network::Handler fact_handler.set(client, facts) # And get the configuration from the config handler - return config_handler.configuration(client) + config = config_handler.configuration(client) + + return translate(config.extract) end def local=(val) @@ -139,5 +141,14 @@ class Puppet::Network::Handler end @fact_handler end + + # Translate our configuration appropriately for sending back to a client. + def translate(config) + if local? + config + else + CGI.escape(config.to_yaml(:UseBlock => true)) + end + end end end diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb index e667007e9..4f93fdbe5 100644 --- a/lib/puppet/node/configuration.rb +++ b/lib/puppet/node/configuration.rb @@ -5,7 +5,7 @@ require 'puppet/external/gratr/digraph' # of the information in the configuration, including the resources # and the relationships between them. class Puppet::Node::Configuration < GRATR::Digraph - attr_accessor :name + attr_accessor :name, :version attr_reader :extraction_format # Add classes to our class list. diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb index 841e58d4d..cc9938e50 100644 --- a/lib/puppet/parser/compile.rb +++ b/lib/puppet/parser/compile.rb @@ -82,7 +82,7 @@ class Puppet::Parser::Compile store() end - return @configuration.extract + return @configuration end # FIXME There are no tests for this. @@ -117,13 +117,13 @@ class Puppet::Parser::Compile # 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) + unless scope.source + raise Puppet::DevError, "No source for scope passed to evaluate_classes" + end found = [] classes.each do |name| # If we can find the class, then make a resource that will evaluate it. if klass = scope.findclass(name) - unless scope.source - raise Puppet::DevError, "No source for %s" % scope.to_s - end # Create a resource to model this class, and then add it to the list # of resources. resource = Puppet::Parser::Resource.new(:type => "class", :title => klass.classname, :scope => scope, :source => scope.source) @@ -406,6 +406,7 @@ class Puppet::Parser::Compile # For maintaining the relationship between scopes and their resources. @configuration = Puppet::Node::Configuration.new(@node.name) + @configuration.version = @parser.version end # Set the node's parameters into the top-scope as variables. diff --git a/spec/unit/parser/compile.rb b/spec/unit/parser/compile.rb index d22b63545..f6b3c9b3f 100755 --- a/spec/unit/parser/compile.rb +++ b/spec/unit/parser/compile.rb @@ -4,8 +4,8 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser::Compile, " when compiling" do before do - @node = mock 'node' - @parser = mock 'parser' + @node = stub 'node', :name => 'mynode' + @parser = stub 'parser', :version => "1.0" @compile = Puppet::Parser::Compile.new(@node, @parser) end @@ -31,10 +31,8 @@ describe Puppet::Parser::Compile, " when compiling" do it "should evaluate any existing classes named in the node" do classes = %w{one two three four} main = stub 'main' - one = stub 'one' - one.expects(:safeevaluate).with(:scope => @compile.topscope) - three = stub 'three' - three.expects(:safeevaluate).with(:scope => @compile.topscope) + one = stub 'one', :classname => "one" + three = stub 'three', :classname => "three" @node.stubs(:name).returns("whatever") @compile.parser.expects(:findclass).with("", "").returns(main) @compile.parser.expects(:findclass).with("", "one").returns(one) @@ -42,7 +40,13 @@ describe Puppet::Parser::Compile, " when compiling" do @compile.parser.expects(:findclass).with("", "three").returns(three) @compile.parser.expects(:findclass).with("", "four").returns(nil) @node.stubs(:classes).returns(classes) - compile_stub(:evaluate_node_classes) - @compile.compile + @compile.send :evaluate_main + @compile.send :evaluate_node_classes + + # Now make sure we've created the appropriate resources. + @compile.resources.find { |r| r.to_s == "Class[one]" }.should be_an_instance_of(Puppet::Parser::Resource) + @compile.resources.find { |r| r.to_s == "Class[three]" }.should be_an_instance_of(Puppet::Parser::Resource) + @compile.resources.find { |r| r.to_s == "Class[two]" }.should be_nil + @compile.resources.find { |r| r.to_s == "Class[four]" }.should be_nil end end diff --git a/test/language/ast.rb b/test/language/ast.rb index f62b2340c..dbc1d04ed 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -68,7 +68,7 @@ class TestAST < Test::Unit::TestCase # make sure our resourcedefaults ast object works correctly. def test_resourcedefaults - interp, scope, source = mkclassframing + scope = mkscope # Now make some defaults for files args = {:source => "/yay/ness", :group => "yayness"} @@ -166,16 +166,16 @@ class TestAST < Test::Unit::TestCase end def test_virtual_collexp - @interp, @scope, @source = mkclassframing + scope = mkscope # make a resource resource = mkresource(:type => "file", :title => "/tmp/testing", - :params => {:owner => "root", :group => "bin", :mode => "644"}) + :scope => scope, :params => {:owner => "root", :group => "bin", :mode => "644"}) run_collection_queries(:virtual) do |string, result, query| code = nil assert_nothing_raised do - str, code = query.evaluate :scope => @scope + str, code = query.evaluate :scope => scope end assert_instance_of(Proc, code) @@ -186,5 +186,3 @@ class TestAST < Test::Unit::TestCase end end end - -# $Id$ diff --git a/test/language/compile.rb b/test/language/compile.rb index 0d9c9e32a..ceec3c346 100755 --- a/test/language/compile.rb +++ b/test/language/compile.rb @@ -23,7 +23,7 @@ class TestCompile < Test::Unit::TestCase def mkparser # This should mock an interpreter - @parser = mock 'parser' + @parser = stub 'parser', :version => "1.0" end def mkcompile(options = {}) @@ -38,7 +38,7 @@ class TestCompile < Test::Unit::TestCase def test_initialize compile = nil node = stub 'node', :name => "foo" - parser = mock 'parser' + parser = stub 'parser', :version => "1.0" assert_nothing_raised("Could not init compile with all required options") do compile = Compile.new(node, parser) end @@ -150,11 +150,10 @@ class TestCompile < Test::Unit::TestCase # The heart of the action. def test_compile compile = mkcompile - compile.instance_variable_get("@configuration").expects(:extract).returns(:config) [:set_node_parameters, :evaluate_main, :evaluate_ast_node, :evaluate_node_classes, :evaluate_generators, :fail_on_unevaluated, :finish].each do |method| compile.expects(method) end - assert_equal(:config, compile.compile, "Did not return the results of the extraction") + assert_instance_of(Puppet::Node::Configuration, compile.compile, "Did not return the configuration") end # Test setting the node's parameters into the top scope. diff --git a/test/language/functions.rb b/test/language/functions.rb index efa506218..395577cb6 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -213,14 +213,15 @@ class TestLangFunctions < Test::Unit::TestCase Puppet[:environment] = "yay" - version = interp.compile(node) - - objects = nil + configuration = nil assert_nothing_raised { - objects = interp.compile(node) + configuration = interp.compile(node) } - fileobj = objects[0] + version = configuration.version + + fileobj = configuration.vertices.find { |r| r.title == file } + assert(fileobj, "File was not in configuration") assert_equal("original text\n", fileobj["content"], "Template did not work") @@ -234,10 +235,7 @@ class TestLangFunctions < Test::Unit::TestCase f.puts "new text" end - assert_nothing_raised { - objects = interp.compile(node) - } - newversion = interp.compile(node) + newversion = interp.compile(node).version assert(version != newversion, "Parse date did not change") end diff --git a/test/language/parser.rb b/test/language/parser.rb index 36e058b11..ddf35e3e3 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -622,7 +622,7 @@ file { "/tmp/yayness": code = nil assert_nothing_raised do - code = interp.compile(mknode).flatten + code = interp.compile(mknode).extract.flatten end assert(code.length == 1, "Did not get the file") assert_instance_of(Puppet::TransObject, code[0]) diff --git a/test/language/scope.rb b/test/language/scope.rb index 213226241..b317fa4c8 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -419,17 +419,17 @@ Host <<||>>" ) } - objects = nil + config = nil # We run it twice because we want to make sure there's no conflict # if we pull it up from the database. node = mknode node.parameters = {"hostname" => node.name} 2.times { |i| assert_nothing_raised { - objects = interp.compile(node) + config = interp.compile(node) } - flat = objects.flatten + flat = config.extract.flatten %w{puppet myhost}.each do |name| assert(flat.find{|o| o.name == name }, "Did not find #{name}") @@ -441,7 +441,7 @@ Host <<||>>" end def test_namespaces - parser, scope, source = mkclassframing + scope = mkscope assert_equal([""], scope.namespaces, "Started out with incorrect namespaces") diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 9e90bbdd6..b8fd8bd83 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -316,7 +316,7 @@ module PuppetTest::ParserTesting comp = nil assert_nothing_raised { - comp = config.to_type + comp = config.extract.to_type } assert_apply(comp) diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb index 54154d504..325602c22 100644 --- a/test/lib/puppettest/resourcetesting.rb +++ b/test/lib/puppettest/resourcetesting.rb @@ -1,21 +1,6 @@ module PuppetTest::ResourceTesting Parser = Puppet::Parser AST = Puppet::Parser::AST - def mkclassframing(parser = nil) - parser ||= mkparser - - parser.newdefine("resource", :arguments => [%w{one}, %w{two value}, %w{three}]) - parser.newclass("") - source = parser.newclass("base") - parser.newclass("sub1", :parent => "base") - parser.newclass("sub2", :parent => "base") - parser.newclass("other") - - config = mkconfig(:parser => parser) - config.topscope.source = source - - return parser, config.topscope, source - end def mkevaltest(parser = nil) parser ||= mkparser |