Skip to content

Commit

Permalink
fix fragment target handling
Browse files Browse the repository at this point in the history
Needed to bind fragment targets to it's parent concat resource's title so that we can
find them in the catalog. Throws a warning if the target is not found.
  • Loading branch information
bmjen committed May 28, 2015
1 parent 02c5f4b commit db33829
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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 @@ -279,7 +279,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
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 @@ -107,6 +107,7 @@

if $_append_header {
concat_fragment { "${name}_header":
target => $name,
tag => $safe_name,
content => $warn_message,
order => '0',
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 db33829

Please sign in to comment.