Skip to content

Commit

Permalink
Merge pull request #328 from puppetlabs/2.0.x-to-master
Browse files Browse the repository at this point in the history
2.0.x to master
  • Loading branch information
Morgan Haskel committed Jun 3, 2015
2 parents 1869563 + 75d1e96 commit 8d7d427
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 12 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
=======
##2015-06-02 - Supported Release 2.0.1
###Summary

This is a bugfix release.

####Bugfixes
- Fixes dependency graphing with concurrent modification of the same file.
- Fixes handling fragment target.
- Fixes the defaulted force behavior to handle empty concats correctly.

=======
##2015-05-12 - Supported Release 2.0.0
###Summary
Expand All @@ -10,6 +21,15 @@ This is a major release. Includes re-implementation of concat to use native Type
####Bugfixes
- Fixes a bug in alpha ordering of fragments.

=======
##2015-06-02 - Supported Release 1.2.3
###Summary

This release includes a README fix to document correct behavior of fragment target parameter.

####Bugfixes

- README Fix to correctly document how a fragment $target param should work.

##2015-05-12 - Supported Release 1.2.2
###Summary
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Specifies a file to read into the content of the fragment. **Note**: You must su

#####`target`

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


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

#####`target`

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

###Removed functionality

Expand Down
28 changes: 26 additions & 2 deletions lib/puppet/type/concat_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ def exists?
end.compact
end

# Copied from puppet's file type
# Autorequire the nearest ancestor directory found in the catalog.
autorequire(:file) do
req = []
path = Pathname.new(self[:path])
if !path.root?
# Start at our parent, to avoid autorequiring ourself
parents = path.parent.enum_for(:ascend)
if found = parents.find { |p| catalog.resource(:file, p.to_s) }
req << found.to_s
end
end

req
end

def should_content
return @generated_content if @generated_content
@generated_content = ""
Expand Down Expand Up @@ -148,10 +164,9 @@ def fragment_content(r)
fragment_content
end
def eval_generate
def generate
file_opts = {
:ensure => self[:ensure] == :absent ? :absent : :file,
:content => self.should_content,
}
[:path, :owner, :group, :mode, :replace, :backup].each do |param|
Expand All @@ -162,4 +177,13 @@ def eval_generate
[Puppet::Type.type(:file).new(file_opts)]
end
def eval_generate
content = should_content
if !content.nil? and !content.empty?
catalog.resource("File[#{self[:path]}]")[:content] = content
end
[]
end
end
16 changes: 16 additions & 0 deletions lib/puppet/type/concat_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
desc "Unique name"
end

newparam(:target) do
desc "Target"
end

newparam(:content) do
desc "Content"
end
Expand All @@ -38,7 +42,19 @@
desc "Tag name to be used by concat to collect all concat_fragments by tag name"
end

autorequire(:file) do
unless catalog.resource("Concat_file[#{self[:target]}]")
warning "Target Concat_file[#{self[:target]}] not found in the catalog"
end
end

validate do
# Check if target is set
fail Puppet::ParseError, "Target not set" if self[:target].nil?

# Check if tag is set
fail Puppet::ParseError, "Tag not set" if self[:tag].nil?

# Check if either source or content is set. raise error if none is set
fail Puppet::ParseError, "Set either 'source' or 'content'" if self[:source].nil? && self[:content].nil?

Expand Down
1 change: 1 addition & 0 deletions manifests/fragment.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
$safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM')

concat_fragment { $name:
target => $target,
tag => $safe_target_name,
order => $order,
content => $content,
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@

if $_append_header {
concat_fragment { "${name}_header":
target => $name,
tag => $safe_name,
content => $warn_message,
order => '0',
Expand Down
8 changes: 4 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"name": "puppetlabs-concat",
"version": "2.0.0",
"version": "2.0.1",
"author": "Puppet Labs",
"summary": "Construct files from multiple fragments.",
"license": "Apache-2.0",
"source": "https://github.com/puppetlabs/puppetlabs-concat",
"project_page": "https://github.com/puppetlabs/puppetlabs-concat",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 4.5.0 < 5.0.0"}
],
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
Expand Down Expand Up @@ -106,5 +103,8 @@
"name": "puppet",
"version_requirement": "3.x"
}
],
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0 < 5.0.0"}
]
}
37 changes: 37 additions & 0 deletions spec/acceptance/concurrency_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper_acceptance'

describe 'with file recursive purge' do
basedir = default.tmpdir('concat')
context 'should still create concat file' do
pp = <<-EOS
file { '#{basedir}/bar':
ensure => directory,
purge => true,
recurse => true,
}
concat { "foobar":
ensure => 'present',
path => '#{basedir}/bar/foobar',
}
concat::fragment { 'foo':
target => 'foobar',
content => 'foo',
}
EOS

it 'applies the manifest twice with no stderr' do
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe file("#{basedir}/bar/foobar") do
it { should be_file }
its(:content) {
should match 'foo'
}
end
end
end

1 change: 0 additions & 1 deletion spec/acceptance/fragment_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
end
describe file("#{basedir}/fail_no_source") do
#FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack.
it { should_not be_file }
it { should_not be_directory }
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper_acceptance'

describe 'deprecation warnings' do
describe 'warnings' do
basedir = default.tmpdir('concat')

shared_examples 'has_warning' do |pp, w|
Expand All @@ -10,7 +10,7 @@
end
end

context 'concat force parameter' do
context 'concat force parameter deprecation' do
pp = <<-EOS
concat { '#{basedir}/file':
force => false,
Expand All @@ -25,7 +25,7 @@
it_behaves_like 'has_warning', pp, w
end

context 'concat::fragment ensure parameter' do
context 'concat::fragment ensure parameter deprecation' do
context 'target file exists' do
pp = <<-EOS
concat { '#{basedir}/file':
Expand All @@ -41,4 +41,21 @@
it_behaves_like 'has_warning', pp, w
end
end

context 'concat::fragment target not found' do
context 'target not found' do
pp = <<-EOS
concat { 'file':
path => '#{basedir}/file',
}
concat::fragment { 'foo':
target => '#{basedir}/file',
content => 'bar',
}
EOS
w = 'not found in the catalog'

it_behaves_like 'has_warning', pp, w
end
end
end

0 comments on commit 8d7d427

Please sign in to comment.