From 2b50f30c703aca5c4f3e89961d64a94d886296bd Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 17 Sep 2010 17:59:56 -0700 Subject: [#4771] Import of manifests with the same name only happens once The function import_if_possible, which was supposed to be responsible for making sure that no two threads tried to import the same file at the same time, was not making this decision based on the full pathname of the file, since it was being invoked before pathnames were resolved. As a result, if we attempted to import two distinct files with the same name at the same time (either in two threads or in a single thread due to recursion), one of the files would not always get imported. Fixed this problem by moving the thread-safety logic to happen after filenames are resolved to absolute paths. This made it possible to simplify the thread-safety logic significantly. --- spec/unit/parser/type_loader_spec.rb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb index 83006b37b..02d543b02 100644 --- a/spec/unit/parser/type_loader_spec.rb +++ b/spec/unit/parser/type_loader_spec.rb @@ -77,13 +77,6 @@ describe Puppet::Parser::TypeLoader do @loader.load_until(["foo"], "bar") { |f| false }.should be_nil end - it "should know when a given name has been loaded" do - @loader.expects(:name2files).returns %w{file} - @loader.expects(:import).with("file",nil) - @loader.load_until(["foo"], "bar") { |f| true } - @loader.should be_loaded("file") - end - it "should set the module name on any created resource types" do type = Puppet::Resource::Type.new(:hostclass, "mytype") @@ -113,7 +106,8 @@ describe Puppet::Parser::TypeLoader do describe "when importing" do before do Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}] - @loader.stubs(:parse_file) + Puppet::Parser::Parser.any_instance.stubs(:parse) + Puppet::Parser::Parser.any_instance.stubs(:file=) end it "should return immediately when imports are being ignored" do @@ -154,16 +148,9 @@ describe Puppet::Parser::TypeLoader do @loader.import("myfile", "/current/file") end - it "should know when a given file has been imported" do - Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.import("myfile") - - @loader.should be_imported("/one") - end - it "should not attempt to import files that have already been imported" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.expects(:parse_file).once + Puppet::Parser::Parser.any_instance.expects(:parse).once @loader.import("myfile") # This will fail if it tries to reimport the file. -- cgit From f95006148c3a0b4d7e8ee1812b1993b674f050e4 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 3 Sep 2010 11:17:35 -0700 Subject: [#4716] ResourceTypeAPI exposes implementation details that are likely to change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made the following modifications to ResourceTypeAPI: (1) returned nil from “define”, “hostclass”, and “node”. (2) renamed “mk_resource_type” and “munge_type_arguments” to “__mk_resource_type__” and “__munge_type_arguments__” to discourage customers from calling them. (3) Made ResourceTypeAPI a class rather than a module, and changed the parser to evaluate the contents of pure ruby manifests using a instances of this class. (4) Changed ResourceTypeAPI to insert newly instantiated types into Thread.current[:known_resource_types] rather than the default environment's known_resource_types. This effectively backports the fix for issue #4657 to 2.6.x. Also backported the new spec tests from #4657. --- spec/unit/parser/parser_spec.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 0657ab37a..f73e07a5c 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -52,15 +52,6 @@ describe Puppet::Parser do @parser.file = "/my/file.rb" @parser.parse end - - describe "in ruby" do - it "should use the ruby interpreter to load the file" do - @parser.file = "/my/file.rb" - @parser.expects(:require).with "/my/file.rb" - - @parser.parse_ruby_file - end - end end describe "when parsing append operator" do -- cgit From 8cd1540f82cbdf903c164bdbc2c7229e34a4178b Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 17 Sep 2010 16:42:40 -0700 Subject: [#4692] undefined variables cause :undef to be passed to functions The :undef symbol, which we use internally to distinguish between undefined variables and variables whose value is the empty string, is being leaked in calls to functions (e.g. "split"). This is a departure from 0.25.x behavior, where undefined variables evaluated to "". This patch restores the 0.25.x behavior. --- spec/unit/parser/ast/function_spec.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/ast/function_spec.rb b/spec/unit/parser/ast/function_spec.rb index c57c7f098..38e344157 100644 --- a/spec/unit/parser/ast/function_spec.rb +++ b/spec/unit/parser/ast/function_spec.rb @@ -61,20 +61,30 @@ describe Puppet::Parser::AST::Function do end it "should call the underlying ruby function" do - argument = stub 'arg', :safeevaluate => "nothing" + argument = stub 'arg', :safeevaluate => ["nothing"] Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument - @scope.expects(:function_exist).with("nothing") + @scope.expects(:function_exist).with(["nothing"]) + + func.evaluate(@scope) + end + + it "should convert :undef to '' in arguments" do + argument = stub 'arg', :safeevaluate => ["foo", :undef, "bar"] + Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) + func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument + + @scope.expects(:function_exist).with(["foo", "", "bar"]) func.evaluate(@scope) end it "should return the ruby function return for rvalue functions" do - argument = stub 'arg', :safeevaluate => "nothing" + argument = stub 'arg', :safeevaluate => ["nothing"] Puppet::Parser::Functions.stubs(:function).with("exist").returns(true) func = Puppet::Parser::AST::Function.new :name => "exist", :ftype => :statement, :arguments => argument - @scope.stubs(:function_exist).with("nothing").returns("returning") + @scope.stubs(:function_exist).with(["nothing"]).returns("returning") func.evaluate(@scope).should == "returning" end -- cgit From 53a2bea4ddad0a9f0d537fd8833a437ed2376889 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Tue, 28 Sep 2010 11:50:56 -0700 Subject: Fix for #4804 -- escaped backslashes in interpolated strings Part of the ongoing refinement / cleanup of the string interpolation semantics. When scanning for an unescaped string terminator we now also allow an 0 or more pairs of backslashes (that is, escaped backslashes) before the terminator. Thanks to Jacob for the test I should have added. --- spec/unit/parser/lexer_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index b27980bf2..2d67bf357 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -30,6 +30,14 @@ describe Puppet::Parser::Lexer do @lexer.line.should == 10 end + + it "should not think the terminator is escaped, when preceeded by an even number of backslashes" do + @lexer.line = 10 + @lexer.string = "here\nis\nthe\nstring\\\\'with\nextra\njunk" + @lexer.slurpstring("'") + + @lexer.line.should == 13 + end end end -- cgit