summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Meier <peter.meier@immerda.ch>2012-05-23 21:42:07 +0200
committerJeff McCune <jeff@puppetlabs.com>2012-11-26 10:35:18 -0800
commitdfcee63afb19d72677f177e83ce237765cccf0f7 (patch)
tree55ccb083e1a5720ad59a74f0d9c04ba6b832099f
parent6c104e5e3ab8cc01749b52efcfd303d05a0964d4 (diff)
downloadpuppet-stdlib-dfcee63afb19d72677f177e83ce237765cccf0f7.tar.gz
puppet-stdlib-dfcee63afb19d72677f177e83ce237765cccf0f7.tar.bz2
(#14670) autorequire a file_line resource's path
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.
-rw-r--r--lib/puppet/type/file_line.rb5
-rw-r--r--spec/unit/puppet/type/file_line_spec.rb19
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 6b35902..f71a4bc 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -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")
diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb
index e1c07ac..1fa8e84 100644
--- a/spec/unit/puppet/type/file_line_spec.rb
+++ b/spec/unit/puppet/type/file_line_spec.rb
@@ -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