Skip to content

Commit e94732b

Browse files
committed
Merge remote-tracking branch 'pr/1532' into 2.7.x
2 parents f720e9e + b247a39 commit e94732b

File tree

5 files changed

+65
-31
lines changed

5 files changed

+65
-31
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
test_name "#7680: 'links => follow' should use the file source content"
2+
confine :except, :platform => 'windows'
3+
4+
agents.each do |agent|
5+
6+
step "Create file content"
7+
real_source = agent.tmpfile('follow_links_source')
8+
dest = agent.tmpfile('follow_links_dest')
9+
symlink = agent.tmpfile('follow_links_symlink')
10+
11+
on agent, "echo 'This is the real content' > #{real_source}"
12+
on agent, "ln -sf #{real_source} #{symlink}"
13+
14+
manifest = <<-MANIFEST
15+
file { '#{dest}':
16+
ensure => file,
17+
source => '#{symlink}',
18+
links => follow,
19+
}
20+
MANIFEST
21+
apply_manifest_on(agent, manifest, :trace => true)
22+
23+
on agent, "cat #{dest}" do
24+
assert_match /This is the real content/, stdout
25+
end
26+
27+
step "Cleanup"
28+
[real_source, dest, symlink].each do |file|
29+
on agent, "rm -f '#{file}'"
30+
end
31+
end
32+
33+

lib/puppet/type/file/source.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def content
101101
return @content if @content
102102
raise Puppet::DevError, "No source for content was stored with the metadata" unless metadata.source
103103

104-
unless tmp = Puppet::FileServing::Content.indirection.find(metadata.source)
104+
unless tmp = Puppet::FileServing::Content.indirection.find(metadata.source, :links => resource[:links])
105105
fail "Could not find any content at %s" % metadata.source
106106
end
107107
@content = tmp.content
@@ -154,7 +154,7 @@ def metadata
154154
return nil unless value
155155
value.each do |source|
156156
begin
157-
if data = Puppet::FileServing::Metadata.indirection.find(source)
157+
if data = Puppet::FileServing::Metadata.indirection.find(source, :links => resource[:links])
158158
@metadata = data
159159
@metadata.source = source
160160
break

spec/integration/type/file_spec.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,20 @@ def get_group(file)
272272

273273
describe "that is readable" do
274274
it "should set the executable bits when creating the destination (#10315)" do
275-
pending "bug #10315"
276-
277275
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0666, :links => :follow)
278276
catalog.apply
279277

278+
File.should be_directory(path)
280279
(get_mode(path) & 07777).should == 0777
281280
end
282281

283282
it "should set the executable bits when overwriting the destination (#10315)" do
284-
pending "bug #10315"
285-
286283
FileUtils.touch(path)
287284

288-
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0666, :links => :follow)
285+
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0666, :links => :follow, :backup => false)
289286
catalog.apply
290287

288+
File.should be_directory(path)
291289
(get_mode(path) & 07777).should == 0777
292290
end
293291
end
@@ -302,37 +300,41 @@ def get_group(file)
302300
set_mode(0700, target)
303301
end
304302

305-
it "should not set executable bits when creating the destination (#10315)" do
306-
pending "bug #10315"
307-
303+
it "should set executable bits when creating the destination (#10315)" do
308304
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0666, :links => :follow)
309305
catalog.apply
310306

311-
(get_mode(path) & 07777).should == 0666
307+
File.should be_directory(path)
308+
(get_mode(path) & 07777).should == 0777
312309
end
313310

314-
it "should not set executable bits when overwriting the destination" do
311+
it "should set executable bits when overwriting the destination" do
315312
FileUtils.touch(path)
316313

317-
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0666, :links => :follow)
314+
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0666, :links => :follow, :backup => false)
318315
catalog.apply
319316

320-
(get_mode(path) & 07777).should == 0666
317+
File.should be_directory(path)
318+
(get_mode(path) & 07777).should == 0777
321319
end
322320
end
323321
end
324322

325323
describe "to a file" do
326-
let(:target) { tmpfile('file_target') }
324+
let(:link_target) { tmpfile('file_target') }
327325

328-
it "should create the file, not a symlink (#2817, #10315)" do
329-
pending "bug #2817, #10315"
326+
before :each do
327+
FileUtils.touch(link_target)
330328

329+
File.symlink(link_target, link)
330+
end
331+
332+
it "should create the file, not a symlink (#2817, #10315)" do
331333
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0600, :links => :follow)
332334
catalog.apply
333335

334336
File.should be_file(path)
335-
(get_mode(path) & 07777) == 0600
337+
(get_mode(path) & 07777).should == 0600
336338
end
337339

338340
it "should overwrite the file" do
@@ -342,7 +344,7 @@ def get_group(file)
342344
catalog.apply
343345

344346
File.should be_file(path)
345-
(get_mode(path) & 07777) == 0600
347+
(get_mode(path) & 07777).should == 0600
346348
end
347349
end
348350

@@ -364,13 +366,11 @@ def get_group(file)
364366

365367
describe "when following all links" do
366368
it "should create the destination and apply executable bits (#10315)" do
367-
pending "bug #10315"
368-
369369
catalog.add_resource described_class.new(:path => path, :source => link, :mode => 0600, :links => :follow)
370370
catalog.apply
371371

372372
File.should be_directory(path)
373-
(get_mode(path) & 07777) == 0777
373+
(get_mode(path) & 07777).should == 0700
374374
end
375375

376376
it "should overwrite the destination and apply executable bits" do
@@ -380,7 +380,7 @@ def get_group(file)
380380
catalog.apply
381381

382382
File.should be_directory(path)
383-
(get_mode(path) & 07777) == 0777
383+
(get_mode(path) & 0111).should == 0100
384384
end
385385
end
386386
end

spec/unit/indirector/catalog/static_compiler_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def build_catalog(options = {})
137137
# a real fileserver initialized for testing.
138138
Puppet::FileServing::Metadata.
139139
indirection.stubs(:find).
140-
with(options[:source].sub('puppet:///','')).
140+
with(options[:source].sub('puppet:///',''), :links => :manage).
141141
returns(fake_fileserver_metadata)
142142

143143
# I want a resource that all the file resources require and another

spec/unit/type/file/source_spec.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
describe "when returning the metadata" do
9393
before do
9494
@metadata = stub 'metadata', :source= => nil
95+
@resource.stubs(:[]).with(:links).returns :manage
9596
end
9697

9798
it "should return already-available metadata" do
@@ -107,38 +108,38 @@
107108

108109
it "should collect its metadata using the Metadata class if it is not already set" do
109110
@source = source.new(:resource => @resource, :value => @foobar)
110-
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri).returns @metadata
111+
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri, :links => :manage).returns @metadata
111112
@source.metadata
112113
end
113114

114115
it "should use the metadata from the first found source" do
115116
metadata = stub 'metadata', :source= => nil
116117
@source = source.new(:resource => @resource, :value => [@foobar, @feebooz])
117-
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri).returns nil
118-
Puppet::FileServing::Metadata.indirection.expects(:find).with(@feebooz_uri).returns metadata
118+
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri, :links => :manage).returns nil
119+
Puppet::FileServing::Metadata.indirection.expects(:find).with(@feebooz_uri, :links => :manage).returns metadata
119120
@source.metadata.should equal(metadata)
120121
end
121122

122123
it "should store the found source as the metadata's source" do
123124
metadata = mock 'metadata'
124125
@source = source.new(:resource => @resource, :value => @foobar)
125-
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri).returns metadata
126+
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri, :links => :manage).returns metadata
126127

127128
metadata.expects(:source=).with(@foobar_uri)
128129
@source.metadata
129130
end
130131

131132
it "should fail intelligently if an exception is encountered while querying for metadata" do
132133
@source = source.new(:resource => @resource, :value => @foobar)
133-
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri).raises RuntimeError
134+
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri, :links => :manage).raises RuntimeError
134135

135136
@source.expects(:fail).raises ArgumentError
136137
lambda { @source.metadata }.should raise_error(ArgumentError)
137138
end
138139

139140
it "should fail if no specified sources can be found" do
140141
@source = source.new(:resource => @resource, :value => @foobar)
141-
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri).returns nil
142+
Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar_uri, :links => :manage).returns nil
142143

143144
@source.expects(:fail).raises RuntimeError
144145

@@ -319,7 +320,7 @@
319320
before(:each) do
320321
metadata = Puppet::FileServing::Metadata.new(path, :source => uri, 'type' => 'file')
321322
#metadata = stub('remote', :ftype => "file", :source => uri)
322-
Puppet::FileServing::Metadata.indirection.stubs(:find).with(uri).returns metadata
323+
Puppet::FileServing::Metadata.indirection.stubs(:find).with(uri, :links => :manage).returns metadata
323324
resource[:source] = uri
324325
end
325326

0 commit comments

Comments
 (0)