diff --git a/deployment/puppet/concat/.fixtures.yml b/deployment/puppet/concat/.fixtures.yml index dc6b41f836..67added0af 100644 --- a/deployment/puppet/concat/.fixtures.yml +++ b/deployment/puppet/concat/.fixtures.yml @@ -2,6 +2,6 @@ fixtures: repositories: 'stdlib': repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.0.0' + ref: '4.2.0' symlinks: 'concat': '#{source_dir}' diff --git a/deployment/puppet/concat/.gitignore b/deployment/puppet/concat/.gitignore index 143345ec18..b5db85e051 100644 --- a/deployment/puppet/concat/.gitignore +++ b/deployment/puppet/concat/.gitignore @@ -1,7 +1,9 @@ -.pkg +pkg/ Gemfile.lock -vendor -spec/fixtures -.rspec_system -.bundle -*.sw* +vendor/ +spec/fixtures/ +.vagrant/ +.bundle/ +coverage/ +.idea/ +*.iml diff --git a/deployment/puppet/concat/.sync.yml b/deployment/puppet/concat/.sync.yml new file mode 100644 index 0000000000..08e91a74a0 --- /dev/null +++ b/deployment/puppet/concat/.sync.yml @@ -0,0 +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/deployment/puppet/concat/.travis.yml b/deployment/puppet/concat/.travis.yml index 4e72cd4cf9..ec6f08dc6d 100644 --- a/deployment/puppet/concat/.travis.yml +++ b/deployment/puppet/concat/.travis.yml @@ -1,40 +1,15 @@ --- -branches: - only: - - master language: ruby -bundler_args: --without development -script: bundle exec rake spec SPEC_OPTS='--format documentation' -# work around RubyGems 2.2.0 breaking ruby 1.8.7 -# https://github.com/rubygems/rubygems/pull/763 -# https://github.com/freerange/mocha/commit/66bab2a8f4e7cd8734bf88e6f32157c0d5153125 -before_install: - - gem update --system 2.1.11 - - gem --version -rvm: - - 1.8.7 - - 1.9.3 - - 2.0.0 -env: - matrix: - - PUPPET_GEM_VERSION="2.7.3" FACTER_GEM_VERSION="1.6.0" - - PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - - PUPPET_GEM_VERSION="~> 3.0" +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 - exclude: - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="2.7.3" FACTER_GEM_VERSION="1.6.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="2.7.3" FACTER_GEM_VERSION="1.6.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" + 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" notifications: email: false diff --git a/deployment/puppet/concat/CHANGELOG b/deployment/puppet/concat/CHANGELOG.md similarity index 50% rename from deployment/puppet/concat/CHANGELOG rename to deployment/puppet/concat/CHANGELOG.md index c66b922d44..2e6064131e 100644 --- a/deployment/puppet/concat/CHANGELOG +++ b/deployment/puppet/concat/CHANGELOG.md @@ -1,21 +1,96 @@ -2014-05-14 1.1.0 +##2015-06-02 - Supported Release 1.2.3 +###Summary -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 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: +####Features - Improved testing, with tests moved to beaker -Bugfixes: +####Bugfixes - No longer attempts to set fragment owner and mode on Windows - Fix numeric sorting - Fix incorrect quoting - Fix newlines -2014-01-03 1.1.0-rc1 - -Summary: +##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. @@ -33,49 +108,104 @@ warnings and we'll be aggressively moving for a 2.0 to remove those too. For further information on deprecations, please read: https://github.com/puppetlabs/puppetlabs-concat/blob/master/README.md#api-deprecations -Removed: +####Removed - Puppet 0.24 support. - Filebucket backup of all file resources except the target concatenated file. - Default owner/user/group values. - Purging of long unused /usr/local/bin/concatfragments.sh -Features: +###Features - Windows support via a ruby version of the concat bash script. - Huge amount of acceptance testing work added. - Documentation (README) completely rewritten. - New parameters in concat: - `ensure`: Controls if the file should be present/absent at all. -- Remove requirement to include concat::setup in manifests. -- Made `gnu` parameter deprecated. -- Added parameter validation. + - Remove requirement to include concat::setup in manifests. + - Made `gnu` parameter deprecated. + - Added parameter validation. -Bugfixes: -- Ensure concat::setup runs before concat::fragment in all cases. -- Pluginsync references updated for modern Puppet. -- Fix incorrect group parameter. -- Use $owner instead of $id to avoid confusion with $::id -- Compatibility fixes for Puppet 2.7/ruby 1.8.7 -- Use LC_ALL=C instead of LANG=C -- Always exec the concatfragments script as root when running as root. -- Syntax and other cleanup changes. +###Bugfixes + - Ensure concat::setup runs before concat::fragment in all cases. + - Pluginsync references updated for modern Puppet. + - Fix incorrect group parameter. + - Use $owner instead of $id to avoid confusion with $::id + - Compatibility fixes for Puppet 2.7/ruby 1.8.7 + - Use LC_ALL=C instead of LANG=C + - Always exec the concatfragments script as root when running as root. + - Syntax and other cleanup changes. -2013-08-09 1.0.0 +##2014-06-25 - Supported Release 1.0.4 +###Summary -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: +####Features - New parameters in concat: - `replace`: specify if concat should replace existing files. - `ensure_newline`: controls if fragments should contain a newline at the end. - Improved README documentation. - Add rspec:system tests (rake spec:system to test concat) -Bugfixes +####Bugfixes - Gracefully handle \n in a fragment resource name. - Adding more helpful message for 'pluginsync = true' - Allow passing `source` and `content` directly to file resource, rather than @@ -85,7 +215,7 @@ defining resource defaults. - Allow WARNMSG to contain/start with '#'. - Replace while-read pattern with for-do in order to support Solaris. -CHANGELOG: +####CHANGELOG: - 2010/02/19 - initial release - 2010/03/12 - add support for 0.24.8 and newer - make the location of sort configurable diff --git a/deployment/puppet/concat/CONTRIBUTING.md b/deployment/puppet/concat/CONTRIBUTING.md new file mode 100644 index 0000000000..f1cbde4bbf --- /dev/null +++ b/deployment/puppet/concat/CONTRIBUTING.md @@ -0,0 +1,220 @@ +Checklist (and a short version for the impatient) +================================================= + + * Commits: + + - Make commits of logical units. + + - Check for unnecessary whitespace with "git diff --check" before + committing. + + - Commit using Unix line endings (check the settings around "crlf" in + git-config(1)). + + - Do not check in commented out code or unneeded files. + + - The first line of the commit message should be a short + description (50 characters is the soft limit, excluding ticket + number(s)), and should skip the full stop. + + - Associate the issue in the message. The first line should include + the issue number in the form "(#XXXX) Rest of message". + + - The body should provide a meaningful commit message, which: + + - uses the imperative, present tense: "change", not "changed" or + "changes". + + - includes motivation for the change, and contrasts its + implementation with the previous behavior. + + - Make sure that you have tests for the bug you are fixing, or + feature you are adding. + + - Make sure the test suites passes after your commit: + `bundle exec rspec spec/acceptance` More information on [testing](#Testing) below + + - When introducing a new feature, make sure it is properly + documented in the README.md + + * Submission: + + * Pre-requisites: + + - Make sure you have a [GitHub account](https://github.com/join) + + - [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: + + - Fork the repository on GitHub. + + - Push your changes to a topic branch in your fork of the + repository. (the format ticket/1234-short_description_of_change is + usually preferred for this project). + + - Submit a pull request to the repository in the puppetlabs + organization. + +The long version +================ + + 1. Make separate commits for logically separate changes. + + Please break your commits down into logically consistent units + which include new or changed tests relevant to the rest of the + change. The goal of doing this is to make the diff easier to + read for whoever is reviewing your code. In general, the easier + your diff is to read, the more likely someone will be happy to + review it and get it into the code base. + + If you are going to refactor a piece of code, please do so as a + separate commit from your feature or bug fix changes. + + We also really appreciate changes that include tests to make + sure the bug is not re-introduced, and that the feature is not + accidentally broken. + + Describe the technical detail of the change(s). If your + description starts to get too long, that is a good sign that you + probably need to split up your commit into more finely grained + pieces. + + Commits which plainly describe the things which help + reviewers check the patch and future developers understand the + code are much more likely to be merged in with a minimum of + bike-shedding or requested changes. Ideally, the commit message + would include information, and be in a form suitable for + inclusion in the release notes for the version of Puppet that + includes them. + + Please also check that you are not introducing any trailing + whitespace or other "whitespace errors". You can do this by + running "git diff --check" on your changes before you commit. + + 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 + directly on "master". + It makes things much easier to keep track of, especially if + you decide to work on another thing before your first change + is merged in. + + GitHub has some pretty good + [general documentation](http://help.github.com/) on using + their site. They also have documentation on + [creating pull requests](http://help.github.com/send-pull-requests/). + + In general, after pushing your topic branch up to your + repository on GitHub, you can switch to the branch in the + GitHub UI and click "Pull Request" towards the top of the page + in order to open a pull request. + + + 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 + location of your branch, along with any other commentary you + may wish to make. + +Testing +======= + +Getting Started +--------------- + +Our puppet modules provide [`Gemfile`](./Gemfile)s which can tell a ruby +package manager such as [bundler](http://bundler.io/) what Ruby packages, +or Gems, are required to build, develop, and test this software. + +Please make sure you have [bundler installed](http://bundler.io/#getting-started) +on your system, then use it to install all dependencies needed for this project, +by running + +```shell +% bundle install +Fetching gem metadata from https://rubygems.org/........ +Fetching gem metadata from https://rubygems.org/.. +Using rake (10.1.0) +Using builder (3.2.2) +-- 8><-- many more --><8 -- +Using rspec-system-puppet (2.2.0) +Using serverspec (0.6.3) +Using rspec-system-serverspec (1.0.0) +Using bundler (1.3.5) +Your bundle is complete! +Use `bundle show [gemname]` to see where a bundled gem is installed. +``` + +NOTE some systems may require you to run this command with sudo. + +If you already have those gems installed, make sure they are up-to-date: + +```shell +% bundle update +``` + +With all dependencies in place and up-to-date we can now run the tests: + +```shell +% rake spec +``` + +This will execute all the [rspec tests](http://rspec-puppet.com/) tests +under [spec/defines](./spec/defines), [spec/classes](./spec/classes), +and so on. rspec tests may have the same kind of dependencies as the +module they are testing. While the module defines in its [Modulefile](./Modulefile), +rspec tests define them in [.fixtures.yml](./fixtures.yml). + +Some puppet modules also come with [beaker](https://github.com/puppetlabs/beaker) +tests. These tests spin up a virtual machine under +[VirtualBox](https://www.virtualbox.org/)) with, controlling it with +[Vagrant](http://www.vagrantup.com/) to actually simulate scripted test +scenarios. In order to run these, you will need both of those tools +installed on your system. + +You can run them by issuing the following command + +```shell +% rake spec_clean +% rspec spec/acceptance +``` + +This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml), +install puppet, copy this module and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb) +and then run all the tests under [spec/acceptance](./spec/acceptance). + +Writing Tests +------------- + +XXX getting started writing tests. + +If you have commit access to the repository +=========================================== + +Even if you have commit access to the repository, you will still need to +go through the process above, and have someone else review and merge +in your changes. The rule is that all changes must be reviewed by a +developer on the project (that did not write the code) to ensure that +all changes go through a code review process. + +Having someone other than the author of the topic branch recorded as +performing the merge is the record that they performed the code +review. + + +Additional Resources +==================== + +* [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) + +* [General GitHub documentation](http://help.github.com/) + +* [GitHub pull request documentation](http://help.github.com/send-pull-requests/) + diff --git a/deployment/puppet/concat/Gemfile b/deployment/puppet/concat/Gemfile index 56b977598c..cc4048aec4 100644 --- a/deployment/puppet/concat/Gemfile +++ b/deployment/puppet/concat/Gemfile @@ -1,18 +1,48 @@ 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 'beaker', :require => false - gem 'beaker-rspec', :require => false gem 'puppet-lint', :require => false - gem 'serverspec', :require => false - gem 'pry', :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 + gem 'beaker', *location_for(beaker_version) + end + 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', *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/deployment/puppet/concat/Modulefile b/deployment/puppet/concat/Modulefile deleted file mode 100644 index ea9ef2c3e3..0000000000 --- a/deployment/puppet/concat/Modulefile +++ /dev/null @@ -1,9 +0,0 @@ -name 'puppetlabs-concat' -version '1.1.0' -source 'git://github.com/puppetlabs/puppetlabs-concat.git' -author 'Puppetlabs' -license 'Apache 2.0' -summary 'Concat module' -description 'Concat module' -project_page 'http://github.com/puppetlabs/puppetlabs-concat' -dependency 'puppetlabs/stdlib', '>= 4.0.0' diff --git a/deployment/puppet/concat/README.md b/deployment/puppet/concat/README.md index 60eca38300..69b9a89836 100644 --- a/deployment/puppet/concat/README.md +++ b/deployment/puppet/concat/README.md @@ -1,6 +1,4 @@ -#Concat - -[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-concat.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-concat) +#concat ####Table of Contents @@ -8,73 +6,58 @@ 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) - * [Setup requirements](#setup-requirements) * [Beginning with concat](#beginning-with-concat) 4. [Usage - Configuration options and additional functionality](#usage) - * [API _deprecations_](#api-deprecations) 5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) -5. [Limitations - OS compatibility, etc.](#limitations) -6. [Development - Guide for contributing to the module](#development) + * [Public Defines](#public-defines) + * [Parameters](#parameters) + * [Deprecations](#deprecations) +6. [Limitations - OS compatibility, etc.](#limitations) +7. [Development - Guide for contributing to the module](#development) ##Overview -This module constructs files from multiple fragments in an ordered way. +The concat module lets you construct files from multiple ordered fragments of text. ##Module Description -This module lets you use many concat::fragment{} resources throughout -your modules to construct a single file at the end. It does this through -a shell (or ruby) script and a temporary holding space for the fragments. +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.[sh|rb] based on platform. -* Adds a concat/ directory into Puppets `vardir`. +* 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. +* One or more concat::fragment{}s. A minimal example might be: -```puppet +~~~ concat { '/tmp/file': ensure => present, } concat::fragment { 'tmpfile': - target => '/tmp/file' + target => '/tmp/file', content => 'test contents', order => '01' } -``` +~~~ ##Usage -Please be aware that there have been a number of [API -_deprecations_](#api-deprecations). +###Maintain a list of the major modules on a node -If you wanted a /etc/motd file that listed all the major modules -on the machine. And that would be maintained automatically even -if you just remove the include lines for other modules you could -use code like below, a sample /etc/motd would be: +To maintain an motd file that lists the modules on one of your nodes, first create a class to frame up the file: -
-Puppet modules on this server:
-
-    -- Apache
-    -- MySQL
-
- -Local sysadmins can also append to the file by just editing /etc/motd.local -their changes will be incorporated into the puppet managed motd. - -```puppet +~~~ class motd { $motd = '/etc/motd' @@ -90,7 +73,7 @@ class motd { order => '01' } - # local users on the machine can append to motd by just creating + # let local users add to the motd by creating a file called # /etc/motd.local concat::fragment{ 'motd_local': target => $motd, @@ -99,8 +82,8 @@ class motd { } } -# used by other modules to register themselves in the motd -define motd::register($content="", $order=10) { +# let other modules register themselves in the motd +define motd::register($content="", $order='10') { if $content == "" { $body = $name } else { @@ -113,329 +96,188 @@ define motd::register($content="", $order=10) { content => " -- $body\n" } } -``` +~~~ -To use this you'd then do something like: +Then, in the declarations for each module on the node, add `motd::register{ 'Apache': }` to register the module in the motd. -```puppet +~~~ 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 -###Classes +**Note**: Several of this module's parameters and features have been deprecated. See the [Deprecations](#deprecations) section below. -####Public classes - -####Private classes -* `concat::setup`: Sets up the concat script/directories. +###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 -###Defines +####`concat` -####concat - -#####`ensure` -Controls if the combined file is present or absent. - -######Example -- ensure => present -- ensure => absent - -#####`path` -Controls the destination of the file to create. - -######Example -- path => '/tmp/filename' - -#####`owner` -Set the owner of the combined file. - -######Example -- owner => 'root' - -#####`group` -Set the group of the combined file. - -######Example -- group => 'root' - -#####`mode` -Set the mode of the combined file. - -######Example -- mode => '0644' - -#####`warn` -Determine if a warning message should be added at the top of the file to let -users know it was autogenerated by Puppet. - -######Example -- warn => true -- warn => false - -#####`warn_message` -Set the contents of the warning message. - -######Example -- warn_message => 'This file is autogenerated!' - -#####`force` -Determine if empty files are allowed when no fragments were added. - -######Example -- force => true -- force => false +All the parameters listed below are optional. #####`backup` -Controls the filebucket behavior used for the file. -######Example -- backup => 'puppet' +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'. -#####`replace` -Controls if Puppet should replace the destination file if it already exists. +#####`ensure` -######Example -- replace => true -- replace => false +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'. -#####`order` -Controls the way in which the shell script chooses to sort the files. It's -rare you'll need to adjust this. - -######Allowed Values -- order => 'alpha' -- order => 'numeric' #####`ensure_newline` -Ensure there's a newline at the end of the fragments. -######Example -- ensure_newline => true -- ensure_newline => false +Specifies whether to ensure there's a new line at the end of each fragment. Valid options: 'true' and 'false'. Default value: 'false'. -####concat::fragment +#####`force` -#####`target` -Choose the destination file of the fragment. - -######Example -- target => '/tmp/testfile' - -#####`content` -Create the content of the fragment. - -######Example -- content => 'test file contents' - -#####`source` -Find the sources within Puppet of the fragment. - -######Example -- source => 'puppet:///modules/test/testfile' -- source => ['puppet:///modules/test/1', 'puppet:///modules/test/2'] - -#####`order` -Order the fragments. - -######Example -- order => '01' - -#####`ensure` -Control the file of fragment created. - -######Example -- ensure => 'present' -- ensure => 'absent' -- ensure => 'file' -- ensure => 'directory' - -#####`mode` -Set the mode of the fragment. - -######Example -- mode => '0644' - -#####`owner` -Set the owner of the fragment. - -######Example -- owner => 'root' +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` -Set the group of the fragment. -######Example -- group => 'root' +Specifies a permissions group for the destination file. Valid options: a string containing a group name. Default value: undefined. -#####`backup` -Control the filebucket behavior for the fragment. +#####`mode` -######Example -- backup => 'puppet' +Specifies the permissions mode of the destination file. Valid options: a string containing a permission mode value in octal notation. Default value: '0644'. -### API _deprecations_ +#####`order` -#### Since version `1.0.0` +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'. -##### `concat{}` `warn` parameter +You can override this setting for individual fragments by adjusting the `order` parameter in their `concat::fragment` declarations. -```puppet -concat { '/tmp/file': - ensure => present, - warn => 'true', # generates stringified boolean value warning -} -``` +#####`owner` -Using stringified Boolean values as the `warn` parameter to `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. -The following strings are considered a stringified Boolean value: +Specifies the owner of the destination file. Valid options: a string containing a username. Default value: undefined. - * `'true'` - * `'yes'` - * `'on'` - * `'false'` - * `'no'` - * `'off'` +#####`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{}` `gnu` parameter -```puppet -concat { '/tmp/file': - ensure => present, - gnu => $foo, # generates deprecation warning -} -``` +**`concat::fragment` has the following deprecations** -The `gnu` parameter to `concat` is deprecated, generates a catalog compile time -warning, and has no effect. This parameter will be removed in a future -release. +#####`backup` -Note that this parameter was silently ignored in the `1.0.0` release. +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. -##### `concat::fragment{}` `ensure` parameter -```puppet -concat::fragment { 'cpuinfo': - ensure => '/proc/cpuinfo', # generates deprecation warning - target => '/tmp/file', -} -``` +#####`group` -Passing a value other than `'present'` or `'absent'` as the `ensure` parameter -to `concat::fragment` is deprecated and generates a catalog compile time -warning. The warning will become a catalog compilation failure in a future -release. +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. -This type emulates the Puppet core `file` type's disfavored [`ensure` -semantics](http://docs.puppetlabs.com/references/latest/type.html#file-attribute-ensure) -of treating a file path as a directive to create a symlink. This feature is -problematic in several ways. It copies an API semantic of another type that is -both frowned upon and not generally well known. It's behavior may be -surprising in that the target concatenated file will not be a symlink nor is -there any common file system that has a concept of a section of a plain file -being symbolically linked to another file. Additionally, the behavior is -generally inconsistent with most Puppet types in that a missing source file -will be silently ignored. +#####`mode` -If you want to use the content of a file as a fragment please use the `source` -parameter. +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. -##### `concat::fragment{}` `mode/owner/group` parameters -```puppet -concat::fragment { 'foo': - target => '/tmp/file', - content => 'foo', - mode => $mode, # generates deprecation warning - owner => $owner, # generates deprecation warning - group => $group, # generates deprecation warning -} -``` +#####`owner` -The `mode` parameter to `concat::fragment` is deprecated, generates a catalog compile time warning, and has no effect. +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. -The `owner` parameter to `concat::fragment` is deprecated, generates a catalog -compile time warning, and has no effect. +#####file paths are deprecated in `ensure` -The `group` parameter to `concat::fragment` is deprecated, generates a catalog -compile time warning, and has no effect. +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. -These parameters had no user visible effect in version `1.0.0` and will be -removed in a future release. +If you want to use the content of a file as a fragment please use the [`source`](#source) parameter. -##### `concat::fragment{}` `backup` parameter +####`concat::setup` -```puppet -concat::fragment { 'foo': - target => '/tmp/file', - content => 'foo', - backup => 'bar', # generates deprecation warning -} -``` - -The `backup` parameter to `concat::fragment` is deprecated, generates a catalog -compile time warning, and has no effect. It will be removed in a future -release. - -In the `1.0.0` release this parameter controlled file bucketing of the file -fragment. Bucketting the fragment(s) is redundant with bucketting the final -concatenated file and this feature has been removed. - -##### `class { 'concat::setup': }` - -```puppet -include concat::setup # generates deprecation warning - -class { 'concat::setup: } # generates deprecation warning -``` - -The `concat::setup` class is deprecated as a public API of this module and -should no longer be directly included in the manifest. This class may be -removed in a future release. - -##### Parameter validation - -While not an API depreciation, users should be aware that all public parameters -in this module are now validated for at least variable type. This may cause -validation errors in a manifest that was previously silently misbehaving. +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: +This module has been tested on [all PE-supported platforms](https://forge.puppetlabs.com/supported#compat-matrix), and no issues have been identified. -* RedHat Enterprise Linux (and Centos) 5/6 -* Debian 6/7 -* Ubuntu 12.04 +##Development -Testing on other platforms has been light and cannot be guaranteed. +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. -#Development +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. -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. - -You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) +For more information, see our [module contribution guide.](https://docs.puppetlabs.com/forge/contributing.html) ###Contributors -The list of contributors can be found at: - -https://github.com/puppetlabs/puppetlabs-concat/graphs/contributors +To see who's already involved, see the [list of contributors.](https://github.com/puppetlabs/puppetlabs-concat/graphs/contributors) diff --git a/deployment/puppet/concat/Rakefile b/deployment/puppet/concat/Rakefile index 23aea87de2..e3be95b0b8 100644 --- a/deployment/puppet/concat/Rakefile +++ b/deployment/puppet/concat/Rakefile @@ -1,5 +1,10 @@ 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_quoted_booleans') +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/deployment/puppet/concat/files/concatfragments.rb b/deployment/puppet/concat/files/concatfragments.rb old mode 100755 new mode 100644 index 73fd7f9b2d..b16f3e13cf --- a/deployment/puppet/concat/files/concatfragments.rb +++ b/deployment/puppet/concat/files/concatfragments.rb @@ -1,3 +1,4 @@ +#!/usr/bin/env ruby # Script to concat files to a config file. # # Given a directory like this: @@ -39,12 +40,13 @@ require 'optparse' require 'fileutils' settings = { - :outfile => "", - :workdir => "", - :test => false, - :force => false, - :warn => "", - :sortarg => "" + :outfile => "", + :workdir => "", + :test => false, + :force => false, + :warn => "", + :sortarg => "", + :newline => false } OptionParser.new do |opts| @@ -76,6 +78,10 @@ OptionParser.new do |opts| opts.on("-n", "--sort", "Sort the output numerically rather than the default alpha sort") do settings[:sortarg] = "-n" end + + opts.on("-l", "--line", "Append a newline") do + settings[:newline] = true + end end.parse! # do we have -o? @@ -110,16 +116,26 @@ end 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)) + f << File.read(File.join("fragments", entry)) + + # append a newline if we were asked to (invoked with -l) + if settings[:newline] + f << "\n" + end + end } end diff --git a/deployment/puppet/concat/files/concatfragments.sh b/deployment/puppet/concat/files/concatfragments.sh deleted file mode 100755 index 7e6b0f5c56..0000000000 --- a/deployment/puppet/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/deployment/puppet/concat/lib/puppet/parser/functions/concat_getparam.rb b/deployment/puppet/concat/lib/puppet/parser/functions/concat_getparam.rb new file mode 100644 index 0000000000..1757bdc546 --- /dev/null +++ b/deployment/puppet/concat/lib/puppet/parser/functions/concat_getparam.rb @@ -0,0 +1,35 @@ +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +Puppet::Parser::Functions.newfunction(:concat_getparam, + :type => :rvalue, + :doc => <<-'ENDOFDOC' +Takes a resource reference and name of the parameter and +returns value of resource's parameter. + +*Examples:* + + define example_resource($param) { + } + + example_resource { "example_resource_instance": + param => "param_value" + } + + concat_getparam(Example_resource["example_resource_instance"], "param") + +Would return: param_value +ENDOFDOC +) do |vals| + reference, param = vals + raise(ArgumentError, 'Must specify a reference') unless reference + raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String + + return '' if param.empty? + + if resource = findresource(reference.to_s) + return resource[param] if resource[param] + end + + return '' +end diff --git a/deployment/puppet/concat/lib/puppet/parser/functions/concat_is_bool.rb b/deployment/puppet/concat/lib/puppet/parser/functions/concat_is_bool.rb new file mode 100644 index 0000000000..c2c2a9f2e7 --- /dev/null +++ b/deployment/puppet/concat/lib/puppet/parser/functions/concat_is_bool.rb @@ -0,0 +1,22 @@ +# +# concat_is_bool.rb +# + +module Puppet::Parser::Functions + newfunction(:concat_is_bool, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a boolean. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "concat_is_bool(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + type = arguments[0] + + result = type.is_a?(TrueClass) || type.is_a?(FalseClass) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/puppet/concat/manifests/fragment.pp b/deployment/puppet/concat/manifests/fragment.pp index 40baadd234..7b13b00425 100644 --- a/deployment/puppet/concat/manifests/fragment.pp +++ b/deployment/puppet/concat/manifests/fragment.pp @@ -28,7 +28,7 @@ define concat::fragment( $target, $content = undef, $source = undef, - $order = 10, + $order = '10', $ensure = undef, $mode = undef, $owner = undef, @@ -40,7 +40,11 @@ define concat::fragment( if !(is_string($source) or is_array($source)) { fail('$source is not a string or an Array.') } - validate_string($order) + if !(is_string($order) or is_integer($order)) { + fail('$order is not a string or integer.') + } 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') } @@ -53,13 +57,20 @@ define concat::fragment( if $backup { warning('The $backup parameter to concat::fragment is deprecated and has no effect') } + + $my_backup = concat_getparam(Concat[$target], 'backup') + $_backup = $my_backup ? { + '' => undef, + default => $my_backup + } + if $ensure == undef { - $_ensure = getparam(Concat[$target], 'ensure') + $my_ensure = concat_getparam(Concat[$target], 'ensure') } else { if ! ($ensure in [ 'present', 'absent' ]) { warning('Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.') } - $_ensure = $ensure + $my_ensure = $ensure } include concat::setup @@ -68,8 +79,9 @@ define concat::fragment( $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 @@ -78,18 +90,18 @@ define concat::fragment( # be paranoid and only allow the fragment's file resource's ensure param to # be file, absent, or a file target - $safe_ensure = $_ensure ? { + $safe_ensure = $my_ensure ? { '' => 'file', undef => 'file', 'file' => 'file', 'present' => 'file', 'absent' => 'absent', - default => $_ensure, + default => $my_ensure, } # if it looks line ensure => /target syntax was used, fish that out - if ! ($_ensure in ['', 'present', 'absent', 'file' ]) { - $ensure_target = $_ensure + if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) { + $ensure_target = $my_ensure } else { $ensure_target = undef } @@ -106,15 +118,15 @@ define concat::fragment( 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, - backup => false, + backup => $_backup, + replace => true, alias => "concat_fragment_${name}", notify => Exec["concat_${target}"] } diff --git a/deployment/puppet/concat/manifests/init.pp b/deployment/puppet/concat/manifests/init.pp index ce50f8f0a1..077a29bd63 100644 --- a/deployment/puppet/concat/manifests/init.pp +++ b/deployment/puppet/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 @@ define concat( $replace = true, $order = 'alpha', $ensure_newline = false, + $validate_cmd = undef, $gnu = undef ) { validate_re($ensure, '^present$|^absent$') @@ -75,10 +76,15 @@ define concat( fail('$warn is not a string or boolean') } validate_bool($force) - validate_string($backup) + if ! concat_is_bool($backup) and ! is_string($backup) { + fail('$backup must be string or bool!') + } validate_bool($replace) validate_re($order, '^alpha$|^numeric$') validate_bool($ensure_newline) + 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') } @@ -93,6 +99,7 @@ define concat( $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 @@ -112,6 +119,7 @@ define concat( $warn_message = $warn } } + # lint:endignore $warnmsg_escaped = regsubst($warn_message, '\'', '\'\\\'\'', 'G') $warnflag = $warnmsg_escaped ? { @@ -135,7 +143,13 @@ define concat( } File { - backup => false, + backup => $backup, + } + + # reset poisoned Exec defaults + Exec { + user => undef, + group => undef, } if $ensure == 'present' { @@ -176,11 +190,29 @@ define concat( 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}", @@ -188,7 +220,7 @@ define concat( notify => File[$name], subscribe => File[$fragdir], unless => "${command} -t", - path => $::path, + path => $command_path, require => [ File[$fragdir], File["${fragdir}/fragments"], @@ -211,10 +243,12 @@ define concat( backup => $backup, } + # lint:ignore:quoted_booleans $absent_exec_command = $::kernel ? { 'windows' => 'cmd.exe /c exit 0', default => 'true', } + # lint:endignore $absent_exec_path = $::kernel ? { 'windows' => $::path, diff --git a/deployment/puppet/concat/manifests/setup.pp b/deployment/puppet/concat/manifests/setup.pp index 14bed0c1f3..c5aedd82bf 100644 --- a/deployment/puppet/concat/manifests/setup.pp +++ b/deployment/puppet/concat/manifests/setup.pp @@ -7,7 +7,7 @@ # 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 file to ${concatdir}/bin +# It also copies out the concatfragments.{sh,rb} file to ${concatdir}/bin # class concat::setup { if $caller_module_name != $module_name { @@ -20,39 +20,45 @@ class concat::setup { 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 be inherited from concatdir and not explicitly set to avoid problems) + # 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' } - - $script_name = $::kernel ? { - 'windows' => '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 } + $default_owner = $::osfamily ? { 'windows' => undef, default => $::id } + + $default_group = $default_owner ? { 'root' => '0', default => undef } $script_mode = $::osfamily ? { 'windows' => undef, default => '0755' } - $script_command = $::kernel ? { - 'windows' => "ruby.exe ${script_path}", + $script_command = $::osfamily? { + 'windows' => "ruby.exe '${script_path}'", + 'openbsd' => "/usr/local/bin/ruby21 '${script_path}'", default => $script_path } - File { - backup => false, - } - file { $script_path: ensure => file, - owner => $script_owner, + 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/deployment/puppet/concat/metadata.json b/deployment/puppet/concat/metadata.json new file mode 100644 index 0000000000..1d45992601 --- /dev/null +++ b/deployment/puppet/concat/metadata.json @@ -0,0 +1,110 @@ +{ + "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" + ] + }, + { + "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/deployment/puppet/concat/spec/acceptance/backup_spec.rb b/deployment/puppet/concat/spec/acceptance/backup_spec.rb index 7b2858d8e9..1d3a5dfe39 100644 --- a/deployment/puppet/concat/spec/acceptance/backup_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/backup_spec.rb @@ -1,50 +1,60 @@ require 'spec_helper_acceptance' describe 'concat backup parameter' do + basedir = default.tmpdir('concat') context '=> puppet' do - before :all do - shell('rm -rf /tmp/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'old contents' > /tmp/concat/file") + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': backup => 'puppet', } concat::fragment { 'new file': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new contents', } EOS it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stderr).to eq("") - expect(r.stdout).to match(/Filebucketed \/tmp\/concat\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents' + expect(r.stdout).to match(/Filebucketed #{basedir}\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents' end - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new contents' } + its(:content) { should match /new contents/ } end end context '=> .backup' do - before :all do - shell('rm -rf /tmp/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'old contents' > /tmp/concat/file") + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new contents', } EOS @@ -52,50 +62,54 @@ describe 'concat backup parameter' do # XXX Puppet doesn't mention anything about filebucketing with a given # extension like .backup it 'applies the manifest twice no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new contents' } + its(:content) { should match /new contents/ } end - describe file('/tmp/concat/file.backup') do + describe file("#{basedir}/file.backup") do it { should be_file } - it { should contain 'old contents' } + its(:content) { should match /old contents/ } end end # XXX The backup parameter uses validate_string() and thus can't be the # boolean false value, but the string 'false' has the same effect in Puppet 3 context "=> 'false'" do - before :all do - shell('rm -rf /tmp/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'old contents' > /tmp/concat/file") + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "old contents\n", + } + EOS + apply_manifest(pp) end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': backup => '.backup', } concat::fragment { 'new file': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new contents', } EOS it 'applies the manifest twice with no "Filebucketed" stdout and no stderr' do apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stderr).to eq("") expect(r.stdout).to_not match(/Filebucketed/) end - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new contents' } + its(:content) { should match /new contents/ } end end end diff --git a/deployment/puppet/concat/spec/acceptance/concat_spec.rb b/deployment/puppet/concat/spec/acceptance/concat_spec.rb index 89919cc53b..c5c9727744 100644 --- a/deployment/puppet/concat/spec/acceptance/concat_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/concat_spec.rb @@ -1,73 +1,119 @@ require 'spec_helper_acceptance' +case fact('osfamily') + when 'AIX' + username = 'root' + groupname = 'system' + scriptname = 'concatfragments.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(/[\/:]/, '_') shared_examples 'successfully_applied' do |pp| it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file("#{default['puppetvardir']}/concat") do + describe file("#{vardir}/concat") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 755 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 755 + } end - describe file("#{default['puppetvardir']}/concat/bin") do + describe file("#{vardir}/concat/bin") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 755 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 755 + } end - describe file("#{default['puppetvardir']}/concat/bin/concatfragments.sh") do + describe file("#{vardir}/concat/bin/#{scriptname}") do it { should be_file } - it { should be_owned_by 'root' } - #it { should be_grouped_into 'root' } - it { should be_mode 755 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 755 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file") do + describe file("#{vardir}/concat/#{safe_basedir}_file") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 750 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 750 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments") do it { should be_directory } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 750 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 750 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 640 + } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments.concat.out") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat.out") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 640 + } end end context 'owner/group root' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp = <<-EOS - concat { '/tmp/concat/file': - owner => 'root', - group => 'root', + concat { '#{basedir}/file': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } @@ -75,89 +121,48 @@ describe 'basic concat test' do it_behaves_like 'successfully_applied', pp - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain '1' } - it { should contain '2' } - end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - end - end - - context 'owner/group non-root' do - before(:all) do - shell "groupadd -g 64444 bob" - shell "useradd -u 42 -g 64444 bob" - end - after(:all) do - shell "userdel bob" - end - - pp=" - concat { '/tmp/concat/file': - owner => 'bob', - group => 'bob', - mode => '0644', + it { should be_owned_by username } + it("should be group", :unless => (fact('osfamily') == 'windows')) { should be_grouped_into groupname } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 644 } - - concat::fragment { '1': - target => '/tmp/concat/file', - content => '1', - order => '01', + its(:content) { + should match '1' + should match '2' } - - concat::fragment { '2': - target => '/tmp/concat/file', - content => '2', - order => '02', + 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 } - " - - it_behaves_like 'successfully_applied', pp - - describe file('/tmp/concat/file') do - it { should be_file } - it { should be_owned_by 'bob' } - it { should be_grouped_into 'bob' } - it { should be_mode 644 } - it { should contain '1' } - it { should contain '2' } end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/01_1") do + describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - it { should contain '1' } - end - describe file("#{default['puppetvardir']}/concat/_tmp_concat_file/fragments/02_2") do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 640 } - it { should contain '2' } + it { should be_owned_by username } + it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) { + should be_mode 640 + } end end context 'ensure' do context 'works when set to present with path set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end pp=" concat { 'file': ensure => present, - path => '/tmp/concat/file', + path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': @@ -169,17 +174,27 @@ describe 'basic concat test' do it_behaves_like 'successfully_applied', pp - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should be_mode 644 } - it { should contain '1' } + 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 => '/tmp/concat/file', + path => '#{basedir}/file', mode => '0644', } concat::fragment { '1': @@ -189,14 +204,12 @@ describe 'basic concat test' do } " - # Can't used shared examples as this will always trigger the exec when - # absent is set. it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should_not be_file } end end diff --git a/deployment/puppet/concat/spec/acceptance/deprecation_warnings_spec.rb b/deployment/puppet/concat/spec/acceptance/deprecation_warnings_spec.rb index f139d818c6..11133ea9f2 100644 --- a/deployment/puppet/concat/spec/acceptance/deprecation_warnings_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/deprecation_warnings_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper_acceptance' 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) @@ -11,11 +12,11 @@ describe 'deprecation warnings' do context 'concat gnu parameter' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': gnu => 'foo', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -28,11 +29,11 @@ describe 'deprecation warnings' do ['true', 'yes', 'on'].each do |warn| context warn do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '#{warn}', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -40,10 +41,12 @@ describe 'deprecation warnings' do it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } - it { should contain 'bar' } + its(:content) { + should match '# This file is managed by Puppet. DO NOT EDIT.' + should match 'bar' + } end end end @@ -51,11 +54,11 @@ describe 'deprecation warnings' do ['false', 'no', 'off'].each do |warn| context warn do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '#{warn}', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -63,99 +66,104 @@ describe 'deprecation warnings' do it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' } - it { should contain 'bar' } + its(:content) { + should_not match '# This file is managed by Puppet. DO NOT EDIT.' + should match 'bar' + } end end end end - context 'concat::fragment ensure parameter' do + context 'concat::fragment ensure parameter', :unless => fact('osfamily') == 'windows' do context 'target file exists' do before(:all) do - shell("/bin/echo 'file1 contents' > /tmp/concat/file1") - end - after(:all) do - # XXX this test may leave behind a symlink in the fragment directory - # which could cause warnings and/or breakage from the subsequent tests - # unless we clean it up. - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file1': + content => "file1 contents\n", + } + EOS + apply_manifest(pp) end pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', - ensure => '/tmp/concat/file1', + target => '#{basedir}/file', + ensure => '#{basedir}/file1', } EOS w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.' it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain 'file1 contents' } + its(:content) { should match 'file1 contents' } end - describe 'the fragment can be changed from a symlink to a plain file' do + describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact("osfamily") == "windows") do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new content', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new content' } - it { should_not contain 'file1 contents' } + its(:content) { + should match 'new content' + should_not match 'file1 contents' + } end end end # target file exists - context 'target does not exist' do + context 'target does not exist', :unless => fact('osfamily') == 'windows' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', - ensure => '/tmp/concat/file1', + target => '#{basedir}/file', + ensure => '#{basedir}/file1', } EOS w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.' it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } end - describe 'the fragment can be changed from a symlink to a plain file' do + describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact('osfamily') == 'windows') do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new content', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain 'new content' } + its(:content) { should match 'new content' } end end end # target file exists @@ -164,9 +172,9 @@ describe 'deprecation warnings' do context 'concat::fragment mode parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', mode => 'bar', } @@ -178,9 +186,9 @@ describe 'deprecation warnings' do context 'concat::fragment owner parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', owner => 'bar', } @@ -192,9 +200,9 @@ describe 'deprecation warnings' do context 'concat::fragment group parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', group => 'bar', } @@ -206,9 +214,9 @@ describe 'deprecation warnings' do context 'concat::fragment backup parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', backup => 'bar', } diff --git a/deployment/puppet/concat/spec/acceptance/empty_spec.rb b/deployment/puppet/concat/spec/acceptance/empty_spec.rb index 09995282a3..4ab6e1e60b 100644 --- a/deployment/puppet/concat/spec/acceptance/empty_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/empty_spec.rb @@ -1,24 +1,23 @@ require 'spec_helper_acceptance' describe 'concat force empty parameter' do + basedir = default.tmpdir('concat') context 'should run successfully' do pp = <<-EOS - concat { '/tmp/concat/file': - owner => root, - group => root, + concat { '#{basedir}/file': mode => '0644', force => true, } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should_not contain '1\n2' } + its(:content) { should_not match /1\n2/ } end end end diff --git a/deployment/puppet/concat/spec/acceptance/fragment_source_spec.rb b/deployment/puppet/concat/spec/acceptance/fragment_source_spec.rb index 3afd53430d..a174e02b4c 100644 --- a/deployment/puppet/concat/spec/acceptance/fragment_source_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/fragment_source_spec.rb @@ -1,122 +1,145 @@ require 'spec_helper_acceptance' -describe 'concat::fragment source' do - context 'should read file fragments from local system' do - before(:all) do - shell("/bin/echo 'file1 contents' > /tmp/concat/file1") - shell("/bin/echo 'file2 contents' > /tmp/concat/file2") - end +case fact('osfamily') + when 'AIX' + username = 'root' + groupname = 'system' + when 'Darwin' + username = 'root' + groupname = 'wheel' + when 'windows' + username = 'Administrator' + groupname = 'Administrators' + else + username = 'root' + groupname = 'root' +end +describe 'concat::fragment source' do + basedir = default.tmpdir('concat') + context 'should read file fragments from local system' do pp = <<-EOS - concat { '/tmp/concat/foo': } + file { '#{basedir}/file1': + content => "file1 contents\n" + } + file { '#{basedir}/file2': + content => "file2 contents\n" + } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', - source => '/tmp/concat/file1', + target => '#{basedir}/foo', + source => '#{basedir}/file1', + require => File['#{basedir}/file1'], } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1 contents', } concat::fragment { '3': - target => '/tmp/concat/foo', - source => '/tmp/concat/file2', + target => '#{basedir}/foo', + source => '#{basedir}/file2', + require => File['#{basedir}/file2'], } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } - it { should contain 'file1 contents' } - it { should contain 'string1 contents' } - 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 context 'should create files containing first match only.' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - shell("/bin/echo 'file1 contents' > /tmp/concat/file1") - shell("/bin/echo 'file2 contents' > /tmp/concat/file2") - end - pp = <<-EOS - concat { '/tmp/concat/result_file1': - owner => root, - group => root, + file { '#{basedir}/file1': + content => "file1 contents\n" + } + file { '#{basedir}/file2': + content => "file2 contents\n" + } + concat { '#{basedir}/result_file1': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } - concat { '/tmp/concat/result_file2': - owner => root, - group => root, + concat { '#{basedir}/result_file2': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } - concat { '/tmp/concat/result_file3': - owner => root, - group => root, + concat { '#{basedir}/result_file3': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '/tmp/concat/result_file1', - source => [ '/tmp/concat/file1', '/tmp/concat/file2' ], + target => '#{basedir}/result_file1', + source => [ '#{basedir}/file1', '#{basedir}/file2' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } concat::fragment { '2': - target => '/tmp/concat/result_file2', - source => [ '/tmp/concat/file2', '/tmp/concat/file1' ], + target => '#{basedir}/result_file2', + source => [ '#{basedir}/file2', '#{basedir}/file1' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } concat::fragment { '3': - target => '/tmp/concat/result_file3', - source => [ '/tmp/concat/file1', '/tmp/concat/file2' ], + target => '#{basedir}/result_file3', + source => [ '#{basedir}/file1', '#{basedir}/file2' ], + require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ], order => '01', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/result_file1') do + describe file("#{basedir}/result_file1") do it { should be_file } - it { should contain 'file1 contents' } - it { should_not contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should_not match 'file2 contents' + } end - describe file('/tmp/concat/result_file2') do + describe file("#{basedir}/result_file2") do it { should be_file } - it { should contain 'file2 contents' } - it { should_not contain 'file1 contents' } + its(:content) { + should match 'file2 contents' + should_not match 'file1 contents' + } end - describe file('/tmp/concat/result_file3') do + describe file("#{basedir}/result_file3") do it { should be_file } - it { should contain 'file1 contents' } - it { should_not contain 'file2 contents' } + its(:content) { + should match 'file1 contents' + should_not match 'file2 contents' + } end end context 'should fail if no match on source.' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - shell('/bin/rm -rf /tmp/concat/fail_no_source /tmp/concat/nofilehere /tmp/concat/nothereeither') - end - pp = <<-EOS - concat { '/tmp/concat/fail_no_source': - owner => root, - group => root, + concat { '#{basedir}/fail_no_source': + owner => '#{username}', + group => '#{groupname}', mode => '0644', } concat::fragment { '1': - target => '/tmp/concat/fail_no_source', - source => [ '/tmp/concat/nofilehere', '/tmp/concat/nothereeither' ], + target => '#{basedir}/fail_no_source', + source => [ '#{basedir}/nofilehere', '#{basedir}/nothereeither' ], order => '01', } EOS @@ -124,7 +147,7 @@ describe 'concat::fragment source' do it 'applies the manifest with resource failures' do apply_manifest(pp, :expect_failures => true) end - describe file('/tmp/concat/fail_no_source') do + describe file("#{basedir}/fail_no_source") do #FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack. it { should_not be_file } it { should_not be_directory } diff --git a/deployment/puppet/concat/spec/acceptance/fragments_are_always_replaced_spec.rb b/deployment/puppet/concat/spec/acceptance/fragments_are_always_replaced_spec.rb new file mode 100644 index 0000000000..70d7382886 --- /dev/null +++ b/deployment/puppet/concat/spec/acceptance/fragments_are_always_replaced_spec.rb @@ -0,0 +1,139 @@ +require 'spec_helper_acceptance' + +describe 'concat::fragment replace' do + basedir = default.tmpdir('concat') + + context 'should create fragment files' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end + + pp1 = <<-EOS + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace unset run 1', + } + EOS + pp2 = <<-EOS + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace unset run 2', + } + EOS + + it 'applies the manifest twice with no stderr' do + apply_manifest(pp1, :catch_failures => true) + apply_manifest(pp1, :catch_changes => true) + apply_manifest(pp2, :catch_failures => true) + apply_manifest(pp2, :catch_changes => true) + end + + describe file("#{basedir}/foo") do + it { should be_file } + 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 + + context 'should replace its own fragment files when caller has File { replace=>true } set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end + + pp1 = <<-EOS + File { replace=>true } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace true set run 1', + } + EOS + pp2 = <<-EOS + File { replace=>true } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace true set run 2', + } + EOS + + it 'applies the manifest twice with no stderr' do + apply_manifest(pp1, :catch_failures => true) + apply_manifest(pp1, :catch_changes => true) + apply_manifest(pp2, :catch_failures => true) + apply_manifest(pp2, :catch_changes => true) + end + + describe file("#{basedir}/foo") do + it { should be_file } + 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 + + context 'should replace its own fragment files even when caller has File { replace=>false } set' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) + end + + pp1 = <<-EOS + File { replace=>false } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace false set run 1', + } + EOS + pp2 = <<-EOS + File { replace=>false } + concat { '#{basedir}/foo': } + + concat::fragment { '1': + target => '#{basedir}/foo', + content => 'caller has replace false set run 2', + } + EOS + + it 'applies the manifest twice with no stderr' do + apply_manifest(pp1, :catch_failures => true) + apply_manifest(pp1, :catch_changes => true) + apply_manifest(pp2, :catch_failures => true) + apply_manifest(pp2, :catch_changes => true) + end + + describe file("#{basedir}/foo") do + it { should be_file } + 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 + +end diff --git a/deployment/puppet/concat/spec/acceptance/newline_spec.rb b/deployment/puppet/concat/spec/acceptance/newline_spec.rb index 1e989df2ab..c1fa16a101 100644 --- a/deployment/puppet/concat/spec/acceptance/newline_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/newline_spec.rb @@ -1,57 +1,67 @@ require 'spec_helper_acceptance' describe 'concat ensure_newline parameter' do + basedir = default.tmpdir('concat') context '=> false' do + before(:all) do + pp = <<-EOS + file { '#{basedir}': + ensure => directory + } + EOS + + apply_manifest(pp) + end pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': ensure_newline => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain '12' } + its(:content) { should match '12' } end end context '=> true' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': ensure_newline => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") - #XXX ensure_newline => true causes changes on every run because the files - #are modified in place. + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain "1\n2\n" } + its(:content) { + should match /1\n2\n/ + } end end end diff --git a/deployment/puppet/concat/spec/acceptance/nodesets/centos-64-x64.yml b/deployment/puppet/concat/spec/acceptance/nodesets/centos-64-x64.yml index 05540ed8c5..0639835490 100644 --- a/deployment/puppet/concat/spec/acceptance/nodesets/centos-64-x64.yml +++ b/deployment/puppet/concat/spec/acceptance/nodesets/centos-64-x64.yml @@ -7,4 +7,4 @@ HOSTS: box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/deployment/puppet/concat/spec/acceptance/nodesets/centos-65-x64.yml b/deployment/puppet/concat/spec/acceptance/nodesets/centos-65-x64.yml new file mode 100644 index 0000000000..4e2cb809e8 --- /dev/null +++ b/deployment/puppet/concat/spec/acceptance/nodesets/centos-65-x64.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-65-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-65-x64-vbox436-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box + hypervisor : vagrant +CONFIG: + type: foss diff --git a/deployment/puppet/concat/spec/acceptance/nodesets/default.yml b/deployment/puppet/concat/spec/acceptance/nodesets/default.yml index ae812b0aef..b826851586 100644 --- a/deployment/puppet/concat/spec/acceptance/nodesets/default.yml +++ b/deployment/puppet/concat/spec/acceptance/nodesets/default.yml @@ -1,10 +1,10 @@ HOSTS: - centos-64-x64.localdomain: + centos-66-x64: roles: - master platform: el-6-x86_64 - box : centos-65-x64-virtualbox-nocm - box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box + box : puppetlabs/centos-6.6-64-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-6.6-64-nocm hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/deployment/puppet/concat/spec/acceptance/nodesets/fedora-18-x64.yml b/deployment/puppet/concat/spec/acceptance/nodesets/fedora-18-x64.yml index 1361649830..624b53716b 100644 --- a/deployment/puppet/concat/spec/acceptance/nodesets/fedora-18-x64.yml +++ b/deployment/puppet/concat/spec/acceptance/nodesets/fedora-18-x64.yml @@ -7,4 +7,4 @@ HOSTS: box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box hypervisor : vagrant CONFIG: - type: foss + type: git diff --git a/deployment/puppet/concat/spec/acceptance/order_spec.rb b/deployment/puppet/concat/spec/acceptance/order_spec.rb index 8bcb7131ce..c158dd8807 100644 --- a/deployment/puppet/concat/spec/acceptance/order_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/order_spec.rb @@ -1,137 +1,123 @@ require 'spec_helper_acceptance' describe 'concat order' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - end + basedir = default.tmpdir('concat') - context '=> alpha' do - pp = <<-EOS - concat { '/tmp/concat/foo': - order => 'alpha' + context '=> ' do + shared_examples 'sortby' do |order_by, match_output| + pp = <<-EOS + concat { '#{basedir}/foo': + order => '#{order_by}' } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1', + order => '1', } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string2', + order => '2', } concat::fragment { '10': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string10', } - EOS + EOS - it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + 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 } + its(:content) { should match match_output } + end end - describe file('/tmp/concat/foo') do - it { should be_file } - it { should contain "string10\nstring1\nsring2" } - end - end - - context '=> numeric' do - pp = <<-EOS - concat { '/tmp/concat/foo': - order => 'numeric' - } - concat::fragment { '1': - target => '/tmp/concat/foo', - content => 'string1', - } - concat::fragment { '2': - target => '/tmp/concat/foo', - content => 'string2', - } - concat::fragment { '10': - target => '/tmp/concat/foo', - content => 'string10', - } - EOS - - it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + describe 'alpha' do + it_behaves_like 'sortby', 'alpha', /string10string1string2/ end - describe file('/tmp/concat/foo') do - it { should be_file } - it { should contain "string1\nstring2\nsring10" } + describe 'numeric' do + it_behaves_like 'sortby', 'numeric', /string1string2string10/ end end end # concat order describe 'concat::fragment order' do - before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') - end + basedir = default.tmpdir('concat') context '=> reverse order' do - pp = <<-EOS - concat { '/tmp/concat/foo': } + shared_examples 'order_by' do |order_by, match_output| + pp = <<-EOS + concat { '#{basedir}/foo': + order => '#{order_by}' + } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1', order => '15', } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string2', # default order 10 } concat::fragment { '3': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string3', order => '1', } - EOS + EOS - it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + 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 } + its(:content) { should match match_output } + end end - - describe file('/tmp/concat/foo') do - it { should be_file } - it { should contain "string3\nstring2\nsring1" } + 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 context '=> normal order' do pp = <<-EOS - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string2', order => '02' } concat::fragment { '3': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'string3', order => '03', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } - it { should contain "string1\nstring2\nsring3" } + its(:content) { should match /string1string2string3/ } end end end # concat::fragment order diff --git a/deployment/puppet/concat/spec/acceptance/quoted_paths_spec.rb b/deployment/puppet/concat/spec/acceptance/quoted_paths_spec.rb index d1a2b5f1bf..042425f921 100644 --- a/deployment/puppet/concat/spec/acceptance/quoted_paths_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/quoted_paths_spec.rb @@ -1,33 +1,42 @@ require 'spec_helper_acceptance' describe 'quoted paths' do + basedir = default.tmpdir('concat') + before(:all) do - shell('rm -rf "/tmp/concat test" /var/lib/puppet/concat') - shell('mkdir -p "/tmp/concat test"') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/concat test': + ensure => directory, + } + EOS + apply_manifest(pp) end context 'path with blanks' do pp = <<-EOS - concat { '/tmp/concat test/foo': + concat { '#{basedir}/concat test/foo': } concat::fragment { '1': - target => '/tmp/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string1', } concat::fragment { '2': - target => '/tmp/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat test/foo') do + describe file("#{basedir}/concat test/foo") do it { should be_file } - it { should contain "string1\nsring2" } + its(:content) { should match /string1string2/ } end end end diff --git a/deployment/puppet/concat/spec/acceptance/replace_spec.rb b/deployment/puppet/concat/spec/acceptance/replace_spec.rb index 7b31e09c44..bd597ed19a 100644 --- a/deployment/puppet/concat/spec/acceptance/replace_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/replace_spec.rb @@ -1,123 +1,140 @@ require 'spec_helper_acceptance' describe 'replacement of' do + basedir = default.tmpdir('concat') context 'file' do context 'should not succeed' do before(:all) do - shell('mkdir -p /tmp/concat') - shell('echo "file exists" > /tmp/concat/file') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "file exists\n" + } + EOS + apply_manifest(pp) end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain 'file exists' } - it { should_not contain '1' } - it { should_not contain '2' } + its(:content) { + should match 'file exists' + should_not match '1' + should_not match '2' + } end end context 'should succeed' do before(:all) do - shell('mkdir -p /tmp/concat') - shell('echo "file exists" > /tmp/concat/file') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + content => "file exists\n" + } + EOS + apply_manifest(pp) end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should_not contain 'file exists' } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should_not match 'file exists' + should match '1' + should match '2' + } end end end # file - context 'symlink' do + context 'symlink', :unless => (fact("osfamily") == "windows") do context 'should not succeed' do # XXX the core puppet file type will replace a symlink with a plain file # when using ensure => present and source => ... but it will not when using # ensure => present and content => ...; this is somewhat confusing behavior before(:all) do - shell('mkdir -p /tmp/concat') - shell('ln -s /tmp/concat/dangling /tmp/concat/file') - end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => link, + target => '#{basedir}/dangling', + } + EOS + apply_manifest(pp) end pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do - it { should be_linked_to '/tmp/concat/dangling' } + # XXX specinfra doesn't support be_linked_to on AIX + describe file("#{basedir}/file"), :unless => (fact("osfamily") == "AIX" or fact("osfamily") == "windows") do + it { should be_linked_to "#{basedir}/dangling" } end - describe file('/tmp/concat/dangling') do + describe file("#{basedir}/dangling") do # XXX serverspec does not have a matcher for 'exists' it { should_not be_file } it { should_not be_directory } @@ -129,38 +146,45 @@ describe 'replacement of' do # when using ensure => present and source => ... but it will not when using # ensure => present and content => ...; this is somewhat confusing behavior before(:all) do - shell('mkdir -p /tmp/concat') - shell('ln -s /tmp/concat/dangling /tmp/concat/file') - end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => link, + target => '#{basedir}/dangling', + } + EOS + apply_manifest(pp) end pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': replace => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end end end # symlink @@ -168,22 +192,26 @@ describe 'replacement of' do context 'directory' do context 'should not succeed' do before(:all) do - shell('mkdir -p /tmp/concat/file') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file': + ensure => directory, + } + EOS + apply_manifest(pp) end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - end - pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS @@ -193,7 +221,7 @@ describe 'replacement of' do expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/change from directory to file failed/) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_directory } end end @@ -204,37 +232,30 @@ describe 'replacement of' do # changed, extended, or a new param introduced to control directory # replacement. context 'should succeed', :pending => 'not yet implemented' do - before(:all) do - shell('mkdir -p /tmp/concat/file') - end - after(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - end - pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': force => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } + its(:content) { should match '1' } end end end # directory diff --git a/deployment/puppet/concat/spec/acceptance/specinfra_stubs.rb b/deployment/puppet/concat/spec/acceptance/specinfra_stubs.rb new file mode 100644 index 0000000000..bae85eff0f --- /dev/null +++ b/deployment/puppet/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/deployment/puppet/concat/spec/acceptance/symbolic_name_spec.rb b/deployment/puppet/concat/spec/acceptance/symbolic_name_spec.rb index 7267f5e6b4..df8d54f525 100644 --- a/deployment/puppet/concat/spec/acceptance/symbolic_name_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/symbolic_name_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper_acceptance' describe 'symbolic name' do + basedir = default.tmpdir('concat') pp = <<-EOS concat { 'not_abs_path': - path => '/tmp/concat/file', + path => '#{basedir}/file', } concat::fragment { '1': @@ -20,13 +21,15 @@ describe 'symbolic name' do EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match '1' + should match '2' + } end end diff --git a/deployment/puppet/concat/spec/acceptance/validation_spec.rb b/deployment/puppet/concat/spec/acceptance/validation_spec.rb new file mode 100644 index 0000000000..c35871b9b5 --- /dev/null +++ b/deployment/puppet/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/deployment/puppet/concat/spec/acceptance/warn_spec.rb b/deployment/puppet/concat/spec/acceptance/warn_spec.rb index cb0b7430dc..2788607c84 100644 --- a/deployment/puppet/concat/spec/acceptance/warn_spec.rb +++ b/deployment/puppet/concat/spec/acceptance/warn_spec.rb @@ -1,97 +1,104 @@ require 'spec_helper_acceptance' describe 'concat warn =>' do + basedir = default.tmpdir('concat') context 'true should enable default warning message' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => true, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } - it { should contain '1' } - 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 pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => false, } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' } - it { should contain '1' } - 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 pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '# foo', } concat::fragment { '1': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '1', order => '01', } concat::fragment { '2': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => '2', order => '02', } EOS it 'applies the manifest twice with no stderr' do - expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("") - expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("") + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } - it { should contain '# foo' } - it { should contain '1' } - it { should contain '2' } + its(:content) { + should match /# foo/ + should match /1/ + should match /2/ + } end end end diff --git a/deployment/puppet/concat/spec/spec.opts b/deployment/puppet/concat/spec/spec.opts new file mode 100644 index 0000000000..91cd6427ed --- /dev/null +++ b/deployment/puppet/concat/spec/spec.opts @@ -0,0 +1,6 @@ +--format +s +--colour +--loadby +mtime +--backtrace diff --git a/deployment/puppet/concat/spec/spec_helper_acceptance.rb b/deployment/puppet/concat/spec/spec_helper_acceptance.rb index 22bd72f06a..da994f8dfb 100644 --- a/deployment/puppet/concat/spec/spec_helper_acceptance.rb +++ b/deployment/puppet/concat/spec/spec_helper_acceptance.rb @@ -1,14 +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' - if hosts.first.is_pe? - install_pe + # This will install the latest available package on el and deb based + # systems fail on windows and osx, and install via gem on other *nixes + foss_opts = {:default_action => 'gem_install'} + + if default.is_pe?; then + install_pe; else - install_puppet + 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 @@ -21,10 +44,8 @@ RSpec.configure do |c| # Configure all nodes in nodeset c.before :suite do - # Install module and dependencies - puppet_module_install(:source => proj_root, :module_name => 'concat') hosts.each do |host| - on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + copy_module_to(host, :source => proj_root, :module_name => 'concat') end end @@ -37,3 +58,4 @@ RSpec.configure do |c| c.treat_symbols_as_metadata_keys_with_true_values = true end + diff --git a/deployment/puppet/concat/spec/unit/classes/concat_setup_spec.rb b/deployment/puppet/concat/spec/unit/classes/concat_setup_spec.rb index 92e01caa97..c6ff93e0ac 100644 --- a/deployment/puppet/concat/spec/unit/classes/concat_setup_spec.rb +++ b/deployment/puppet/concat/spec/unit/classes/concat_setup_spec.rb @@ -5,13 +5,22 @@ describe 'concat::setup', :type => :class do shared_examples 'setup' do |concatdir| concatdir = '/foo' if concatdir.nil? - let(:facts) {{ :concat_basedir => concatdir }} + let(:facts) do + { + :concat_basedir => concatdir, + :caller_module_name => 'Test', + :osfamily => 'Debian', + :id => 'root', + :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', - :backup => false, + :owner => 'root', + :group => 0, + :source => 'puppet:///modules/concat/concatfragments.rb', }) end @@ -20,7 +29,8 @@ describe 'concat::setup', :type => :class do should contain_file(file).with({ :ensure => 'directory', :mode => '0755', - :backup => false, + :owner => 'root', + :group => 0, }) end end @@ -39,4 +49,50 @@ describe 'concat::setup', :type => :class do skip('rspec-puppet support for testing warning()') end end + + context "on osfamily Solaris" do + concatdir = '/foo' + let(:facts) do + { + :concat_basedir => concatdir, + :caller_module_name => 'Test', + :osfamily => 'Solaris', + :id => 'root', + :is_pe => false, + } + end + + it do + should contain_file("#{concatdir}/bin/concatfragments.rb").with({ + :ensure => 'file', + :owner => 'root', + :group => 0, + :mode => '0755', + :source => 'puppet:///modules/concat/concatfragments.rb', + }) + end + end # on osfamily Solaris + + context "on osfamily windows" do + concatdir = '/foo' + let(:facts) do + { + :concat_basedir => concatdir, + :caller_module_name => 'Test', + :osfamily => 'windows', + :id => 'batman', + :is_pe => false, + } + end + + it do + should contain_file("#{concatdir}/bin/concatfragments.rb").with({ + :ensure => 'file', + :owner => nil, + :group => nil, + :mode => nil, + :source => 'puppet:///modules/concat/concatfragments.rb', + }) + end + end # on osfamily windows end diff --git a/deployment/puppet/concat/spec/unit/defines/concat_fragment_spec.rb b/deployment/puppet/concat/spec/unit/defines/concat_fragment_spec.rb index c4e0a34403..6cf3e42960 100644 --- a/deployment/puppet/concat/spec/unit/defines/concat_fragment_spec.rb +++ b/deployment/puppet/concat/spec/unit/defines/concat_fragment_spec.rb @@ -17,14 +17,24 @@ describe 'concat::fragment', :type => :define do concatdir = '/var/lib/puppet/concat' fragdir = "#{concatdir}/#{safe_target_name}" id = 'root' + gid = 'root' if p[:ensure] == 'absent' - safe_ensure = p[:ensure] + safe_ensure = p[:ensure] else safe_ensure = 'file' end let(:title) { title } - let(:facts) {{ :concat_basedir => concatdir, :id => id }} + 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]}': }" @@ -36,11 +46,12 @@ describe 'concat::fragment', :type => :define do 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 => false, + :backup => 'puppet', }) end end @@ -64,11 +75,11 @@ describe 'concat::fragment', :type => :define do 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 - should compile.and_raise_error(/is not a string/) + expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # target => @@ -85,7 +96,7 @@ describe 'concat::fragment', :type => :define do 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 @@ -106,11 +117,11 @@ describe 'concat::fragment', :type => :define do 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 - should compile.and_raise_error(/is not a string/) + expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # content => @@ -127,11 +138,11 @@ describe 'concat::fragment', :type => :define do 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 - should compile.and_raise_error(/is not a string or an Array/) + expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/) end end end # source => @@ -148,11 +159,39 @@ describe 'concat::fragment', :type => :define do 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 - should compile.and_raise_error(/is not a string/) + 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 => @@ -162,7 +201,15 @@ describe 'concat::fragment', :type => :define do context 'ensure => target and source' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) do + { + :concat_basedir => '/tmp', + :osfamily => 'Debian', + :id => 'root', + :is_pe => false, + :gid => 'root', + } + end let(:params) do { :target => '/etc/motd', @@ -172,13 +219,21 @@ describe 'concat::fragment', :type => :define do end it 'should fail' do - should compile.and_raise_error(/#{Regexp.escape(error_msg)}/m) + expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'ensure => target and content' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) do + { + :concat_basedir => '/tmp', + :osfamily => 'Debian', + :id => 'root', + :is_pe => false, + :gid => 'root', + } + end let(:params) do { :target => '/etc/motd', @@ -188,13 +243,21 @@ describe 'concat::fragment', :type => :define do end it 'should fail' do - should compile.and_raise_error(/#{Regexp.escape(error_msg)}/m) + expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'source and content' do let(:title) { 'motd_header' } - let(:facts) {{ :concat_basedir => '/tmp' }} + let(:facts) do + { + :concat_basedir => '/tmp', + :osfamily => 'Debian', + :id => 'root', + :is_pe => false, + :gid => 'root', + } + end let(:params) do { :target => '/etc/motd', @@ -204,7 +267,7 @@ describe 'concat::fragment', :type => :define do end it 'should fail' do - should compile.and_raise_error(/#{Regexp.escape(error_msg)}/m) + expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end diff --git a/deployment/puppet/concat/spec/unit/defines/concat_spec.rb b/deployment/puppet/concat/spec/unit/defines/concat_spec.rb index 8d214d78f2..115a0f55bc 100644 --- a/deployment/puppet/concat/spec/unit/defines/concat_spec.rb +++ b/deployment/puppet/concat/spec/unit/defines/concat_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe 'concat', :type => :define do - shared_examples 'concat' do |title, params, id| + shared_examples 'concat' do |title, params, id| params = {} if params.nil? id = 'root' if id.nil? @@ -19,6 +19,7 @@ describe 'concat', :type => :define do :replace => true, :order => 'alpha', :ensure_newline => false, + :validate_cmd => nil, }.merge(params) safe_name = title.gsub('/', '_') @@ -28,12 +29,21 @@ describe 'concat', :type => :define do default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.' file_defaults = { - :backup => false, + :backup => p[:backup], } let(:title) { title } let(:params) { params } - let(:facts) {{ :concat_basedir => concatdir, :id => id }} + let(:facts) do + { + :concat_basedir => concatdir, + :id => id, + :osfamily => 'Debian', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + :kernel => 'Linux', + :is_pe => false, + } + end if p[:ensure] == 'present' it do @@ -68,23 +78,24 @@ describe 'concat', :type => :define do 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}\"" - # flag order: fragdir, warnflag, forceflag, orderflag, newlineflag + # flag order: fragdir, warnflag, forceflag, orderflag, newlineflag if p.has_key?(:warn) case p[:warn] when TrueClass @@ -127,7 +138,6 @@ describe 'concat', :type => :define do it do should contain_file(file).with(file_defaults.merge({ :ensure => 'absent', - :backup => false, :force => true, })) end @@ -165,7 +175,7 @@ describe 'concat', :type => :define do context title do let(:title) { title } it 'should fail' do - should compile.and_raise_error(/is not an absolute path/) + expect { should }.to raise_error(Puppet::Error, /is not an absolute path/) end end end @@ -195,7 +205,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :ensure => 'invalid' }} it 'should fail' do - should compile.and_raise_error(/#{Regexp.escape('does not match "^present$|^absent$"')}/) + expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^present$|^absent$"')}/) end end end # ensure => @@ -210,7 +220,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :path => path }} it 'should fail' do - should compile.and_raise_error(/is not an absolute path/) + expect { should }.to raise_error(Puppet::Error, /is not an absolute path/) end end end @@ -225,7 +235,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :owner => false }} it 'should fail' do - should compile.and_raise_error(/is not a string/) + expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # owner => @@ -239,7 +249,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :group => false }} it 'should fail' do - should compile.and_raise_error(/is not a string/) + expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # group => @@ -253,7 +263,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :mode => false }} it 'should fail' do - should compile.and_raise_error(/is not a string/) + expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # mode => @@ -281,7 +291,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :warn => 123 }} it 'should fail' do - should compile.and_raise_error(/is not a string or boolean/) + expect { should }.to raise_error(Puppet::Error, /is not a string or boolean/) end end end # warn => @@ -297,7 +307,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :force => 123 }} it 'should fail' do - should compile.and_raise_error(/is not a boolean/) + expect { should }.to raise_error(Puppet::Error, /is not a boolean/) end end end # force => @@ -308,10 +318,18 @@ describe 'concat', :type => :define do end context 'false' do + it_behaves_like 'concat', '/etc/foo.bar', { :backup => false } + end + + context 'true' do + it_behaves_like 'concat', '/etc/foo.bar', { :backup => true } + end + + context 'true' do let(:title) { '/etc/foo.bar' } - let(:params) {{ :backup => false }} + let(:params) {{ :backup => [] }} it 'should fail' do - should compile.and_raise_error(/is not a string/) + expect { should }.to raise_error(Puppet::Error, /backup must be string or bool/) end end end # backup => @@ -327,7 +345,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :replace => 123 }} it 'should fail' do - should compile.and_raise_error(/is not a boolean/) + expect { should }.to raise_error(Puppet::Error, /is not a boolean/) end end end # replace => @@ -343,7 +361,7 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :order => 'invalid' }} it 'should fail' do - should compile.and_raise_error(/#{Regexp.escape('does not match "^alpha$|^numeric$"')}/) + expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape('does not match "^alpha$|^numeric$"')}/) end end end # order => @@ -359,11 +377,27 @@ describe 'concat', :type => :define do let(:title) { '/etc/foo.bar' } let(:params) {{ :ensure_newline => 123 }} it 'should fail' do - should compile.and_raise_error(/is not a boolean/) + expect { should }.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 + + [ 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