diff --git a/.travis.yml b/.travis.yml index ec6f08d..001fb85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,18 @@ --- +sudo: false language: ruby 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 include: - 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" + - rvm: 2.1.6 + env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" notifications: email: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e60641..68baf33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,257 +1,278 @@ +##2015-06-02 - Supported Release 2.0.1 [YANKED] +###Summary + +This is a bugfix release. + +####Bugfixes +- Fixes dependency graphing with concurrent modification of the same file. +- Fixes handling fragment target. +- Fixes the defaulted force behavior to handle empty concats correctly. + ##2015-06-02 - Supported Release 1.2.3 ###Summary This release includes a README fix to document correct behavior of fragment target parameter. ####Bugfixes - README Fix to correctly document how a fragment $target param should work. +##2015-05-12 - Supported Release 2.0.0 [YANKED] +###Summary + +This is a major release. Includes re-implementation of concat to use native Type and Providers, resulting in significantly improved performance and testability. Also includes a bugfix to alpha ordering of fragments. + +####Features +- Re-implementation of concat to use native Type and Providers. + +####Bugfixes +- Fixes a bug in alpha ordering of fragments. + ##2015-05-12 - Supported Release 1.2.2 ###Summary This release includes a bugfix. ####Bugfixes - Fixes a bug introduced by MODULES-1700, in handling default retrieval of fragment backup parameter. ##2015-04-14 - Supported Release 1.2.1 ###Summary This release includes bugfixes, test improvements, and a rewritten README. ####Bugfixes - Verifies existence of $is_pe before using it. - Adds validation for $order param to not allow restricted characters. - Sets the group id on Fragments for versions of Facter that contain the $gid fact. - Sets the script group to 0 if the script is owned by root. - Explicitly sets script and concat directories to the same owner and group. - Re-adds support for fragment backup, so that static compiler can work with filebucket (MODULES-1700). ##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. ####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 - Improved testing, with tests moved to beaker ####Bugfixes - No longer attempts to set fragment owner and mode on Windows - Fix numeric sorting - Fix incorrect quoting - 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 would like to thank him for the huge amount of work he put into this release. This module deprecates a bunch of old parameters and usage patterns, modernizes much of the manifest code, simplifies a whole bunch of logic and makes improvements to almost all parts of the module. The other major feature is windows support, courtesy of luisfdez, with an alternative version of the concat bash script in ruby. We've attempted to ensure that there are no backwards incompatible changes, all users of 1.0.0 should be able to use 1.1.0 without any failures, but you may find deprecation 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 - 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 - 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. ###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. ##2013-08-09 - 1.0.0 ###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 - 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 - 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 defining resource defaults. - Added -r flag to read so that filenames with \ will be read correctly. - sort always uses LANG=C. - Allow WARNMSG to contain/start with '#'. - Replace while-read pattern with for-do in order to support Solaris. ####CHANGELOG: - 2010/02/19 - initial release - 2010/03/12 - add support for 0.24.8 and newer - make the location of sort configurable - add the ability to add shell comment based warnings to top of files - add the ablity to create empty files - 2010/04/05 - fix parsing of WARN and change code style to match rest of the code - Better and safer boolean handling for warn and force - Don't use hard coded paths in the shell script, set PATH top of the script - Use file{} to copy the result and make all fragments owned by root. This means we can chnage the ownership/group of the resulting file at any time. - You can specify ensure => "/some/other/file" in concat::fragment to include the contents of a symlink into the final file. - 2010/04/16 - Add more cleaning of the fragment name - removing / from the $name - 2010/05/22 - Improve documentation and show the use of ensure => - 2010/07/14 - Add support for setting the filebucket behavior of files - 2010/10/04 - Make the warning message configurable - 2010/12/03 - Add flags to make concat work better on Solaris - thanks Jonathan Boyett - 2011/02/03 - Make the shell script more portable and add a config option for root group - 2011/06/21 - Make base dir root readable only for security - 2011/06/23 - Set base directory using a fact instead of hardcoding it - 2011/06/23 - Support operating as non privileged user - 2011/06/23 - Support dash instead of bash or sh - 2011/07/11 - Better solaris support - 2011/12/05 - Use fully qualified variables - 2011/12/13 - Improve Nexenta support - 2012/04/11 - Do not use any GNU specific extensions in the shell script - 2012/03/24 - Comply to community style guides - 2012/05/23 - Better errors when basedir isnt set - 2012/05/31 - Add spec tests - 2012/07/11 - Include concat::setup in concat improving UX - 2012/08/14 - Puppet Lint improvements - 2012/08/30 - The target path can be different from the $name - 2012/08/30 - More Puppet Lint cleanup - 2012/09/04 - RELEASE 0.2.0 - 2012/12/12 - Added (file) $replace parameter to concat diff --git a/Gemfile b/Gemfile index a1cfe6c..bfe64b1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,51 +1,48 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" 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-core', '3.1.7', :require => false - gem 'rspec-puppet', '~> 1.0', :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'puppet-lint', :require => false gem 'simplecov', :require => false gem 'puppet_facts', :require => false gem 'json', :require => false end -beaker_version = ENV['BEAKER_VERSION'] -beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] group :system_tests do - if beaker_version + if beaker_version = ENV['BEAKER_VERSION'] gem 'beaker', *location_for(beaker_version) end - if beaker_rspec_version + if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] gem 'beaker-rspec', *location_for(beaker_rspec_version) else gem 'beaker-rspec', :require => false end gem 'serverspec', :require => false gem 'beaker-puppet_install_helper', :require => false end + + if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', *location_for(facterversion) + gem 'facter', facterversion, :require => false else gem 'facter', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', *location_for(puppetversion) + gem 'puppet', puppetversion, :require => false else gem 'puppet', :require => false end # vim:ft=ruby diff --git a/README.md b/README.md index 69b9a89..afec06d 100644 --- a/README.md +++ b/README.md @@ -1,283 +1,283 @@ #concat ####Table of Contents 1. [Overview](#overview) 2. [Module Description - What the module does and why it is useful](#module-description) 3. [Setup - The basics of getting started with concat](#setup) * [What concat affects](#what-concat-affects) * [Beginning with concat](#beginning-with-concat) 4. [Usage - Configuration options and additional functionality](#usage) 5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) * [Public Defines](#public-defines) * [Parameters](#parameters) * [Deprecations](#deprecations) 6. [Limitations - OS compatibility, etc.](#limitations) 7. [Development - Guide for contributing to the module](#development) ##Overview The concat module lets you construct files from multiple ordered fragments of text. ##Module Description The concat module lets you gather `concat::fragment` resources from your other modules and order them through a single `concat` resource into a coherent file. It does this through a Ruby script and a temporary holding space for the fragments. ##Setup ###What concat affects * Installs `concatfragments.rb`. * Adds a `concat/` directory into Puppet's `vardir`. ###Beginning with concat To start using concat you need to create: * A concat{} resource for the final file. * One or more concat::fragment{}s. A minimal example might be: ~~~ concat { '/tmp/file': ensure => present, } concat::fragment { 'tmpfile': target => '/tmp/file', content => 'test contents', order => '01' } ~~~ ##Usage ###Maintain a list of the major modules on a node To maintain an motd file that lists the modules on one of your nodes, first create a class to frame up the file: ~~~ class motd { $motd = '/etc/motd' concat { $motd: owner => 'root', group => 'root', mode => '0644' } concat::fragment{ 'motd_header': target => $motd, content => "\nPuppet modules on this server:\n\n", order => '01' } # let local users add to the motd by creating a file called # /etc/motd.local concat::fragment{ 'motd_local': target => $motd, source => '/etc/motd.local', order => '15' } } # let other modules register themselves in the motd define motd::register($content="", $order='10') { if $content == "" { $body = $name } else { $body = $content } concat::fragment{ "motd_fragment_$name": target => '/etc/motd', order => $order, content => " -- $body\n" } } ~~~ Then, in the declarations for each module on the node, add `motd::register{ 'Apache': }` to register the module in the motd. ~~~ class apache { include apache::install, apache::config, apache::service motd::register{ 'Apache': } } ~~~ These two steps populate the /etc/motd file with a list of the installed and registered modules, which stays updated even if you just remove the registered modules' `include` lines. System administrators can append text to the list by writing to /etc/motd.local. When you're finished, the motd file will look something like this: ~~~ Puppet modules on this server: -- Apache -- MySQL ~~~ ##Reference **Note**: Several of this module's parameters and features have been deprecated. See the [Deprecations](#deprecations) section below. ###Public defines * `concat`: Manages a file, compiled from one or more text fragments. * `concat::fragment`: Manages a fragment of text to be compiled into a file. ###Parameters ####`concat` All the parameters listed below are optional. #####`backup` Specifies whether (and how) to back up the destination file before overwriting it. Your value gets passed on to Puppet's [native `file` resource](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-backup) for execution. Valid options: 'true', 'false', or a string representing either a target filebucket or a filename extension beginning with ".". Default value: 'puppet'. #####`ensure` Specifies whether the destination file should exist. Setting to 'absent' tells Puppet to delete the destination file if it exists, and negates the effect of any other parameters. Valid options: 'present' and 'absent'. Default value: 'present'. #####`ensure_newline` Specifies whether to ensure there's a new line at the end of each fragment. Valid options: 'true' and 'false'. Default value: 'false'. #####`force` In case no fragments have been added, this parameter specifies whether to go ahead and create a potentially empty file. Valid options: 'true' and 'false'. Default value: 'false'. #####`group` Specifies a permissions group for the destination file. Valid options: a string containing a group name. Default value: undefined. #####`mode` Specifies the permissions mode of the destination file. Valid options: a string containing a permission mode value in octal notation. Default value: '0644'. #####`order` Specifies a method for sorting your fragments by name within the destination file. Valid options: 'alpha' (e.g., '1, 10, 2') or 'numeric' (e.g., '1, 2, 10'). Default value: 'alpha'. You can override this setting for individual fragments by adjusting the `order` parameter in their `concat::fragment` declarations. #####`owner` Specifies the owner of the destination file. Valid options: a string containing a username. Default value: undefined. #####`path` Specifies a destination file for the combined fragments. Valid options: a string containing an absolute path. Default value: the title of your declared resource. #####`replace` Specifies whether to overwrite the destination file if it already exists. Valid options: 'true' and 'false'. Default value: 'true'. #####`validate_cmd` Specifies a validation command to apply to the destination file. Requires Puppet version 3.5 or newer. Valid options: a string to be passed to a file resource. Default value: undefined. #####`warn` Specifies whether to add a warning message at the top of the destination file so users know it was autogenerated by Puppet. Valid options: 'true', 'false', or a string to be delivered as a warning message. Default value: 'false'. If you set this parameter to 'true', Puppet adds the following message: ~~~ # This file is managed by Puppet. DO NOT EDIT. ~~~ ####`concat::fragment` Except where noted, all the below parameters are optional. #####`content` Supplies the content of the fragment. **Note**: You must supply either a `content` parameter or a `source` parameter. Valid options: a string. Default value: undef. #####`ensure` Specifies whether the fragment should be included in the destination file or discarded. Valid options: 'present' and 'absent'. Default value: 'present'. #####`order` Reorders your fragments within the destination file. Fragments that share the same order number are ordered by name. Valid options: a string (recommended) or an integer. Default value: '10'. #####`source` Specifies a file to read into the content of the fragment. **Note**: You must supply either a `content` parameter or a `source` parameter. Valid options: a string or an array, containing one or more Puppet URLs. Default value: undefined. #####`target` *Required.* Specifies the destination file of the fragment. Valid options: a string containing the title of the parent `concat` resource. ###Deprecations **`concat` has the following deprecations** #####`gnu` Generates a catalog compile time warning and has no effect. This parameter was silently ignored in version `1.0.0` and will be removed in a future release. #####stringified 'true'/'false' values deprecated in `warn` Passing stringified boolean values (strings of 'true' and 'false') to the `warn` parameter of `concat` is deprecated. Generates a catalog compile time warning, and will be silently treated as the concatenated file header/warning message in a future release. Please migrate to using the Puppet DSL's native [Boolean data type](http://docs.puppetlabs.com/puppet/3/reference/lang_datatypes.html#booleans). **`concat::fragment` has the following deprecations** #####`backup` Generates a catalog compile time warning and has no effect. In the `1.0.0` release this parameter controlled file bucketing of the file fragment. Bucketing the fragment(s) is redundant with bucketing the final concatenated file and this feature has been removed. #####`group` Generates a catalog compile time warning and has no effect. Had no user-visible effect in version `1.0.0` and will be removed in a future release. #####`mode` Generates a catalog compile time warning and has no effect. Had no user-visible effect in version `1.0.0` and will be removed in a future release. #####`owner` Generates a catalog compile time warning and has no effect. Had no user-visible effect in version `1.0.0` and will be removed in a future release. #####file paths are deprecated in `ensure` Passing a value other than 'present' or 'absent' in the `ensure` parameter of `concat::fragment` is **deprecated**, and generates a catalog compile time warning. The warning will become a catalog compilation failure in a future release. If you want to use the content of a file as a fragment please use the [`source`](#source) parameter. ####`concat::setup` The `concat::setup` class should no longer be directly included in the manifest. It will be removed in a future release. ##Limitations -This module has been tested on [all PE-supported platforms](https://forge.puppetlabs.com/supported#compat-matrix), and no issues have been identified. +This module has been tested on [all PE-supported platforms](https://forge.puppetlabs.com/supported#compat-matrix), and no issues have been identified. Additionally, it is tested (but not supported) on Solaris 12. ##Development Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our [module contribution guide.](https://docs.puppetlabs.com/forge/contributing.html) ###Contributors To see who's already involved, see the [list of contributors.](https://github.com/puppetlabs/puppetlabs-concat/graphs/contributors) diff --git a/Rakefile b/Rakefile index e3be95b..181157e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' -PuppetLint.configuration.fail_on_warnings +PuppetLint.configuration.fail_on_warnings = true PuppetLint.configuration.send('relative') PuppetLint.configuration.send('disable_80chars') PuppetLint.configuration.send('disable_class_inherits_from_params_class') 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/manifests/init.pp b/manifests/init.pp index 077a29b..43261dd 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,268 +1,276 @@ # == Define: concat # # Sets up so that you can use fragments to build a final config file, # # === Options: # # [*ensure*] # Present/Absent # [*path*] # The path to the final file. Use this in case you want to differentiate # between the name of a resource and the file path. Note: Use the name you # provided in the target of your fragments. # [*owner*] # Who will own the file # [*group*] # Who will own the file # [*mode*] # The mode of the final file # [*force*] # Enables creating empty files if no fragments are present # [*warn*] # Adds a normal shell style comment top of the file indicating that it is # built by puppet # [*force*] # [*backup*] # Controls the filebucketing behavior of the final file and see File type # reference for its use. Defaults to 'puppet' # [*replace*] # Whether to replace a file that already exists on the local system # [*order*] # [*ensure_newline*] # [*gnu*] # Deprecated # # === Actions: # * Creates fragment directories if it didn't exist already # * Executes the concatfragments.rb script to build the final file, this # script will create directory/fragments.concat. Execution happens only # when: # * The directory changes # * fragments.concat != final destination, this means rebuilds will happen # whenever someone changes or deletes the final file. Checking is done # using /usr/bin/cmp. # * The Exec gets notified by something else - like the concat::fragment # define # * Copies the file over to the final destination using a file resource # # === Aliases: # # * The exec can notified using Exec["concat_/path/to/file"] or # Exec["concat_/path/to/directory"] # * The final file can be referenced as File["/path/to/file"] or # File["concat_/path/to/file"] # define concat( $ensure = 'present', $path = $name, $owner = undef, $group = undef, $mode = '0644', $warn = false, $force = false, $backup = 'puppet', $replace = true, $order = 'alpha', $ensure_newline = false, $validate_cmd = undef, $gnu = undef ) { validate_re($ensure, '^present$|^absent$') validate_absolute_path($path) validate_string($owner) validate_string($group) validate_string($mode) if ! (is_string($warn) or $warn == true or $warn == false) { fail('$warn is not a string or boolean') } validate_bool($force) 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) 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') } include concat::setup $safe_name = regsubst($name, '[/:]', '_', 'G') $concatdir = $concat::setup::concatdir $fragdir = "${concatdir}/${safe_name}" $concat_name = 'fragments.concat.out' $script_command = $concat::setup::script_command $default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.' $bool_warn_message = 'Using stringified boolean values (\'true\', \'yes\', \'on\', \'false\', \'no\', \'off\') to represent boolean true/false as the $warn parameter to concat is deprecated and will be treated as the warning message in a future release' # lint:ignore:quoted_booleans case $warn { true: { $warn_message = $default_warn_message } + # lint:ignore:quoted_booleans 'true', 'yes', 'on': { + # lint:endignore warning($bool_warn_message) $warn_message = $default_warn_message } false: { $warn_message = '' } + # lint:ignore:quoted_booleans 'false', 'no', 'off': { + # lint:endignore warning($bool_warn_message) $warn_message = '' } default: { $warn_message = $warn } } # lint:endignore $warnmsg_escaped = regsubst($warn_message, '\'', '\'\\\'\'', 'G') $warnflag = $warnmsg_escaped ? { '' => '', default => "-w '${warnmsg_escaped}'" } $forceflag = $force ? { true => '-f', false => '', } $orderflag = $order ? { 'numeric' => '-n', 'alpha' => '', } $newlineflag = $ensure_newline ? { true => '-l', false => '', } File { backup => $backup, } # reset poisoned Exec defaults Exec { user => undef, group => undef, } if $ensure == 'present' { file { $fragdir: ensure => directory, mode => '0750', } file { "${fragdir}/fragments": ensure => directory, mode => '0750', force => true, ignore => ['.svn', '.git', '.gitignore'], notify => Exec["concat_${name}"], purge => true, recurse => true, } file { "${fragdir}/fragments.concat": ensure => present, mode => '0640', } file { "${fragdir}/${concat_name}": ensure => present, mode => '0640', } file { $name: 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 defined('$is_pe') and str2bool("${::is_pe}") { # lint:ignore:only_variable_string if $::kernel == 'windows' { $command_path = "${::env_windows_installdir}/bin:${::path}" } else { - $command_path = "/opt/puppet/bin:${::path}" + $command_path = "/opt/puppetlabs/puppet/bin:/opt/puppet/bin:${::path}" } - } else { + } elsif $::kernel == 'windows' { $command_path = $::path + } else { + $command_path = "/opt/puppetlabs/puppet/bin:${::path}" } # if puppet is running as root, this exec should also run as root to allow # 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}", command => $command, notify => File[$name], subscribe => File[$fragdir], unless => "${command} -t", path => $command_path, require => [ File[$fragdir], File["${fragdir}/fragments"], File["${fragdir}/fragments.concat"], ], } } else { file { [ $fragdir, "${fragdir}/fragments", "${fragdir}/fragments.concat", "${fragdir}/${concat_name}" ]: ensure => absent, force => true, } file { $path: ensure => absent, backup => $backup, } # lint:ignore:quoted_booleans $absent_exec_command = $::kernel ? { 'windows' => 'cmd.exe /c exit 0', + # lint:ignore:quoted_booleans default => 'true', + # lint:endignore } # lint:endignore $absent_exec_path = $::kernel ? { 'windows' => $::path, default => '/bin:/usr/bin', } # Need to have an unless here for idempotency. exec { "concat_${name}": alias => "concat_${fragdir}", command => $absent_exec_command, unless => $absent_exec_command, path => $absent_exec_path, } } } # vim:sw=2:ts=2:expandtab:textwidth=79 diff --git a/manifests/setup.pp b/manifests/setup.pp index c5aedd8..6d5d8b2 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -1,64 +1,65 @@ # === Class: concat::setup # # Sets up the concat system. This is a private class. # # [$concatdir] # is where the fragments live and is set on the fact concat_basedir. # Since puppet should always manage files in $concatdir and they should # not be deleted ever, /tmp is not an option. # # It also copies out the concatfragments.{sh,rb} file to ${concatdir}/bin # class concat::setup { if $caller_module_name != $module_name { warning("${name} is deprecated as a public API of the ${module_name} module and should no longer be directly included in the manifest.") } if $::concat_basedir { $concatdir = $::concat_basedir } else { 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,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' } # 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}" $default_owner = $::osfamily ? { 'windows' => undef, default => $::id } $default_group = $default_owner ? { 'root' => '0', default => undef } $script_mode = $::osfamily ? { 'windows' => undef, default => '0755' } $script_command = $::osfamily? { 'windows' => "ruby.exe '${script_path}'", 'openbsd' => "/usr/local/bin/ruby21 '${script_path}'", + 'freebsd' => "/usr/local/bin/ruby '${script_path}'", default => $script_path } file { $script_path: ensure => file, owner => $default_owner, group => $default_group, mode => $script_mode, source => "puppet:///modules/concat/${script_name}", } file { [ $concatdir, "${concatdir}/bin" ]: ensure => directory, owner => $default_owner, group => $default_group, mode => '0755', } } diff --git a/metadata.json b/metadata.json index 1d45992..6f6adab 100644 --- a/metadata.json +++ b/metadata.json @@ -1,110 +1,111 @@ { "name": "puppetlabs-concat", "version": "1.2.3", "author": "Puppet Labs", "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://tickets.puppetlabs.com/browse/MODULES", "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" + "11", + "12" ] }, { "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/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index c5c9727..72b4b22 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -1,217 +1,229 @@ require 'spec_helper_acceptance' case fact('osfamily') when 'AIX' username = 'root' groupname = 'system' scriptname = 'concatfragments.rb' - vardir = default['puppetvardir'] + vardir = default.puppet['vardir'] + if vardir.nil? or vardir == '' + vardir = '/opt/puppetlabs/puppet/cache' + end when 'Darwin' username = 'root' groupname = 'wheel' scriptname = 'concatfragments.rb' - vardir = default['puppetvardir'] + vardir = default.puppet['vardir'] + if vardir.nil? or vardir == '' + vardir = '/opt/puppetlabs/puppet/cache' + end when 'windows' username = 'Administrator' groupname = 'Administrators' scriptname = 'concatfragments.rb' - result = on default, "echo #{default['puppetvardir']}" + result = on default, "echo #{default.puppet['vardir']}" vardir = result.raw_output.chomp when 'Solaris' username = 'root' groupname = 'root' scriptname = 'concatfragments.rb' - vardir = default['puppetvardir'] + vardir = default.puppet['vardir'] + if vardir.nil? or vardir == '' + vardir = '/opt/puppetlabs/puppet/cache' + end else username = 'root' groupname = 'root' scriptname = 'concatfragments.rb' - vardir = default['puppetvardir'] + vardir = default.puppet['vardir'] + if vardir.nil? or vardir == '' + vardir = '/opt/puppetlabs/puppet/cache' + end 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 apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end describe file("#{vardir}/concat") do it { should be_directory } 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("#{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')) { should be_mode 755 } end describe file("#{vardir}/concat/bin/#{scriptname}") do it { should be_file } 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("#{vardir}/concat/#{safe_basedir}_file") do it { should be_directory } 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("#{vardir}/concat/#{safe_basedir}_file/fragments") do it { should be_directory } 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("#{vardir}/concat/#{safe_basedir}_file/fragments.concat") do it { should be_file } 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("#{vardir}/concat/#{safe_basedir}_file/fragments.concat.out") do it { should be_file } 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 { '#{basedir}/file': owner => '#{username}', group => '#{groupname}', mode => '0644', } concat::fragment { '1': target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': target => '#{basedir}/file', content => '2', order => '02', } EOS it_behaves_like 'successfully_applied', pp describe file("#{basedir}/file") do it { should be_file } 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 } its(:content) { should match '1' should match '2' } end describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do it { should be_file } 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("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do it { should be_file } 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 => '#{basedir}/file', mode => '0644', } concat::fragment { '1': target => 'file', content => '1', order => '01', } " it_behaves_like 'successfully_applied', pp describe file("#{basedir}/file") do it { should be_file } it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { should be_mode 644 } its(:content) { should match '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 => '#{basedir}/file', mode => '0644', } concat::fragment { '1': target => 'file', content => '1', order => '01', } " 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_not be_file } end end end end diff --git a/spec/unit/defines/concat_fragment_spec.rb b/spec/unit/defines/concat_fragment_spec.rb index 6cf3e42..40866a8 100644 --- a/spec/unit/defines/concat_fragment_spec.rb +++ b/spec/unit/defines/concat_fragment_spec.rb @@ -1,330 +1,338 @@ require 'spec_helper' describe 'concat::fragment', :type => :define do shared_examples 'fragment' do |title, params| params = {} if params.nil? p = { :content => nil, :source => nil, :order => 10, :ensure => 'present', }.merge(params) safe_name = title.gsub(/[\/\n]/, '_') safe_target_name = p[:target].gsub(/[\/\n]/, '_') concatdir = '/var/lib/puppet/concat' fragdir = "#{concatdir}/#{safe_target_name}" id = 'root' gid = 'root' if p[:ensure] == 'absent' safe_ensure = p[:ensure] else safe_ensure = 'file' end let(:title) { title } let(:facts) do { :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 } let(:pre_condition) do "concat{ '#{p[:target]}': }" end it do should contain_class('concat::setup') should contain_concat(p[:target]) 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], :alias => "concat_fragment_#{title}", :backup => 'puppet', }) + # The defined() function doesn't seem to work properly with puppet 3.4 and rspec. + # defined() works on its own, rspec works on its own, but together they + # determine that $gid is not defined and cause errors here. Work around + # it by ignoring this check for older puppet version. + if Puppet::Util::Package.versioncmp(Puppet.version, '3.5.0') >= 0 + should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({ + :group => gid, + }) + end end end context 'title' do ['0', '1', 'a', 'z'].each do |title| it_behaves_like 'fragment', title, { :target => '/etc/motd', } end end # title context 'target =>' do ['./etc/motd', 'etc/motd', 'motd_header'].each do |target| context target do it_behaves_like 'fragment', target, { :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :target => false }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a string/) end end end # target => context 'ensure =>' do ['present', 'absent'].each do |ens| context ens do it_behaves_like 'fragment', 'motd_header', { :ensure => ens, :target => '/etc/motd', } end end context 'any value other than \'present\' or \'absent\'' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }} it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # ensure => context 'content =>' do ['', 'ashp is our hero'].each do |content| context content do it_behaves_like 'fragment', 'motd_header', { :content => content, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :content => false, :target => '/etc/motd' }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a string/) end end end # content => context 'source =>' do ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source| context source do it_behaves_like 'fragment', 'motd_header', { :source => source, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :source => false, :target => '/etc/motd' }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a string or an Array/) end end end # source => context 'order =>' do ['', '42', 'a', 'z'].each do |order| context '\'\'' do it_behaves_like 'fragment', 'motd_header', { :order => order, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } 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/) + expect { catalogue }.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/) + expect { catalogue }.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/) + expect { catalogue }.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/) + expect { catalogue }.to raise_error(Puppet::Error, /cannot contain/) end end end # order => context 'more than one content source' do error_msg = 'You cannot specify more than one of $content, $source, $ensure => /target' context 'ensure => target and source' do let(:title) { 'motd_header' } let(:facts) do { :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', :is_pe => false, :gid => 'root', } end let(:params) do { :target => '/etc/motd', :ensure => '/foo', :source => '/bar', } end it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) + expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'ensure => target and content' do let(:title) { 'motd_header' } let(:facts) do { :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', :is_pe => false, :gid => 'root', } end let(:params) do { :target => '/etc/motd', :ensure => '/foo', :content => 'bar', } end it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) + expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'source and content' do let(:title) { 'motd_header' } let(:facts) do { :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', :is_pe => false, :gid => 'root', } end let(:params) do { :target => '/etc/motd', :source => '/foo', :content => 'bar', } end it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) + expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end end # more than one content source describe 'deprecated parameter' do context 'mode =>' do context '1755' do it_behaves_like 'fragment', 'motd_header', { :mode => '1755', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # mode => context 'owner =>' do context 'apenny' do it_behaves_like 'fragment', 'motd_header', { :owner => 'apenny', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # owner => context 'group =>' do context 'apenny' do it_behaves_like 'fragment', 'motd_header', { :group => 'apenny', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # group => context 'backup =>' do context 'foo' do it_behaves_like 'fragment', 'motd_header', { :backup => 'foo', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # backup => end # deprecated params end diff --git a/spec/unit/defines/concat_spec.rb b/spec/unit/defines/concat_spec.rb index 115a0f5..b5dd253 100644 --- a/spec/unit/defines/concat_spec.rb +++ b/spec/unit/defines/concat_spec.rb @@ -1,415 +1,417 @@ require 'spec_helper' describe 'concat', :type => :define do shared_examples 'concat' do |title, params, id| params = {} if params.nil? id = 'root' if id.nil? # default param values p = { :ensure => 'present', :path => title, :owner => nil, :group => nil, :mode => '0644', :warn => false, :force => false, :backup => 'puppet', :replace => true, :order => 'alpha', :ensure_newline => false, :validate_cmd => nil, }.merge(params) safe_name = title.gsub('/', '_') concatdir = '/var/lib/puppet/concat' fragdir = "#{concatdir}/#{safe_name}" concat_name = 'fragments.concat.out' default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.' file_defaults = { :backup => p[:backup], } let(:title) { title } let(:params) { params } 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', :is_pe => false, } end if p[:ensure] == 'present' it do should contain_file(fragdir).with(file_defaults.merge({ :ensure => 'directory', :mode => '0750', })) end it do should contain_file("#{fragdir}/fragments").with(file_defaults.merge({ :ensure => 'directory', :mode => '0750', :force => true, :ignore => ['.svn', '.git', '.gitignore'], :purge => true, :recurse => true, })) end [ "#{fragdir}/fragments.concat", "#{fragdir}/#{concat_name}", ].each do |file| it do should contain_file(file).with(file_defaults.merge({ :ensure => 'present', :mode => '0640', })) end end 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}", :validate_cmd => p[:validate_cmd], :backup => p[:backup], })) end cmd = "#{concatdir}/bin/concatfragments.rb " + "-o \"#{concatdir}/#{safe_name}/fragments.concat.out\" " + "-d \"#{concatdir}/#{safe_name}\"" # flag order: fragdir, warnflag, forceflag, orderflag, newlineflag if p.has_key?(:warn) case p[:warn] when TrueClass message = default_warn_message when 'true', 'yes', 'on' # should generate a stringified boolean warning message = default_warn_message when FalseClass message = nil when 'false', 'no', 'off' # should generate a stringified boolean warning message = nil else message = p[:warn] end unless message.nil? cmd += " -w \'#{message}\'" end end cmd += " -f" if p[:force] cmd += " -n" if p[:order] == 'numeric' cmd += " -l" if p[:ensure_newline] == true it do should contain_exec("concat_#{title}").with({ :alias => "concat_#{fragdir}", :command => cmd, :unless => "#{cmd} -t", }) end else [ fragdir, "#{fragdir}/fragments", "#{fragdir}/fragments.concat", "#{fragdir}/#{concat_name}", ].each do |file| it do should contain_file(file).with(file_defaults.merge({ :ensure => 'absent', :force => true, })) end end it do should contain_file(title).with(file_defaults.merge({ :ensure => 'absent', :backup => p[:backup], })) end it do should contain_exec("concat_#{title}").with({ :alias => "concat_#{fragdir}", :command => 'true', :unless => 'true', :path => '/bin:/usr/bin', }) end end end context 'title' do context 'without path param' do # title/name is the default value for the path param. therefore, the # title must be an absolute path unless path is specified ['/foo', '/foo/bar', '/foo/bar/baz'].each do |title| context title do it_behaves_like 'concat', '/etc/foo.bar' end end ['./foo', 'foo', 'foo/bar'].each do |title| context title do let(:title) { title } it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not an absolute path/) + expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/) end end end end context 'with path param' do ['./foo', 'foo', 'foo/bar'].each do |title| context title do it_behaves_like 'concat', title, { :path => '/etc/foo.bar' } end end end end # title => context 'as non-root user' do it_behaves_like 'concat', '/etc/foo.bar', {}, 'bob' end context 'ensure =>' do ['present', 'absent'].each do |ens| context ens do it_behaves_like 'concat', '/etc/foo.bar', { :ensure => ens } end end context 'invalid' do let(:title) { '/etc/foo.bar' } let(:params) {{ :ensure => 'invalid' }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/) + expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/) end end end # ensure => context 'path =>' do context '/foo' do it_behaves_like 'concat', '/etc/foo.bar', { :path => '/foo' } end ['./foo', 'foo', 'foo/bar', false].each do |path| context path do let(:title) { '/etc/foo.bar' } let(:params) {{ :path => path }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not an absolute path/) + expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/) end end end end # path => context 'owner =>' do context 'apenney' do it_behaves_like 'concat', '/etc/foo.bar', { :owner => 'apenny' } end context 'false' do let(:title) { '/etc/foo.bar' } let(:params) {{ :owner => false }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a string/) end end end # owner => context 'group =>' do context 'apenney' do it_behaves_like 'concat', '/etc/foo.bar', { :group => 'apenny' } end context 'false' do let(:title) { '/etc/foo.bar' } let(:params) {{ :group => false }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a string/) end end end # group => context 'mode =>' do context '1755' do it_behaves_like 'concat', '/etc/foo.bar', { :mode => '1755' } end context 'false' do let(:title) { '/etc/foo.bar' } let(:params) {{ :mode => false }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a string/) end end end # mode => context 'warn =>' do [true, false, '# foo'].each do |warn| context warn do it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn } end end context '(stringified boolean)' do ['true', 'yes', 'on', 'false', 'no', 'off'].each do |warn| context warn do it_behaves_like 'concat', '/etc/foo.bar', { :warn => warn } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end end context '123' do let(:title) { '/etc/foo.bar' } let(:params) {{ :warn => 123 }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string or boolean/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a string or boolean/) end end end # warn => context 'force =>' do [true, false].each do |force| context force do it_behaves_like 'concat', '/etc/foo.bar', { :force => force } end end context '123' do let(:title) { '/etc/foo.bar' } let(:params) {{ :force => 123 }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a boolean/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/) end end end # force => context 'backup =>' do context 'reverse' do it_behaves_like 'concat', '/etc/foo.bar', { :backup => 'reverse' } 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 => [] }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /backup must be string or bool/) + expect { catalogue }.to raise_error(Puppet::Error, /backup must be string or bool/) end end end # backup => context 'replace =>' do [true, false].each do |replace| context replace do it_behaves_like 'concat', '/etc/foo.bar', { :replace => replace } end end context '123' do let(:title) { '/etc/foo.bar' } let(:params) {{ :replace => 123 }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a boolean/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/) end end end # replace => context 'order =>' do ['alpha', 'numeric'].each do |order| context order do it_behaves_like 'concat', '/etc/foo.bar', { :order => order } end end context 'invalid' do let(:title) { '/etc/foo.bar' } let(:params) {{ :order => 'invalid' }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/) + expect { catalogue }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/) end end end # order => context 'ensure_newline =>' do [true, false].each do |ensure_newline| context 'true' do it_behaves_like 'concat', '/etc/foo.bar', { :ensure_newline => ensure_newline} end end context '123' do let(:title) { '/etc/foo.bar' } let(:params) {{ :ensure_newline => 123 }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a boolean/) + expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/) end 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 + if Puppet::Util::Package::versioncmp(Puppet::version, '3.5.0') > 0 + 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/) + [ 1234, true ].each do |cmd| + context cmd do + let(:title) { '/etc/foo.bar' } + let(:params) {{ :validate_cmd => cmd }} + it 'should fail' do + expect { catalogue }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/) + end 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 skip('rspec-puppet support for testing warning()') end end end end end # vim:sw=2:ts=2:expandtab:textwidth=79