diff options
| author | Ian Ward Comfort <icomfort@stanford.edu> | 2011-02-17 17:23:29 -0800 |
|---|---|---|
| committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-04-22 11:10:59 -0700 |
| commit | f21162bdbae516d2613052d35a2f8bbd34d0bf86 (patch) | |
| tree | 41eb0d91a769542ef9b2eb5318db702e2f9f315a /spec | |
| parent | ea348761df0b5297dbac50c7f1c48d22746524fa (diff) | |
| download | puppet-f21162bdbae516d2613052d35a2f8bbd34d0bf86.tar.gz puppet-f21162bdbae516d2613052d35a2f8bbd34d0bf86.tar.xz puppet-f21162bdbae516d2613052d35a2f8bbd34d0bf86.zip | |
(#6368) Make the File type autorequire its nearest ancestor directory
The File type will now autorequire the nearest ancestor directory found in the
catalog, not just the file's parent directory. This is useful for setting up
transitive relationships in cases when a package or other resource creates a
large directory hierarchy, e.g.
package { 'foo': ensure => present }
file { '/var/lib/foo': require => Package['foo'] }
This will make File resources at arbitrarily deep levels under /var/lib/foo
automatically (transitively) require the foo package.
Only the nearest ancestor is autorequired, to prevent explosion of the
relationship graph.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/type/file_spec.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb index 539782fd4..223873fe3 100755 --- a/spec/unit/type/file_spec.rb +++ b/spec/unit/type/file_spec.rb @@ -169,6 +169,25 @@ describe Puppet::Type.type(:file) do reqs[0].target.must == file end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz") + dir = Puppet::Type::File.new(:path => "/foo") + root = Puppet::Type::File.new(:path => "/") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end + + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "/foo/bar/baz") + @catalog.add_resource file + file.autorequire.should be_empty + end + it "should not autorequire its parent dir if its parent dir is itself" do file = Puppet::Type::File.new(:path => "/") @catalog.add_resource file @@ -242,6 +261,25 @@ describe Puppet::Type.type(:file) do reqs[0].target.must == file end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") + dir = Puppet::Type::File.new(:path => "X:/foo") + root = Puppet::Type::File.new(:path => "X:/") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end + + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "X:/foo/bar/baz") + @catalog.add_resource file + file.autorequire.should be_empty + end + it "should not autorequire its parent dir if its parent dir is itself" do file = Puppet::Type::File.new(:path => "X:/") @catalog.add_resource file @@ -303,6 +341,25 @@ describe Puppet::Type.type(:file) do reqs[0].target.must == file end + it "should autorequire its nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") + dir = Puppet::Type::File.new(:path => "//server/foo/bar") + root = Puppet::Type::File.new(:path => "//server/foo") + @catalog.add_resource file + @catalog.add_resource dir + @catalog.add_resource root + reqs = file.autorequire + reqs.length.must == 1 + reqs[0].source.must == dir + reqs[0].target.must == file + end + + it "should not autorequire anything when there is no nearest ancestor directory" do + file = Puppet::Type::File.new(:path => "//server/foo/bar/baz/qux") + @catalog.add_resource file + file.autorequire.should be_empty + end + it "should not autorequire its parent dir if its parent dir is itself" do file = Puppet::Type::File.new(:path => "//server/foo") @catalog.add_resource file |
