From 8dedb6bffb9efd3510e9e869fcdbf39b8e53e1d2 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Fri, 23 May 2014 10:02:00 -0700 Subject: [PATCH] Validate the concat::fragment order parameter as string||integer This is to work around a validation issue that arises under the 3.x future parser, as proper numeric types have been introduced (ie, not all scalar values are strings). Users have come to expect to to be able to pass in unquoted integer values to the order parameter which will fail to validate as a string when the future parser is enabled. --- .fixtures.yml | 2 +- Modulefile | 2 +- README.md | 4 +++- manifests/fragment.pp | 4 +++- spec/unit/defines/concat_fragment_spec.rb | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index dc6b41f..67added 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,6 +2,6 @@ fixtures: repositories: 'stdlib': repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.0.0' + ref: '4.2.0' symlinks: 'concat': '#{source_dir}' diff --git a/Modulefile b/Modulefile index ea9ef2c..bc1f199 100644 --- a/Modulefile +++ b/Modulefile @@ -6,4 +6,4 @@ license 'Apache 2.0' summary 'Concat module' description 'Concat module' project_page 'http://github.com/puppetlabs/puppetlabs-concat' -dependency 'puppetlabs/stdlib', '>= 4.0.0' +dependency 'puppetlabs/stdlib', '>= 4.2.0' diff --git a/README.md b/README.md index 60eca38..3f26ee7 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ class motd { } # used by other modules to register themselves in the motd -define motd::register($content="", $order=10) { +define motd::register($content="", $order='10') { if $content == "" { $body = $name } else { @@ -247,6 +247,8 @@ Order the fragments. ######Example - order => '01' +Best practice is to pass a string to this parameter but integer values are accepted. + #####`ensure` Control the file of fragment created. diff --git a/manifests/fragment.pp b/manifests/fragment.pp index a51b8c2..daa6a23 100644 --- a/manifests/fragment.pp +++ b/manifests/fragment.pp @@ -40,7 +40,9 @@ define concat::fragment( if !(is_string($source) or is_array($source)) { fail('$source is not a string or an Array.') } - validate_string($order) + if !(is_string($order) or is_integer($order)) { + fail('$order is not a string or integer.') + } if $mode { warning('The $mode parameter to concat::fragment is deprecated and has no effect') } diff --git a/spec/unit/defines/concat_fragment_spec.rb b/spec/unit/defines/concat_fragment_spec.rb index 3b5269e..3c61aab 100644 --- a/spec/unit/defines/concat_fragment_spec.rb +++ b/spec/unit/defines/concat_fragment_spec.rb @@ -152,7 +152,7 @@ describe 'concat::fragment', :type => :define do let(:params) {{ :order => false, :target => '/etc/motd' }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { should }.to raise_error(Puppet::Error, /is not a string or integer/) end end end # order =>