#mod 'puppetlabs/stunnel', '0.1.0'
mod 'puppetlabs/stdlib', '4.6.0'
-mod 'puppetlabs/concat', '2.0.0'
+mod 'puppetlabs/concat', '1.2.2'
mod 'elasticsearch/elasticsearch', '0.9.5'
-=======
-##2015-05-12 - Supported Release 2.0.0
-###Summary
-
-This is a major release. Includes re-implementation of concat to use native Type and Providers, resulting in significantly improved performance and testability. Also includes a bugfix to alpha ordering of fragments.
-
-####Features
-- Re-implementation of concat to use native Type and Providers.
-
-####Bugfixes
-- Fixes a bug in alpha ordering of fragments.
-
-
##2015-05-12 - Supported Release 1.2.2
###Summary
end
group :development, :unit_tests do
+ gem 'rake', :require => false
gem 'rspec-core', '3.1.7', :require => false
- gem 'rspec-puppet', '~> 2.0', :require => false
+ gem 'rspec-puppet', '~> 1.0', :require => false
gem 'puppetlabs_spec_helper', :require => false
+ gem 'puppet-lint', :require => false
gem 'simplecov', :require => false
gem 'puppet_facts', :require => false
gem 'json', :require => false
- gem 'pry'
end
+beaker_version = ENV['BEAKER_VERSION']
+beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
group :system_tests do
- if beaker_version = ENV['BEAKER_VERSION']
+ if beaker_version
gem 'beaker', *location_for(beaker_version)
end
- if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
+ if beaker_rspec_version
gem 'beaker-rspec', *location_for(beaker_rspec_version)
else
gem 'beaker-rspec', :require => false
gem 'serverspec', :require => false
end
-
-
if facterversion = ENV['FACTER_GEM_VERSION']
- gem 'facter', facterversion, :require => false
+ gem 'facter', *location_for(facterversion)
else
gem 'facter', :require => false
end
if puppetversion = ENV['PUPPET_GEM_VERSION']
- gem 'puppet', puppetversion, :require => false
+ gem 'puppet', *location_for(puppetversion)
else
gem 'puppet', :require => false
end
* [Beginning with concat](#beginning-with-concat)
4. [Usage - Configuration options and additional functionality](#usage)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
- * [Defines](#defines)
+ * [Public Defines](#public-defines)
* [Parameters](#parameters)
- * [Removed functionality](#removed-functionality)
+ * [Deprecations](#deprecations)
6. [Limitations - OS compatibility, etc.](#limitations)
7. [Development - Guide for contributing to the module](#development)
##Module Description
-The concat module lets you gather `concat::fragment` resources from your other modules and order them into a coherent file through a single `concat` resource.
+The concat module lets you gather `concat::fragment` resources from your other modules and order them through a single `concat` resource into a coherent file. It does this through a Ruby script and a temporary holding space for the fragments.
+
+##Setup
+
+###What concat affects
+
+* Installs `concatfragments.rb`.
+* Adds a `concat/` directory into Puppet's `vardir`.
###Beginning with concat
##Reference
-###Defines
+**Note**: Several of this module's parameters and features have been deprecated. See the [Deprecations](#deprecations) section below.
+
+###Public defines
* `concat`: Manages a file, compiled from one or more text fragments.
* `concat::fragment`: Manages a fragment of text to be compiled into a file.
-###Types
-* `concat_file`: Generates a file with content from fragments sharing a common unique tag.
-* `concat_fragment`: Manages the fragment.
-
###Parameters
-####Define: `concat`
+####`concat`
All the parameters listed below are optional.
Specifies whether the destination file should exist. Setting to 'absent' tells Puppet to delete the destination file if it exists, and negates the effect of any other parameters. Valid options: 'present' and 'absent'. Default value: 'present'.
+
#####`ensure_newline`
-Specifies whether to add a line break at the end of each fragment that doesn't already end in one. Valid options: 'true' and 'false'. Default value: 'false'.
+Specifies whether to ensure there's a new line at the end of each fragment. Valid options: 'true' and 'false'. Default value: 'false'.
#####`force`
-Deprecated as of concat v2.0.0. Has no effect.
+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`
#####`owner`
+
Specifies the owner of the destination file. Valid options: a string containing a username. Default value: undefined.
#####`path`
+
Specifies a destination file for the combined fragments. Valid options: a string containing an absolute path. Default value: the title of your declared resource.
#####`replace`
#####`warn`
-Specifies whether to add a header message at the top of the destination file. Valid options: the booleans 'true' and 'false', or a string to serve as the header. Default value: 'false'.
+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 'warn' to 'true', `concat` adds the following message:
+
+If you set this parameter to 'true', Puppet adds the following message:
~~~
# This file is managed by Puppet. DO NOT EDIT.
~~~
-####Define: `concat::fragment`
+####`concat::fragment`
+
Except where noted, all the below parameters are optional.
#####`ensure`
-Deprecated as of concat v2.0.0. Has no effect.
+Specifies whether the fragment should be included in the destination file or discarded. Valid options: 'present' and 'absent'. Default value: 'present'.
#####`order`
*Required.* Specifies the destination file of the fragment. Valid options: a string containing an absolute path.
+###Deprecations
-####Type: `concat_file`
-
-#####`backup`
-
-Specifies whether (and how) to back up the destination file before overwriting it. Your value gets passed on to Puppet's [native `file` resource](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-backup) for execution. Valid options: 'true', 'false', or a string representing either a target filebucket or a filename extension beginning with ".". Default value: 'puppet'.
-
-#####`ensure`
-
-Specifies whether the destination file should exist. Setting to 'absent' tells Puppet to delete the destination file if it exists, and negates the effect of any other parameters. Valid options: 'present' and 'absent'. Default value: 'present'.
-
-#####`ensure_newline`
-
-Specifies whether to add a line break at the end of each fragment that doesn't already end in one. Valid options: 'true' and 'false'. Default value: 'false'.
-
-#####`group`
-
-Specifies a permissions group for the destination file. Valid options: a string containing a group name. Default value: undefined.
-
-#####`mode`
-
-Specifies the permissions mode of the destination file. Valid options: a string containing a permission mode value in octal notation. Default value: '0644'.
-
-#####`order`
-
-Specifies a method for sorting your fragments by name within the destination file. Valid options: 'alpha' (e.g., '1, 10, 2') or 'numeric' (e.g., '1, 2, 10'). Default value: 'numeric'.
-
-You can override this setting for individual fragments by adjusting the `order` parameter in their `concat::fragment` declarations.
+**`concat` has the following deprecations**
-#####`owner`
+#####`gnu`
-Specifies the owner of the destination file. Valid options: a string containing a username. Default value: undefined.
+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.
-#####`path`
+#####stringified 'true'/'false' values deprecated in `warn`
-Specifies a destination file for the combined fragments. Valid options: a string containing an absolute path. Default value: the title of your declared resource.
+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.
-#####`replace`
-
-Specifies whether to overwrite the destination file if it already exists. Valid options: 'true' and 'false'. Default value: 'true'.
-
-####`tag`
-
-*Required.* Specifies a unique tag reference to collect all concat_fragments with the same tag.
-
-#####`validate_cmd`
+Please migrate to using the Puppet DSL's native [Boolean data
+type](http://docs.puppetlabs.com/puppet/3/reference/lang_datatypes.html#booleans).
-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.
-####Type: `concat_fragment`
+**`concat::fragment` has the following deprecations**
-#####`content`
+#####`backup`
-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.
+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.
-#####`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'.
+#####`group`
-#####`source`
+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.
-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.
+#####`mode`
-#####`tag`
+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.
-*Required.* Specifies a unique tag to be used by concat_file to reference and collect content.
-#####`target`
+#####`owner`
-*Required.* Specifies the destination file of the fragment. Valid options: a string containing an absolute path.
+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.
-###Removed functionality
+#####file paths are deprecated in `ensure`
-The following functionality existed in previous versions of the concat module, but was removed in version 2.0.0:
+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.
-Parameters removed from `concat::fragment`:
-* `gnu`
-* `backup`
-* `group`
-* `mode`
-* `owner`
+If you want to use the content of a file as a fragment please use the [`source`](#source) parameter.
-The `concat::setup` class has also been removed.
+####`concat::setup`
-Prior to concat version 2.0.0, if you set the `warn` parameter to a string value of 'true', 'false', 'yes', 'no', 'on', or 'off', the module translated the string to the corresponding boolean value. In concat version 2.0.0 and newer, the `warn_header` parameter treats those values the same as other strings and uses them as the content of your header message. To avoid that, pass the 'true' and 'false' values as booleans instead of strings.
+The `concat::setup` class should no longer be directly included in the manifest. It will be removed in a future release.
##Limitations
###Contributors
-Richard Pijnenburg ([@Richardp82](http://twitter.com/richardp82))
-
-Joshua Hoblitt ([@jhoblitt](http://twitter.com/jhoblitt))
-
-[More contributors.](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)
\ No newline at end of file
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
-PuppetLint.configuration.fail_on_warnings = true
+PuppetLint.configuration.fail_on_warnings
PuppetLint.configuration.send('relative')
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
{
- "CHANGELOG.md": "c5810ae257f789f7fea08d9629144f7d",
+ "CHANGELOG.md": "34635b8c35237d282737636ac4cc94fb",
"CONTRIBUTING.md": "e2b8e8e433fc76b3798b7fe435f49375",
- "Gemfile": "78b3171b07a747a7353350504f144f64",
+ "Gemfile": "95b12671812d21665a8a986f008cf8e6",
"LICENSE": "f5a76685d453424cd63dde1535811cf0",
- "README.md": "6df5e549bec657669f9b65069becd6ff",
- "Rakefile": "d953eb985f82600dc3b9ac6e1f2cfe64",
- "lib/puppet/type/concat_file.rb": "7cc4e5b1f1cc8354bcbab4de386d8805",
- "lib/puppet/type/concat_fragment.rb": "f661ea5a5143387513571e1892eeb74f",
- "manifests/fragment.pp": "e758dfb57f0fe796abcaf64af10a9c57",
- "manifests/init.pp": "8443e17ab8eaecb0db764701083b504c",
- "metadata.json": "1fcd602ed1156173234655457518ef63",
- "spec/acceptance/backup_spec.rb": "242ce4dce1efba5efb21850b9bb2a342",
- "spec/acceptance/concat_spec.rb": "90da0deea2501ab1abc74fac31f02857",
- "spec/acceptance/deprecation_warnings_spec.rb": "1b005f407eba3a6a3b93bed1d3e529dd",
- "spec/acceptance/fragment_source_spec.rb": "3d0e708a392e4b75e8484f2f0b4d256f",
+ "README.md": "4bc34f3895f17ab66f7dd4c5712c92e1",
+ "Rakefile": "9ae42c3a3ad6949efb2df1cd12ced1b6",
+ "files/concatfragments.rb": "b684db0eac243553a6a79365119a363d",
+ "lib/facter/concat_basedir.rb": "ff080677e7f192b9b96911698b0b9b3d",
+ "lib/puppet/parser/functions/concat_getparam.rb": "7654b44a87a05b2f2e9de2eaadf1ff8f",
+ "lib/puppet/parser/functions/concat_is_bool.rb": "a5dc6980d7f27d1b858e791964682756",
+ "manifests/fragment.pp": "6261ad7c56847a13f0718eaac4b4d1a6",
+ "manifests/init.pp": "cf5dfb69d7af67d934a4a5bc7b07e3e6",
+ "manifests/setup.pp": "706e4a1fd1326de5f0fa1a466ceb147b",
+ "metadata.json": "d5154f6d7d9d8b153343b29e5244aced",
+ "spec/acceptance/backup_spec.rb": "1d60ad406485b47b42547f24a0b68dce",
+ "spec/acceptance/concat_spec.rb": "2d9a1ec1293adec240e4d784285f7d8b",
+ "spec/acceptance/deprecation_warnings_spec.rb": "c52721536ea53cd3e2a0aff897951e72",
+ "spec/acceptance/empty_spec.rb": "c787d7f36b3ba142f2592db3d1b59439",
+ "spec/acceptance/fragment_source_spec.rb": "594cef5172b52aa65dc16ebd34fad9c6",
"spec/acceptance/fragments_are_always_replaced_spec.rb": "be39ed9ed30e7bb48aaccda2d7f730ac",
"spec/acceptance/newline_spec.rb": "5aaf65972c4f8ed4fd1592cd863583f5",
"spec/acceptance/nodesets/aix-71-vcloud.yml": "de6cc5bf18be2be8d50e62503652cb32",
"spec/acceptance/nodesets/debian-607-x64.yml": "d566bf76f534e2af7c9a4605316d232c",
"spec/acceptance/nodesets/debian-70rc1-x64.yml": "31ccca73af7b74e1cc2fb0035c230b2c",
"spec/acceptance/nodesets/debian-73-x64.yml": "bd3ea8245ce691c2b234529d62d043eb",
- "spec/acceptance/nodesets/default.yml": "3e5c36e6aa5a690229e720f4048bb8af",
+ "spec/acceptance/nodesets/default.yml": "efd15b1780bb8e68000a7a4e9e09a132",
"spec/acceptance/nodesets/fedora-18-x64.yml": "acc126fa764c39a3b1df36e9224a21d9",
"spec/acceptance/nodesets/sles-11-x64.yml": "44e4c6c15c018333bfa9840a5e702f66",
"spec/acceptance/nodesets/sles-11sp1-x64.yml": "fa0046bd89c1ab4ba9521ad79db234cd",
"spec/acceptance/nodesets/ubuntu-server-10044-x64.yml": "75e86400b7889888dc0781c0ae1a1297",
"spec/acceptance/nodesets/ubuntu-server-12042-x64.yml": "d30d73e34cd50b043c7d14e305955269",
"spec/acceptance/nodesets/ubuntu-server-1404-x64.yml": "5f0aed10098ac5b78e4217bb27c7aaf0",
- "spec/acceptance/order_spec.rb": "14e739dc02b4a4b48c5ed4d2c9bf1d17",
+ "spec/acceptance/nodesets/windows.yml": "4e39ce8395cccdc0831c104c0d9dce1f",
+ "spec/acceptance/order_spec.rb": "76679ada1cd77b8b0663d0a65a4c7a25",
"spec/acceptance/quoted_paths_spec.rb": "a7810ac24a913bbc0d733f9b1d263748",
- "spec/acceptance/replace_spec.rb": "f0c42c610e53fc9739581d99a3cd94b0",
+ "spec/acceptance/replace_spec.rb": "48f4bb04e8f471cbaba0d9b53a8ab0f0",
"spec/acceptance/specinfra_stubs.rb": "27839261403d8bbccf506552f9d8ef38",
"spec/acceptance/symbolic_name_spec.rb": "b40452adbfebb0ea9d56547d9daee700",
"spec/acceptance/validation_spec.rb": "e54226b10f46cfa9e89e57398eddbbd2",
- "spec/acceptance/warn_header_spec.rb": "269e9329646674ec6975c34e0c58e8c1",
+ "spec/acceptance/warn_spec.rb": "cbf24bb8d9d5e9930e33632afb1d7647",
"spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c",
"spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
- "spec/spec_helper_acceptance.rb": "8e54857655edc99e04917061bcd90eb2",
- "spec/unit/defines/concat_fragment_spec.rb": "c348de6b52813bfdf1d5003f1234a164",
- "spec/unit/defines/concat_spec.rb": "5ca746486a405dc226fc34cf35ac9e54",
+ "spec/spec_helper_acceptance.rb": "41172ccedb75a916bd2f60658c42e1fb",
+ "spec/unit/classes/concat_setup_spec.rb": "fccc98ce6dee37e2d5824424ce473645",
+ "spec/unit/defines/concat_fragment_spec.rb": "b22e7e05e30b786e873f56c3c7d222f2",
+ "spec/unit/defines/concat_spec.rb": "535132b39f126f14202ca44bc57f00a4",
+ "spec/unit/facts/concat_basedir_spec.rb": "cf00f5a07948436fa0a84d00fc098539",
"tests/fragment.pp": "9adc3d9ba61676066072e1b949a37dbb",
- "tests/init.pp": "356477e6c25394550886bf1c1edb72a4"
+ "tests/init.pp": "bd3ce7d2ee146744b5dbbaae8a927043"
}
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env ruby
+# 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.rb -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.
+require 'optparse'
+require 'fileutils'
+
+settings = {
+ :outfile => "",
+ :workdir => "",
+ :test => false,
+ :force => false,
+ :warn => "",
+ :sortarg => "",
+ :newline => false
+}
+
+OptionParser.new do |opts|
+ opts.banner = "Usage: #{$0} [options]"
+ opts.separator "Specific options:"
+
+ opts.on("-o", "--outfile OUTFILE", String, "The file to create from the sources") do |o|
+ settings[:outfile] = o
+ end
+
+ opts.on("-d", "--workdir WORKDIR", String, "The directory where the fragments are kept") do |d|
+ settings[:workdir] = d
+ end
+
+ opts.on("-t", "--test", "Test to find out if a build is needed") do
+ settings[:test] = true
+ end
+
+ opts.separator "Other options:"
+ opts.on("-w", "--warn WARNMSG", String,
+ "Add a shell style comment at the top of the created file to warn users that it is generated by puppet") do |w|
+ settings[:warn] = w
+ end
+
+ opts.on("-f", "--force", "Enables the creation of empty output files when no fragments are found") do
+ settings[:force] = true
+ end
+
+ 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?
+raise 'Please specify an output file with -o' unless !settings[:outfile].empty?
+
+# do we have -d?
+raise 'Please specify fragments directory with -d' unless !settings[:workdir].empty?
+
+# can we write to -o?
+if File.file?(settings[:outfile])
+ if !File.writable?(settings[:outfile])
+ raise "Cannot write to #{settings[:outfile]}"
+ end
+else
+ if !File.writable?(File.dirname(settings[:outfile]))
+ raise "Cannot write to dirname #{File.dirname(settings[:outfile])} to create #{settings[:outfile]}"
+ end
+end
+
+# do we have a fragments subdir inside the work dir?
+if !File.directory?(File.join(settings[:workdir], "fragments")) && !File.executable?(File.join(settings[:workdir], "fragments"))
+ raise "Cannot access the fragments directory"
+end
+
+# are there actually any fragments?
+if (Dir.entries(File.join(settings[:workdir], "fragments")) - %w{ . .. }).empty?
+ if !settings[:force]
+ raise "The fragments directory is empty, cowardly refusing to make empty config files"
+ end
+end
+
+Dir.chdir(settings[:workdir])
+
+if settings[:warn].empty?
+ File.open("fragments.concat", 'w') { |f| f.write("") }
+else
+ 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|
+ 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))
+
+ # append a newline if we were asked to (invoked with -l)
+ if settings[:newline]
+ f << "\n"
+ end
+
+ end
+ }
+end
+
+if !settings[:test]
+ # This is a real run, copy the file to outfile
+ FileUtils.cp 'fragments.concat', settings[:outfile]
+else
+ # Just compare the result to outfile to help the exec decide
+ if FileUtils.cmp 'fragments.concat', settings[:outfile]
+ exit 0
+ else
+ exit 1
+ end
+end
--- /dev/null
+# == Fact: concat_basedir
+#
+# A custom fact that sets the default location for fragments
+#
+# "${::vardir}/concat/"
+#
+Facter.add("concat_basedir") do
+ setcode do
+ File.join(Puppet[:vardir],"concat")
+ end
+end
--- /dev/null
+# 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
--- /dev/null
+#
+# 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 :
+++ /dev/null
-require 'puppet/type/file/owner'
-require 'puppet/type/file/group'
-require 'puppet/type/file/mode'
-require 'puppet/util/checksums'
-
-Puppet::Type.newtype(:concat_file) do
- @doc = "Gets all the file fragments and puts these into the target file.
- This will mostly be used with exported resources.
-
- example:
- Concat_fragment <<| tag == 'unique_tag' |>>
-
- concat_file { '/tmp/file':
- tag => 'unique_tag', # Mandatory
- path => '/tmp/file', # Optional. If given it overrides the resource name
- owner => 'root', # Optional. Default to undef
- group => 'root', # Optional. Default to undef
- mode => '0644' # Optional. Default to undef
- order => 'numeric' # Optional, Default to 'numeric'
- ensure_newline => false # Optional, Defaults to false
- }
- "
- ensurable do
- defaultvalues
-
- defaultto { :present }
- end
-
- def exists?
- self[:ensure] == :present
- end
-
- newparam(:name, :namevar => true) do
- desc "Resource name"
- end
-
- newparam(:tag) do
- desc "Tag reference to collect all concat_fragment's with the same tag"
- end
-
- newparam(:path) do
- desc "The output file"
- defaultto do
- resource.value(:name)
- end
- end
-
- newparam(:owner, :parent => Puppet::Type::File::Owner) do
- desc "Desired file owner."
- end
-
- newparam(:group, :parent => Puppet::Type::File::Group) do
- desc "Desired file group."
- end
-
- newparam(:mode, :parent => Puppet::Type::File::Mode) do
- desc "Desired file mode."
- end
-
- newparam(:order) do
- desc "Controls the ordering of fragments. Can be set to alphabetical or numeric."
- defaultto 'numeric'
- end
-
- newparam(:backup) do
- desc "Controls the filebucketing behavior of the final file and see File type reference for its use."
- defaultto 'puppet'
- end
-
- newparam(:replace) do
- desc "Whether to replace a file that already exists on the local system."
- defaultto true
- end
-
- newparam(:validate_cmd) do
- desc "Validates file."
- end
-
- newparam(:ensure_newline) do
- desc "Whether to ensure there is a newline after each fragment."
- defaultto false
- end
-
- autorequire(:concat_fragment) do
- catalog.resources.collect do |r|
- if r.is_a?(Puppet::Type.type(:concat_fragment)) && r[:tag] == self[:tag]
- r.name
- end
- end.compact
- end
-
- def should_content
- return @generated_content if @generated_content
- @generated_content = ""
- content_fragments = []
-
- resources = catalog.resources.select do |r|
- r.is_a?(Puppet::Type.type(:concat_fragment)) && r[:tag] == self[:tag]
- end
-
- resources.each do |r|
- content_fragments << ["#{r[:order]}___#{r[:name]}", fragment_content(r)]
- end
-
- if self[:order] == 'numeric'
- sorted = content_fragments.sort do |a, b|
- def decompound(d)
- d.split('___').map { |v| v =~ /^\d+$/ ? v.to_i : v }
- end
-
- decompound(a[0]) <=> decompound(b[0])
- end
- else
- sorted = content_fragments.sort do |a, b|
- def decompound(d)
- d.split('___').first
- end
-
- decompound(a[0]) <=> decompound(b[0])
- end
- end
-
- @generated_content = sorted.map { |cf| cf[1] }.join
-
- @generated_content
- end
-
- def fragment_content(r)
- if r[:content].nil? == false
- fragment_content = r[:content]
- elsif r[:source].nil? == false
- @source = nil
- Array(r[:source]).each do |source|
- if Puppet::FileServing::Metadata.indirection.find(source)
- @source = source
- break
- end
- end
- self.fail "Could not retrieve source(s) #{r[:source].join(", ")}" unless @source
- tmp = Puppet::FileServing::Content.indirection.find(@source, :environment => catalog.environment)
- fragment_content = tmp.content unless tmp.nil?
- end
-
- if self[:ensure_newline]
- fragment_content<<"\n" unless fragment_content =~ /\n$/
- end
-
- fragment_content
- end
-
- def eval_generate
- file_opts = {
- :ensure => self[:ensure] == :absent ? :absent : :file,
- :content => self.should_content,
- }
-
- [:path, :owner, :group, :mode, :replace, :backup].each do |param|
- unless self[param].nil?
- file_opts[param] = self[param]
- end
- end
-
- [Puppet::Type.type(:file).new(file_opts)]
- end
-end
+++ /dev/null
-Puppet::Type.newtype(:concat_fragment) do
- @doc = "Create a concat fragment to be used by concat.
- the `concat_fragment` type creates a file fragment to be collected by concat based on the tag.
- The example is based on exported resources.
-
- Example:
- @@concat_fragment { \"uniqe_name_${::fqdn}\":
- tag => 'unique_name',
- order => 10, # Optional. Default to 10
- content => 'some content' # OR
- content => template('template.erb') # OR
- source => 'puppet:///path/to/file'
- }
- "
-
- newparam(:name, :namevar => true) do
- desc "Unique name"
- end
-
- newparam(:content) do
- desc "Content"
- end
-
- newparam(:source) do
- desc "Source"
- end
-
- newparam(:order) do
- desc "Order"
- defaultto '10'
- validate do |val|
- fail Puppet::ParseError, '$order is not a string or integer.' if !(val.is_a? String or val.is_a? Integer)
- fail Puppet::ParseError, "Order cannot contain '/', ':', or '\n'." if val.to_s =~ /[:\n\/]/
- end
- end
-
- newparam(:tag) do
- desc "Tag name to be used by concat to collect all concat_fragments by tag name"
- end
-
- validate do
- # Check if either source or content is set. raise error if none is set
- fail Puppet::ParseError, "Set either 'source' or 'content'" if self[:source].nil? && self[:content].nil?
-
- # Check if both are set, if so rais error
- fail Puppet::ParseError, "Can't use 'source' and 'content' at the same time" if !self[:source].nil? && !self[:content].nil?
- end
-end
# == Define: concat::fragment
#
-# Creates a concat_fragment in the catalogue
+# Puts a file fragment into a directory previous setup using concat
#
# === Options:
#
# [*order*]
# By default all files gets a 10_ prefix in the directory you can set it to
# anything else using this to influence the order of the content in the file
+# [*ensure*]
+# Present/Absent or destination to a file to include another file
+# [*mode*]
+# Deprecated
+# [*owner*]
+# Deprecated
+# [*group*]
+# Deprecated
+# [*backup*]
+# Deprecated
#
define concat::fragment(
$target,
- $ensure = undef,
$content = undef,
$source = undef,
$order = '10',
+ $ensure = undef,
+ $mode = undef,
+ $owner = undef,
+ $group = undef,
+ $backup = undef
) {
validate_string($target)
-
- if $ensure != undef {
- warning('The $ensure parameter to concat::fragment is deprecated and has no effect.')
- }
-
validate_string($content)
if !(is_string($source) or is_array($source)) {
fail('$source is not a string or an Array.')
}
-
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')
+ }
+ if $owner {
+ warning('The $owner parameter to concat::fragment is deprecated and has no effect')
+ }
+ if $group {
+ warning('The $group parameter to concat::fragment is deprecated and has no effect')
+ }
+ if $backup {
+ warning('The $backup parameter to concat::fragment is deprecated and has no effect')
+ }
- if ! ($content or $source) {
- crit('No content, source or symlink specified')
- } elsif ($content and $source) {
- fail("Can't use 'source' and 'content' at the same time")
+ $my_backup = concat_getparam(Concat[$target], 'backup')
+ $_backup = $my_backup ? {
+ '' => undef,
+ default => $my_backup
}
- $safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM')
+ if $ensure == undef {
+ $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.')
+ }
+ $my_ensure = $ensure
+ }
- concat_fragment { $name:
- tag => $safe_target_name,
- order => $order,
- content => $content,
+ include concat::setup
+
+ $safe_name = regsubst($name, '[/:\n]', '_', 'GM')
+ $safe_target_name = regsubst($target, '[/:\n]', '_', 'GM')
+ $concatdir = $concat::setup::concatdir
+ $fragdir = "${concatdir}/${safe_target_name}"
+ $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
+ # backwards compatiblity with previous concat::fragment versions that
+ # supported the file type's ensure => /target syntax
+
+ # be paranoid and only allow the fragment's file resource's ensure param to
+ # be file, absent, or a file target
+ $safe_ensure = $my_ensure ? {
+ '' => 'file',
+ undef => 'file',
+ 'file' => 'file',
+ 'present' => 'file',
+ 'absent' => 'absent',
+ default => $my_ensure,
+ }
+
+ # if it looks line ensure => /target syntax was used, fish that out
+ if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) {
+ $ensure_target = $my_ensure
+ } else {
+ $ensure_target = undef
+ }
+
+ # the file type's semantics only allows one of: ensure => /target, content,
+ # or source
+ if ($ensure_target and $source) or
+ ($ensure_target and $content) or
+ ($source and $content) {
+ fail('You cannot specify more than one of $content, $source, $ensure => /target')
+ }
+
+ if ! ($content or $source or $ensure_target) {
+ crit('No content, source or symlink specified')
+ }
+
+ file { "${fragdir}/fragments/${order}_${safe_name}":
+ ensure => $safe_ensure,
+ owner => $fragowner,
+ group => $fraggroup,
+ mode => $fragmode,
source => $source,
+ content => $content,
+ backup => $_backup,
+ replace => true,
+ alias => "concat_fragment_${name}",
+ notify => Exec["concat_${target}"]
}
}
# Who will own the file
# [*mode*]
# The mode of the final file
+# [*force*]
+# Enables creating empty files if no fragments are present
# [*warn*]
# Adds a normal shell style comment top of the file indicating that it is
# built by puppet
+# [*force*]
# [*backup*]
# Controls the filebucketing behavior of the final file and see File type
# reference for its use. Defaults to 'puppet'
# [*replace*]
# Whether to replace a file that already exists on the local system
# [*order*]
-# Select whether to order associated fragments by 'alpha' or 'numeric'.
-# Defaults to 'alpha'.
# [*ensure_newline*]
-# Specifies whether to ensure there's a new line at the end of each fragment.
-# Valid options: 'true' and 'false'. Default value: 'false'.
-# [*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.
+# [*gnu*]
+# Deprecated
+#
+# === Actions:
+# * Creates fragment directories if it didn't exist already
+# * Executes the concatfragments.rb script to build the final file, this
+# script will create directory/fragments.concat. Execution happens only
+# when:
+# * The directory changes
+# * fragments.concat != final destination, this means rebuilds will happen
+# whenever someone changes or deletes the final file. Checking is done
+# using /usr/bin/cmp.
+# * The Exec gets notified by something else - like the concat::fragment
+# define
+# * Copies the file over to the final destination using a file resource
+#
+# === Aliases:
+#
+# * The exec can notified using Exec["concat_/path/to/file"] or
+# Exec["concat_/path/to/directory"]
+# * The final file can be referenced as File["/path/to/file"] or
+# File["concat_/path/to/file"]
#
-
define concat(
$ensure = 'present',
$path = $name,
$group = undef,
$mode = '0644',
$warn = false,
- $force = undef,
+ $force = false,
$backup = 'puppet',
$replace = true,
$order = 'alpha',
$ensure_newline = false,
$validate_cmd = undef,
+ $gnu = undef
) {
validate_re($ensure, '^present$|^absent$')
validate_absolute_path($path)
if ! (is_string($warn) or $warn == true or $warn == false) {
fail('$warn is not a string or boolean')
}
- if ! is_bool($backup) and ! is_string($backup) {
+ validate_bool($force)
+ if ! concat_is_bool($backup) and ! is_string($backup) {
fail('$backup must be string or bool!')
}
validate_bool($replace)
validate_re($order, '^alpha$|^numeric$')
validate_bool($ensure_newline)
-
if $validate_cmd and ! is_string($validate_cmd) {
fail('$validate_cmd must be a string')
}
-
- if $force != undef {
- warning('The $force parameter to concat is deprecated and has no effect.')
+ if $gnu {
+ warning('The $gnu parameter to concat is deprecated and has no effect')
}
- $safe_name = regsubst($name, '[/:\n\s]', '_', 'G')
- $default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
+ include concat::setup
+
+ $safe_name = regsubst($name, '[/:]', '_', 'G')
+ $concatdir = $concat::setup::concatdir
+ $fragdir = "${concatdir}/${safe_name}"
+ $concat_name = 'fragments.concat.out'
+ $script_command = $concat::setup::script_command
+ $default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
+ $bool_warn_message = 'Using stringified boolean values (\'true\', \'yes\', \'on\', \'false\', \'no\', \'off\') to represent boolean true/false as the $warn parameter to concat is deprecated and will be treated as the warning message in a future release'
case $warn {
true: {
$warn_message = $default_warn_message
- $_append_header = true
+ }
+ 'true', 'yes', 'on': {
+ warning($bool_warn_message)
+ $warn_message = $default_warn_message
}
false: {
$warn_message = ''
- $_append_header = false
+ }
+ 'false', 'no', 'off': {
+ warning($bool_warn_message)
+ $warn_message = ''
}
default: {
$warn_message = $warn
- $_append_header = true
}
}
+ $warnmsg_escaped = regsubst($warn_message, '\'', '\'\\\'\'', 'G')
+ $warnflag = $warnmsg_escaped ? {
+ '' => '',
+ default => "-w '${warnmsg_escaped}'"
+ }
+
+ $forceflag = $force ? {
+ true => '-f',
+ false => '',
+ }
+
+ $orderflag = $order ? {
+ 'numeric' => '-n',
+ 'alpha' => '',
+ }
+
+ $newlineflag = $ensure_newline ? {
+ true => '-l',
+ false => '',
+ }
+
+ File {
+ backup => $backup,
+ }
+
+ # reset poisoned Exec defaults
+ Exec {
+ user => undef,
+ group => undef,
+ }
+
if $ensure == 'present' {
- concat_file { $name:
- tag => $safe_name,
- path => $path,
- owner => $owner,
- group => $group,
- mode => $mode,
- replace => $replace,
- backup => $backup,
- order => $order,
- ensure_newline => $ensure_newline,
- validate_cmd => $validate_cmd,
- }
-
- if $_append_header {
- concat_fragment { "${name}_header":
- tag => $safe_name,
- content => $warn_message,
- order => '0',
+ file { $fragdir:
+ ensure => directory,
+ mode => '0750',
+ }
+
+ file { "${fragdir}/fragments":
+ ensure => directory,
+ mode => '0750',
+ force => true,
+ ignore => ['.svn', '.git', '.gitignore'],
+ notify => Exec["concat_${name}"],
+ purge => true,
+ recurse => true,
+ }
+
+ file { "${fragdir}/fragments.concat":
+ ensure => present,
+ mode => '0640',
+ }
+
+ file { "${fragdir}/${concat_name}":
+ ensure => present,
+ mode => '0640',
+ }
+
+ file { $name:
+ ensure => present,
+ owner => $owner,
+ group => $group,
+ mode => $mode,
+ replace => $replace,
+ path => $path,
+ alias => "concat_${name}",
+ source => "${fragdir}/${concat_name}",
+ backup => $backup,
+ }
+
+ # Only newer versions of puppet 3.x support the validate_cmd parameter
+ if $validate_cmd {
+ File[$name] {
+ validate_cmd => $validate_cmd,
}
}
+
+ # remove extra whitespace from string interpolation to make testing easier
+ $command = strip(regsubst("${script_command} -o \"${fragdir}/${concat_name}\" -d \"${fragdir}\" ${warnflag} ${forceflag} ${orderflag} ${newlineflag}", '\s+', ' ', 'G'))
+
+ # make sure ruby is in the path for PE
+ if defined('$is_pe') and $::is_pe {
+ if $::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.rb script to potentially be installed in path that
+ # may not be accessible by a target non-root owner.
+ exec { "concat_${name}":
+ alias => "concat_${fragdir}",
+ command => $command,
+ notify => File[$name],
+ subscribe => File[$fragdir],
+ unless => "${command} -t",
+ path => $command_path,
+ require => [
+ File[$fragdir],
+ File["${fragdir}/fragments"],
+ File["${fragdir}/fragments.concat"],
+ ],
+ }
} else {
- concat_file { $name:
- ensure => $ensure,
- tag => $safe_name,
- path => $path,
+ file { [
+ $fragdir,
+ "${fragdir}/fragments",
+ "${fragdir}/fragments.concat",
+ "${fragdir}/${concat_name}"
+ ]:
+ ensure => absent,
+ force => true,
+ }
+
+ file { $path:
+ ensure => absent,
backup => $backup,
}
+
+ $absent_exec_command = $::kernel ? {
+ 'windows' => 'cmd.exe /c exit 0',
+ default => 'true',
+ }
+
+ $absent_exec_path = $::kernel ? {
+ 'windows' => $::path,
+ default => '/bin:/usr/bin',
+ }
+
+ # Need to have an unless here for idempotency.
+ exec { "concat_${name}":
+ alias => "concat_${fragdir}",
+ command => $absent_exec_command,
+ unless => $absent_exec_command,
+ path => $absent_exec_path,
+ }
}
}
+# vim:sw=2:ts=2:expandtab:textwidth=79
--- /dev/null
+# === Class: concat::setup
+#
+# Sets up the concat system. This is a private class.
+#
+# [$concatdir]
+# is where the fragments live and is set on the fact concat_basedir.
+# Since puppet should always manage files in $concatdir and they should
+# not be deleted ever, /tmp is not an option.
+#
+# It also copies out the concatfragments.{sh,rb} file to ${concatdir}/bin
+#
+class concat::setup {
+ if $caller_module_name != $module_name {
+ warning("${name} is deprecated as a public API of the ${module_name} module and should no longer be directly included in the manifest.")
+ }
+
+ if $::concat_basedir {
+ $concatdir = $::concat_basedir
+ } else {
+ fail ('$concat_basedir not defined. Try running again with pluginsync=true on the [master] and/or [main] section of your node\'s \'/etc/puppet/puppet.conf\'.')
+ }
+
+ # owner,group and mode of fragment files (on windows owner and access rights should
+ # be inherited from concatdir and not explicitly set to avoid problems)
+ $fragment_owner = $::osfamily ? { 'windows' => undef, default => $::id }
+ $fragment_mode = $::osfamily ? { 'windows' => undef, default => '0640' }
+ # test on gid fact availability to support older facter versions
+ if defined('$gid') and $::gid and $::osfamily != 'Windows' {
+ $fragment_group = $::gid
+ } else {
+ $fragment_group = undef
+ }
+
+ $script_name = 'concatfragments.rb'
+
+ $script_path = "${concatdir}/bin/${script_name}"
+
+ $default_owner = $::osfamily ? { 'windows' => undef, default => $::id }
+
+ $default_group = $default_owner ? { 'root' => '0', default => undef }
+
+ $script_mode = $::osfamily ? { 'windows' => undef, default => '0755' }
+
+ $script_command = $::osfamily? {
+ 'windows' => "ruby.exe '${script_path}'",
+ 'openbsd' => "/usr/local/bin/ruby21 '${script_path}'",
+ default => $script_path
+ }
+
+ file { $script_path:
+ ensure => file,
+ owner => $default_owner,
+ group => $default_group,
+ mode => $script_mode,
+ source => "puppet:///modules/concat/${script_name}",
+ }
+
+ file { [ $concatdir, "${concatdir}/bin" ]:
+ ensure => directory,
+ owner => $default_owner,
+ group => $default_group,
+ mode => '0755',
+ }
+}
{
"name": "puppetlabs-concat",
- "version": "2.0.0",
+ "version": "1.2.2",
"author": "Puppet Labs",
"summary": "Construct files from multiple fragments.",
"license": "Apache-2.0",
"project_page": "https://github.com/puppetlabs/puppetlabs-concat",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
"dependencies": [
- {"name":"puppetlabs/stdlib","version_requirement":">= 4.5.0 < 5.0.0"}
+ {"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0 < 5.0.0"}
],
"operatingsystem_support": [
{
"requirements": [
{
"name": "pe",
- "version_requirement": ">= 3.7.0 < 4.0.0"
+ "version_requirement": "3.x"
},
{
"name": "puppet",
it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do
apply_manifest(pp, :catch_failures => true) do |r|
- expect(r.stdout).to match(/Filebucketed #{basedir}\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/)
+ expect(r.stdout).to match(/Filebucketed #{basedir}\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents'
end
apply_manifest(pp, :catch_changes => true)
end
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
+
+ describe file("#{vardir}/concat") do
+ it { should be_directory }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 755
+ }
+ end
+ describe file("#{vardir}/concat/bin") do
+ it { should be_directory }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 755
+ }
+ end
+ describe file("#{vardir}/concat/bin/#{scriptname}") do
+ it { should be_file }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 755
+ }
+ end
+ describe file("#{vardir}/concat/#{safe_basedir}_file") do
+ it { should be_directory }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 750
+ }
+ end
+ describe file("#{vardir}/concat/#{safe_basedir}_file/fragments") do
+ it { should be_directory }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 750
+ }
+ end
+ describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat") do
+ it { should be_file }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 640
+ }
+ end
+ describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat.out") do
+ it { should be_file }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 640
+ }
+ end
end
context 'owner/group root' do
should match '2'
}
end
+ describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do
+ it { should be_file }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 640
+ }
+ end
+ describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do
+ it { should be_file }
+ it { should be_owned_by username }
+ it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
+ should be_mode 640
+ }
+ end
end
context 'ensure' do
end
end
- context 'concat force parameter' do
+ context 'concat gnu parameter' do
pp = <<-EOS
concat { '#{basedir}/file':
- force => false,
+ gnu => 'foo',
}
concat::fragment { 'foo':
target => '#{basedir}/file',
content => 'bar',
}
EOS
- w = 'The $force parameter to concat is deprecated and has no effect.'
+ w = 'The $gnu parameter to concat is deprecated and has no effect'
it_behaves_like 'has_warning', pp, w
end
- context 'concat::fragment ensure parameter' do
+ context 'concat warn parameter =>' do
+ ['true', 'yes', 'on'].each do |warn|
+ context warn do
+ pp = <<-EOS
+ concat { '#{basedir}/file':
+ warn => '#{warn}',
+ }
+ concat::fragment { 'foo':
+ target => '#{basedir}/file',
+ content => 'bar',
+ }
+ EOS
+ w = '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'
+
+ it_behaves_like 'has_warning', pp, w
+
+ describe file("#{basedir}/file") do
+ it { should be_file }
+ its(:content) {
+ should match '# This file is managed by Puppet. DO NOT EDIT.'
+ should match 'bar'
+ }
+ end
+ end
+ end
+
+ ['false', 'no', 'off'].each do |warn|
+ context warn do
+ pp = <<-EOS
+ concat { '#{basedir}/file':
+ warn => '#{warn}',
+ }
+ concat::fragment { 'foo':
+ target => '#{basedir}/file',
+ content => 'bar',
+ }
+ EOS
+ w = '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'
+
+ it_behaves_like 'has_warning', pp, w
+
+ describe file("#{basedir}/file") do
+ it { should be_file }
+ 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', :unless => fact('osfamily') == 'windows' do
context 'target file exists' do
+ before(:all) do
+ pp = <<-EOS
+ file { '#{basedir}':
+ ensure => directory,
+ }
+ file { '#{basedir}/file1':
+ content => "file1 contents\n",
+ }
+ EOS
+ apply_manifest(pp)
+ end
+
+ pp = <<-EOS
+ concat { '#{basedir}/file': }
+ concat::fragment { 'foo':
+ 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("#{basedir}/file") do
+ it { should be_file }
+ its(:content) { should match 'file1 contents' }
+ end
+
+ describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact("osfamily") == "windows") do
+ pp = <<-EOS
+ concat { '#{basedir}/file': }
+ concat::fragment { 'foo':
+ target => '#{basedir}/file',
+ content => 'new 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 }
+ its(:content) {
+ should match 'new content'
+ should_not match 'file1 contents'
+ }
+ end
+ end
+ end # target file exists
+
+ context 'target does not exist', :unless => fact('osfamily') == 'windows' do
+ pp = <<-EOS
+ concat { '#{basedir}/file': }
+ concat::fragment { 'foo':
+ 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("#{basedir}/file") do
+ it { should be_file }
+ end
+
+ describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact('osfamily') == 'windows') do
+ pp = <<-EOS
+ concat { '#{basedir}/file': }
+ concat::fragment { 'foo':
+ target => '#{basedir}/file',
+ content => 'new 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 }
+ its(:content) { should match 'new content' }
+ end
+ end
+ end # target file exists
+
+ end # concat::fragment ensure parameter
+
+ context 'concat::fragment mode parameter' do
pp = <<-EOS
- concat { '#{basedir}/file':
+ concat { '#{basedir}/file': }
+ concat::fragment { 'foo':
+ target => '#{basedir}/file',
+ content => 'bar',
+ mode => 'bar',
}
+ EOS
+ w = 'The $mode parameter to concat::fragment is deprecated and has no effect'
+
+ it_behaves_like 'has_warning', pp, w
+ end
+
+ context 'concat::fragment owner parameter' do
+ pp = <<-EOS
+ concat { '#{basedir}/file': }
concat::fragment { 'foo':
target => '#{basedir}/file',
- ensure => false,
content => 'bar',
+ owner => 'bar',
}
EOS
- w = 'The $ensure parameter to concat::fragment is deprecated and has no effect.'
+ w = 'The $owner parameter to concat::fragment is deprecated and has no effect'
+
+ it_behaves_like 'has_warning', pp, w
+ end
+
+ context 'concat::fragment group parameter' do
+ pp = <<-EOS
+ concat { '#{basedir}/file': }
+ concat::fragment { 'foo':
+ target => '#{basedir}/file',
+ content => 'bar',
+ group => 'bar',
+ }
+ EOS
+ w = 'The $group parameter to concat::fragment is deprecated and has no effect'
+
+ it_behaves_like 'has_warning', pp, w
+ end
+
+ context 'concat::fragment backup parameter' do
+ pp = <<-EOS
+ concat { '#{basedir}/file': }
+ concat::fragment { 'foo':
+ target => '#{basedir}/file',
+ content => 'bar',
+ backup => 'bar',
+ }
+ EOS
+ w = 'The $backup parameter to concat::fragment is deprecated and has no effect'
it_behaves_like 'has_warning', pp, w
- end
end
+
+ context 'include concat::setup' do
+ pp = <<-EOS
+ include concat::setup
+ EOS
+ w = 'concat::setup is deprecated as a public API of the concat module and should no longer be directly included in the manifest.'
+
+ it_behaves_like 'has_warning', pp, w
+ end
+
end
--- /dev/null
+require 'spec_helper_acceptance'
+
+describe 'concat force empty parameter' do
+ basedir = default.tmpdir('concat')
+ context 'should run successfully' do
+ pp = <<-EOS
+ concat { '#{basedir}/file':
+ mode => '0644',
+ force => true,
+ }
+ 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 }
+ its(:content) { should_not match /1\n2/ }
+ end
+ end
+end
EOS
it 'applies the manifest with resource failures' do
- expect(apply_manifest(pp, :catch_failures => true).stderr).to match(/Failed to generate additional resources using 'eval_generate'/)
+ apply_manifest(pp, :expect_failures => true)
end
describe file("#{basedir}/fail_no_source") do
#FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack.
HOSTS:
- centos-65-x64:
+ centos-66-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
+ 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
--- /dev/null
+HOSTS:
+ w2012:
+ roles:
+ - agent
+ - default
+ platform: windows-2012-x86_64
+ template: win-2012-x86_64
+ hypervisor: vcloud
+ debian-7-i386-master:
+ roles:
+ - master
+ - database
+ - dashboard
+ platform: debian-7-i386
+ template: debian-7-i386
+ hypervisor: vcloud
+CONFIG:
+ type: foss
+ ssh:
+ keys: "~/.ssh/id_rsa-acceptance"
+ datastore: instance0
+ folder: Delivery/Quality Assurance/Enterprise/Dynamic
+ resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
+ pooling_api: http://vcloud.delivery.puppetlabs.net/
+
end
describe 'alpha' do
- it_behaves_like 'sortby', 'alpha', /string1string10string2/
+ it_behaves_like 'sortby', 'alpha', /string10string1string2/
end
describe 'numeric' do
end
end
describe 'alpha' do
- it_should_behave_like 'order_by', 'alpha', /string3string2string1/
+ it_should_behave_like 'order_by', 'alpha', /string2string1string3/
end
describe 'numeric' do
it_should_behave_like 'order_by', 'numeric', /string3string2string1/
end
end
- # XXX
+ # XXX concat's force param currently enables the creation of empty files
# when there are no fragments, and the replace param will only replace
# files and symlinks, not directories. The semantics either need to be
# changed, extended, or a new param introduced to control directory
context 'should succeed', :pending => 'not yet implemented' do
pp = <<-EOS
concat { '#{basedir}/file':
+ force => true,
}
concat::fragment { '1':
+++ /dev/null
-require 'spec_helper_acceptance'
-
-describe 'concat warn =>' do
- basedir = default.tmpdir('concat')
- context 'true should enable default warning message' do
- pp = <<-EOS
- concat { '#{basedir}/file':
- warn => true,
- }
-
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- order => '01',
- }
-
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- order => '02',
- }
- 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 }
- 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 { '#{basedir}/file':
- warn => false,
- }
-
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- order => '01',
- }
-
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- order => '02',
- }
- 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 }
- 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 { '#{basedir}/file':
- warn => "# foo\n",
- }
-
- concat::fragment { '1':
- target => '#{basedir}/file',
- content => '1',
- order => '01',
- }
-
- concat::fragment { '2':
- target => '#{basedir}/file',
- content => '2',
- order => '02',
- }
- 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 }
- its(:content) {
- should match /# foo/
- should match /1/
- should match /2/
- }
- end
- end
-end
--- /dev/null
+require 'spec_helper_acceptance'
+
+describe 'concat warn =>' do
+ basedir = default.tmpdir('concat')
+ context 'true should enable default warning message' do
+ pp = <<-EOS
+ concat { '#{basedir}/file':
+ warn => true,
+ }
+
+ concat::fragment { '1':
+ target => '#{basedir}/file',
+ content => '1',
+ order => '01',
+ }
+
+ concat::fragment { '2':
+ target => '#{basedir}/file',
+ content => '2',
+ order => '02',
+ }
+ 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 }
+ 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 { '#{basedir}/file':
+ warn => false,
+ }
+
+ concat::fragment { '1':
+ target => '#{basedir}/file',
+ content => '1',
+ order => '01',
+ }
+
+ concat::fragment { '2':
+ target => '#{basedir}/file',
+ content => '2',
+ order => '02',
+ }
+ 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 }
+ 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 { '#{basedir}/file':
+ warn => '# foo',
+ }
+
+ concat::fragment { '1':
+ target => '#{basedir}/file',
+ content => '1',
+ order => '01',
+ }
+
+ concat::fragment { '2':
+ target => '#{basedir}/file',
+ content => '2',
+ order => '02',
+ }
+ 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 }
+ its(:content) {
+ should match /# foo/
+ should match /1/
+ should match /2/
+ }
+ end
+ end
+end
hosts.each do |host|
on hosts, "mkdir -p #{host['distmoduledir']}"
if host['platform'] =~ /sles-1/i || host['platform'] =~ /solaris-1/i
- get_deps = <<-EOS
+ get_stdlib = <<-EOS
package{'wget':}
- exec{'download-stdlib':
+ 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_deps)
+ 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
--- /dev/null
+require 'spec_helper'
+
+describe 'concat::setup', :type => :class do
+
+ shared_examples 'setup' do |concatdir|
+ concatdir = '/foo' if concatdir.nil?
+
+ 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.rb").with({
+ :mode => '0755',
+ :owner => 'root',
+ :group => 0,
+ :source => 'puppet:///modules/concat/concatfragments.rb',
+ })
+ end
+
+ [concatdir, "#{concatdir}/bin"].each do |file|
+ it do
+ should contain_file(file).with({
+ :ensure => 'directory',
+ :mode => '0755',
+ :owner => 'root',
+ :group => 0,
+ })
+ end
+ end
+ end
+
+ context 'facts' do
+ context 'concat_basedir =>' do
+ context '/foo' do
+ it_behaves_like 'setup', '/foo'
+ end
+ end
+ end # facts
+
+ context 'deprecated as a public class' do
+ it 'should create a warning' 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
:content => nil,
:source => nil,
:order => 10,
+ :ensure => 'present',
}.merge(params)
+ safe_name = title.gsub(/[\/\n]/, '_')
+ safe_target_name = p[:target].gsub(/[\/\n]/, '_')
+ concatdir = '/var/lib/puppet/concat'
+ fragdir = "#{concatdir}/#{safe_target_name}"
id = 'root'
gid = 'root'
+ if p[:ensure] == 'absent'
+ safe_ensure = p[:ensure]
+ else
+ safe_ensure = 'file'
+ end
let(:title) { title }
+ let(:facts) do
+ {
+ :concat_basedir => concatdir,
+ :id => id,
+ :gid => gid,
+ :osfamily => 'Debian',
+ :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
+ :is_pe => false,
+ }
+ end
let(:params) { params }
let(:pre_condition) do
"concat{ '#{p[:target]}': }"
end
it do
+ should contain_class('concat::setup')
should contain_concat(p[:target])
- should contain_concat_file(p[:target])
- should contain_concat_fragment(title)
+ should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({
+ :ensure => safe_ensure,
+ :owner => id,
+ :group => gid,
+ :mode => '0640',
+ :source => p[:source],
+ :content => p[:content],
+ :alias => "concat_fragment_#{title}",
+ :backup => 'puppet',
+ })
end
end
['0', '1', 'a', 'z'].each do |title|
it_behaves_like 'fragment', title, {
:target => '/etc/motd',
- :content => "content for #{title}"
}
end
end # title
context target do
it_behaves_like 'fragment', target, {
:target => '/etc/motd',
- :content => "content for #{target}"
}
end
end
context 'false' do
let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
let(:params) {{ :target => false }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+ expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # target =>
+ context 'ensure =>' do
+ ['present', 'absent'].each do |ens|
+ context ens do
+ it_behaves_like 'fragment', 'motd_header', {
+ :ensure => ens,
+ :target => '/etc/motd',
+ }
+ end
+ end
+
+ context 'any value other than \'present\' or \'absent\'' do
+ let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
+ let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }}
+
+ it 'should create a warning' do
+ skip('rspec-puppet support for testing warning()')
+ end
+ end
+ end # ensure =>
+
context 'content =>' do
['', 'ashp is our hero'].each do |content|
context content do
context 'false' do
let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
let(:params) {{ :content => false, :target => '/etc/motd' }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+ expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # content =>
context 'false' do
let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
let(:params) {{ :source => false, :target => '/etc/motd' }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::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 =>
+ context 'order =>' do
+ ['', '42', 'a', 'z'].each do |order|
+ context '\'\'' do
+ it_behaves_like 'fragment', 'motd_header', {
+ :order => order,
+ :target => '/etc/motd',
+ }
+ end
+ end
+
+ context 'false' do
+ let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
+ let(:params) {{ :order => false, :target => '/etc/motd' }}
+
+ it 'should fail' do
+ expect { should }.to raise_error(Puppet::Error, /is not a string or integer/)
+ end
+ end
+
+ context '123:456' do
+ let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
+ let(:params) {{ :order => '123:456', :target => '/etc/motd' }}
+
+ it 'should fail' do
+ expect { should }.to raise_error(Puppet::Error, /cannot contain/)
+ end
+ end
+ context '123/456' do
+ let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
+ let(:params) {{ :order => '123/456', :target => '/etc/motd' }}
+
+ it 'should fail' do
+ expect { should }.to raise_error(Puppet::Error, /cannot contain/)
+ end
+ end
+ context '123\n456' do
+ let(:title) { 'motd_header' }
+ let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
+ let(:params) {{ :order => "123\n456", :target => '/etc/motd' }}
+
+ it 'should fail' do
+ expect { should }.to raise_error(Puppet::Error, /cannot contain/)
+ end
+ end
+ end # order =>
+
context 'more than one content source' do
+ error_msg = 'You cannot specify more than one of $content, $source, $ensure => /target'
+
+ context 'ensure => target and source' do
+ let(:title) { 'motd_header' }
+ let(:facts) do
+ {
+ :concat_basedir => '/tmp',
+ :osfamily => 'Debian',
+ :id => 'root',
+ :is_pe => false,
+ :gid => 'root',
+ }
+ end
+ let(:params) do
+ {
+ :target => '/etc/motd',
+ :ensure => '/foo',
+ :source => '/bar',
+ }
+ end
+
+ it 'should fail' do
+ expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
+ end
+ end
+
+ context 'ensure => target and content' do
+ let(:title) { 'motd_header' }
+ let(:facts) do
+ {
+ :concat_basedir => '/tmp',
+ :osfamily => 'Debian',
+ :id => 'root',
+ :is_pe => false,
+ :gid => 'root',
+ }
+ end
+ let(:params) do
+ {
+ :target => '/etc/motd',
+ :ensure => '/foo',
+ :content => 'bar',
+ }
+ end
+
+ it 'should fail' do
+ expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
+ end
+ end
+
context 'source and content' do
let(:title) { 'motd_header' }
+ let(:facts) do
+ {
+ :concat_basedir => '/tmp',
+ :osfamily => 'Debian',
+ :id => 'root',
+ :is_pe => false,
+ :gid => 'root',
+ }
+ end
let(:params) do
{
- :target => '/etc/motd',
+ :target => '/etc/motd',
:source => '/foo',
:content => 'bar',
}
end
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /Can't use 'source' and 'content' at the same time/)
+ expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m)
end
end
+
end # more than one content source
+
+ describe 'deprecated parameter' do
+ context 'mode =>' do
+ context '1755' do
+ it_behaves_like 'fragment', 'motd_header', {
+ :mode => '1755',
+ :target => '/etc/motd',
+ }
+
+ it 'should create a warning' do
+ skip('rspec-puppet support for testing warning()')
+ end
+ end
+ end # mode =>
+
+ context 'owner =>' do
+ context 'apenny' do
+ it_behaves_like 'fragment', 'motd_header', {
+ :owner => 'apenny',
+ :target => '/etc/motd',
+ }
+
+ it 'should create a warning' do
+ skip('rspec-puppet support for testing warning()')
+ end
+ end
+ end # owner =>
+
+ context 'group =>' do
+ context 'apenny' do
+ it_behaves_like 'fragment', 'motd_header', {
+ :group => 'apenny',
+ :target => '/etc/motd',
+ }
+
+ it 'should create a warning' do
+ skip('rspec-puppet support for testing warning()')
+ end
+ end
+ end # group =>
+
+ context 'backup =>' do
+ context 'foo' do
+ it_behaves_like 'fragment', 'motd_header', {
+ :backup => 'foo',
+ :target => '/etc/motd',
+ }
+
+ it 'should create a warning' do
+ skip('rspec-puppet support for testing warning()')
+ end
+ end
+ end # backup =>
+ end # deprecated params
+
end
:group => nil,
:mode => '0644',
:warn => false,
+ :force => false,
:backup => 'puppet',
:replace => true,
+ :order => 'alpha',
+ :ensure_newline => false,
+ :validate_cmd => nil,
}.merge(params)
safe_name = title.gsub('/', '_')
+ concatdir = '/var/lib/puppet/concat'
+ fragdir = "#{concatdir}/#{safe_name}"
concat_name = 'fragments.concat.out'
- default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
+ default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
file_defaults = {
:backup => p[:backup],
let(:params) { params }
let(:facts) do
{
+ :concat_basedir => concatdir,
:id => id,
:osfamily => 'Debian',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
if p[:ensure] == 'present'
it do
- should contain_concat(title).with(file_defaults.merge({
+ should contain_file(fragdir).with(file_defaults.merge({
+ :ensure => 'directory',
+ :mode => '0750',
+ }))
+ end
+
+ it do
+ should contain_file("#{fragdir}/fragments").with(file_defaults.merge({
+ :ensure => 'directory',
+ :mode => '0750',
+ :force => true,
+ :ignore => ['.svn', '.git', '.gitignore'],
+ :purge => true,
+ :recurse => true,
+ }))
+ end
+
+ [
+ "#{fragdir}/fragments.concat",
+ "#{fragdir}/#{concat_name}",
+ ].each do |file|
+ it do
+ should contain_file(file).with(file_defaults.merge({
+ :ensure => 'present',
+ :mode => '0640',
+ }))
+ end
+ end
+
+ it do
+ should contain_file(title).with(file_defaults.merge({
:ensure => 'present',
:owner => p[:owner],
:group => p[:group],
:mode => p[:mode],
+ :replace => p[:replace],
:path => p[:path],
+ :alias => "concat_#{title}",
+ :source => "#{fragdir}/#{concat_name}",
+ :validate_cmd => p[:validate_cmd],
:backup => p[:backup],
- :replace => p[:replace],
}))
end
+
+ cmd = "#{concatdir}/bin/concatfragments.rb " +
+ "-o \"#{concatdir}/#{safe_name}/fragments.concat.out\" " +
+ "-d \"#{concatdir}/#{safe_name}\""
+
+ # flag order: fragdir, warnflag, forceflag, orderflag, newlineflag
+ if p.has_key?(:warn)
+ case p[:warn]
+ when TrueClass
+ message = default_warn_message
+ when 'true', 'yes', 'on'
+ # should generate a stringified boolean warning
+ message = default_warn_message
+ when FalseClass
+ message = nil
+ when 'false', 'no', 'off'
+ # should generate a stringified boolean warning
+ message = nil
+ else
+ message = p[:warn]
+ end
+
+ unless message.nil?
+ cmd += " -w \'#{message}\'"
+ end
+ end
+
+ cmd += " -f" if p[:force]
+ cmd += " -n" if p[:order] == 'numeric'
+ cmd += " -l" if p[:ensure_newline] == true
+
+ it do
+ should contain_exec("concat_#{title}").with({
+ :alias => "concat_#{fragdir}",
+ :command => cmd,
+ :unless => "#{cmd} -t",
+ })
+ end
else
+ [
+ fragdir,
+ "#{fragdir}/fragments",
+ "#{fragdir}/fragments.concat",
+ "#{fragdir}/#{concat_name}",
+ ].each do |file|
+ it do
+ should contain_file(file).with(file_defaults.merge({
+ :ensure => 'absent',
+ :force => true,
+ }))
+ end
+ end
+
it do
- should contain_concat(title).with(file_defaults.merge({
+ should contain_file(title).with(file_defaults.merge({
:ensure => 'absent',
:backup => p[:backup],
}))
end
+
+ it do
+ should contain_exec("concat_#{title}").with({
+ :alias => "concat_#{fragdir}",
+ :command => 'true',
+ :unless => 'true',
+ :path => '/bin:/usr/bin',
+ })
+ end
end
end
context title do
let(:title) { title }
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
+ expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
end
end
end
end
context 'with path param' do
- ['/foo', 'foo', 'foo/bar'].each do |title|
+ ['./foo', 'foo', 'foo/bar'].each do |title|
context title do
it_behaves_like 'concat', title, { :path => '/etc/foo.bar' }
end
let(:title) { '/etc/foo.bar' }
let(:params) {{ :ensure => 'invalid' }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::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 =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :path => path }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not an absolute path/)
+ expect { should }.to raise_error(Puppet::Error, /is not an absolute path/)
end
end
end
let(:title) { '/etc/foo.bar' }
let(:params) {{ :owner => false }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+ expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # owner =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :group => false }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+ expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # group =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :mode => false }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a string/)
+ expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # mode =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :warn => 123 }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a string or boolean/)
+ expect { should }.to raise_error(Puppet::Error, /is not a string or boolean/)
end
end
end # warn =>
+ context 'force =>' do
+ [true, false].each do |force|
+ context force do
+ it_behaves_like 'concat', '/etc/foo.bar', { :force => force }
+ end
+ end
+
+ context '123' do
+ let(:title) { '/etc/foo.bar' }
+ let(:params) {{ :force => 123 }}
+ it 'should fail' do
+ expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
+ end
+ end
+ end # force =>
+
context 'backup =>' do
context 'reverse' do
it_behaves_like 'concat', '/etc/foo.bar', { :backup => 'reverse' }
let(:title) { '/etc/foo.bar' }
let(:params) {{ :backup => [] }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /backup must be string or bool/)
+ expect { should }.to raise_error(Puppet::Error, /backup must be string or bool/)
end
end
end # backup =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :replace => 123 }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
+ expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # replace =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :order => 'invalid' }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::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 =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :ensure_newline => 123 }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /is not a boolean/)
+ expect { should }.to raise_error(Puppet::Error, /is not a boolean/)
end
end
end # ensure_newline =>
let(:title) { '/etc/foo.bar' }
let(:params) {{ :validate_cmd => cmd }}
it 'should fail' do
- expect { catalogue }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
+ expect { should }.to raise_error(Puppet::Error, /\$validate_cmd must be a string/)
end
end
end
end # validate_cmd =>
+
+ describe 'deprecated parameter' do
+ context 'gnu =>' do
+ context 'foo' do
+ it_behaves_like 'concat', '/etc/foo.bar', { :gnu => 'foo'}
+
+ it 'should create a warning' do
+ skip('rspec-puppet support for testing warning()')
+ end
+ end
+ end
+ end
+
end
+
+# vim:sw=2:ts=2:expandtab:textwidth=79
--- /dev/null
+require 'spec_helper'
+
+describe 'concat_basedir', :type => :fact do
+ before(:each) { Facter.clear }
+
+ context 'Puppet[:vardir] ==' do
+ it '/var/lib/puppet' do
+ Puppet.stubs(:[]).with(:vardir).returns('/var/lib/puppet')
+ Facter.fact(:concat_basedir).value.should == '/var/lib/puppet/concat'
+ end
+
+ it '/home/apenny/.puppet/var' do
+ Puppet.stubs(:[]).with(:vardir).returns('/home/apenny/.puppet/var')
+ Facter.fact(:concat_basedir).value.should == '/home/apenny/.puppet/var/concat'
+ end
+ end
+
+end
concat { '/tmp/concat':
ensure => present,
+ force => true,
owner => 'root',
group => 'root',
mode => '0644',