Please review pull request #660: (#13204) Don't ignore missing PATH.augnew files opened by (domcleal)

Description:

This is a followup to pull req #587, where a better solution was discussed that doesn't squash other errors.

Commit log:
The original fix for #13204 may have masked other potential bugs if the
PATH.augnew file was missing. It simply tested for the file existance and not
only when duplicate save events occurred.

This change de-duplicates the list of save events instead, so if a bug appeared
where PATH.augnew was genuinely missing, the error wouldn't be squashed.

  • Opened: Wed Apr 11 22:54:26 UTC 2012
  • Based on: puppetlabs:2.7.x (cb505786b6c306d6972aaf24cdd62409fa7a001f)
  • Requested merge: domcleal:tickets/2.7.x/13204-aug-boot-enoent-uniq (c01cac95f3985fcfe4404ef2ea6f5167806836ce)

Diff follows:

diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 7681909..6998121 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -297,9 +297,8 @@ def need_to_run?
           saved_files = @aug.match("/augeas/events/saved")
           if saved_files.size > 0
             root = resource[:root].sub(/^\/$/, "")
-            saved_files.each do |key|
-              saved_file = @aug.get(key).sub(/^\/files/, root)
-              next unless File.exists?(saved_file + ".augnew")
+            saved_files.map! {|key| @aug.get(key).sub(/^\/files/, root) }
+            saved_files.uniq.each do |saved_file|
               if Puppet[:show_diff]
                 notice "\n" + diff(saved_file, saved_file + ".augnew")
               end
diff --git a/spec/unit/provider/augeas/augeas_spec.rb b/spec/unit/provider/augeas/augeas_spec.rb
index 36bcdfa..9385c0c 100755
--- a/spec/unit/provider/augeas/augeas_spec.rb
+++ b/spec/unit/provider/augeas/augeas_spec.rb
@@ -329,7 +329,6 @@
       it "should call diff when a file is shown to have been changed" do
         file = "/etc/hosts"
         File.stubs(:delete)
-        File.stubs(:exists?).returns(true)
 
         @resource[:context] = "/files"
         @resource[:changes] = ["set #{file}/foo bar"]
@@ -347,7 +346,6 @@
         file1 = "/etc/hosts"
         file2 = "/etc/resolv.conf"
         File.stubs(:delete)
-        File.stubs(:exists?).returns(true)
 
         @resource[:context] = "/files"
         @resource[:changes] = ["set #{file1}/foo bar", "set #{file2}/baz biz"]
@@ -368,7 +366,6 @@
           root = "/tmp/foo"
           file = "/etc/hosts"
           File.stubs(:delete)
-          File.stubs(:exists?).returns(true)
 
           @resource[:context] = "/files"
           @resource[:changes] = ["set #{file}/foo bar"]
@@ -401,7 +398,6 @@
 
       it "should cleanup the .augnew file" do
         file = "/etc/hosts"
-        File.stubs(:exists?).returns(true)
 
         @resource[:context] = "/files"
         @resource[:changes] = ["set #{file}/foo bar"]
@@ -421,11 +417,6 @@
       it "should handle duplicate /augeas/events/saved filenames" do
         file = "/etc/hosts"
 
-        augnew = states("augnew").starts_as("present")
-
-        File.stubs(:exists?).returns(true).when(augnew.is("present"))
-        File.stubs(:exists?).returns(false).when(augnew.is("absent"))
-
         @resource[:context] = "/files"
         @resource[:changes] = ["set #{file}/foo bar"]
 
@@ -435,9 +426,9 @@
         @augeas.expects(:set).with("/augeas/save", "newfile")
         @augeas.expects(:close)
 
-        File.expects(:delete).with(file + ".augnew").when(augnew.is("present")).then(augnew.is("absent"))
+        File.expects(:delete).with(file + ".augnew").once()
 
-        @provider.expects(:diff).with("#{file}", "#{file}.augnew").returns("").when(augnew.is("present"))
+        @provider.expects(:diff).with("#{file}", "#{file}.augnew").returns("").once()
         @provider.should be_need_to_run
       end
 

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to