Skip to content

Commit

Permalink
(PUP-3399) autorequire local file sources
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed May 4, 2022
1 parent d894861 commit df2f75f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/puppet/type/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ def self.title_patterns
end
# if the resource is a link, make sure the target is created first
req << self[:target] if self[:target]
# if the resource has a source set, make sure it is created first
self[:source]&.each do |src|
req << src[7..] if src.start_with?('file://')
end
req
end

Expand Down
35 changes: 35 additions & 0 deletions spec/unit/type/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,41 @@
end
end

describe "source" do
it "should require file resource when specified with the source property" do
file = described_class.new(:path => File.expand_path("/foo"), :ensure => :file, :source => File.expand_path("/bar"))
source = described_class.new(:path => File.expand_path("/bar"), :ensure => :file)
catalog.add_resource file
catalog.add_resource source
reqs = file.autorequire
expect(reqs.size).to eq(1)
expect(reqs[0].source).to eq(source)
expect(reqs[0].target).to eq(file)
end

it "should require file resource when specified with the source property as an array" do
file = described_class.new(:path => File.expand_path("/foo"), :ensure => :file, :source => [File.expand_path("/bar")])
source = described_class.new(:path => File.expand_path("/bar"), :ensure => :file)
catalog.add_resource file
catalog.add_resource source
reqs = file.autorequire
expect(reqs.size).to eq(1)
expect(reqs[0].source).to eq(source)
expect(reqs[0].target).to eq(file)
end

it "should not require source if source is not local" do
file = described_class.new(:path => File.expand_path('/foo'), :ensure => :file, :source => 'puppet:///modules/nfs/conf')
catalog.add_resource file
expect(file.autorequire.size).to eq(0)
end
it "should not require source if source is not managed" do
file = described_class.new(:path => File.expand_path('/foo'), :ensure => :file, :source => '/bar')
catalog.add_resource file
expect(file.autorequire.size).to eq(0)
end
end

describe "directories" do
it "should autorequire its parent directory" do
dir = described_class.new(:path => File.dirname(path))
Expand Down

0 comments on commit df2f75f

Please sign in to comment.