]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(#14670) autorequire a file_line resource's path
authorPeter Meier <peter.meier@immerda.ch>
Wed, 23 May 2012 19:42:07 +0000 (21:42 +0200)
committerJeff McCune <jeff@puppetlabs.com>
Mon, 26 Nov 2012 18:35:18 +0000 (10:35 -0800)
If we manage a file we edit with file_line, it should be autorequired by
file_line.  Without this patch applied the relationship is not
automatically setup and the user is forced to manually manage the
relationship.

lib/puppet/type/file_line.rb
spec/unit/puppet/type/file_line_spec.rb

index 6b3590237eb04b4f4e72b0ccef1706ab64679e83..f71a4bc7b6f2c264a88d355f023a04d7e8b7004d 100644 (file)
@@ -50,6 +50,11 @@ Puppet::Type.newtype(:file_line) do
     end
   end
 
+  # Autorequire the file resource if it's being managed
+  autorequire(:file) do
+    self[:path]
+  end
+
   validate do
     unless self[:line] and self[:path]
       raise(Puppet::Error, "Both line and path are required attributes")
index e1c07ac6ea66b98d4b2926d21a659e343086111b..1fa8e8462286f60ce2f5855ff77eb6c73798fc71 100644 (file)
@@ -48,4 +48,23 @@ describe Puppet::Type.type(:file_line) do
   it 'should default to ensure => present' do
     file_line[:ensure].should eq :present
   end
+
+  it "should autorequire the file it manages" do
+    catalog = Puppet::Resource::Catalog.new
+    file = Puppet::Type.type(:file).new(:name => "/tmp/path")
+    catalog.add_resource file
+    catalog.add_resource file_line
+    reqs = file_line.autorequire
+    reqs.size.should eq 1
+    reqs[0].source.should eq file
+    reqs[0].target.should eq file_line
+  end
+
+  it "should not autorequire the file it manages if it is not managed" do
+    catalog = Puppet::Resource::Catalog.new
+    catalog.add_resource file_line
+    reqs = file_line.autorequire
+    reqs.size.should eq 0
+  end
+
 end