From cdd066bd51e8407ebea47b3f65a021dc491e24e0 Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Wed, 15 Oct 2014 17:35:27 +1100 Subject: [PATCH] Bumped concat version to latest --- Puppetfile | 4 +- concat/.travis.yml | 4 +- concat/{CHANGELOG => CHANGELOG.md} | 127 ++++++++-- concat/Gemfile | 2 +- concat/Modulefile | 9 - concat/README.md | 12 +- concat/files/concatfragments.rb | 16 +- .../parser/functions/concat_getparam.rb | 35 +++ .../puppet/parser/functions/concat_is_bool.rb | 22 ++ concat/manifests/fragment.pp | 3 +- concat/manifests/init.pp | 8 +- concat/metadata.json | 113 +++++++++ concat/spec/acceptance/backup_spec.rb | 78 +++--- concat/spec/acceptance/concat_spec.rb | 231 +++++++++--------- .../acceptance/deprecation_warnings_spec.rb | 94 +++---- concat/spec/acceptance/empty_spec.rb | 11 +- .../spec/acceptance/fragment_source_spec.rb | 121 +++++---- .../fragments_are_always_replaced_spec.rb | 133 ++++++++++ concat/spec/acceptance/newline_spec.rb | 40 +-- .../acceptance/nodesets/centos-64-x64.yml | 2 +- concat/spec/acceptance/nodesets/default.yml | 8 +- .../acceptance/nodesets/fedora-18-x64.yml | 2 +- .../nodesets/ubuntu-server-10044-x64.yml | 2 +- .../nodesets/ubuntu-server-12042-x64.yml | 2 +- concat/spec/acceptance/order_spec.rb | 86 ++++--- concat/spec/acceptance/quoted_paths_spec.rb | 29 ++- concat/spec/acceptance/replace_spec.rb | 157 ++++++------ concat/spec/acceptance/symbolic_name_spec.rb | 9 +- concat/spec/acceptance/warn_spec.rb | 37 +-- concat/spec/spec_helper_acceptance.rb | 20 +- concat/spec/unit/classes/concat_setup_spec.rb | 23 +- .../spec/unit/defines/concat_fragment_spec.rb | 33 ++- concat/spec/unit/defines/concat_spec.rb | 23 +- 33 files changed, 1010 insertions(+), 486 deletions(-) rename concat/{CHANGELOG => CHANGELOG.md} (65%) delete mode 100644 concat/Modulefile mode change 100755 => 100644 concat/files/concatfragments.rb create mode 100644 concat/lib/puppet/parser/functions/concat_getparam.rb create mode 100644 concat/lib/puppet/parser/functions/concat_is_bool.rb create mode 100644 concat/metadata.json create mode 100644 concat/spec/acceptance/fragments_are_always_replaced_spec.rb diff --git a/Puppetfile b/Puppetfile index 682d728e0..8bfe706ee 100644 --- a/Puppetfile +++ b/Puppetfile @@ -19,8 +19,8 @@ mod 'common', :git => 'https://github.com/purpleidea/puppet-common.git' mod 'concat', - :commit => '07bba0bcad2e3a2baf19dbff8b1a5146d9141153', - :git => 'https://github.com/puppetlabs/puppetlabs-concat.git' + :commit => '644fb1b6dc8b64accc4d1208d6127b79a08a38b7' + :git => 'https://github.com/puppetlabs/puppetlabs-concat.git', mod 'firewall', :commit => 'd5a10f5a52d84b9fcfb8fc65ef505685a07d5799', diff --git a/concat/.travis.yml b/concat/.travis.yml index a40ae502e..66e90e38d 100644 --- a/concat/.travis.yml +++ b/concat/.travis.yml @@ -6,9 +6,7 @@ matrix: fast_finish: true include: - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" + env: PUPPET_GEM_VERSION="~> 3.0" - rvm: 1.9.3 env: PUPPET_GEM_VERSION="~> 3.0" - rvm: 2.0.0 diff --git a/concat/CHANGELOG b/concat/CHANGELOG.md similarity index 65% rename from concat/CHANGELOG rename to concat/CHANGELOG.md index c66b922d4..54367bef3 100644 --- a/concat/CHANGELOG +++ b/concat/CHANGELOG.md @@ -1,21 +1,41 @@ -2014-05-14 1.1.0 +##2014-09-10 - Supported Release 1.1.1 -Summary +###Summary + +This is a bugfix release, and the first supported release of the 1.1.x series. + +####Bugfixes +- Make the `$order` parameter default to a string and be validated as an integer + or a string +- Use the ruby script on Solaris to not break Sol10 support +- Add quotes to the ruby script location for Windows +- Fix typos in README.md +- Make regex in concat::setup case-insensitive to make it work on Windows +- Make sure concat fragments are always replaced +- Fix validation to allow `$backup` to be a boolean +- Remove dependency on stdlib 4.x +- Fix for lack of idempotency with `ensure => 'absent'` +- Fix tests and spec_helper +- Synchronized files for more consistency across modules via modulesync + +##2014-05-14 - Release 1.1.0 + +###Summary This release is primarily a bugfix release since 1.1.0-rc1. -Features: +####Features - Improved testing, with tests moved to beaker -Bugfixes: +####Bugfixes - No longer attempts to set fragment owner and mode on Windows - Fix numeric sorting - Fix incorrect quoting - Fix newlines -2014-01-03 1.1.0-rc1 +##2014-01-03 - Release 1.1.0-rc1 -Summary: +###Summary This release of concat was 90% written by Joshua Hoblitt, and the module team would like to thank him for the huge amount of work he put into this release. @@ -33,49 +53,106 @@ warnings and we'll be aggressively moving for a 2.0 to remove those too. For further information on deprecations, please read: https://github.com/puppetlabs/puppetlabs-concat/blob/master/README.md#api-deprecations -Removed: +####Removed - Puppet 0.24 support. - Filebucket backup of all file resources except the target concatenated file. - Default owner/user/group values. - Purging of long unused /usr/local/bin/concatfragments.sh -Features: +###Features - Windows support via a ruby version of the concat bash script. - Huge amount of acceptance testing work added. - Documentation (README) completely rewritten. - New parameters in concat: - `ensure`: Controls if the file should be present/absent at all. -- Remove requirement to include concat::setup in manifests. -- Made `gnu` parameter deprecated. -- Added parameter validation. + - Remove requirement to include concat::setup in manifests. + - Made `gnu` parameter deprecated. + - Added parameter validation. + +###Bugfixes + - Ensure concat::setup runs before concat::fragment in all cases. + - Pluginsync references updated for modern Puppet. + - Fix incorrect group parameter. + - Use $owner instead of $id to avoid confusion with $::id + - Compatibility fixes for Puppet 2.7/ruby 1.8.7 + - Use LC_ALL=C instead of LANG=C + - Always exec the concatfragments script as root when running as root. + - Syntax and other cleanup changes. + +##2014-06-25 - Supported Release 1.0.4 +###Summary + +This release has test fixes. + +####Features +- Added test support for OSX. + +####Bugfixes + +####Known bugs + +* Not supported on Windows. + +##2014-06-04 - Release 1.0.3 +###Summary + +This release adds compatibility for PE3.3 and fixes tests. + +####Features +- Added test support for Ubuntu Trusty. + +####Bugfixes + +####Known bugs + +*Not supported on Windows. + +##2014-03-04 - Supported Release 1.0.2 +###Summary + +This is a supported release. No functional changes were made from 1.0.1. + +####Features +- Huge amount of tests backported from 1.1. +- Documentation rewrite. + +####Bugfixes + +####Known Bugs + +* Not supported on Windows. + + +##2014-02-12 - 1.0.1 + +###Summary + +Minor bugfixes for sorting of fragments and ordering of resources. + +####Bugfixes +- LANG => C replaced with LC_ALL => C to reduce spurious recreation of +fragments. +- Corrected pluginsync documentation. +- Ensure concat::setup always runs before fragments. -Bugfixes: -- Ensure concat::setup runs before concat::fragment in all cases. -- Pluginsync references updated for modern Puppet. -- Fix incorrect group parameter. -- Use $owner instead of $id to avoid confusion with $::id -- Compatibility fixes for Puppet 2.7/ruby 1.8.7 -- Use LC_ALL=C instead of LANG=C -- Always exec the concatfragments script as root when running as root. -- Syntax and other cleanup changes. -2013-08-09 1.0.0 +##2013-08-09 - 1.0.0 -Summary: +###Summary Many new features and bugfixes in this release, and if you're a heavy concat user you should test carefully before upgrading. The features should all be backwards compatible but only light testing has been done from our side before this release. -Features: +####Features - New parameters in concat: - `replace`: specify if concat should replace existing files. - `ensure_newline`: controls if fragments should contain a newline at the end. - Improved README documentation. - Add rspec:system tests (rake spec:system to test concat) -Bugfixes +####Bugfixes - Gracefully handle \n in a fragment resource name. - Adding more helpful message for 'pluginsync = true' - Allow passing `source` and `content` directly to file resource, rather than @@ -85,7 +162,7 @@ defining resource defaults. - Allow WARNMSG to contain/start with '#'. - Replace while-read pattern with for-do in order to support Solaris. -CHANGELOG: +####CHANGELOG: - 2010/02/19 - initial release - 2010/03/12 - add support for 0.24.8 and newer - make the location of sort configurable diff --git a/concat/Gemfile b/concat/Gemfile index e960f7c4b..081b1a291 100644 --- a/concat/Gemfile +++ b/concat/Gemfile @@ -5,7 +5,7 @@ group :development, :test do gem 'rspec-puppet', :require => false gem 'puppetlabs_spec_helper', :require => false gem 'serverspec', :require => false - gem 'puppet-lint', :require => false + gem 'puppet-lint', '0.3.2', :require => false gem 'beaker', :require => false gem 'beaker-rspec', :require => false gem 'pry', :require => false diff --git a/concat/Modulefile b/concat/Modulefile deleted file mode 100644 index bc1f1994d..000000000 --- a/concat/Modulefile +++ /dev/null @@ -1,9 +0,0 @@ -name 'puppetlabs-concat' -version '1.1.0' -source 'git://github.com/puppetlabs/puppetlabs-concat.git' -author 'Puppetlabs' -license 'Apache 2.0' -summary 'Concat module' -description 'Concat module' -project_page 'http://github.com/puppetlabs/puppetlabs-concat' -dependency 'puppetlabs/stdlib', '>= 4.2.0' diff --git a/concat/README.md b/concat/README.md index b884a0ac7..2ed9024eb 100644 --- a/concat/README.md +++ b/concat/README.md @@ -173,17 +173,13 @@ Set the mode of the combined file. #####`warn` Determine if a warning message should be added at the top of the file to let -users know it was autogenerated by Puppet. +users know it was autogenerated by Puppet. It should be a boolean or a string +containing the contents of the warning message. ######Example - warn => true - warn => false - -#####`warn_message` -Set the contents of the warning message. - -######Example -- warn_message => 'This file is autogenerated!' +- warn => '# This file is autogenerated!' #####`force` Determine if empty files are allowed when no fragments were added. @@ -255,8 +251,6 @@ Control the file of fragment created. ######Example - ensure => 'present' - ensure => 'absent' -- ensure => 'file' -- ensure => 'directory' #####`mode` Set the mode of the fragment. diff --git a/concat/files/concatfragments.rb b/concat/files/concatfragments.rb old mode 100755 new mode 100644 index cb66b03da..904f82460 --- a/concat/files/concatfragments.rb +++ b/concat/files/concatfragments.rb @@ -45,7 +45,8 @@ :test => false, :force => false, :warn => "", - :sortarg => "" + :sortarg => "", + :newline => false } OptionParser.new do |opts| @@ -77,6 +78,10 @@ opts.on("-n", "--sort", "Sort the output numerically rather than the default alpha sort") do settings[:sortarg] = "-n" end + + opts.on("-l", "--line", "Append a newline") do + settings[:newline] = true + end end.parse! # do we have -o? @@ -119,8 +124,15 @@ # find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir open('fragments.concat', 'a') do |f| Dir.entries("fragments").sort.each{ |entry| + if File.file?(File.join("fragments", entry)) - f << File.read(File.join("fragments", entry)) + f << File.read(File.join("fragments", entry)) + + # append a newline if we were asked to (invoked with -l) + if settings[:newline] + f << "\n" + end + end } end diff --git a/concat/lib/puppet/parser/functions/concat_getparam.rb b/concat/lib/puppet/parser/functions/concat_getparam.rb new file mode 100644 index 000000000..1757bdc54 --- /dev/null +++ b/concat/lib/puppet/parser/functions/concat_getparam.rb @@ -0,0 +1,35 @@ +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +Puppet::Parser::Functions.newfunction(:concat_getparam, + :type => :rvalue, + :doc => <<-'ENDOFDOC' +Takes a resource reference and name of the parameter and +returns value of resource's parameter. + +*Examples:* + + define example_resource($param) { + } + + example_resource { "example_resource_instance": + param => "param_value" + } + + concat_getparam(Example_resource["example_resource_instance"], "param") + +Would return: param_value +ENDOFDOC +) do |vals| + reference, param = vals + raise(ArgumentError, 'Must specify a reference') unless reference + raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String + + return '' if param.empty? + + if resource = findresource(reference.to_s) + return resource[param] if resource[param] + end + + return '' +end diff --git a/concat/lib/puppet/parser/functions/concat_is_bool.rb b/concat/lib/puppet/parser/functions/concat_is_bool.rb new file mode 100644 index 000000000..c2c2a9f2e --- /dev/null +++ b/concat/lib/puppet/parser/functions/concat_is_bool.rb @@ -0,0 +1,22 @@ +# +# concat_is_bool.rb +# + +module Puppet::Parser::Functions + newfunction(:concat_is_bool, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a boolean. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "concat_is_bool(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + type = arguments[0] + + result = type.is_a?(TrueClass) || type.is_a?(FalseClass) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/concat/manifests/fragment.pp b/concat/manifests/fragment.pp index 28f825197..34ec4c248 100644 --- a/concat/manifests/fragment.pp +++ b/concat/manifests/fragment.pp @@ -56,7 +56,7 @@ warning('The $backup parameter to concat::fragment is deprecated and has no effect') } if $ensure == undef { - $my_ensure = getparam(Concat[$target], 'ensure') + $my_ensure = concat_getparam(Concat[$target], 'ensure') } else { if ! ($ensure in [ 'present', 'absent' ]) { warning('Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.') @@ -117,6 +117,7 @@ source => $source, content => $content, backup => false, + replace => true, alias => "concat_fragment_${name}", notify => Exec["concat_${target}"] } diff --git a/concat/manifests/init.pp b/concat/manifests/init.pp index 91d82ebd3..77f9d5fd2 100644 --- a/concat/manifests/init.pp +++ b/concat/manifests/init.pp @@ -75,7 +75,9 @@ fail('$warn is not a string or boolean') } validate_bool($force) - validate_string($backup) + if ! concat_is_bool($backup) and ! is_string($backup) { + fail('$backup must be string or bool!') + } validate_bool($replace) validate_re($order, '^alpha$|^numeric$') validate_bool($ensure_newline) @@ -221,10 +223,12 @@ default => '/bin:/usr/bin', } + # Need to have an unless here for idempotency. exec { "concat_${name}": alias => "concat_${fragdir}", command => $absent_exec_command, - path => $absent_exec_path + unless => $absent_exec_command, + path => $absent_exec_path, } } } diff --git a/concat/metadata.json b/concat/metadata.json new file mode 100644 index 000000000..5a48a8fd4 --- /dev/null +++ b/concat/metadata.json @@ -0,0 +1,113 @@ +{ + "name": "puppetlabs-concat", + "version": "1.1.1", + "author": "Puppet Labs", + "summary": "Concat module", + "license": "Apache-2.0", + "source": "https://github.com/puppetlabs/puppetlabs-concat", + "project_page": "https://github.com/puppetlabs/puppetlabs-concat", + "issues_url": "https://github.com/puppetlabs/puppetlabs-concat/issues", + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "Scientific", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "10 SP4", + "11 SP1", + "12" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04", + "14.04" + ] + }, + { + "operatingsystem": "Solaris", + "operatingsystemrelease": [ + "10", + "11" + ] + }, + { + "operatingsystem": "Windows", + "operatingsystemrelease": [ + "Server 2003 R2", + "Server 2008 R2", + "Server 2012", + "Server 2012 R2" + ] + }, + { + "operatingsystem": "AIX", + "operatingsystemrelease": [ + "5.3", + "6.1", + "7.1" + ] + }, + { + "operatingsystem": "OSX", + "operatingsystemrelease": [ + "10.9" + ] + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": "3.x" + }, + { + "name": "puppet", + "version_requirement": "3.x" + } + ], + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 3.2.0 < 5.0.0" + } + ] +} diff --git a/concat/spec/acceptance/backup_spec.rb b/concat/spec/acceptance/backup_spec.rb index 7b2858d8e..1989f4458 100644 --- a/concat/spec/acceptance/backup_spec.rb +++ b/concat/spec/acceptance/backup_spec.rb @@ -1,50 +1,60 @@ require 'spec_helper_acceptance' describe 'concat backup parameter' do + basedir = default.tmpdir('concat') context '=> puppet' do - before :all do - shell('rm -rf /tmp/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'old contents' > /tmp/concat/file") + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': backup => 'puppet', } concat::fragment { 'new file': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new contents', } EOS it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stderr).to eq("") - expect(r.stdout).to match(/Filebucketed \/tmp\/concat\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents' + expect(r.stdout).to match(/Filebucketed #{basedir}\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents' end - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'new contents' } end end context '=> .backup' do - before :all do - shell('rm -rf /tmp/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'old contents' > /tmp/concat/file") + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new contents', } EOS @@ -52,15 +62,15 @@ # XXX Puppet doesn't mention anything about filebucketing with a given # extension like .backup it 'applies the manifest twice no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'new contents' } end - describe file('/tmp/concat/file.backup') do + describe file("#{basedir}/file.backup") do it { should be_file } it { should contain 'old contents' } end @@ -69,31 +79,35 @@ # XXX The backup parameter uses validate_string() and thus can't be the # boolean false value, but the string 'false' has the same effect in Puppet 3 context "=> 'false'" do - before :all do - shell('rm -rf /tmp/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'old contents' > /tmp/concat/file") + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new contents', } EOS it 'applies the manifest twice with no "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stderr).to eq("") expect(r.stdout).to_not match(/Filebucketed/) end - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'new contents' } end diff --git a/concat/spec/acceptance/concat_spec.rb b/concat/spec/acceptance/concat_spec.rb index 89919cc53..7cec1a5a0 100644 --- a/concat/spec/acceptance/concat_spec.rb +++ b/concat/spec/acceptance/concat_spec.rb @@ -1,73 +1,119 @@ require 'spec_helper_acceptance' +case fact('osfamily') +when 'AIX' + username = 'root' + groupname = 'system' + scriptname = 'concatfragments.sh' + vardir = default['puppetvardir'] +when 'Darwin' + username = 'root' + groupname = 'wheel' + scriptname = 'concatfragments.sh' + vardir = default['puppetvardir'] +when 'windows' + username = 'Administrator' + groupname = 'Administrators' + scriptname = 'concatfragments.rb' + result = on default, "echo #{default['puppetvardir']}" + vardir = result.raw_output.chomp +when 'Solaris' + username = 'root' + groupname = 'root' + scriptname = 'concatfragments.rb' + vardir = default['puppetvardir'] +else + username = 'root' + groupname = 'root' + scriptname = 'concatfragments.sh' + vardir = default['puppetvardir'] +end + describe 'basic concat test' do + basedir = default.tmpdir('concat') + safe_basedir = basedir.gsub(/[\/:]/,'_') shared_examples 'successfully_applied' do |pp| it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file("#{default['puppetvardir']}/concat") do + describe file("#{vardir}/concat") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 755 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 755 + } end - describe file("#{default['puppetvardir']}/concat/bin") do + describe file("#{vardir}/concat/bin") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 755 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 755 + } end - describe file("#{default['puppetvardir']}/concat/bin/concatfragments.sh") do + describe file("#{vardir}/concat/bin/#{scriptname}") do it { should be_file } - it { should be_owned_by 'root' } - #it { should be_grouped_into 'root' } - it { should be_mode 755 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 755 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file") do + describe file("#{vardir}/concat/#{safe_basedir}_file") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 750 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 750 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 750 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 750 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 640 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat.out") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat.out") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 640 + } end end context 'owner/group root' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp = <<-EOS - concat { '/tmp/concat/file': - owner => 'root', - group => 'root', + concat { '#{basedir}/file': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } @@ -75,89 +121,46 @@ it_behaves_like 'successfully_applied', pp - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain '1' } - it { should contain '2' } - end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - end - end - - context 'owner/group non-root' do - before(:all) do - shell "groupadd -g 64444 bob" - shell "useradd -u 42 -g 64444 bob" - end - after(:all) do - shell "userdel bob" - end - - pp=" - concat { '/tmp/concat/file': - owner => 'bob', - group => 'bob', - mode => '0644', - } - - concat::fragment { '1': - target => '/tmp/concat/file', - content => '1', - order => '01', + it { should be_owned_by username } + it("should be group", :unless => (fact('osfamily') == 'windows')) { should be_grouped_into groupname } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 644 } - - concat::fragment { '2': - target => '/tmp/concat/file', - content => '2', - order => '02', - } - " - - it_behaves_like 'successfully_applied', pp - - describe file('/tmp/concat/file') do - it { should be_file } - it { should be_owned_by 'bob' } - it { should be_grouped_into 'bob' } - it { should be_mode 644 } it { should contain '1' } it { should contain '2' } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - it { should contain '1' } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 640 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - it { should contain '2' } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 640 + } end end context 'ensure' do context 'works when set to present with path set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp=" concat { 'file': ensure => present, - path => '/tmp/concat/file', + path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': @@ -169,17 +172,27 @@ it_behaves_like 'successfully_applied', pp - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should be_mode 644 } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 644 + } it { should contain '1' } end end context 'works when set to absent with path set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp=" concat { 'file': ensure => absent, - path => '/tmp/concat/file', + path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': @@ -189,14 +202,12 @@ } " - # Can't used shared examples as this will always trigger the exec when - # absent is set. it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should_not be_file } end end diff --git a/concat/spec/acceptance/deprecation_warnings_spec.rb b/concat/spec/acceptance/deprecation_warnings_spec.rb index f139d818c..dc2f234d0 100644 --- a/concat/spec/acceptance/deprecation_warnings_spec.rb +++ b/concat/spec/acceptance/deprecation_warnings_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper_acceptance' describe 'deprecation warnings' do + basedir = default.tmpdir('concat') shared_examples 'has_warning'do |pp, w| it 'applies the manifest twice with a stderr regex' do @@ -11,11 +12,11 @@ context 'concat gnu parameter' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': gnu => 'foo', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -28,11 +29,11 @@ ['true', 'yes', 'on'].each do |warn| context warn do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '#{warn}', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -40,7 +41,7 @@ it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain 'bar' } @@ -51,11 +52,11 @@ ['false', 'no', 'off'].each do |warn| context warn do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '#{warn}', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -63,7 +64,7 @@ it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain 'bar' } @@ -72,50 +73,51 @@ end end - context 'concat::fragment ensure parameter' do + context 'concat::fragment ensure parameter', :unless => fact('osfamily') == 'windows' do context 'target file exists' do before(:all) do - shell("/bin/echo 'file1 contents' > /tmp/concat/file1") - end - after(:all) do - # XXX this test may leave behind a symlink in the fragment directory - # which could cause warnings and/or breakage from the subsequent tests - # unless we clean it up. - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file1': + content => "file1 contents\n", + } + EOS + apply_manifest(pp) end pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', - ensure => '/tmp/concat/file1', + target => '#{basedir}/file', + ensure => '#{basedir}/file1', } EOS w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.' it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'file1 contents' } end - describe 'the fragment can be changed from a symlink to a plain file' do + describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact("osfamily") == "windows") do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new content', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'new content' } it { should_not contain 'file1 contents' } @@ -123,37 +125,37 @@ end end # target file exists - context 'target does not exist' do + context 'target does not exist', :unless => fact('osfamily') == 'windows' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', - ensure => '/tmp/concat/file1', + target => '#{basedir}/file', + ensure => '#{basedir}/file1', } EOS w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.' it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } end - describe 'the fragment can be changed from a symlink to a plain file' do + describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact('osfamily') == 'windows') do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new content', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'new content' } end @@ -164,9 +166,9 @@ context 'concat::fragment mode parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', mode => 'bar', } @@ -178,9 +180,9 @@ context 'concat::fragment owner parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', owner => 'bar', } @@ -192,9 +194,9 @@ context 'concat::fragment group parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', group => 'bar', } @@ -206,9 +208,9 @@ context 'concat::fragment backup parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', backup => 'bar', } diff --git a/concat/spec/acceptance/empty_spec.rb b/concat/spec/acceptance/empty_spec.rb index 09995282a..dc57cb791 100644 --- a/concat/spec/acceptance/empty_spec.rb +++ b/concat/spec/acceptance/empty_spec.rb @@ -1,22 +1,21 @@ require 'spec_helper_acceptance' describe 'concat force empty parameter' do + basedir = default.tmpdir('concat') context 'should run successfully' do pp = <<-EOS - concat { '/tmp/concat/file': - owner => root, - group => root, + concat { '#{basedir}/file': mode => '0644', force => true, } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should_not contain '1\n2' } end diff --git a/concat/spec/acceptance/fragment_source_spec.rb b/concat/spec/acceptance/fragment_source_spec.rb index 3afd53430..f3bbfccdf 100644 --- a/concat/spec/acceptance/fragment_source_spec.rb +++ b/concat/spec/acceptance/fragment_source_spec.rb @@ -1,35 +1,54 @@ require 'spec_helper_acceptance' +case fact('osfamily') +when 'AIX' + username = 'root' + groupname = 'system' +when 'Darwin' + username = 'root' + groupname = 'wheel' +when 'windows' + username = 'Administrator' + groupname = 'Administrators' +else + username = 'root' + groupname = 'root' +end + describe 'concat::fragment source' do + basedir = default.tmpdir('concat') context 'should read file fragments from local system' do - before(:all) do - shell("/bin/echo 'file1 contents' > /tmp/concat/file1") - shell("/bin/echo 'file2 contents' > /tmp/concat/file2") - end - pp = <<-EOS - concat { '/tmp/concat/foo': } + file { '#{basedir}/file1': + content => "file1 contents\n" + } + file { '#{basedir}/file2': + content => "file2 contents\n" + } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', - source => '/tmp/concat/file1', + target => '#{basedir}/foo', + source => '#{basedir}/file1', + require => File['#{basedir}/file1'], } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1 contents', } concat::fragment { '3': - target => '/tmp/concat/foo', - source => '/tmp/concat/file2', + target => '#{basedir}/foo', + source => '#{basedir}/file2', + require => File['#{basedir}/file2'], } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } it { should contain 'file1 contents' } it { should contain 'string1 contents' } @@ -38,62 +57,64 @@ end # should read file fragments from local system context 'should create files containing first match only.' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'file1 contents' > /tmp/concat/file1") - shell("/bin/echo 'file2 contents' > /tmp/concat/file2") - end - pp = <<-EOS - concat { '/tmp/concat/result_file1': - owner => root, - group => root, + file { '#{basedir}/file1': + content => "file1 contents\n" + } + file { '#{basedir}/file2': + content => "file2 contents\n" + } + concat { '#{basedir}/result_file1': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } - concat { '/tmp/concat/result_file2': - owner => root, - group => root, + concat { '#{basedir}/result_file2': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } - concat { '/tmp/concat/result_file3': - owner => root, - group => root, + concat { '#{basedir}/result_file3': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '/tmp/concat/result_file1', - source => [ '/tmp/concat/file1', '/tmp/concat/file2' ], + target => '#{basedir}/result_file1', + source => [ '#{basedir}/file1', '#{basedir}/file2' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } concat::fragment { '2': - target => '/tmp/concat/result_file2', - source => [ '/tmp/concat/file2', '/tmp/concat/file1' ], + target => '#{basedir}/result_file2', + source => [ '#{basedir}/file2', '#{basedir}/file1' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } concat::fragment { '3': - target => '/tmp/concat/result_file3', - source => [ '/tmp/concat/file1', '/tmp/concat/file2' ], + target => '#{basedir}/result_file3', + source => [ '#{basedir}/file1', '#{basedir}/file2' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/result_file1') do + describe file("#{basedir}/result_file1") do it { should be_file } it { should contain 'file1 contents' } it { should_not contain 'file2 contents' } end - describe file('/tmp/concat/result_file2') do + describe file("#{basedir}/result_file2") do it { should be_file } it { should contain 'file2 contents' } it { should_not contain 'file1 contents' } end - describe file('/tmp/concat/result_file3') do + describe file("#{basedir}/result_file3") do it { should be_file } it { should contain 'file1 contents' } it { should_not contain 'file2 contents' } @@ -101,22 +122,16 @@ end context 'should fail if no match on source.' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - shell('/bin/rm -rf /tmp/concat/fail_no_source /tmp/concat/nofilehere /tmp/concat/nothereeither') - end - pp = <<-EOS - concat { '/tmp/concat/fail_no_source': - owner => root, - group => root, + concat { '#{basedir}/fail_no_source': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '/tmp/concat/fail_no_source', - source => [ '/tmp/concat/nofilehere', '/tmp/concat/nothereeither' ], + target => '#{basedir}/fail_no_source', + source => [ '#{basedir}/nofilehere', '#{basedir}/nothereeither' ], order => '01', } EOS @@ -124,7 +139,7 @@ it 'applies the manifest with resource failures' do apply_manifest(pp, :expect_failures => true) end - describe file('/tmp/concat/fail_no_source') do + 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 } diff --git a/concat/spec/acceptance/fragments_are_always_replaced_spec.rb b/concat/spec/acceptance/fragments_are_always_replaced_spec.rb new file mode 100644 index 000000000..ac714a964 --- /dev/null +++ b/concat/spec/acceptance/fragments_are_always_replaced_spec.rb @@ -0,0 +1,133 @@ +require 'spec_helper_acceptance' + +describe 'concat::fragment replace' do + basedir = default.tmpdir('concat') + + context 'should create fragment files' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end + + pp1 = <<-EOS + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace unset run 1', + } + EOS + pp2 = <<-EOS + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace unset run 2', + } + EOS + + it 'applies the manifest twice with no stderr' do + apply_manifest(pp1, :catch_failures => true) + apply_manifest(pp1, :catch_changes => true) + apply_manifest(pp2, :catch_failures => true) + apply_manifest(pp2, :catch_changes => true) + end + + describe file("#{basedir}/foo") do + it { should be_file } + it { should_not contain 'caller has replace unset run 1' } + it { should contain 'caller has replace unset run 2' } + end + end # should create fragment files + + context 'should replace its own fragment files when caller has File { replace=>true } set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end + + pp1 = <<-EOS + File { replace=>true } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace true set run 1', + } + EOS + pp2 = <<-EOS + File { replace=>true } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace true set run 2', + } + EOS + + it 'applies the manifest twice with no stderr' do + apply_manifest(pp1, :catch_failures => true) + apply_manifest(pp1, :catch_changes => true) + apply_manifest(pp2, :catch_failures => true) + apply_manifest(pp2, :catch_changes => true) + end + + describe file("#{basedir}/foo") do + it { should be_file } + it { should_not contain 'caller has replace true set run 1' } + it { should contain 'caller has replace true set run 2' } + end + end # should replace its own fragment files when caller has File(replace=>true) set + + context 'should replace its own fragment files even when caller has File { replace=>false } set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end + + pp1 = <<-EOS + File { replace=>false } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace false set run 1', + } + EOS + pp2 = <<-EOS + File { replace=>false } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace false set run 2', + } + EOS + + it 'applies the manifest twice with no stderr' do + apply_manifest(pp1, :catch_failures => true) + apply_manifest(pp1, :catch_changes => true) + apply_manifest(pp2, :catch_failures => true) + apply_manifest(pp2, :catch_changes => true) + end + + describe file("#{basedir}/foo") do + it { should be_file } + it { should_not contain 'caller has replace false set run 1' } + it { should contain 'caller has replace false set run 2' } + end + end # should replace its own fragment files even when caller has File(replace=>false) set + +end diff --git a/concat/spec/acceptance/newline_spec.rb b/concat/spec/acceptance/newline_spec.rb index 1e989df2a..d182f2adc 100644 --- a/concat/spec/acceptance/newline_spec.rb +++ b/concat/spec/acceptance/newline_spec.rb @@ -1,27 +1,37 @@ require 'spec_helper_acceptance' describe 'concat ensure_newline parameter' do + basedir = default.tmpdir('concat') context '=> false' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory + } + EOS + + apply_manifest(pp) + end pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': ensure_newline => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '12' } end @@ -29,29 +39,29 @@ context '=> true' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': ensure_newline => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") - #XXX ensure_newline => true causes changes on every run because the files - #are modified in place. + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain "1\n2\n" } + it("should contain 1\n2\n", :unless => (fact('osfamily') == 'Solaris')) { + should contain "1\n2\n" + } end end end diff --git a/concat/spec/acceptance/nodesets/centos-64-x64.yml b/concat/spec/acceptance/nodesets/centos-64-x64.yml index 05540ed8c..063983549 100644 --- a/concat/spec/acceptance/nodesets/centos-64-x64.yml +++ b/concat/spec/acceptance/nodesets/centos-64-x64.yml @@ -7,4 +7,4 @@ HOSTS: box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/concat/spec/acceptance/nodesets/default.yml b/concat/spec/acceptance/nodesets/default.yml index ae812b0ae..063983549 100644 --- a/concat/spec/acceptance/nodesets/default.yml +++ b/concat/spec/acceptance/nodesets/default.yml @@ -1,10 +1,10 @@ HOSTS: - centos-64-x64.localdomain: + centos-64-x64: roles: - master platform: el-6-x86_64 - box : centos-65-x64-virtualbox-nocm - box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box + box : centos-64-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/concat/spec/acceptance/nodesets/fedora-18-x64.yml b/concat/spec/acceptance/nodesets/fedora-18-x64.yml index 136164983..624b53716 100644 --- a/concat/spec/acceptance/nodesets/fedora-18-x64.yml +++ b/concat/spec/acceptance/nodesets/fedora-18-x64.yml @@ -7,4 +7,4 @@ HOSTS: box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/concat/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml b/concat/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml index 5ca1514e4..5047017e6 100644 --- a/concat/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml +++ b/concat/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml @@ -7,4 +7,4 @@ HOSTS: box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/concat/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/concat/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml index d065b304f..1c7a34ccb 100644 --- a/concat/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml +++ b/concat/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml @@ -7,4 +7,4 @@ HOSTS: box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/concat/spec/acceptance/order_spec.rb b/concat/spec/acceptance/order_spec.rb index 8bcb7131c..fd7b05b4f 100644 --- a/concat/spec/acceptance/order_spec.rb +++ b/concat/spec/acceptance/order_spec.rb @@ -1,137 +1,143 @@ require 'spec_helper_acceptance' describe 'concat order' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - end + basedir = default.tmpdir('concat') context '=> alpha' do pp = <<-EOS - concat { '/tmp/concat/foo': + concat { '#{basedir}/foo': order => 'alpha' } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1', } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string2', } concat::fragment { '10': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string10', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } - it { should contain "string10\nstring1\nsring2" } + #XXX Solaris 10 doesn't support multi-line grep + it("should contain string10\nstring1\nsring2", :unless => (fact('osfamily') == 'Solaris')) { + should contain "string10\nstring1\nsring2" + } end end context '=> numeric' do pp = <<-EOS - concat { '/tmp/concat/foo': + concat { '#{basedir}/foo': order => 'numeric' } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1', } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string2', } concat::fragment { '10': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string10', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } - it { should contain "string1\nstring2\nsring10" } + #XXX Solaris 10 doesn't support multi-line grep + it("should contain string1\nstring2\nsring10", :unless => (fact('osfamily') == 'Solaris')) { + should contain "string1\nstring2\nsring10" + } end end end # concat order describe 'concat::fragment order' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - end + basedir = default.tmpdir('concat') context '=> reverse order' do pp = <<-EOS - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1', order => '15', } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string2', # default order 10 } concat::fragment { '3': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string3', order => '1', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } - it { should contain "string3\nstring2\nsring1" } + #XXX Solaris 10 doesn't support multi-line grep + it("should contain string3\nstring2\nsring1", :unless => (fact('osfamily') == 'Solaris')) { + should contain "string3\nstring2\nsring1" + } end end context '=> normal order' do pp = <<-EOS - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string2', order => '02' } concat::fragment { '3': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string3', order => '03', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } - it { should contain "string1\nstring2\nsring3" } + #XXX Solaris 10 doesn't support multi-line grep + it("should contain string1\nstring2\nsring3", :unless => (fact('osfamily') == 'Solaris')) { + should contain "string1\nstring2\nsring3" + } end end end # concat::fragment order diff --git a/concat/spec/acceptance/quoted_paths_spec.rb b/concat/spec/acceptance/quoted_paths_spec.rb index d1a2b5f1b..165c153fe 100644 --- a/concat/spec/acceptance/quoted_paths_spec.rb +++ b/concat/spec/acceptance/quoted_paths_spec.rb @@ -1,33 +1,44 @@ require 'spec_helper_acceptance' describe 'quoted paths' do + basedir = default.tmpdir('concat') + before(:all) do - shell('rm -rf "/tmp/concat test" /var/lib/puppet/concat') - shell('mkdir -p "/tmp/concat test"') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/concat test': + ensure => directory, + } + EOS + apply_manifest(pp) end context 'path with blanks' do pp = <<-EOS - concat { '/tmp/concat test/foo': + concat { '#{basedir}/concat test/foo': } concat::fragment { '1': - target => '/tmp/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string1', } concat::fragment { '2': - target => '/tmp/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat test/foo') do + describe file("#{basedir}/concat test/foo") do it { should be_file } - it { should contain "string1\nsring2" } + it("should contain string1\nstring2", :unless => (fact('osfamily') == 'Solaris')) { + should contain "string1\nstring2" + } end end end diff --git a/concat/spec/acceptance/replace_spec.rb b/concat/spec/acceptance/replace_spec.rb index 7b31e09c4..688234548 100644 --- a/concat/spec/acceptance/replace_spec.rb +++ b/concat/spec/acceptance/replace_spec.rb @@ -1,38 +1,42 @@ require 'spec_helper_acceptance' describe 'replacement of' do + basedir = default.tmpdir('concat') context 'file' do context 'should not succeed' do before(:all) do - shell('mkdir -p /tmp/concat') - shell('echo "file exists" > /tmp/concat/file') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "file exists\n" + } + EOS + apply_manifest(pp) end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'file exists' } it { should_not contain '1' } @@ -42,35 +46,38 @@ context 'should succeed' do before(:all) do - shell('mkdir -p /tmp/concat') - shell('echo "file exists" > /tmp/concat/file') - end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "file exists\n" + } + EOS + apply_manifest(pp) end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should_not contain 'file exists' } it { should contain '1' } @@ -79,45 +86,51 @@ end end # file - context 'symlink' do + context 'symlink', :unless => (fact("osfamily") == "windows") do context 'should not succeed' do # XXX the core puppet file type will replace a symlink with a plain file # when using ensure => present and source => ... but it will not when using # ensure => present and content => ...; this is somewhat confusing behavior before(:all) do - shell('mkdir -p /tmp/concat') - shell('ln -s /tmp/concat/dangling /tmp/concat/file') - end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => link, + target => '#{basedir}/dangling', + } + EOS + apply_manifest(pp) end pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do - it { should be_linked_to '/tmp/concat/dangling' } + # XXX specinfra doesn't support be_linked_to on AIX + describe file("#{basedir}/file"), :unless => (fact("osfamily") == "AIX" or fact("osfamily") == "windows") do + it { should be_linked_to "#{basedir}/dangling" } end - describe file('/tmp/concat/dangling') do + describe file("#{basedir}/dangling") do # XXX serverspec does not have a matcher for 'exists' it { should_not be_file } it { should_not be_directory } @@ -129,35 +142,40 @@ # when using ensure => present and source => ... but it will not when using # ensure => present and content => ...; this is somewhat confusing behavior before(:all) do - shell('mkdir -p /tmp/concat') - shell('ln -s /tmp/concat/dangling /tmp/concat/file') - end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => link, + target => '#{basedir}/dangling', + } + EOS + apply_manifest(pp) end pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '1' } it { should contain '2' } @@ -168,22 +186,26 @@ context 'directory' do context 'should not succeed' do before(:all) do - shell('mkdir -p /tmp/concat/file') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => directory, + } + EOS + apply_manifest(pp) end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - end - pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS @@ -193,7 +215,7 @@ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_directory } end end @@ -204,35 +226,28 @@ # changed, extended, or a new param introduced to control directory # replacement. context 'should succeed', :pending => 'not yet implemented' do - before(:all) do - shell('mkdir -p /tmp/concat/file') - end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': force => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '1' } end diff --git a/concat/spec/acceptance/symbolic_name_spec.rb b/concat/spec/acceptance/symbolic_name_spec.rb index 7267f5e6b..b0dceac8c 100644 --- a/concat/spec/acceptance/symbolic_name_spec.rb +++ b/concat/spec/acceptance/symbolic_name_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper_acceptance' describe 'symbolic name' do + basedir = default.tmpdir('concat') pp = <<-EOS concat { 'not_abs_path': - path => '/tmp/concat/file', + path => '#{basedir}/file', } concat::fragment { '1': @@ -20,11 +21,11 @@ EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '1' } it { should contain '2' } diff --git a/concat/spec/acceptance/warn_spec.rb b/concat/spec/acceptance/warn_spec.rb index cb0b7430d..2fa529da2 100644 --- a/concat/spec/acceptance/warn_spec.rb +++ b/concat/spec/acceptance/warn_spec.rb @@ -1,31 +1,32 @@ require 'spec_helper_acceptance' describe 'concat warn =>' do + basedir = default.tmpdir('concat') context 'true should enable default warning message' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain '1' } @@ -34,29 +35,29 @@ end context 'false should not enable default warning message' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain '1' } @@ -65,29 +66,29 @@ end context '# foo should overide default warning message' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '# foo', } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '# foo' } it { should contain '1' } diff --git a/concat/spec/spec_helper_acceptance.rb b/concat/spec/spec_helper_acceptance.rb index 22bd72f06..b34a188d6 100644 --- a/concat/spec/spec_helper_acceptance.rb +++ b/concat/spec/spec_helper_acceptance.rb @@ -2,11 +2,12 @@ require 'beaker-rspec/helpers/serverspec' unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' - if hosts.first.is_pe? - install_pe - else - install_puppet - end + # This will install the latest available package on el and deb based + # systems fail on windows and osx, and install via gem on other *nixes + foss_opts = { :default_action => 'gem_install' } + + if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end + hosts.each do |host| on hosts, "mkdir -p #{host['distmoduledir']}" end @@ -22,8 +23,15 @@ # Configure all nodes in nodeset c.before :suite do # Install module and dependencies - puppet_module_install(:source => proj_root, :module_name => 'concat') hosts.each do |host| + on host, "mkdir -p #{host['distmoduledir']}/concat" + result = on host, "echo #{host['distmoduledir']}/concat" + target = result.raw_output.chomp + + %w(files lib manifests metadata.json).each do |file| + scp_to host, "#{proj_root}/#{file}", target + end + #copy_module_to(host, :source => proj_root, :module_name => 'concat') on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } end end diff --git a/concat/spec/unit/classes/concat_setup_spec.rb b/concat/spec/unit/classes/concat_setup_spec.rb index 3096e7368..b25428ef5 100644 --- a/concat/spec/unit/classes/concat_setup_spec.rb +++ b/concat/spec/unit/classes/concat_setup_spec.rb @@ -5,7 +5,14 @@ shared_examples 'setup' do |concatdir| concatdir = '/foo' if concatdir.nil? - let(:facts) {{ :concat_basedir => concatdir }} + let(:facts) do + { + :concat_basedir => concatdir, + :caller_module_name => 'Test', + :osfamily => 'Debian', + :id => 'root', + } + end it do should contain_file("#{concatdir}/bin/concatfragments.sh").with({ @@ -44,9 +51,10 @@ concatdir = '/foo' let(:facts) do { - :concat_basedir => concatdir, - :osfamily => 'Solaris', - :id => 'root', + :concat_basedir => concatdir, + :caller_module_name => 'Test', + :osfamily => 'Solaris', + :id => 'root', } end @@ -65,9 +73,10 @@ concatdir = '/foo' let(:facts) do { - :concat_basedir => concatdir, - :osfamily => 'windows', - :id => 'batman', + :concat_basedir => concatdir, + :caller_module_name => 'Test', + :osfamily => 'windows', + :id => 'batman', } end diff --git a/concat/spec/unit/defines/concat_fragment_spec.rb b/concat/spec/unit/defines/concat_fragment_spec.rb index 3c61aabf7..64ae7dbdf 100644 --- a/concat/spec/unit/defines/concat_fragment_spec.rb +++ b/concat/spec/unit/defines/concat_fragment_spec.rb @@ -24,7 +24,14 @@ end let(:title) { title } - let(:facts) {{ :concat_basedir => concatdir, :id => id }} + let(:facts) do + { + :concat_basedir => concatdir, + :id => id, + :osfamily => 'Debian', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + } + end let(:params) { params } let(:pre_condition) do "concat{ '#{p[:target]}': }" @@ -162,7 +169,13 @@ context 'ensure => target and source' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) do + { + :concat_basedir => '/tmp', + :osfamily => 'Debian', + :id => 'root', + } + end let(:params) do { :target => '/etc/motd', @@ -178,7 +191,13 @@ context 'ensure => target and content' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) do + { + :concat_basedir => '/tmp', + :osfamily => 'Debian', + :id => 'root', + } + end let(:params) do { :target => '/etc/motd', @@ -194,7 +213,13 @@ context 'source and content' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) do + { + :concat_basedir => '/tmp', + :osfamily => 'Debian', + :id => 'root', + } + end let(:params) do { :target => '/etc/motd', diff --git a/concat/spec/unit/defines/concat_spec.rb b/concat/spec/unit/defines/concat_spec.rb index 9fdd7b26f..7682cdf0b 100644 --- a/concat/spec/unit/defines/concat_spec.rb +++ b/concat/spec/unit/defines/concat_spec.rb @@ -33,7 +33,15 @@ let(:title) { title } let(:params) { params } - let(:facts) {{ :concat_basedir => concatdir, :id => id }} + let(:facts) do + { + :concat_basedir => concatdir, + :id => id, + :osfamily => 'Debian', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + :kernel => 'Linux', + } + end if p[:ensure] == 'present' it do @@ -144,6 +152,7 @@ should contain_exec("concat_#{title}").with({ :alias => "concat_#{fragdir}", :command => 'true', + :unless => 'true', :path => '/bin:/usr/bin', }) end @@ -307,10 +316,18 @@ end context 'false' do + it_behaves_like 'concat', '/etc/foo.bar', { :backup => false } + end + + context 'true' do + it_behaves_like 'concat', '/etc/foo.bar', { :backup => true } + end + + context 'true' do let(:title) { '/etc/foo.bar' } - let(:params) {{ :backup => false }} + let(:params) {{ :backup => [] }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { should }.to raise_error(Puppet::Error, /backup must be string or bool/) end end end # backup =>