From a63e8a9549a627153fb9ea8450778454f541617f Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Tue, 3 Mar 2015 11:31:14 +0100 Subject: [PATCH] Update concat to 30fbfe11aaf6d9d90e2cbf8cb5e20f2bd7748123 30fbfe11aaf6d9d90e2cbf8cb5e20f2bd7748123 Merge pull request #277 from buzzdeee/concat_order_verification_fix a3d8632a2ef95dd7da88ca848dd369299cd4fd8a Merge pull request #230 from duritong/set_group_for_fragments b897904dda59638f515f62129c46607674cfc35b When testing the order parameter on sanity, make sure that pattern matching is only exercised on strings. Integers don't like that. 0aa6c635c13e5978f38000e2f6d64b4796a02b4a set group of fragments to gid eb04c55ef581e3bc25ee27c758138d61bd9a7f44 Merge pull request #275 from mhaskel/validate_order 2ca56da4d286eccda77cbd28208f2f19b6d77e0c Add validation for order parameter 2d60bcb4f94af1ca52f5849a87602cf8683f4e2a Merge pull request #270 from raphink/dev/is_pe 9e1a8f86b52ab0b148a90d6e9d57c28725fce553 Merge pull request #274 from puppetlabs/revert-273-fix_strict_vars 410e180336de566cdf89581d4eb4ffb8ca5136b2 Revert "Lookup is_pe fact with getvar" a4133c496e686744206a42ae1c0cc5d57f6bcf36 Merge pull request #273 from cmurphy/fix_strict_vars 59d7a3a75c70a446b26a6d5501eb9042611e2749 Lookup is_pe fact with getvar 9b3f4b32d9da9ee18cde665d0532ebe543319bda Merge pull request #271 from nibalizer/master 0e0dc74662f3373e12ef4b1557276250df596812 Removing travis badge 6a0e9cc40341d4242ad6d7b91f83e5f39f1c0d6c Check if $is_pe exists before using it f6e9f0a4ec925aa0c77975940ea2a834a8029dc6 Merge pull request #269 from mhaskel/merge_1.2.x_into_master 3173e966979a9ccf0f20ca905e55731f3a5e71f7 1.2.0 prep c7c0e4ae5edad5b52bcd991361f958f96bb46d6b Merge pull request #266 from mhaskel/remove_shell 7eb14b776838039ac923e8ff8e56871a3b35df1a Remove shell script 20d0a5fde111e6216d3aafeddf2c60eb338e6baa Merge pull request #265 from mhaskel/validation_test_fix 36ff0ea613371262551b09a9236a7e30d3d21e41 The validation acceptance test is very Linux specific 164a9a01a8614be151de814116d405a6ac430104 Merge pull request #263 from cmurphy/fix_validate_cmd a198e5db14c8f36a919b2f6b7bd7dc3ce2891dbe Fix validate_cmd file resource parameter 3a634af4aa438da2ae1fffbdaa08ee0d51cd912e Merge pull request #243 from jmkeyes/add-validation-command bccd7ed992969d1151fc787fa36bafce062f36d5 Merge pull request #262 from cyberious/master 520287fd0546f96d58722c014c44bfa42d853e6a Fix Solaris 10 errors in tests and more issues with Windows checks of owner 88869c6aedd03d2995173e557440298a760ce2d0 Merge pull request #260 from cyberious/master b9b13d28068b25968a88fa308664540fe73df08f Currently sorting by numeric and the ruby file is not supported, this fixes that 7bc211ceba390f4a44ae2857b79eb8237fa2e529 MODULES-1764 Fix missing method for check_is_owned_by for windows 40200a6d844f828019be066aa91e6841d6d360dd Merge pull request #261 from mhaskel/merge_1.1.x_to_master 3b2e37ab1ea236f4be82b439f19aead2e8ffb8b7 MODULES-1456 - make sure ruby is in path on PE fa5c1cfac30544661711eb34ecd157312bb578c4 Merge pull request #249 from nosolutions/master 9036086db6bff330c821dab62fcc3b417e4ee19f Merge pull request #258 from cmurphy/rspec aacf1bd5e14972d0645961354bb80a727bdc3abe Pin rspec gems 2518958db0c7715f3d228969bf9f8b810c874742 Merge pull request #256 from cyberious/BeakerRspecPin 7d49b5f4f8b07a1eabe62948da99ef7104ea383b Beaker-Rspec broken on Windows, enable ability to pin to older version until fixed be933446dc0e466e10dd0c2e119f9ae16118a05d Merge pull request #255 from hunner/fix_pending cff25a8b60a49649f53a55c77426c7159801081a Fix pending tests 7ed3f566c68b05ecf3fc54e4c0d7e0cf2487f11b Merge pull request #254 from cmurphy/master ce90edc4b78b01673f0e82ca7c5314d8f0677e01 Add IntelliJ files to the ignore list aab8e17cac690cc7a22bb297d85346d9981c2e53 Merge pull request #250 from laurenrother/summary dbf3124b96edf36e57c64b859768d7a1e1406688 Merge pull request #252 from cmurphy/master ee87c656418d24e088627105feac774296cda903 Add json gem 440a6b7be36cb052d9093aa3c1f7b1d3b1d8041d Update .travis.yml, Gemfile, Rakefile, and CONTRIBUTING.md 8fb09fbcc9491e33067dff385e717a0461016664 Merge pull request #251 from cmurphy/puppet_27 6f1e97a916eae69f52375187774c4a2c49a62ffe Define travis matrix in .sync.yml 027484da3a243f9f2db3011616f560879604cf01 Add metadata summary per FM-1523 4fc1dfc46210a3623aba931f5fd746edb5036280 use concatfragments.rb on AIX 708def1aeb23b8dcccc163c6e7866e2b60476655 Merge pull request #248 from mhaskel/merge_1.1.x d3446f666c36a831bc42a2489b1e886783fbfe69 Merge remote-tracking branch 'upstream/1.1.x' into merge_1.1.x 351d5f66e44ef7e15aacc12b2c1ec5b36bae0d65 Merge pull request #247 from mhaskel/work_around_cert_issues dc9f4b3f6f46728bfcd7256bec5ab7aa93126feb Use a path that works on both 32 and 64-bit windows 0133d3ac4908bfcf1c5073bfee07b3d9e162522d Add acceptance test for validate_cmd parameter. 79c5e45a24a104eecc66149b5e15f9d52ade29bb Add unit tests for validate_cmd parameter. 09a01d80875c8572433c75b19612be6ae8fdb742 Ensure validate_cmd is a string and fail explicitly otherwise. 5f5b892843e163f99987884a4472f983d36cd7b6 Merge pull request #245 from mhaskel/merge_1.1.x 0613485f11fca030b372aab61b98554e55bc332a Merge remote-tracking branch 'upstream/1.1.x' into merge_1.1.x b69246a732c0fbc9f8418c06e94c1ebdcd770b5a Merge pull request #244 from mhaskel/work_around_cert_issues c79d81a8fe47a02ffcc1f2b04859ec9988ceadc2 Work around cert issues on solaris and windows 561935586de2d38d7b5a94f44b6986429c0725a9 Support running a validation command on the destination file. d97a047e3591faf33897b4d57c7a75a829e39185 Merge pull request #231 from GeoffWilliams/poison_exec_defaults_fix 520224fbe1de086001c118eda9f88ec670fcaf98 Merge pull request #242 from mhaskel/test ab06c2b8c09d9da82b53a62a5389427720519cd5 Merge pull request #241 from cyberious/InstallCert 8cb4c2447a3fa424cfb1f18b84604fe725360c13 Use apply manifest instead of timeout transaction if it does hang 75dd7251795b2757779c2d42649eaa99546ffcad Merge pull request #240 from mhaskel/1.1.2-prep ea3d6e3146a356febb36cb5cb99f7619d49fb3f4 1.1.2 prep 73c7896632011116012a4dd188c3dea5b95c56f8 Merge pull request #239 from mhaskel/pull_master_to_1.1.x fe9730ab6cba6c8354c84e7da88e4198796f8e03 Merge pull request #238 from mhaskel/windows_cert_fix 624ae75baabff2a0e4749cfda095671505ac4698 Install certs on windows ed6efe8972c7d7f2d592a012ac9e9bad57d7513e Reset poisoned defaults from Exec --- Puppetfile | 2 +- concat/.gitignore | 2 + concat/.sync.yml | 8 + concat/.travis.yml | 2 +- concat/CHANGELOG.md | 32 +++- concat/CONTRIBUTING.md | 22 +-- concat/Gemfile | 37 +++-- concat/README.md | 10 +- concat/Rakefile | 2 +- concat/files/concatfragments.rb | 25 ++-- concat/files/concatfragments.sh | 140 ------------------ concat/manifests/fragment.pp | 10 +- concat/manifests/init.pp | 52 +++++-- concat/manifests/setup.pp | 18 +-- concat/metadata.json | 11 +- concat/spec/acceptance/backup_spec.rb | 8 +- concat/spec/acceptance/concat_spec.rb | 64 ++++---- .../acceptance/deprecation_warnings_spec.rb | 24 +-- concat/spec/acceptance/empty_spec.rb | 2 +- .../spec/acceptance/fragment_source_spec.rb | 50 ++++--- .../fragments_are_always_replaced_spec.rb | 18 ++- concat/spec/acceptance/newline_spec.rb | 8 +- .../nodesets/ubuntu-server-10044-x64.yml | 2 +- .../nodesets/ubuntu-server-12042-x64.yml | 2 +- concat/spec/acceptance/order_spec.rb | 100 +++++-------- concat/spec/acceptance/quoted_paths_spec.rb | 4 +- concat/spec/acceptance/replace_spec.rb | 24 +-- concat/spec/acceptance/specinfra_stubs.rb | 19 +++ concat/spec/acceptance/symbolic_name_spec.rb | 6 +- concat/spec/acceptance/validation_spec.rb | 35 +++++ concat/spec/acceptance/warn_spec.rb | 24 +-- concat/spec/spec_helper_acceptance.rb | 38 +++-- concat/spec/unit/classes/concat_setup_spec.rb | 9 +- .../spec/unit/defines/concat_fragment_spec.rb | 58 ++++++-- concat/spec/unit/defines/concat_spec.rb | 43 ++++-- 35 files changed, 492 insertions(+), 419 deletions(-) delete mode 100755 concat/files/concatfragments.sh create mode 100644 concat/spec/acceptance/specinfra_stubs.rb create mode 100644 concat/spec/acceptance/validation_spec.rb diff --git a/Puppetfile b/Puppetfile index 1346f40e3..abc85c012 100644 --- a/Puppetfile +++ b/Puppetfile @@ -23,7 +23,7 @@ mod 'common', :git => 'https://github.com/purpleidea/puppet-common.git' mod 'concat', - :commit => '644fb1b6dc8b64accc4d1208d6127b79a08a38b7', + :commit => '30fbfe11aaf6d9d90e2cbf8cb5e20f2bd7748123', :git => 'https://github.com/puppetlabs/puppetlabs-concat.git' mod 'firewall', diff --git a/concat/.gitignore b/concat/.gitignore index b5b7a00d6..b5db85e05 100644 --- a/concat/.gitignore +++ b/concat/.gitignore @@ -5,3 +5,5 @@ spec/fixtures/ .vagrant/ .bundle/ coverage/ +.idea/ +*.iml diff --git a/concat/.sync.yml b/concat/.sync.yml index ed97d539c..08e91a74a 100644 --- a/concat/.sync.yml +++ b/concat/.sync.yml @@ -1 +1,9 @@ --- +.travis.yml: + includes: + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" diff --git a/concat/.travis.yml b/concat/.travis.yml index 66e90e38d..ec6f08dc6 100644 --- a/concat/.travis.yml +++ b/concat/.travis.yml @@ -1,6 +1,6 @@ --- language: ruby -bundler_args: --without development +bundler_args: --without system_tests script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" matrix: fast_finish: true diff --git a/concat/CHANGELOG.md b/concat/CHANGELOG.md index 54367bef3..2043b6046 100644 --- a/concat/CHANGELOG.md +++ b/concat/CHANGELOG.md @@ -1,5 +1,31 @@ -##2014-09-10 - Supported Release 1.1.1 +##2015-02-17 - Supported Release 1.2.0 +###Summary + +This release includes a number of bugfixes and adds support for running a validation command when using puppet >= 3.5.0. + +####Features +- Support running a validation command for Puppet >= 3.5.0 +####Bugfixes +- Reset poisoned defaults from Exec +- Use concatfragments.rb on AIX since it doesn't support print0 +- Make sure ruby is in the path for PE (MODULES-1456) +- Fix missing method for check_is_owned_by for windows (MODULES-1764) +- Fix sort by numeric + +##2014-10-28 - Supported Release 1.1.2 +###Summary + +This release includes bugfixes and test improvements. The module was tested against SLES10 and SLES12 and found to work against those platforms with no module improvements. Metadata was updated to include those as supported platforms. + +####Bugfixes +- newline didn't work for Windows and Solaris. This has been fixed. +- Install certs on Windows for acceptance tests +- Update tests to work with strict variables (no module updates were required) +- Update tests to work on Windows +- Fix typo in CHANGELOG.md + +##2014-09-10 - Supported Release 1.1.1 ###Summary This is a bugfix release, and the first supported release of the 1.1.x series. @@ -19,7 +45,6 @@ This is a bugfix release, and the first supported release of the 1.1.x series. - 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. @@ -34,7 +59,6 @@ This release is primarily a bugfix release since 1.1.0-rc1. - Fix newlines ##2014-01-03 - Release 1.1.0-rc1 - ###Summary This release of concat was 90% written by Joshua Hoblitt, and the module team @@ -124,7 +148,6 @@ This is a supported release. No functional changes were made from 1.0.1. ##2014-02-12 - 1.0.1 - ###Summary Minor bugfixes for sorting of fragments and ordering of resources. @@ -137,7 +160,6 @@ fragments. ##2013-08-09 - 1.0.0 - ###Summary Many new features and bugfixes in this release, and if you're a heavy concat diff --git a/concat/CONTRIBUTING.md b/concat/CONTRIBUTING.md index e1288478a..f1cbde4bb 100644 --- a/concat/CONTRIBUTING.md +++ b/concat/CONTRIBUTING.md @@ -41,11 +41,9 @@ Checklist (and a short version for the impatient) * Pre-requisites: - - Sign the [Contributor License Agreement](https://cla.puppetlabs.com/) - - Make sure you have a [GitHub account](https://github.com/join) - - [Create a ticket](http://projects.puppetlabs.com/projects/modules/issues/new), or [watch the ticket](http://projects.puppetlabs.com/projects/modules/issues) you are patching for. + - [Create a ticket](https://tickets.puppetlabs.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppetlabs.com/browse/) you are patching for. * Preferred method: @@ -94,17 +92,7 @@ The long version whitespace or other "whitespace errors". You can do this by running "git diff --check" on your changes before you commit. - 2. Sign the Contributor License Agreement - - Before we can accept your changes, we do need a signed Puppet - Labs Contributor License Agreement (CLA). - - You can access the CLA via the [Contributor License Agreement link](https://cla.puppetlabs.com/) - - If you have any questions about the CLA, please feel free to - contact Puppet Labs via email at cla-submissions@puppetlabs.com. - - 3. Sending your patches + 2. Sending your patches To submit your changes via a GitHub pull request, we _highly_ recommend that you have them on a topic branch, instead of @@ -124,7 +112,7 @@ The long version in order to open a pull request. - 4. Update the related GitHub issue. + 3. Update the related GitHub issue. If there is a GitHub issue associated with the change you submitted, then you should update the ticket to include the @@ -220,14 +208,12 @@ review. Additional Resources ==================== -* [Getting additional help](http://projects.puppetlabs.com/projects/puppet/wiki/Getting_Help) +* [Getting additional help](http://puppetlabs.com/community/get-help) * [Writing tests](http://projects.puppetlabs.com/projects/puppet/wiki/Development_Writing_Tests) * [Patchwork](https://patchwork.puppetlabs.com) -* [Contributor License Agreement](https://projects.puppetlabs.com/contributor_licenses/sign) - * [General GitHub documentation](http://help.github.com/) * [GitHub pull request documentation](http://help.github.com/send-pull-requests/) diff --git a/concat/Gemfile b/concat/Gemfile index 081b1a291..a9e0734a4 100644 --- a/concat/Gemfile +++ b/concat/Gemfile @@ -1,25 +1,44 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" -group :development, :test do +def location_for(place, fake_version = nil) + if place =~ /^(git:[^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + +group :development, :unit_tests do gem 'rake', :require => false - gem 'rspec-puppet', :require => false + gem 'rspec-core', '3.1.7', :require => false + gem 'rspec-puppet', '~> 1.0', :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'serverspec', :require => false - gem 'puppet-lint', '0.3.2', :require => false - gem 'beaker', :require => false - gem 'beaker-rspec', :require => false - gem 'pry', :require => false + gem 'puppet-lint', :require => false gem 'simplecov', :require => false + gem 'puppet_facts', :require => false + gem 'json', :require => false +end + +beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] +group :system_tests do + if beaker_rspec_version + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end + gem 'serverspec', :require => false end if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', facterversion, :require => false + gem 'facter', *location_for(facterversion) else gem 'facter', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false + gem 'puppet', *location_for(puppetversion) else gem 'puppet', :require => false end diff --git a/concat/README.md b/concat/README.md index 2ed9024eb..b1cb66b64 100644 --- a/concat/README.md +++ b/concat/README.md @@ -1,7 +1,5 @@ #Concat -[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-concat.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-concat) - ####Table of Contents 1. [Overview](#overview) @@ -216,6 +214,14 @@ Ensure there's a newline at the end of the fragments. - ensure_newline => true - ensure_newline => false +#####`validate_cmd` +Ensure the destination file passes the following validation command. +Only supported on Puppet >= 3.5.0. + +######Example +- validate_cmd => '/usr/sbin/apache2 -t -f %' +- validate_cmd => '/usr/sbin/visudo -c -f %' + ####concat::fragment #####`target` diff --git a/concat/Rakefile b/concat/Rakefile index 5868545f2..e3be95b0b 100644 --- a/concat/Rakefile +++ b/concat/Rakefile @@ -2,9 +2,9 @@ require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' PuppetLint.configuration.fail_on_warnings +PuppetLint.configuration.send('relative') PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send('disable_class_parameter_defaults') PuppetLint.configuration.send('disable_documentation') PuppetLint.configuration.send('disable_single_quote_string_with_variables') PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] diff --git a/concat/files/concatfragments.rb b/concat/files/concatfragments.rb index 904f82460..b16f3e13c 100644 --- a/concat/files/concatfragments.rb +++ b/concat/files/concatfragments.rb @@ -40,13 +40,13 @@ require 'fileutils' settings = { - :outfile => "", - :workdir => "", - :test => false, - :force => false, - :warn => "", - :sortarg => "", - :newline => false + :outfile => "", + :workdir => "", + :test => false, + :force => false, + :warn => "", + :sortarg => "", + :newline => false } OptionParser.new do |opts| @@ -116,15 +116,18 @@ Dir.chdir(settings[:workdir]) if settings[:warn].empty? - File.open("fragments.concat", 'w') {|f| f.write("") } + File.open("fragments.concat", 'w') { |f| f.write("") } else - File.open("fragments.concat", 'w') {|f| f.write("#{settings[:warn]}\n") } + File.open("fragments.concat", 'w') { |f| f.write("#{settings[:warn]}\n") } end # 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| - + fragments = Dir.entries("fragments").sort + if settings[:sortarg] == '-n' + fragments = fragments.sort_by { |v| v.split('_').map(&:to_i) } + end + fragments.each { |entry| if File.file?(File.join("fragments", entry)) f << File.read(File.join("fragments", entry)) diff --git a/concat/files/concatfragments.sh b/concat/files/concatfragments.sh deleted file mode 100755 index 7e6b0f5c5..000000000 --- a/concat/files/concatfragments.sh +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/sh - -# Script to concat files to a config file. -# -# Given a directory like this: -# /path/to/conf.d -# |-- fragments -# | |-- 00_named.conf -# | |-- 10_domain.net -# | `-- zz_footer -# -# The script supports a test option that will build the concat file to a temp location and -# use /usr/bin/cmp to verify if it should be run or not. This would result in the concat happening -# twice on each run but gives you the option to have an unless option in your execs to inhibit rebuilds. -# -# Without the test option and the unless combo your services that depend on the final file would end up -# restarting on each run, or in other manifest models some changes might get missed. -# -# OPTIONS: -# -o The file to create from the sources -# -d The directory where the fragments are kept -# -t Test to find out if a build is needed, basically concats the files to a temp -# location and compare with what's in the final location, return codes are designed -# for use with unless on an exec resource -# -w Add a shell style comment at the top of the created file to warn users that it -# is generated by puppet -# -f Enables the creation of empty output files when no fragments are found -# -n Sort the output numerically rather than the default alpha sort -# -# the command: -# -# concatfragments.sh -o /path/to/conffile.cfg -d /path/to/conf.d -# -# creates /path/to/conf.d/fragments.concat and copies the resulting -# file to /path/to/conffile.cfg. The files will be sorted alphabetically -# pass the -n switch to sort numerically. -# -# The script does error checking on the various dirs and files to make -# sure things don't fail. - -OUTFILE="" -WORKDIR="" -TEST="" -FORCE="" -WARN="" -SORTARG="" -ENSURE_NEWLINE="" - -PATH=/sbin:/usr/sbin:/bin:/usr/bin - -## Well, if there's ever a bad way to do things, Nexenta has it. -## http://nexenta.org/projects/site/wiki/Personalities -unset SUN_PERSONALITY - -while getopts "o:s:d:tnw:fl" options; do - case $options in - o ) OUTFILE=$OPTARG;; - d ) WORKDIR=$OPTARG;; - n ) SORTARG="-n";; - w ) WARNMSG="$OPTARG";; - f ) FORCE="true";; - t ) TEST="true";; - l ) ENSURE_NEWLINE="true";; - * ) echo "Specify output file with -o and fragments directory with -d" - exit 1;; - esac -done - -# do we have -o? -if [ "x${OUTFILE}" = "x" ]; then - echo "Please specify an output file with -o" - exit 1 -fi - -# do we have -d? -if [ "x${WORKDIR}" = "x" ]; then - echo "Please fragments directory with -d" - exit 1 -fi - -# can we write to -o? -if [ -f "${OUTFILE}" ]; then - if [ ! -w "${OUTFILE}" ]; then - echo "Cannot write to ${OUTFILE}" - exit 1 - fi -else - if [ ! -w `dirname "${OUTFILE}"` ]; then - echo "Cannot write to `dirname \"${OUTFILE}\"` to create ${OUTFILE}" - exit 1 - fi -fi - -# do we have a fragments subdir inside the work dir? -if [ ! -d "${WORKDIR}/fragments" ] && [ ! -x "${WORKDIR}/fragments" ]; then - echo "Cannot access the fragments directory" - exit 1 -fi - -# are there actually any fragments? -if [ ! "$(ls -A """${WORKDIR}/fragments""")" ]; then - if [ "x${FORCE}" = "x" ]; then - echo "The fragments directory is empty, cowardly refusing to make empty config files" - exit 1 - fi -fi - -cd "${WORKDIR}" - -if [ "x${WARNMSG}" = "x" ]; then - : > "fragments.concat" -else - printf '%s\n' "$WARNMSG" > "fragments.concat" -fi - -# find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir -IFS_BACKUP=$IFS -IFS=' -' -for fragfile in `find fragments/ -type f -follow -print0 | xargs -0 -n1 basename | LC_ALL=C sort ${SORTARG}` -do - cat "fragments/$fragfile" >> "fragments.concat" - # Handle newlines. - if [ "x${ENSURE_NEWLINE}" != "x" ]; then - echo >> "fragments.concat" - fi -done -IFS=$IFS_BACKUP - -if [ "x${TEST}" = "x" ]; then - # This is a real run, copy the file to outfile - cp fragments.concat "${OUTFILE}" - RETVAL=$? -else - # Just compare the result to outfile to help the exec decide - cmp "${OUTFILE}" fragments.concat - RETVAL=$? -fi - -exit $RETVAL diff --git a/concat/manifests/fragment.pp b/concat/manifests/fragment.pp index 34ec4c248..b6a2b0232 100644 --- a/concat/manifests/fragment.pp +++ b/concat/manifests/fragment.pp @@ -42,6 +42,8 @@ } if !(is_string($order) or is_integer($order)) { fail('$order is not a string or integer.') + } elsif (is_string($order) and $order =~ /[:\n\/]/) { + fail("Order cannot contain '/', ':', or '\n'.") } if $mode { warning('The $mode parameter to concat::fragment is deprecated and has no effect') @@ -70,8 +72,9 @@ $safe_target_name = regsubst($target, '[/:\n]', '_', 'GM') $concatdir = $concat::setup::concatdir $fragdir = "${concatdir}/${safe_target_name}" - $fragowner = $concat::setup::fragment_owner - $fragmode = $concat::setup::fragment_mode + $fragowner = $concat::setup::fragment_owner + $fraggroup = $concat::setup::fragment_group + $fragmode = $concat::setup::fragment_mode # The file type's semantics are problematic in that ensure => present will # not over write a pre-existing symlink. We are attempting to provide @@ -108,11 +111,10 @@ crit('No content, source or symlink specified') } - # punt on group ownership until some point in the distant future when $::gid - # can be relied on to be present file { "${fragdir}/fragments/${order}_${safe_name}": ensure => $safe_ensure, owner => $fragowner, + group => $fraggroup, mode => $fragmode, source => $source, content => $content, diff --git a/concat/manifests/init.pp b/concat/manifests/init.pp index 77f9d5fd2..fa05a1004 100644 --- a/concat/manifests/init.pp +++ b/concat/manifests/init.pp @@ -34,7 +34,7 @@ # # === Actions: # * Creates fragment directories if it didn't exist already -# * Executes the concatfragments.sh script to build the final file, this +# * Executes the concatfragments.rb script to build the final file, this # script will create directory/fragments.concat. Execution happens only # when: # * The directory changes @@ -64,6 +64,7 @@ $replace = true, $order = 'alpha', $ensure_newline = false, + $validate_cmd = undef, $gnu = undef ) { validate_re($ensure, '^present$|^absent$') @@ -81,6 +82,9 @@ validate_bool($replace) validate_re($order, '^alpha$|^numeric$') validate_bool($ensure_newline) + if $validate_cmd and ! is_string($validate_cmd) { + fail('$validate_cmd must be a string') + } if $gnu { warning('The $gnu parameter to concat is deprecated and has no effect') } @@ -140,6 +144,12 @@ backup => false, } + # reset poisoned Exec defaults + Exec { + user => undef, + group => undef, + } + if $ensure == 'present' { file { $fragdir: ensure => directory, @@ -167,22 +177,40 @@ } file { $name: - ensure => present, - owner => $owner, - group => $group, - mode => $mode, - replace => $replace, - path => $path, - alias => "concat_${name}", - source => "${fragdir}/${concat_name}", - backup => $backup, + ensure => present, + owner => $owner, + group => $group, + mode => $mode, + replace => $replace, + path => $path, + alias => "concat_${name}", + source => "${fragdir}/${concat_name}", + backup => $backup, + } + + # Only newer versions of puppet 3.x support the validate_cmd parameter + if $validate_cmd { + File[$name] { + validate_cmd => $validate_cmd, + } } # remove extra whitespace from string interpolation to make testing easier $command = strip(regsubst("${script_command} -o \"${fragdir}/${concat_name}\" -d \"${fragdir}\" ${warnflag} ${forceflag} ${orderflag} ${newlineflag}", '\s+', ' ', 'G')) + # make sure ruby is in the path for PE + if defined('$is_pe') and $::is_pe { + if $::kernel == 'windows' { + $command_path = "${::env_windows_installdir}/bin:${::path}" + } else { + $command_path = "/opt/puppet/bin:${::path}" + } + } else { + $command_path = $::path + } + # if puppet is running as root, this exec should also run as root to allow - # the concatfragments.sh script to potentially be installed in path that + # the concatfragments.rb script to potentially be installed in path that # may not be accessible by a target non-root owner. exec { "concat_${name}": alias => "concat_${fragdir}", @@ -190,7 +218,7 @@ notify => File[$name], subscribe => File[$fragdir], unless => "${command} -t", - path => $::path, + path => $command_path, require => [ File[$fragdir], File["${fragdir}/fragments"], diff --git a/concat/manifests/setup.pp b/concat/manifests/setup.pp index 1a6af6487..d1a3adf37 100644 --- a/concat/manifests/setup.pp +++ b/concat/manifests/setup.pp @@ -20,21 +20,19 @@ fail ('$concat_basedir not defined. Try running again with pluginsync=true on the [master] and/or [main] section of your node\'s \'/etc/puppet/puppet.conf\'.') } - # owner and mode of fragment files (on windows owner and access rights should + # owner,group and mode of fragment files (on windows owner and access rights should # be inherited from concatdir and not explicitly set to avoid problems) $fragment_owner = $::osfamily ? { 'windows' => undef, default => $::id } $fragment_mode = $::osfamily ? { 'windows' => undef, default => '0640' } - - # PR #174 introduced changes to the concatfragments.sh script that are - # incompatible with Solaris 10 but reportedly OK on Solaris 11. As a work - # around we are enable the .rb concat script on all Solaris versions. If - # this goes smoothly, we should move towards completely eliminating the .sh - # version. - $script_name = $::osfamily? { - /(?i:(Windows|Solaris))/ => 'concatfragments.rb', - default => 'concatfragments.sh' + # test on gid fact availability to support older facter versions + if defined('$gid') and $::gid and $::osfamily != 'Windows' { + $fragment_group = $::gid + } else { + $fragment_group = undef } + $script_name = 'concatfragments.rb' + $script_path = "${concatdir}/bin/${script_name}" $script_owner = $::osfamily ? { 'windows' => undef, default => $::id } diff --git a/concat/metadata.json b/concat/metadata.json index 5a48a8fd4..9d7a46dd0 100644 --- a/concat/metadata.json +++ b/concat/metadata.json @@ -1,12 +1,12 @@ { "name": "puppetlabs-concat", - "version": "1.1.1", + "version": "1.2.0", "author": "Puppet Labs", - "summary": "Concat module", + "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://github.com/puppetlabs/puppetlabs-concat/issues", + "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "operatingsystem_support": [ { "operatingsystem": "RedHat", @@ -105,9 +105,6 @@ } ], "dependencies": [ - { - "name": "puppetlabs/stdlib", - "version_requirement": ">= 3.2.0 < 5.0.0" - } + {"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 1989f4458..1d3a5dfe3 100644 --- a/concat/spec/acceptance/backup_spec.rb +++ b/concat/spec/acceptance/backup_spec.rb @@ -33,7 +33,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new contents' } + its(:content) { should match /new contents/ } end end @@ -68,11 +68,11 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new contents' } + its(:content) { should match /new contents/ } end describe file("#{basedir}/file.backup") do it { should be_file } - it { should contain 'old contents' } + its(:content) { should match /old contents/ } end end @@ -109,7 +109,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new contents' } + its(:content) { should match /new contents/ } end end end diff --git a/concat/spec/acceptance/concat_spec.rb b/concat/spec/acceptance/concat_spec.rb index 7cec1a5a0..c5c972774 100644 --- a/concat/spec/acceptance/concat_spec.rb +++ b/concat/spec/acceptance/concat_spec.rb @@ -1,37 +1,37 @@ 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'] + when 'AIX' + username = 'root' + groupname = 'system' + scriptname = 'concatfragments.rb' + vardir = default['puppetvardir'] + when 'Darwin' + username = 'root' + groupname = 'wheel' + scriptname = 'concatfragments.rb' + 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.rb' + vardir = default['puppetvardir'] end describe 'basic concat test' do basedir = default.tmpdir('concat') - safe_basedir = basedir.gsub(/[\/:]/,'_') + safe_basedir = basedir.gsub(/[\/:]/, '_') shared_examples 'successfully_applied' do |pp| it 'applies the manifest twice with no stderr' do @@ -46,7 +46,7 @@ should be_mode 755 } end - describe file("#{vardir}/concat/bin") do + describe file("#{vardir}/concat/bin") do it { should be_directory } it { should be_owned_by username } it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { @@ -128,8 +128,10 @@ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { should be_mode 644 } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do it { should be_file } @@ -177,7 +179,7 @@ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { should be_mode 644 } - it { should contain '1' } + its(:content) { should match '1' } end end context 'works when set to absent with path set' do diff --git a/concat/spec/acceptance/deprecation_warnings_spec.rb b/concat/spec/acceptance/deprecation_warnings_spec.rb index dc2f234d0..11133ea9f 100644 --- a/concat/spec/acceptance/deprecation_warnings_spec.rb +++ b/concat/spec/acceptance/deprecation_warnings_spec.rb @@ -3,7 +3,7 @@ describe 'deprecation warnings' do basedir = default.tmpdir('concat') - shared_examples 'has_warning'do |pp, w| + 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) @@ -43,8 +43,10 @@ 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' } + its(:content) { + should match '# This file is managed by Puppet. DO NOT EDIT.' + should match 'bar' + } end end end @@ -66,8 +68,10 @@ 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' } + its(:content) { + should_not match '# This file is managed by Puppet. DO NOT EDIT.' + should match 'bar' + } end end end @@ -100,7 +104,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'file1 contents' } + its(:content) { should match 'file1 contents' } end describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact("osfamily") == "windows") do @@ -119,8 +123,10 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new content' } - it { should_not contain 'file1 contents' } + its(:content) { + should match 'new content' + should_not match 'file1 contents' + } end end end # target file exists @@ -157,7 +163,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new content' } + its(:content) { should match 'new content' } end end end # target file exists diff --git a/concat/spec/acceptance/empty_spec.rb b/concat/spec/acceptance/empty_spec.rb index dc57cb791..4ab6e1e60 100644 --- a/concat/spec/acceptance/empty_spec.rb +++ b/concat/spec/acceptance/empty_spec.rb @@ -17,7 +17,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should_not contain '1\n2' } + its(:content) { should_not match /1\n2/ } end end end diff --git a/concat/spec/acceptance/fragment_source_spec.rb b/concat/spec/acceptance/fragment_source_spec.rb index f3bbfccdf..a174e02b4 100644 --- a/concat/spec/acceptance/fragment_source_spec.rb +++ b/concat/spec/acceptance/fragment_source_spec.rb @@ -1,18 +1,18 @@ 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' + 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 @@ -50,9 +50,11 @@ describe file("#{basedir}/foo") do it { should be_file } - it { should contain 'file1 contents' } - it { should contain 'string1 contents' } - it { should contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should match 'string1 contents' + should match 'file2 contents' + } end end # should read file fragments from local system @@ -106,18 +108,24 @@ end describe file("#{basedir}/result_file1") do it { should be_file } - it { should contain 'file1 contents' } - it { should_not contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should_not match 'file2 contents' + } end describe file("#{basedir}/result_file2") do it { should be_file } - it { should contain 'file2 contents' } - it { should_not contain 'file1 contents' } + its(:content) { + should match 'file2 contents' + should_not match 'file1 contents' + } end describe file("#{basedir}/result_file3") do it { should be_file } - it { should contain 'file1 contents' } - it { should_not contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should_not match 'file2 contents' + } end end diff --git a/concat/spec/acceptance/fragments_are_always_replaced_spec.rb b/concat/spec/acceptance/fragments_are_always_replaced_spec.rb index ac714a964..70d738288 100644 --- a/concat/spec/acceptance/fragments_are_always_replaced_spec.rb +++ b/concat/spec/acceptance/fragments_are_always_replaced_spec.rb @@ -39,8 +39,10 @@ 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' } + its(:content) { + should_not match 'caller has replace unset run 1' + should match 'caller has replace unset run 2' + } end end # should create fragment files @@ -82,8 +84,10 @@ 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' } + its(:content) { + should_not match 'caller has replace true set run 1' + should match 'caller has replace true set run 2' + } end end # should replace its own fragment files when caller has File(replace=>true) set @@ -125,8 +129,10 @@ 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' } + its(:content) { + should_not match 'caller has replace false set run 1' + should match 'caller has replace false set run 2' + } end end # should replace its own fragment files even when caller has File(replace=>false) set diff --git a/concat/spec/acceptance/newline_spec.rb b/concat/spec/acceptance/newline_spec.rb index d182f2adc..c1fa16a10 100644 --- a/concat/spec/acceptance/newline_spec.rb +++ b/concat/spec/acceptance/newline_spec.rb @@ -33,7 +33,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '12' } + its(:content) { should match '12' } end end @@ -54,13 +54,13 @@ it 'applies the manifest twice with no stderr' do apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + apply_manifest(pp, :catch_changes => true) end describe file("#{basedir}/file") do it { should be_file } - it("should contain 1\n2\n", :unless => (fact('osfamily') == 'Solaris')) { - should contain "1\n2\n" + its(:content) { + should match /1\n2\n/ } end end diff --git a/concat/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml b/concat/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml index 5047017e6..5ca1514e4 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: git + type: foss diff --git a/concat/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/concat/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml index 1c7a34ccb..d065b304f 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: git + type: foss diff --git a/concat/spec/acceptance/order_spec.rb b/concat/spec/acceptance/order_spec.rb index fd7b05b4f..c158dd880 100644 --- a/concat/spec/acceptance/order_spec.rb +++ b/concat/spec/acceptance/order_spec.rb @@ -3,69 +3,45 @@ describe 'concat order' do basedir = default.tmpdir('concat') - context '=> alpha' do - pp = <<-EOS + context '=> ' do + shared_examples 'sortby' do |order_by, match_output| + pp = <<-EOS concat { '#{basedir}/foo': - order => 'alpha' + order => '#{order_by}' } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', + order => '1', } concat::fragment { '2': target => '#{basedir}/foo', content => 'string2', + order => '2', } concat::fragment { '10': target => '#{basedir}/foo', content => 'string10', } - EOS + EOS - it 'applies the manifest twice with no stderr' do - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end + 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}/foo") do - it { should be_file } - #XXX Solaris 10 doesn't support multi-line grep - it("should contain string10\nstring1\nsring2", :unless => (fact('osfamily') == 'Solaris')) { - should contain "string10\nstring1\nsring2" - } + describe file("#{basedir}/foo") do + it { should be_file } + its(:content) { should match match_output } + end end - end - context '=> numeric' do - pp = <<-EOS - concat { '#{basedir}/foo': - order => 'numeric' - } - concat::fragment { '1': - target => '#{basedir}/foo', - content => 'string1', - } - concat::fragment { '2': - target => '#{basedir}/foo', - content => 'string2', - } - concat::fragment { '10': - target => '#{basedir}/foo', - content => 'string10', - } - EOS - - it 'applies the manifest twice with no stderr' do - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) + describe 'alpha' do + it_behaves_like 'sortby', 'alpha', /string10string1string2/ end - describe file("#{basedir}/foo") do - it { should be_file } - #XXX Solaris 10 doesn't support multi-line grep - it("should contain string1\nstring2\nsring10", :unless => (fact('osfamily') == 'Solaris')) { - should contain "string1\nstring2\nsring10" - } + describe 'numeric' do + it_behaves_like 'sortby', 'numeric', /string1string2string10/ end end end # concat order @@ -74,8 +50,11 @@ basedir = default.tmpdir('concat') context '=> reverse order' do - pp = <<-EOS - concat { '#{basedir}/foo': } + shared_examples 'order_by' do |order_by, match_output| + pp = <<-EOS + concat { '#{basedir}/foo': + order => '#{order_by}' + } concat::fragment { '1': target => '#{basedir}/foo', content => 'string1', @@ -91,19 +70,23 @@ content => 'string3', order => '1', } - EOS + EOS - it 'applies the manifest twice with no stderr' do - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end + 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}/foo") do - it { should be_file } - #XXX Solaris 10 doesn't support multi-line grep - it("should contain string3\nstring2\nsring1", :unless => (fact('osfamily') == 'Solaris')) { - should contain "string3\nstring2\nsring1" - } + describe file("#{basedir}/foo") do + it { should be_file } + its(:content) { should match match_output } + end + end + describe 'alpha' do + it_should_behave_like 'order_by', 'alpha', /string2string1string3/ + end + describe 'numeric' do + it_should_behave_like 'order_by', 'numeric', /string3string2string1/ end end @@ -134,10 +117,7 @@ describe file("#{basedir}/foo") do it { should be_file } - #XXX Solaris 10 doesn't support multi-line grep - it("should contain string1\nstring2\nsring3", :unless => (fact('osfamily') == 'Solaris')) { - should contain "string1\nstring2\nsring3" - } + its(:content) { should match /string1string2string3/ } 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 165c153fe..042425f92 100644 --- a/concat/spec/acceptance/quoted_paths_spec.rb +++ b/concat/spec/acceptance/quoted_paths_spec.rb @@ -36,9 +36,7 @@ describe file("#{basedir}/concat test/foo") do it { should be_file } - it("should contain string1\nstring2", :unless => (fact('osfamily') == 'Solaris')) { - should contain "string1\nstring2" - } + its(:content) { should match /string1string2/ } end end end diff --git a/concat/spec/acceptance/replace_spec.rb b/concat/spec/acceptance/replace_spec.rb index 688234548..bd597ed19 100644 --- a/concat/spec/acceptance/replace_spec.rb +++ b/concat/spec/acceptance/replace_spec.rb @@ -38,9 +38,11 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain 'file exists' } - it { should_not contain '1' } - it { should_not contain '2' } + its(:content) { + should match 'file exists' + should_not match '1' + should_not match '2' + } end end @@ -79,9 +81,11 @@ describe file("#{basedir}/file") do it { should be_file } - it { should_not contain 'file exists' } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should_not match 'file exists' + should match '1' + should match '2' + } end end end # file @@ -177,8 +181,10 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end end end # symlink @@ -249,7 +255,7 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } + its(:content) { should match '1' } end end end # directory diff --git a/concat/spec/acceptance/specinfra_stubs.rb b/concat/spec/acceptance/specinfra_stubs.rb new file mode 100644 index 000000000..bae85eff0 --- /dev/null +++ b/concat/spec/acceptance/specinfra_stubs.rb @@ -0,0 +1,19 @@ +class Specinfra::Command::Windows::Base::File < Specinfra::Command::Windows::Base + class << self + def check_is_owned_by(file, owner) + Backend::PowerShell::Command.new do + exec "if((Get-Item '#{file}').GetAccessControl().Owner -match '#{owner}' + -or ((Get-Item '#{file}').GetAccessControl().Owner -match '#{owner}').Length -gt 0){ exit 0 } else { exit 1 }" + end + end + end +end + + +class Specinfra::Command::Base::File < Specinfra::Command::Base + class << self + def get_content(file) + "cat '#{file}' 2> /dev/null || echo -n" + end + end +end diff --git a/concat/spec/acceptance/symbolic_name_spec.rb b/concat/spec/acceptance/symbolic_name_spec.rb index b0dceac8c..df8d54f52 100644 --- a/concat/spec/acceptance/symbolic_name_spec.rb +++ b/concat/spec/acceptance/symbolic_name_spec.rb @@ -27,7 +27,9 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end end diff --git a/concat/spec/acceptance/validation_spec.rb b/concat/spec/acceptance/validation_spec.rb new file mode 100644 index 000000000..c35871b9b --- /dev/null +++ b/concat/spec/acceptance/validation_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_acceptance' + +describe 'concat validate_cmd parameter', :unless => (fact('kernel') != 'Linux') do + basedir = default.tmpdir('concat') + context '=> "/usr/bin/test -e %"' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory + } + EOS + + apply_manifest(pp) + end + pp = <<-EOS + concat { '#{basedir}/file': + validate_cmd => '/usr/bin/test -e %', + } + concat::fragment { 'content': + target => '#{basedir}/file', + content => 'content', + } + 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}/file") do + it { should be_file } + it { should contain 'content' } + end + end +end diff --git a/concat/spec/acceptance/warn_spec.rb b/concat/spec/acceptance/warn_spec.rb index 2fa529da2..2788607c8 100644 --- a/concat/spec/acceptance/warn_spec.rb +++ b/concat/spec/acceptance/warn_spec.rb @@ -28,9 +28,11 @@ 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' } - it { should contain '2' } + its(:content) { + should match /# This file is managed by Puppet\. DO NOT EDIT\./ + should match /1/ + should match /2/ + } end end context 'false should not enable default warning message' do @@ -59,9 +61,11 @@ 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' } - it { should contain '2' } + its(:content) { + should_not match /# This file is managed by Puppet\. DO NOT EDIT\./ + should match /1/ + should match /2/ + } end end context '# foo should overide default warning message' do @@ -90,9 +94,11 @@ describe file("#{basedir}/file") do it { should be_file } - it { should contain '# foo' } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match /# foo/ + should match /1/ + should match /2/ + } end end end diff --git a/concat/spec/spec_helper_acceptance.rb b/concat/spec/spec_helper_acceptance.rb index b34a188d6..da994f8df 100644 --- a/concat/spec/spec_helper_acceptance.rb +++ b/concat/spec/spec_helper_acceptance.rb @@ -1,15 +1,37 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' +require 'acceptance/specinfra_stubs' unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no' # 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' } + foss_opts = {:default_action => 'gem_install'} - if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end + if default.is_pe?; then + install_pe; + else + install_puppet(foss_opts); + end hosts.each do |host| on hosts, "mkdir -p #{host['distmoduledir']}" + if host['platform'] =~ /sles-1/i || host['platform'] =~ /solaris-1/i + get_stdlib = <<-EOS + package{'wget':} + exec{'download': + command => "wget -P /root/ https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.5.1.tar.gz --no-check-certificate", + path => ['/opt/csw/bin/','/usr/bin/'] + } + EOS + apply_manifest_on(host, get_stdlib) + # have to use force otherwise it checks ssl cert even though it is a local file + on host, puppet('module install /root/puppetlabs-stdlib-4.5.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} + elsif host['platform'] =~ /windows/i + on host, shell('curl -k -o c:/puppetlabs-stdlib-4.5.1.tar.gz https://forgeapi.puppetlabs.com/v3/files/puppetlabs-stdlib-4.5.1.tar.gz') + on host, puppet('module install c:/puppetlabs-stdlib-4.5.1.tar.gz --force --ignore-dependencies'), {:acceptable_exit_codes => [0, 1]} + else + on host, puppet('module install puppetlabs-stdlib'), {:acceptable_exit_codes => [0, 1]} + end end end @@ -22,17 +44,8 @@ # Configure all nodes in nodeset c.before :suite do - # Install module and dependencies 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] } + copy_module_to(host, :source => proj_root, :module_name => 'concat') end end @@ -45,3 +58,4 @@ c.treat_symbols_as_metadata_keys_with_true_values = true end + diff --git a/concat/spec/unit/classes/concat_setup_spec.rb b/concat/spec/unit/classes/concat_setup_spec.rb index b25428ef5..e97a29caa 100644 --- a/concat/spec/unit/classes/concat_setup_spec.rb +++ b/concat/spec/unit/classes/concat_setup_spec.rb @@ -11,13 +11,14 @@ :caller_module_name => 'Test', :osfamily => 'Debian', :id => 'root', + :is_pe => false, } end it do - should contain_file("#{concatdir}/bin/concatfragments.sh").with({ + should contain_file("#{concatdir}/bin/concatfragments.rb").with({ :mode => '0755', - :source => 'puppet:///modules/concat/concatfragments.sh', + :source => 'puppet:///modules/concat/concatfragments.rb', :backup => false, }) end @@ -43,7 +44,7 @@ context 'deprecated as a public class' do it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end @@ -55,6 +56,7 @@ :caller_module_name => 'Test', :osfamily => 'Solaris', :id => 'root', + :is_pe => false, } end @@ -77,6 +79,7 @@ :caller_module_name => 'Test', :osfamily => 'windows', :id => 'batman', + :is_pe => false, } end diff --git a/concat/spec/unit/defines/concat_fragment_spec.rb b/concat/spec/unit/defines/concat_fragment_spec.rb index 64ae7dbdf..1dc7c38f4 100644 --- a/concat/spec/unit/defines/concat_fragment_spec.rb +++ b/concat/spec/unit/defines/concat_fragment_spec.rb @@ -17,6 +17,7 @@ concatdir = '/var/lib/puppet/concat' fragdir = "#{concatdir}/#{safe_target_name}" id = 'root' + gid = 'root' if p[:ensure] == 'absent' safe_ensure = p[:ensure] else @@ -28,8 +29,10 @@ { :concat_basedir => concatdir, :id => id, + :gid => gid, :osfamily => 'Debian', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + :is_pe => false, } end let(:params) { params } @@ -43,6 +46,7 @@ should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({ :ensure => safe_ensure, :owner => id, + :group => gid, :mode => '0640', :source => p[:source], :content => p[:content], @@ -71,7 +75,7 @@ context 'false' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :target => false }} it 'should fail' do @@ -92,11 +96,11 @@ context 'any value other than \'present\' or \'absent\'' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }} it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end end # ensure => @@ -113,7 +117,7 @@ context 'false' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :content => false, :target => '/etc/motd' }} it 'should fail' do @@ -134,7 +138,7 @@ context 'false' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :source => false, :target => '/etc/motd' }} it 'should fail' do @@ -155,13 +159,41 @@ context 'false' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :order => false, :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string or integer/) end end + + context '123:456' do + let(:title) { 'motd_header' } + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} + let(:params) {{ :order => '123:456', :target => '/etc/motd' }} + + it 'should fail' do + expect { should }.to raise_error(Puppet::Error, /cannot contain/) + end + end + context '123/456' do + let(:title) { 'motd_header' } + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} + let(:params) {{ :order => '123/456', :target => '/etc/motd' }} + + it 'should fail' do + expect { should }.to raise_error(Puppet::Error, /cannot contain/) + end + end + context '123\n456' do + let(:title) { 'motd_header' } + let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} + let(:params) {{ :order => "123\n456", :target => '/etc/motd' }} + + it 'should fail' do + expect { should }.to raise_error(Puppet::Error, /cannot contain/) + end + end end # order => context 'more than one content source' do @@ -174,6 +206,8 @@ :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', + :is_pe => false, + :gid => 'root', } end let(:params) do @@ -196,6 +230,8 @@ :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', + :is_pe => false, + :gid => 'root', } end let(:params) do @@ -218,6 +254,8 @@ :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', + :is_pe => false, + :gid => 'root', } end let(:params) do @@ -244,7 +282,7 @@ } it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end end # mode => @@ -257,7 +295,7 @@ } it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end end # owner => @@ -270,7 +308,7 @@ } it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end end # group => @@ -283,7 +321,7 @@ } it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end end # backup => diff --git a/concat/spec/unit/defines/concat_spec.rb b/concat/spec/unit/defines/concat_spec.rb index 7682cdf0b..a748f9607 100644 --- a/concat/spec/unit/defines/concat_spec.rb +++ b/concat/spec/unit/defines/concat_spec.rb @@ -19,6 +19,7 @@ :replace => true, :order => 'alpha', :ensure_newline => false, + :validate_cmd => nil, }.merge(params) safe_name = title.gsub('/', '_') @@ -40,6 +41,7 @@ :osfamily => 'Debian', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', :kernel => 'Linux', + :is_pe => false, } end @@ -76,19 +78,20 @@ it do should contain_file(title).with(file_defaults.merge({ - :ensure => 'present', - :owner => p[:owner], - :group => p[:group], - :mode => p[:mode], - :replace => p[:replace], - :path => p[:path], - :alias => "concat_#{title}", - :source => "#{fragdir}/#{concat_name}", - :backup => p[:backup], + :ensure => 'present', + :owner => p[:owner], + :group => p[:group], + :mode => p[:mode], + :replace => p[:replace], + :path => p[:path], + :alias => "concat_#{title}", + :source => "#{fragdir}/#{concat_name}", + :validate_cmd => p[:validate_cmd], + :backup => p[:backup], })) end - cmd = "#{concatdir}/bin/concatfragments.sh " + + cmd = "#{concatdir}/bin/concatfragments.rb " + "-o \"#{concatdir}/#{safe_name}/fragments.concat.out\" " + "-d \"#{concatdir}/#{safe_name}\"" @@ -279,7 +282,7 @@ it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn } it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end end @@ -380,13 +383,29 @@ end end # ensure_newline => + context 'validate_cmd =>' do + context '/usr/bin/test -e %' do + it_behaves_like 'concat', '/etc/foo.bar', { :validate_cmd => '/usr/bin/test -e %' } + end + + [ 1234, true ].each do |cmd| + context cmd do + let(:title) { '/etc/foo.bar' } + let(:params) {{ :validate_cmd => cmd }} + it 'should fail' do + expect { should }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/) + end + end + end + end # validate_cmd => + describe 'deprecated parameter' do context 'gnu =>' do context 'foo' do it_behaves_like 'concat', '/etc/foo.bar', { :gnu => 'foo'} it 'should create a warning' do - pending('rspec-puppet support for testing warning()') + skip('rspec-puppet support for testing warning()') end end end