Skip to content

Commit 8d7d427

Browse files
author
Morgan Haskel
committed
Merge pull request #328 from puppetlabs/2.0.x-to-master
2.0.x to master
2 parents 1869563 + 75d1e96 commit 8d7d427

10 files changed

Lines changed: 127 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
=======
2+
##2015-06-02 - Supported Release 2.0.1
3+
###Summary
4+
5+
This is a bugfix release.
6+
7+
####Bugfixes
8+
- Fixes dependency graphing with concurrent modification of the same file.
9+
- Fixes handling fragment target.
10+
- Fixes the defaulted force behavior to handle empty concats correctly.
11+
112
=======
213
##2015-05-12 - Supported Release 2.0.0
314
###Summary
@@ -10,6 +21,15 @@ This is a major release. Includes re-implementation of concat to use native Type
1021
####Bugfixes
1122
- Fixes a bug in alpha ordering of fragments.
1223

24+
=======
25+
##2015-06-02 - Supported Release 1.2.3
26+
###Summary
27+
28+
This release includes a README fix to document correct behavior of fragment target parameter.
29+
30+
####Bugfixes
31+
32+
- README Fix to correctly document how a fragment $target param should work.
1333

1434
##2015-05-12 - Supported Release 1.2.2
1535
###Summary

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Specifies a file to read into the content of the fragment. **Note**: You must su
212212

213213
#####`target`
214214

215-
*Required.* Specifies the destination file of the fragment. Valid options: a string containing an absolute path.
215+
*Required.* Specifies the destination file of the fragment. Valid options: a string containing the title of the parent `concat` resource.
216216

217217

218218
####Type: `concat_file`
@@ -283,7 +283,7 @@ Specifies a file to read into the content of the fragment. **Note**: You must su
283283

284284
#####`target`
285285

286-
*Required.* Specifies the destination file of the fragment. Valid options: a string containing an absolute path.
286+
*Required.* Specifies the destination file of the fragment. Valid options: a string containing the title of the parent `concat_file` resource.
287287

288288
###Removed functionality
289289

lib/puppet/type/concat_file.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ def exists?
8989
end.compact
9090
end
9191

92+
# Copied from puppet's file type
93+
# Autorequire the nearest ancestor directory found in the catalog.
94+
autorequire(:file) do
95+
req = []
96+
path = Pathname.new(self[:path])
97+
if !path.root?
98+
# Start at our parent, to avoid autorequiring ourself
99+
parents = path.parent.enum_for(:ascend)
100+
if found = parents.find { |p| catalog.resource(:file, p.to_s) }
101+
req << found.to_s
102+
end
103+
end
104+
105+
req
106+
end
107+
92108
def should_content
93109
return @generated_content if @generated_content
94110
@generated_content = ""
@@ -148,10 +164,9 @@ def fragment_content(r)
148164
fragment_content
149165
end
150166
151-
def eval_generate
167+
def generate
152168
file_opts = {
153169
:ensure => self[:ensure] == :absent ? :absent : :file,
154-
:content => self.should_content,
155170
}
156171
157172
[:path, :owner, :group, :mode, :replace, :backup].each do |param|
@@ -162,4 +177,13 @@ def eval_generate
162177
163178
[Puppet::Type.type(:file).new(file_opts)]
164179
end
180+
181+
def eval_generate
182+
content = should_content
183+
184+
if !content.nil? and !content.empty?
185+
catalog.resource("File[#{self[:path]}]")[:content] = content
186+
end
187+
[]
188+
end
165189
end

lib/puppet/type/concat_fragment.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
desc "Unique name"
1818
end
1919

20+
newparam(:target) do
21+
desc "Target"
22+
end
23+
2024
newparam(:content) do
2125
desc "Content"
2226
end
@@ -38,7 +42,19 @@
3842
desc "Tag name to be used by concat to collect all concat_fragments by tag name"
3943
end
4044

45+
autorequire(:file) do
46+
unless catalog.resource("Concat_file[#{self[:target]}]")
47+
warning "Target Concat_file[#{self[:target]}] not found in the catalog"
48+
end
49+
end
50+
4151
validate do
52+
# Check if target is set
53+
fail Puppet::ParseError, "Target not set" if self[:target].nil?
54+
55+
# Check if tag is set
56+
fail Puppet::ParseError, "Tag not set" if self[:tag].nil?
57+
4258
# Check if either source or content is set. raise error if none is set
4359
fail Puppet::ParseError, "Set either 'source' or 'content'" if self[:source].nil? && self[:content].nil?
4460

manifests/fragment.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
$safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM')
4848

4949
concat_fragment { $name:
50+
target => $target,
5051
tag => $safe_target_name,
5152
order => $order,
5253
content => $content,

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110

111111
if $_append_header {
112112
concat_fragment { "${name}_header":
113+
target => $name,
113114
tag => $safe_name,
114115
content => $warn_message,
115116
order => '0',

metadata.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{
22
"name": "puppetlabs-concat",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"author": "Puppet Labs",
55
"summary": "Construct files from multiple fragments.",
66
"license": "Apache-2.0",
77
"source": "https://github.com/puppetlabs/puppetlabs-concat",
88
"project_page": "https://github.com/puppetlabs/puppetlabs-concat",
99
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
10-
"dependencies": [
11-
{"name":"puppetlabs/stdlib","version_requirement":">= 4.5.0 < 5.0.0"}
12-
],
1310
"operatingsystem_support": [
1411
{
1512
"operatingsystem": "RedHat",
@@ -106,5 +103,8 @@
106103
"name": "puppet",
107104
"version_requirement": "3.x"
108105
}
106+
],
107+
"dependencies": [
108+
{"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0 < 5.0.0"}
109109
]
110110
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'with file recursive purge' do
4+
basedir = default.tmpdir('concat')
5+
context 'should still create concat file' do
6+
pp = <<-EOS
7+
file { '#{basedir}/bar':
8+
ensure => directory,
9+
purge => true,
10+
recurse => true,
11+
}
12+
13+
concat { "foobar":
14+
ensure => 'present',
15+
path => '#{basedir}/bar/foobar',
16+
}
17+
18+
concat::fragment { 'foo':
19+
target => 'foobar',
20+
content => 'foo',
21+
}
22+
EOS
23+
24+
it 'applies the manifest twice with no stderr' do
25+
apply_manifest(pp, :catch_failures => true)
26+
apply_manifest(pp, :catch_changes => true)
27+
end
28+
29+
describe file("#{basedir}/bar/foobar") do
30+
it { should be_file }
31+
its(:content) {
32+
should match 'foo'
33+
}
34+
end
35+
end
36+
end
37+

spec/acceptance/fragment_source_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149
end
150150
describe file("#{basedir}/fail_no_source") do
151151
#FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack.
152-
it { should_not be_file }
153152
it { should_not be_directory }
154153
end
155154
end

spec/acceptance/deprecation_warnings_spec.rb renamed to spec/acceptance/warnings_spec.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'spec_helper_acceptance'
22

3-
describe 'deprecation warnings' do
3+
describe 'warnings' do
44
basedir = default.tmpdir('concat')
55

66
shared_examples 'has_warning' do |pp, w|
@@ -10,7 +10,7 @@
1010
end
1111
end
1212

13-
context 'concat force parameter' do
13+
context 'concat force parameter deprecation' do
1414
pp = <<-EOS
1515
concat { '#{basedir}/file':
1616
force => false,
@@ -25,7 +25,7 @@
2525
it_behaves_like 'has_warning', pp, w
2626
end
2727

28-
context 'concat::fragment ensure parameter' do
28+
context 'concat::fragment ensure parameter deprecation' do
2929
context 'target file exists' do
3030
pp = <<-EOS
3131
concat { '#{basedir}/file':
@@ -41,4 +41,21 @@
4141
it_behaves_like 'has_warning', pp, w
4242
end
4343
end
44+
45+
context 'concat::fragment target not found' do
46+
context 'target not found' do
47+
pp = <<-EOS
48+
concat { 'file':
49+
path => '#{basedir}/file',
50+
}
51+
concat::fragment { 'foo':
52+
target => '#{basedir}/file',
53+
content => 'bar',
54+
}
55+
EOS
56+
w = 'not found in the catalog'
57+
58+
it_behaves_like 'has_warning', pp, w
59+
end
60+
end
4461
end

0 commit comments

Comments
 (0)