diff --git a/lib/puppet/type/concat_fragment.rb b/lib/puppet/type/concat_fragment.rb index 4567f2f..ac6b25b 100644 --- a/lib/puppet/type/concat_fragment.rb +++ b/lib/puppet/type/concat_fragment.rb @@ -1,64 +1,64 @@ Puppet::Type.newtype(:concat_fragment) do @doc = "Create a concat fragment to be used by concat. the `concat_fragment` type creates a file fragment to be collected by concat based on the tag. The example is based on exported resources. Example: @@concat_fragment { \"uniqe_name_${::fqdn}\": tag => 'unique_name', order => 10, # Optional. Default to 10 content => 'some content' # OR content => template('template.erb') # OR source => 'puppet:///path/to/file' } " newparam(:name, :namevar => true) do desc "Unique name" end newparam(:target) do desc "Target" end newparam(:content) do desc "Content" end newparam(:source) do desc "Source" end newparam(:order) do desc "Order" defaultto '10' validate do |val| fail Puppet::ParseError, '$order is not a string or integer.' if !(val.is_a? String or val.is_a? Integer) fail Puppet::ParseError, "Order cannot contain '/', ':', or '\n'." if val.to_s =~ /[:\n\/]/ end end newparam(:tag) do 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" + if catalog.resources.select {|x| x.class == Puppet::Type::Concat_file and x[:path] == self[:target] }.empty? + warning "Target Concat_file with path of #{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? # Check if both are set, if so rais error fail Puppet::ParseError, "Can't use 'source' and 'content' at the same time" if !self[:source].nil? && !self[:content].nil? end end diff --git a/spec/acceptance/warnings_spec.rb b/spec/acceptance/warnings_spec.rb index 89b3c3c..4ad7a97 100644 --- a/spec/acceptance/warnings_spec.rb +++ b/spec/acceptance/warnings_spec.rb @@ -1,61 +1,61 @@ require 'spec_helper_acceptance' describe 'warnings' do basedir = default.tmpdir('concat') shared_examples 'has_warning' do |pp, w| it 'applies the manifest twice with a stderr regex' do expect(apply_manifest(pp, :catch_failures => true).stderr).to match(/#{Regexp.escape(w)}/m) expect(apply_manifest(pp, :catch_changes => true).stderr).to match(/#{Regexp.escape(w)}/m) end end context 'concat force parameter deprecation' do pp = <<-EOS concat { '#{basedir}/file': force => false, } concat::fragment { 'foo': target => '#{basedir}/file', content => 'bar', } EOS w = 'The $force parameter to concat is deprecated and has no effect.' it_behaves_like 'has_warning', pp, w end context 'concat::fragment ensure parameter deprecation' do context 'target file exists' do pp = <<-EOS concat { '#{basedir}/file': } concat::fragment { 'foo': target => '#{basedir}/file', ensure => false, content => 'bar', } EOS w = 'The $ensure parameter to concat::fragment is deprecated and has no effect.' 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', + target => '#{basedir}/bar', content => 'bar', } EOS w = 'not found in the catalog' it_behaves_like 'has_warning', pp, w end end end