[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Jesse Wolfe jes5199 at gmail.com
Tue May 10 08:08:38 UTC 2011


The following commit has been merged in the experimental branch:
commit daaa048a8d8829ad509b4a456826cc8a33cf6444
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Thu Mar 24 17:51:59 2011 -0700

    (#5477) Allow watch_file to watch non-existent files, especially site.pp
    
    The watch_file mechanism would refuse to monitor paths to files that
    didn't exist. This patch makes it possible to watch a file that hasn't
    been created yet, so when it is created, you manifests will get
    reparsed.
    
    Paired-With: Max Martin <max at puppetlabs.com>
    Reviewed-By: Jacob Helwig <jacob at puppetlabs.com>

diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index 7877b7f..d505306 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -76,7 +76,7 @@ class Puppet::Node::Environment
     # per environment semantics with an efficient most common cases; we almost
     # always just return our thread's known-resource types.  Only at the start
     # of a compilation (after our thread var has been set to nil) or when the
-    # environment has changed do we delve deeper. 
+    # environment has changed do we delve deeper.
     Thread.current[:known_resource_types] = nil if (krt = Thread.current[:known_resource_types]) && krt.environment != self
     Thread.current[:known_resource_types] ||= synchronize {
       if @known_resource_types.nil? or @known_resource_types.stale?
@@ -128,7 +128,7 @@ class Puppet::Node::Environment
     to_s.to_sym
   end
 
-  # The only thing we care about when serializing an environment is its 
+  # The only thing we care about when serializing an environment is its
   # identity; everything else is ephemeral and should not be stored or
   # transmitted.
   def to_zaml(z)
@@ -156,7 +156,6 @@ class Puppet::Node::Environment
       parser.string = code
     else
       file = Puppet.settings.value(:manifest, name.to_s)
-      return empty_parse_result unless File.exist?(file)
       parser.file = file
     end
     parser.parse
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 4050ade..2f41661 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -312,7 +312,8 @@ class Puppet::Parser::Lexer
   def file=(file)
     @file = file
     @line = 1
-    @scanner = StringScanner.new(File.read(file))
+    contents = File.exists?(file) ? File.read(file) : ""
+    @scanner = StringScanner.new(contents)
   end
 
   def shift_token
@@ -547,7 +548,7 @@ class Puppet::Parser::Lexer
     value,terminator = slurpstring('"$')
     token_queue << [TOKENS[token_type[terminator]],preamble+value]
     if terminator != '$' or @scanner.scan(/\{/)
-      token_queue.shift 
+      token_queue.shift
     elsif var_name = @scanner.scan(%r{(\w*::)*\w+|[0-9]})
       token_queue << [TOKENS[:VARIABLE],var_name]
       tokenize_interpolated_string(DQ_continuation_token_types)
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 746aa0f..7888fe1 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -79,7 +79,6 @@ class Puppet::Parser::Parser
       unless file =~ /\.pp$/
         file = file + ".pp"
       end
-      raise Puppet::Error, "Could not find file #{file}" unless FileTest.exist?(file)
     end
     raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file)
 
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
index e39aa87..ed71a64 100644
--- a/lib/puppet/simple_graph.rb
+++ b/lib/puppet/simple_graph.rb
@@ -367,7 +367,7 @@ class Puppet::SimpleGraph
     return [] unless ns = (options[:direction] == :in) ? @in_to[v] : @out_from[v]
     (options[:type] == :edges) ? ns.values.flatten : ns.keys
   end
-  
+
   # Take container information from another graph and use it
   # to replace any container vertices with their respective leaves.
   # This creates direct relationships where there were previously
@@ -387,7 +387,7 @@ class Puppet::SimpleGraph
       children = other.adjacent(container, :direction => :out)
 
       # MQR TODO: Luke suggests that it should be possible to refactor the system so that
-      #           container nodes are retained, thus obviating the need for the whit. 
+      #           container nodes are retained, thus obviating the need for the whit.
       children = [whit_class.new(:name => container.name, :catalog => other)] if children.empty?
 
       # First create new edges for each of the :in edges
diff --git a/lib/puppet/util/loadedfile.rb b/lib/puppet/util/loadedfile.rb
index 735dba4..d2f5d09 100755
--- a/lib/puppet/util/loadedfile.rb
+++ b/lib/puppet/util/loadedfile.rb
@@ -34,10 +34,6 @@ module Puppet
     # Create the file.  Must be passed the file path.
     def initialize(file)
       @file = file
-      unless FileTest.exists?(@file)
-        raise Puppet::NoSuchFile,
-          "Can not use a non-existent file for parsing"
-      end
       @statted = 0
       @stamp = nil
       @tstamp = stamp
@@ -50,7 +46,7 @@ module Puppet
         @statted = Time.now.to_i
         begin
           @stamp = File.stat(@file).ctime
-        rescue Errno::ENOENT
+        rescue Errno::ENOENT, Errno::ENOTDIR
           @stamp = Time.now
         end
       end
diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb
index 153be5f..05527e7 100755
--- a/spec/unit/node/environment_spec.rb
+++ b/spec/unit/node/environment_spec.rb
@@ -6,6 +6,7 @@ require 'puppet/node/environment'
 require 'puppet/util/execution'
 
 describe Puppet::Node::Environment do
+  include PuppetSpec::Files
   after do
     Puppet::Node::Environment.clear
   end
@@ -276,16 +277,11 @@ describe Puppet::Node::Environment do
 
   describe "when performing initial import" do
     before do
-      @parser = stub 'parser', :file= => nil, :string => nil, :parse => nil
+      @parser = stub 'parser'
       Puppet::Parser::Parser.stubs(:new).returns @parser
       @env = Puppet::Node::Environment.new("env")
     end
 
-    it "should create a new parser instance" do
-      Puppet::Parser::Parser.expects(:new).returns @parser
-      @env.instance_eval { perform_initial_import }
-    end
-
     it "should set the parser's string to the 'code' setting and parse if code is available" do
       Puppet.settings[:code] = "my code"
       @parser.expects(:string=).with "my code"
@@ -294,25 +290,26 @@ describe Puppet::Node::Environment do
     end
 
     it "should set the parser's file to the 'manifest' setting and parse if no code is available and the manifest is available" do
-      File.stubs(:expand_path).with("/my/file").returns "/my/file"
-      File.expects(:exist?).with("/my/file").returns true
-      Puppet.settings[:manifest] = "/my/file"
-      @parser.expects(:file=).with "/my/file"
+      filename = tmpfile('myfile')
+      File.open(filename, 'w'){|f| }
+      Puppet.settings[:manifest] = filename
+      @parser.expects(:file=).with filename
       @parser.expects(:parse)
       @env.instance_eval { perform_initial_import }
     end
 
-    it "should not attempt to load a manifest if none is present" do
-      File.stubs(:expand_path).with("/my/file").returns "/my/file"
-      File.expects(:exist?).with("/my/file").returns false
-      Puppet.settings[:manifest] = "/my/file"
-      @parser.expects(:file=).never
-      @parser.expects(:parse).never
+    it "should pass the manifest file to the parser even if it does not exist on disk" do
+      filename = tmpfile('myfile')
+      Puppet.settings[:code] = ""
+      Puppet.settings[:manifest] = filename
+      @parser.expects(:file=).with(filename).once
+      @parser.expects(:parse).once
       @env.instance_eval { perform_initial_import }
     end
 
     it "should fail helpfully if there is an error importing" do
       File.stubs(:exist?).returns true
+      @parser.expects(:file=).once
       @parser.expects(:parse).raises ArgumentError
       lambda { @env.instance_eval { perform_initial_import } }.should raise_error(Puppet::Error)
     end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 96df613..bc9e22e 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -676,3 +676,15 @@ describe "Puppet::Parser::Lexer in the old tests when lexing example files" do
     end
   end
 end
+
+describe "when trying to lex an non-existent file" do
+  include PuppetSpec::Files
+
+  it "should return an empty list of tokens" do
+    lexer = Puppet::Parser::Lexer.new
+    lexer.file = nofile = tmpfile('lexer')
+    File.exists?(nofile).should == false
+
+    lexer.fullscan.should == [[false,false]]
+  end
+end
diff --git a/spec/unit/util/loadedfile_spec.rb b/spec/unit/util/loadedfile_spec.rb
index 23d2766..92daeb9 100755
--- a/spec/unit/util/loadedfile_spec.rb
+++ b/spec/unit/util/loadedfile_spec.rb
@@ -6,6 +6,7 @@ require 'tempfile'
 require 'puppet/util/loadedfile'
 
 describe Puppet::Util::LoadedFile do
+  include PuppetSpec::Files
   before(:each) do
     @f = Tempfile.new('loadedfile_test')
     @f.puts "yayness"
@@ -18,6 +19,12 @@ describe Puppet::Util::LoadedFile do
     @fake_now = Time.now + (2 * Puppet[:filetimeout])
   end
 
+  it "should accept files that don't exist" do
+    nofile = tmpfile('testfile')
+    File.exists?(nofile).should == false
+    lambda{ Puppet::Util::LoadedFile.new(nofile) }.should_not raise_error
+  end
+
   it "should recognize when the file has not changed" do
     # Use fake "now" so that we can be sure changed? actually checks, without sleeping
     # for Puppet[:filetimeout] seconds.
diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb
index ab54c8c..f118dc9 100755
--- a/spec/unit/util/rdoc/parser_spec.rb
+++ b/spec/unit/util/rdoc/parser_spec.rb
@@ -20,8 +20,9 @@ describe RDoc::Parser do
       @parser.stubs(:scan_top_level)
       parser = stub 'parser'
       Puppet::Parser::Parser.stubs(:new).returns(parser)
-      parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
+      parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once
       parser.expects(:file=).with("module/manifests/init.pp")
+      parser.expects(:file=).with("/dev/null/manifests/site.pp")
 
       @parser.scan
     end
@@ -29,7 +30,7 @@ describe RDoc::Parser do
     it "should scan the ast for Puppet files" do
       parser = stub_everything 'parser'
       Puppet::Parser::Parser.stubs(:new).returns(parser)
-      parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
+      parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once
 
       @parser.expects(:scan_top_level)
 
@@ -39,7 +40,7 @@ describe RDoc::Parser do
     it "should return a PuppetTopLevel to RDoc" do
       parser = stub_everything 'parser'
       Puppet::Parser::Parser.stubs(:new).returns(parser)
-      parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
+      parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once
 
       @parser.expects(:scan_top_level)
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list