summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml9
-rw-r--r--Gemfile106
-rw-r--r--README.markdown89
-rw-r--r--lib/puppet/functions/deprecation.rb6
-rw-r--r--lib/puppet/functions/type_of.rb2
-rw-r--r--lib/puppet/parser/functions/deprecation.rb4
-rw-r--r--lib/puppet/parser/functions/ensure_packages.rb2
-rw-r--r--lib/puppet/parser/functions/fqdn_uuid.rb92
-rw-r--r--lib/puppet/parser/functions/pry.rb30
-rw-r--r--spec/acceptance/deprecation_spec.rb17
-rw-r--r--spec/fixtures/test/manifests/ensure_resources.pp4
-rw-r--r--spec/functions/deprecation_spec.rb5
-rwxr-xr-xspec/functions/ensure_packages_spec.rb8
-rw-r--r--spec/functions/fqdn_uuid_spec.rb14
-rw-r--r--spec/unit/ensure_resources_spec.rb22
15 files changed, 357 insertions, 53 deletions
diff --git a/.travis.yml b/.travis.yml
index 0cde21d..d972387 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,6 +4,9 @@ sudo: false
language: ruby
cache: bundler
script: "bundle exec rake validate lint spec"
+#Inserting below due to the following issue: https://github.com/travis-ci/travis-ci/issues/3531#issuecomment-88311203
+before_install:
+ - gem update bundler
matrix:
fast_finish: true
include:
@@ -34,11 +37,5 @@ matrix:
- rvm: 1.9.3
bundler_args: --without system_tests
env: PUPPET_GEM_VERSION="~> 3.0"
- - rvm: 2.1.9
- bundler_args: --without system_tests
- env: PUPPET_GEM_VERSION="~> 4.6.0"
- - rvm: 2.1.9
- bundler_args: --without system_tests
- env: PUPPET_GEM_VERSION="~> 4.7.0"
notifications:
email: false
diff --git a/Gemfile b/Gemfile
index c8af871..3d46720 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,50 +2,86 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"
-def location_from_env(env, default_location = [])
- if location = ENV[env]
- if location =~ /^((?:git|https?)[:@][^#]*)#(.*)/
- [{ :git => $1, :branch => $2, :require => false }]
- elsif location =~ /^file:\/\/(.*)/
- ['>= 0', { :path => File.expand_path($1), :require => false }]
- else
- [location, { :require => false }]
- end
+# Determines what type of gem is requested based on place_or_version.
+def gem_type(place_or_version)
+ if place_or_version =~ /^git:/
+ :git
+ elsif place_or_version =~ /^file:/
+ :file
else
- default_location
+ :gem
end
end
-group :development, :unit_tests do
- gem 'metadata-json-lint'
- gem 'puppet_facts'
- gem 'puppet-blacksmith', '>= 3.4.0'
- gem 'puppetlabs_spec_helper', '>= 1.2.1'
- gem 'rspec-puppet', '>= 2.3.2', :git => 'https://github.com/rodjek/rspec-puppet.git', :branch => 'fb27c533e2664057fba4b73d0bd902a946abfce0'
- # the newly released mocha 1.2.0 causes hangs during spec testing. See MODULES-3958 for a long-term solution
- gem 'mocha', '< 1.2.0'
- gem 'rspec-puppet-facts'
- gem 'simplecov'
- gem 'parallel_tests', '< 2.10.0' if RUBY_VERSION < '2.0.0'
- gem 'parallel_tests' if RUBY_VERSION >= '2.0.0'
- gem 'rubocop', '0.41.2' if RUBY_VERSION < '2.0.0'
- gem 'rubocop' if RUBY_VERSION >= '2.0.0'
- gem 'rubocop-rspec', '~> 1.6' if RUBY_VERSION >= '2.3.0'
- gem 'json_pure', '<= 2.0.1' if RUBY_VERSION < '2.0.0'
+# Find a location or specific version for a gem. place_or_version can be a
+# version, which is most often used. It can also be git, which is specified as
+# `git://somewhere.git#branch`. You can also use a file source location, which
+# is specified as `file://some/location/on/disk`.
+def location_for(place_or_version, fake_version = nil)
+ if place_or_version =~ /^(git[:@][^#]*)#(.*)/
+ [fake_version, { :git => $1, :branch => $2, :require => false }].compact
+ elsif place_or_version =~ /^file:\/\/(.*)/
+ ['>= 0', { :path => File.expand_path($1), :require => false }]
+ else
+ [place_or_version, { :require => false }]
+ end
+end
+
+# Used for gem conditionals
+supports_windows = false
+
+group :development do
+ gem 'puppet-lint', :require => false
+ gem 'metadata-json-lint', :require => false, :platforms => 'ruby'
+ gem 'puppet_facts', :require => false
+ gem 'puppet-blacksmith', '>= 3.4.0', :require => false, :platforms => 'ruby'
+ gem 'puppetlabs_spec_helper', '>= 1.2.1', :require => false
+ gem 'rspec-puppet', '>= 2.3.2', :require => false
+ gem 'rspec-puppet-facts', :require => false, :platforms => 'ruby'
+ gem 'mocha', '< 1.2.0', :require => false
+ gem 'simplecov', :require => false, :platforms => 'ruby'
+ gem 'parallel_tests', '< 2.10.0', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
+ gem 'parallel_tests', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
+ gem 'rubocop', '0.41.2', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
+ gem 'rubocop', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
+ gem 'rubocop-rspec', '~> 1.6', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')
+ gem 'pry', :require => false
+ gem 'json_pure', '<= 2.0.1', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
+ gem 'fast_gettext', '1.1.0', :require => false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0')
+ gem 'fast_gettext', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
end
+
group :system_tests do
- gem 'beaker', *location_from_env('BEAKER_VERSION', []) if RUBY_VERSION >= '2.3.0'
- gem 'beaker', *location_from_env('BEAKER_VERSION', ['< 3']) if RUBY_VERSION < '2.3.0'
- gem 'beaker-rspec', *location_from_env('BEAKER_RSPEC_VERSION', ['>= 3.4'])
- gem 'serverspec'
- gem 'beaker-puppet_install_helper'
- gem 'master_manipulator'
- gem 'beaker-hostgenerator', *location_from_env('BEAKER_HOSTGENERATOR_VERSION', [])
+ gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '~> 2.20') if supports_windows
+ gem 'beaker', *location_for(ENV['BEAKER_VERSION']) if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0') and ! supports_windows
+ gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '< 3') if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.3.0') and ! supports_windows
+ gem 'beaker-pe', :require => false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')
+ gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '>= 3.4') if ! supports_windows
+ gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '~> 5.1') if supports_windows
+ gem 'beaker-puppet_install_helper', :require => false
+ gem 'master_manipulator', :require => false
+ gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
+ gem 'beaker-abs', *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1')
end
-gem 'facter', *location_from_env('FACTER_GEM_VERSION')
-gem 'puppet', *location_from_env('PUPPET_GEM_VERSION')
+gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
+# Only explicitly specify Facter/Hiera if a version has been specified.
+# Otherwise it can lead to strange bundler behavior. If you are seeing weird
+# gem resolution behavior, try setting `DEBUG_RESOLVER` environment variable
+# to `1` and then run bundle install.
+gem 'facter', *location_for(ENV['FACTER_GEM_VERSION']) if ENV['FACTER_GEM_VERSION']
+gem 'hiera', *location_for(ENV['HIERA_GEM_VERSION']) if ENV['HIERA_GEM_VERSION']
+
+
+# Evaluate Gemfile.local if it exists
if File.exists? "#{__FILE__}.local"
eval(File.read("#{__FILE__}.local"), binding)
end
+
+# Evaluate ~/.gemfile if it exists
+if File.exists?(File.join(Dir.home, '.gemfile'))
+ eval(File.read(File.join(Dir.home, '.gemfile')), binding)
+end
+
+# vim:ft=ruby
diff --git a/README.markdown b/README.markdown
index cc29af9..a4c30b5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -578,6 +578,15 @@ fqdn_rotate([1, 2, 3], 'custom seed')
*Type*: rvalue.
+#### `fqdn_uuid`
+
+Returns a rfc4122 valid version 5 UUID based on an FQDN string under the DNS namespace
+
+ * fqdn_uuid('puppetlabs.com') returns '9c70320f-6815-5fc5-ab0f-debe68bf764c'
+ * fqdn_uuid('google.com') returns '64ee70a4-8cc1-5d25-abf2-dea6c79a09c8'
+
+*Type*: rvalue.
+
#### `get_module_path`
Returns the absolute path of the specified module for the current environment.
@@ -712,46 +721,68 @@ See the [`assert_type()`](https://docs.puppetlabs.com/references/latest/function
#### `is_absolute_path`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the given path is absolute. *Type*: rvalue.
#### `is_array`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the variable passed to this function is an array. *Type*: rvalue.
#### `is_bool`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the variable passed to this function is a boolean. *Type*: rvalue.
#### `is_domain_name`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the string passed to this function is a syntactically correct domain name. *Type*: rvalue.
#### `is_float`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the variable passed to this function is a float. *Type*: rvalue.
#### `is_function_available`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Accepts a string as an argument and determines whether the Puppet runtime has access to a function by that name. It returns 'true' if the function exists, 'false' if not. *Type*: rvalue.
#### `is_hash`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the variable passed to this function is a hash. *Type*: rvalue.
#### `is_integer`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the variable returned to this string is an integer. *Type*: rvalue.
#### `is_ip_address`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the string passed to this function is a valid IP address. *Type*: rvalue.
#### `is_ipv6_address`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the string passed to this function is a valid IPv6 address. *Type*: rvalue.
#### `is_ipv4_address`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the string passed to this function is a valid IPv4 address. *Type*: rvalue.
#### `is_mac_address`
@@ -760,10 +791,14 @@ Returns 'true' if the string passed to this function is a valid MAC address. *Ty
#### `is_numeric`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the variable passed to this function is a number. *Type*: rvalue.
#### `is_string`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Returns 'true' if the variable passed to this function is a string. *Type*: rvalue.
#### `join`
@@ -909,6 +944,20 @@ For example:
*Type*: rvalue.
+#### `pry`
+
+This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation. Should only be used when running `puppet apply` or running a puppet master in the foreground. This requires the `pry` gem to be installed in puppet's rubygems.
+
+*Examples:*
+```puppet
+pry()
+```
+Once in a pry session, some interesting commands:
+
+* Run `catalog` to see the contents currently compiling catalog
+* Run `cd catalog` and `ls` to see catalog methods and instance variables
+* Run `@resource_table` to see the current catalog resource table
+
#### `assert_private`
Sets the current class or definition as private. Calling the class or definition from outside the current module will fail.
@@ -1030,7 +1079,7 @@ Returns a new string where runs of the same character that occur in this set are
#### `str2bool`
-Converts certain strings to a boolean. This attempts to convert strings that contain the values '1', 't', 'y', or 'yes' to true. Strings that contain values '0', 'f', 'n', or 'no', or that are an empty string or undefined are converted to false. Any other value causes an error. *Type*: rvalue.
+Converts certain strings to a boolean. This attempts to convert strings that contain the values '1', 'true', 't', 'y', or 'yes' to true. Strings that contain values '0', 'false', 'f', 'n', or 'no', or that are an empty string or undefined are converted to false. Any other value causes an error. These checks are case insensitive. *Type*: rvalue.
#### `str2saltedsha512`
@@ -1164,6 +1213,8 @@ Returns a string description of the type when passed a value. Type can be a stri
#### `type_of`
+This function is provided for backwards compatibility but is generally not preferred over the built-in [type() function](https://docs.puppet.com/puppet/latest/reference/function.html#type) provided by Puppet.
+
Returns the literal type when passed a value. Requires the new parser. Useful for comparison of types with `<=` such as in `if type_of($some_value) <= Array[String] { ... }` (which is equivalent to `if $some_value =~ Array[String] { ... }`) *Type*: rvalue.
#### `union`
@@ -1228,6 +1279,8 @@ validate_absolute_path($undefined)
#### `validate_array`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that all passed values are array data structures. Aborts catalog compilation if any value fails this check.
The following values pass:
@@ -1276,6 +1329,8 @@ validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers
#### `validate_bool`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that all passed values are either true or false. Aborts catalog compilation if any value fails this check.
The following values will pass:
@@ -1316,6 +1371,8 @@ validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to va
#### `validate_hash`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that all passed values are hash data structures. Aborts catalog compilation if any value fails this check.
The following values will pass:
@@ -1338,6 +1395,8 @@ Validates that all passed values are hash data structures. Aborts catalog compil
#### `validate_integer`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that the first argument is an integer (or an array of integers). Aborts catalog compilation if any of the checks fail.
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
@@ -1396,6 +1455,8 @@ Validates that the first argument is an integer (or an array of integers). Abort
#### `validate_ip_address`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that the argument is an IP address, regardless of it is an IPv4 or an IPv6
address. It also validates IP address with netmask. The argument must be given as a string.
@@ -1444,24 +1505,28 @@ validate_legacy("Optional[String]", "validate_re", "Value to be validated", ["."
This function supports updating modules from Puppet 3 style argument validation (using the stdlib `validate_*` functions) to Puppet 4 data types, without breaking functionality for those depending on Puppet 3 style validation.
-> Note: This function relies on internal APIs from Puppet 4.4.0 (PE 2016.1) onwards, and doesn't work on earlier versions.
+> Note: This function is compatible only with Puppet 4.4.0 (PE 2016.1) and later.
##### For module users
-If you are running Puppet 4 and receiving deprecation warnings about `validate_*` functions, the `validate_legacy` function can help you find and resolve the deprecated code.
+If you are running Puppet 4, the `validate_legacy` function can help you find and resolve deprecated Puppet 3 `validate_*` functions. These functions are deprecated as of stdlib version 4.13 and will be removed in a future version of stdlib.
-In Puppet 3, the `validate_*` functions were the only way to easily check the types of class and defined type arguments. Some of the functions provided additional helpers like [validate_numeric](#validate_numeric), which unintentionally allowed not only numbers, but also arrays of numbers. Puppet 4 allows much better defined type checking using [data types](https://docs.puppet.com/puppet/latest/reference/lang_data.html), without such unintentional effects. The `validate_legacy` function makes these differences visible and makes it easier to move to the clearer Puppet 4 syntax.
+Puppet 4 allows improved defined type checking using [data types](https://docs.puppet.com/puppet/latest/reference/lang_data.html). Data types avoid some of the problems with Puppet 3's `validate_*` functions, which could sometimes be inconsistent. For example, [validate_numeric](#validate_numeric) unintentionally allowed not only numbers, but also arrays of numbers or strings that looked like numbers.
-Depending on the current state of development of the modules you use and the data you feed those modules, you'll encounter different messages:
+If you run Puppet 4 and use modules with deprecated `validate_*` functions, you might encounter deprecation messages. The `validate_legacy` function makes these differences visible and makes it easier to move to the clearer Puppet 4 syntax.
+
+The deprecation messages you get can vary, depending on the modules and data that you use. These deprecation messages appear by default only in Puppet 4:
* `Notice: Accepting previously invalid value for target type '<type>'`: This message is informational only. You're using values that are allowed by the new type, but would have been invalid by the old validation function.
* `Warning: This method is deprecated, please use the stdlib validate_legacy function`: The module has not yet upgraded to `validate_legacy`. Use the [deprecation](#deprecation) options to silence warnings for now, or submit a fix with the module's developer. See the information [for module developers](#for-module-developers) below for how to fix the issue.
-* `Warning: validate_legacy(<function>) expected <type> value, got <actual type>_`: Your code passes a value that was accepted by the Puppet 3 style validation, but will not be accepted by the next version of the module. Most often, you can fix this by removing quotes from numbers or booleans.
+* `Warning: validate_legacy(<function>) expected <type> value, got <actual type>_`: Your code passes a value that was accepted by the Puppet 3-style validation, but will not be accepted by the next version of the module. Most often, you can fix this by removing quotes from numbers or booleans.
* `Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, validate_legacy(<function>) expected <type> value, got <actual type>`: Your code passes a value that is not acceptable to either the new or the old style validation.
##### For module developers
-Many `validate_*` functions have surprising holes in their validation. For example, [validate_numeric](#validate_numeric) allows not only numbers, but also arrays of numbers or strings that look like numbers, without giving you any control over the specifics. In contrast, Puppet 4 [data types](https://docs.puppet.com/puppet/latest/reference/lang_data.html) allows you to choose between `Numeric`, `Array[Numeric]`, or `Optional[Numeric]`. The `validate_legacy` function helps you move from Puppet 3 style validation to Puppet 4 validation without breaking functionality your module's users depend on.
+The `validate_legacy` function helps you move from Puppet 3 style validation to Puppet 4 validation without breaking functionality your module's users depend on.
+
+Moving to Puppet 4 type validation allows much better defined type checking using [data types](https://docs.puppet.com/puppet/latest/reference/lang_data.html). Many of Puppet 3's `validate_*` functions have surprising holes in their validation. For example, [validate_numeric](#validate_numeric) allows not only numbers, but also arrays of numbers or strings that look like numbers, without giving you any control over the specifics.
For each parameter of your classes and defined types, choose a new Puppet 4 data type to use. In most cases, the new data type allows a different set of values than the original `validate_*` function. The situation then looks like this:
@@ -1504,6 +1569,8 @@ Always note such changes in your CHANGELOG and README.
#### `validate_numeric`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that the first argument is a numeric value (or an array or string of numeric values). Aborts catalog compilation if any of the checks fail.
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
@@ -1520,6 +1587,8 @@ Validates that the first argument is a numeric value (or an array or string of n
#### `validate_re`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Performs simple validation of a string against one or more regular expressions. The first argument of this function should be the string to
test, and the second argument should be a stringified regular expression (without the // delimiters) or an array of regular expressions. If none of the regular expressions match the string passed in, compilation aborts with a parse error.
@@ -1554,6 +1623,8 @@ test, and the second argument should be a stringified regular expression (withou
#### `validate_slength`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that the first argument is a string (or an array of strings), and is less than or equal to the length of the second argument. It fails if the first argument is not a string or array of strings, or if the second argument is not convertable to a number. Optionally, a minimum string length can be given as the third argument.
The following values pass:
@@ -1576,6 +1647,8 @@ Validates that the first argument is a string (or an array of strings), and is l
#### `validate_string`
+**Deprecated. Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy).**
+
Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check.
The following values pass:
@@ -1646,7 +1719,7 @@ Takes one element from first array given and merges corresponding elements from
As of Puppet Enterprise 3.7, the stdlib module is no longer included in PE. PE users should install the most recent release of stdlib for compatibility with Puppet modules.
-###Version Compatibility
+### Version Compatibility
Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x |
:---------------|:-----:|:---:|:---:|:----:
diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb
index a860aa2..39d9bc7 100644
--- a/lib/puppet/functions/deprecation.rb
+++ b/lib/puppet/functions/deprecation.rb
@@ -8,6 +8,12 @@ Puppet::Functions.create_function(:deprecation) do
end
def deprecation(key, message)
+ if defined? Puppet::Pops::PuppetStack.stacktrace()
+ stacktrace = Puppet::Pops::PuppetStack.stacktrace()
+ file = stacktrace[0]
+ line = stacktrace[1]
+ message = "#{message} at #{file}:#{line}"
+ end
# depending on configuration setting of strict
case Puppet.settings[:strict]
when :off
diff --git a/lib/puppet/functions/type_of.rb b/lib/puppet/functions/type_of.rb
index 02cdd4d..01f1f49 100644
--- a/lib/puppet/functions/type_of.rb
+++ b/lib/puppet/functions/type_of.rb
@@ -10,6 +10,8 @@
# See the documentation for "The Puppet Type System" for more information about types.
# See the `assert_type()` function for flexible ways to assert the type of a value.
#
+# The built-in type() function in puppet is generally preferred over this function
+# this function is provided for backwards compatibility.
Puppet::Functions.create_function(:type_of) do
def type_of(value)
Puppet::Pops::Types::TypeCalculator.infer_set(value)
diff --git a/lib/puppet/parser/functions/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb
index e30f3a0..cd64fe2 100644
--- a/lib/puppet/parser/functions/deprecation.rb
+++ b/lib/puppet/parser/functions/deprecation.rb
@@ -1,5 +1,5 @@
module Puppet::Parser::Functions
- newfunction(:deprecation, :type => :rvalue, :doc => <<-EOS
+ newfunction(:deprecation, :doc => <<-EOS
Function to print deprecation warnings (this is the 3.X version of it), The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method.).
EOS
) do |arguments|
@@ -9,7 +9,7 @@ EOS
key = arguments[0]
message = arguments[1]
-
+
if ENV['STDLIB_LOG_DEPRECATIONS'] == "true"
warning("deprecation. #{key}. #{message}")
end
diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb
index 532b702..439af1e 100644
--- a/lib/puppet/parser/functions/ensure_packages.rb
+++ b/lib/puppet/parser/functions/ensure_packages.rb
@@ -25,7 +25,7 @@ third argument to the ensure_resource() function.
end
Puppet::Parser::Functions.function(:ensure_resources)
- function_ensure_resources(['package', Hash(arguments[0]), defaults ])
+ function_ensure_resources(['package', arguments[0].dup, defaults ])
else
packages = Array(arguments[0])
diff --git a/lib/puppet/parser/functions/fqdn_uuid.rb b/lib/puppet/parser/functions/fqdn_uuid.rb
new file mode 100644
index 0000000..30205d0
--- /dev/null
+++ b/lib/puppet/parser/functions/fqdn_uuid.rb
@@ -0,0 +1,92 @@
+require 'digest/sha1'
+
+module Puppet::Parser::Functions
+ newfunction(:fqdn_uuid, :type => :rvalue, :doc => <<-END) do |args|
+
+ Creates a UUID based on a given string, assumed to be the FQDN
+
+ For example, to generate a UUID based on the FQDN of a system:
+
+ Usage:
+
+ $uuid = fqdn_uuid($::fqdn)
+
+ The generated UUID will be the same for the given hostname
+
+ The resulting UUID is returned on the form:
+
+ 1d839dea-5e10-5243-88eb-e66815bd7d5c
+
+ (u.e. without any curly braces.)
+
+ The generated UUID is a version 5 UUID with the V5 DNS namespace:
+
+ 6ba7b810-9dad-11d1-80b4-00c04fd430c8
+
+ This only supports a the V5 SHA-1 hash, using the DNS namespace.
+
+ Please consult http://www.ietf.org/rfc/rfc4122.txt for the details on
+ UUID generation and example implementation.
+
+ No verification is present at the moment as whether the domain name given
+ is in fact a correct fully-qualified domain name. Therefore any arbitrary
+ string and/or alpha-numeric value can subside for a domain name.
+ EOS
+
+ END
+
+ if args.length == 0
+ raise(ArgumentError, "fqdn_uuid: No arguments given")
+ elsif args.length == 1
+ fqdn = args[0]
+ else
+ raise(ArgumentError, "fqdn_uuid: Too many arguments given (#{args.length})")
+ end
+
+ # Code lovingly taken from
+ # https://github.com/puppetlabs/marionette-collective/blob/master/lib/mcollective/ssl.rb
+
+ # This is the UUID version 5 type DNS name space which is as follows:
+ #
+ # 6ba7b810-9dad-11d1-80b4-00c04fd430c8
+ #
+ uuid_name_space_dns = [0x6b,
+ 0xa7,
+ 0xb8,
+ 0x10,
+ 0x9d,
+ 0xad,
+ 0x11,
+ 0xd1,
+ 0x80,
+ 0xb4,
+ 0x00,
+ 0xc0,
+ 0x4f,
+ 0xd4,
+ 0x30,
+ 0xc8
+ ].map {|b| b.chr}.join
+
+ sha1 = Digest::SHA1.new
+ sha1.update(uuid_name_space_dns)
+ sha1.update(fqdn)
+
+ # first 16 bytes..
+ bytes = sha1.digest[0, 16].bytes.to_a
+
+ # version 5 adjustments
+ bytes[6] &= 0x0f
+ bytes[6] |= 0x50
+
+ # variant is DCE 1.1
+ bytes[8] &= 0x3f
+ bytes[8] |= 0x80
+
+ bytes = [4, 2, 2, 2, 6].collect do |i|
+ bytes.slice!(0, i).pack('C*').unpack('H*')
+ end
+
+ bytes.join('-')
+ end
+end
diff --git a/lib/puppet/parser/functions/pry.rb b/lib/puppet/parser/functions/pry.rb
new file mode 100644
index 0000000..c18ef7e
--- /dev/null
+++ b/lib/puppet/parser/functions/pry.rb
@@ -0,0 +1,30 @@
+#
+# pry.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:pry, :type => :statement, :doc => <<-EOS
+This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation.
+
+*Examples:*
+
+ pry()
+ EOS
+ ) do |arguments|
+ begin
+ require 'pry'
+ rescue LoadError
+ raise(Puppet::Error, "pry(): Requires the 'pry' rubygem to use, but it was not found")
+ end
+ #
+ ## Run `catalog` to see the contents currently compiling catalog
+ ## Run `cd catalog` and `ls` to see catalog methods and instance variables
+ ## Run `@resource_table` to see the current catalog resource table
+ #
+ if $stdout.isatty
+ binding.pry # rubocop:disable Lint/Debugger
+ else
+ Puppet.warning 'pry(): cowardly refusing to start the debugger on a daemonized master'
+ end
+ end
+end
diff --git a/spec/acceptance/deprecation_spec.rb b/spec/acceptance/deprecation_spec.rb
index ea13700..7a0b34c 100644
--- a/spec/acceptance/deprecation_spec.rb
+++ b/spec/acceptance/deprecation_spec.rb
@@ -82,4 +82,21 @@ describe 'deprecation function' do
it { is_expected.to be_file }
end
end
+
+ context 'puppet 3 test', if: get_puppet_version =~ /^3/ do
+ before :all do
+ @result = on(default, puppet('apply', '--parser=future', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
+ end
+ after :all do
+ apply_manifest(remove_file_manifest)
+ end
+
+ it "should return a deprecation error" do
+ expect(@result.stderr).to match(/Warning: message/)
+ end
+ it "should pass without error" do
+ expect(@result.exit_code).to eq(0)
+ end
+ end
+
end
diff --git a/spec/fixtures/test/manifests/ensure_resources.pp b/spec/fixtures/test/manifests/ensure_resources.pp
new file mode 100644
index 0000000..bd26002
--- /dev/null
+++ b/spec/fixtures/test/manifests/ensure_resources.pp
@@ -0,0 +1,4 @@
+# A helper class to test the ensure_resources function
+class test::ensure_resources($resource_type, $title_hash, $attributes_hash) {
+ ensure_resources($resource_type, $title_hash, $attributes_hash)
+}
diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb
index 9859833..cee4f1c 100644
--- a/spec/functions/deprecation_spec.rb
+++ b/spec/functions/deprecation_spec.rb
@@ -41,11 +41,14 @@ if Puppet.version.to_f >= 4.0
}
end
else
+ # Puppet version < 4 will use these tests.
describe 'deprecation' do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
- ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ before(:all) do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ end
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
index c824732..5d97684 100755
--- a/spec/functions/ensure_packages_spec.rb
+++ b/spec/functions/ensure_packages_spec.rb
@@ -33,4 +33,12 @@ describe 'ensure_packages' do
it { expect(lambda { catalogue }).to contain_package('facter').with_ensure('present').with_provider("gem") }
end
end
+
+ context 'given hash of packages' do
+ before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_package('foo').with({'provider' => 'rpm', 'ensure' => 'present'}) }
+ it { expect(lambda { catalogue }).to contain_package('bar').with({'provider' => 'gem', 'ensure' => 'present'}) }
+ end
end
diff --git a/spec/functions/fqdn_uuid_spec.rb b/spec/functions/fqdn_uuid_spec.rb
new file mode 100644
index 0000000..a2d1618
--- /dev/null
+++ b/spec/functions/fqdn_uuid_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe 'fqdn_uuid' do
+
+ context "Invalid parameters" do
+ it { should run.with_params().and_raise_error(ArgumentError, /No arguments given$/) }
+ end
+
+ context "given string" do
+ it { should run.with_params('puppetlabs.com').and_return('9c70320f-6815-5fc5-ab0f-debe68bf764c') }
+ it { should run.with_params('google.com').and_return('64ee70a4-8cc1-5d25-abf2-dea6c79a09c8') }
+ end
+
+end
diff --git a/spec/unit/ensure_resources_spec.rb b/spec/unit/ensure_resources_spec.rb
new file mode 100644
index 0000000..aea723e
--- /dev/null
+++ b/spec/unit/ensure_resources_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe 'test::ensure_resources', type: :class do
+ let(:params) {{ resource_type: 'user', title_hash: title_param, attributes_hash: {'ensure' => 'present'} }}
+
+ describe 'given a title hash of multiple resources' do
+
+ let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }, 'alex' => { 'gid' => 'mygroup', 'uid' => '700'}} }
+
+ it { is_expected.to compile }
+ it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) }
+ it { is_expected.to contain_user('alex').with({ 'gid' => 'mygroup', 'uid' => '700', 'ensure' => 'present'}) }
+ end
+
+ describe 'given a title hash of a single resource' do
+
+ let(:title_param) { {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }} }
+
+ it { is_expected.to compile }
+ it { is_expected.to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600', 'ensure' => 'present'}) }
+ end
+end