diff options
author | Luke Kanies <luke@madstop.com> | 2008-10-27 12:10:36 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-11-04 16:20:45 -0600 |
commit | b4f4866b452cad870e635a8c97e265bd47e3f5ff (patch) | |
tree | ee2e38027c9b6408561d8769bbcfabbd73e0189c | |
parent | caf15c27b84f2777d68e569cea11ef9534c44ed4 (diff) | |
download | puppet-b4f4866b452cad870e635a8c97e265bd47e3f5ff.tar.gz puppet-b4f4866b452cad870e635a8c97e265bd47e3f5ff.tar.xz puppet-b4f4866b452cad870e635a8c97e265bd47e3f5ff.zip |
Making it so (once again) files with sources set can still be deleted
(which I think is kinda stupid, but apparently people want it).
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/type/file.rb | 3 | ||||
-rwxr-xr-x | lib/puppet/type/file/source.rb | 3 | ||||
-rwxr-xr-x | spec/integration/type/file.rb | 35 | ||||
-rwxr-xr-x | spec/unit/type/file/source.rb | 10 | ||||
-rwxr-xr-x | test/ral/type/file.rb | 47 |
5 files changed, 48 insertions, 50 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 155cf62f4..24ffc4a95 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -691,8 +691,7 @@ module Puppet } # If the file doesn't exist but we have a source, then call - # retrieve on the source property so it will set the 'should' - # values all around. + # set our 'should' values based on the source file. if @parameters.include?(:source) @parameters[:source].copy_source_values end diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index 60d4a5708..04a6931f9 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -129,7 +129,8 @@ module Puppet end end - @resource[:ensure] = metadata.ftype + # Set the 'ensure' value, unless we're trying to delete the file. + @resource[:ensure] = metadata.ftype unless @resource[:ensure] == :absent if metadata.ftype == "link" @resource[:target] = metadata.destination diff --git a/spec/integration/type/file.rb b/spec/integration/type/file.rb index 7d5a0c280..7f5e9cbac 100755 --- a/spec/integration/type/file.rb +++ b/spec/integration/type/file.rb @@ -178,4 +178,39 @@ describe Puppet::Type.type(:file) do end end + + it "should create files with content if both 'content' and 'ensure' are set" do + dest = tmpfile("files_with_content") + + file = Puppet.type(:file).create( + :name => dest, + :ensure => "file", + :content => "this is some content, yo" + ) + + catalog = Puppet::Node::Catalog.new + catalog.add_resource file + catalog.apply + + File.read(dest).should == "this is some content, yo" + end + + it "should delete files with sources but that are set for deletion" do + dest = tmpfile("dest_source_with_ensure") + source = tmpfile("source_source_with_ensure") + File.open(source, "w") { |f| f.puts "yay" } + File.open(dest, "w") { |f| f.puts "boo" } + + file = Puppet.type(:file).create( + :name => dest, + :ensure => :absent, + :source => source + ) + + catalog = Puppet::Node::Catalog.new + catalog.add_resource file + catalog.apply + + File.should_not be_exist(dest) + end end diff --git a/spec/unit/type/file/source.rb b/spec/unit/type/file/source.rb index 5a677e725..2bb19eecc 100755 --- a/spec/unit/type/file/source.rb +++ b/spec/unit/type/file/source.rb @@ -122,6 +122,16 @@ describe Puppet::Type.type(:file).attrclass(:source) do @source.copy_source_values end + it "should not set 'ensure' if it is already set to 'absent'" do + @resource.stubs(:[]) + @resource.stubs(:[]=) + @metadata.stubs(:ftype).returns "foobar" + + @resource.expects(:[]).with(:ensure).returns :absent + @resource.expects(:[]=).with(:ensure, "foobar").never + @source.copy_source_values + end + describe "and the source is a file" do before do @metadata.stubs(:ftype).returns "file" diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb index f14281d33..255b9e7eb 100755 --- a/test/ral/type/file.rb +++ b/test/ral/type/file.rb @@ -741,53 +741,6 @@ class TestFile < Test::Unit::TestCase assert_events([], file) end - # Make sure that content gets used before ensure - def test_contentbeatsensure - dest = tempfile() - - file = nil - assert_nothing_raised { - file = Puppet.type(:file).create( - :name => dest, - :ensure => "file", - :content => "this is some content, yo" - ) - } - - currentvalues = file.retrieve - - assert_events([:file_created], file) - file.retrieve - assert_events([], file) - assert_events([], file) - end - - # Make sure that content gets used before ensure - def test_deletion_beats_source - dest = tempfile() - source = tempfile() - File.open(source, "w") { |f| f.puts "yay" } - - file = nil - assert_nothing_raised { - file = Puppet.type(:file).create( - :name => dest, - :ensure => :absent, - :source => source - ) - } - - file.retrieve - - assert_events([], file) - assert(! FileTest.exists?(dest), "file was copied during deletion") - - # Now create the dest, and make sure it gets deleted - File.open(dest, "w") { |f| f.puts "boo" } - assert_events([:file_removed], file) - assert(! FileTest.exists?(dest), "file was not deleted during deletion") - end - def test_nameandpath path = tempfile() |