diff --git a/README.md b/README.md index 1a08875..f042b21 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,50 @@ # Extlib module for Puppet [![Build Status](https://travis-ci.org/voxpupuli/puppet-extlib.png?branch=master)](https://travis-ci.org/voxpupuli/puppet-extlib) [![Puppet Forge](https://img.shields.io/puppetforge/v/puppet/extlib.svg)](https://forge.puppetlabs.com/puppet/extlib) [![Puppet Forge - downloads](https://img.shields.io/puppetforge/dt/puppet/extlib.svg)](https://forge.puppetlabs.com/puppet/extlib) [![Puppet Forge - endorsement](https://img.shields.io/puppetforge/e/puppet/extlib.svg)](https://forge.puppetlabs.com/puppet/extlib) [![Puppet Forge - scores](https://img.shields.io/puppetforge/f/puppet/extlib.svg)](https://forge.puppetlabs.com/puppet/extlib) #### Table of Contents 1. [Overview](#overview) 2. [Setup - The basics of getting started with extlib](#setup) 3. [Usage - Configuration options and additional functionality](#usage) 4. [Limitations - OS compatibility, etc.](#limitations) 5. [Development - Guide for contributing to the module](#development) ## Overview This module provides functions and facts that are out of scope for [stdlib](https://github.com/puppetlabs/puppetlabs-stdlib). Some of them are even intrinsically tied to stdlib. ## Setup ```console % puppet module install puppet-extlib ``` ## Usage Since `puppet/extlib` version 3, all functions are provided under the `extlib` namespace. -Non namespaced versions are available in this release, but deprecated and will be removed in the next major release. +Non namespaced versions were removed in version 5. All functions are documented in [REFERENCE.md](REFERENCE.md) ## Limitations Some functions require puppetlabs-stdlib (>= 4.6.0) and all functions are only compatible with Puppet 4.7 and later. ## Development We highly welcome new contributions to this module, especially those that include documentation, and rspec tests ;) but will happily guide you through the process, so, yes, please submit that pull request! Reference documentation is generated using puppet-strings. To regenerate it, please run the rake task as follows. ```console bundle exec rake reference ``` diff --git a/REFERENCE.md b/REFERENCE.md index 47191d2..f601b57 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,773 +1,745 @@ # Reference ## Table of Contents **Functions** * [`extlib::cache_data`](#extlibcache_data): Retrieves data from a cache file, or creates it with supplied data if the file doesn't exist * [`extlib::default_content`](#extlibdefault_content): Takes an optional content and an optional template name and returns the contents of a file. * [`extlib::dir_split`](#extlibdir_split): Splits the given directory or directories into individual paths. * [`extlib::dump_args`](#extlibdump_args): Prints the args to STDOUT in Pretty JSON format. * [`extlib::echo`](#extlibecho): This function outputs the variable content and its type to the debug log. It's similiar to the `notice` function but provides a better output * [`extlib::file_separator`](#extlibfile_separator): Returns the os specific file path separator. * [`extlib::has_module`](#extlibhas_module): A function that lets you know whether a specific module is on your modulepath. * [`extlib::ip_to_cron`](#extlibip_to_cron): Provides a "random" value to cron based on the last bit of the machine IP address. used to avoid starting a certain cron job at the same time * [`extlib::mkdir_p`](#extlibmkdir_p): Like the unix command mkdir_p except with puppet code. * [`extlib::path_join`](#extlibpath_join): Take one or more paths and join them together using the os specific separator. * [`extlib::random_password`](#extlibrandom_password): A function to return a string of arbitrary length that contains randomly selected characters. * [`extlib::read_url`](#extlibread_url): Fetch a string from a URL (should only be used with 'small' remote files). This function should only be used with trusted/internal sources. * [`extlib::resources_deep_merge`](#extlibresources_deep_merge): Deeply merge a "defaults" hash into a "resources" hash like the ones expected by `create_resources()`. * [`extlib::sort_by_version`](#extlibsort_by_version): A function that sorts an array of version numbers. -**Facts** - -* [`puppet_config`](#puppet_config): A fact to expose puppet settings on the agent, unlike `$settings::` which is resolved on the puppet master - ## Functions ### extlib::cache_data Type: Ruby 4.x API Retrieves data from a cache file, or creates it with supplied data if the file doesn't exist Useful for having data that's randomly generated once on the master side (e.g. a password), but then stays the same on subsequent runs. Because it's stored on the master on disk, it doesn't work when you use mulitple Puppet masters that don't share their vardir. #### Examples ##### Calling the function ```puppet $password = cache_data('mysql', 'mysql_password', 'this_is_my_password') ``` ##### With a random password ```puppet $password = cache_data('mysql', 'mysql_password', random_password()) ``` #### `extlib::cache_data(String[1] $namespace, String[1] $name, Any $initial_data)` Retrieves data from a cache file, or creates it with supplied data if the file doesn't exist Useful for having data that's randomly generated once on the master side (e.g. a password), but then stays the same on subsequent runs. Because it's stored on the master on disk, it doesn't work when you use mulitple Puppet masters that don't share their vardir. Returns: `Any` The cached value when it exists. The initial data when no cache exists ##### Examples ###### Calling the function ```puppet $password = cache_data('mysql', 'mysql_password', 'this_is_my_password') ``` ###### With a random password ```puppet $password = cache_data('mysql', 'mysql_password', random_password()) ``` ##### `namespace` Data type: `String[1]` Namespace for the cache ##### `name` Data type: `String[1]` Cache key within the namespace ##### `initial_data` Data type: `Any` The data for when there is no cache yet ### extlib::default_content Type: Ruby 4.x API Takes an optional content and an optional template name and returns the contents of a file. #### Examples ##### Using the function with a file resource. ```puppet $config_file_content = default_content($file_content, $template_location) file { '/tmp/x': ensure => 'file', content => $config_file_content, } ``` #### `extlib::default_content(Optional[String] $content, Optional[String] $template_name)` Takes an optional content and an optional template name and returns the contents of a file. Returns: `Optional[String]` Returns the value of the content parameter if it's a non empty string. Otherwise returns the rendered output from `template_name`. Returns `undef` if both `content` and `template_name` are `undef`. ##### Examples ###### Using the function with a file resource. ```puppet $config_file_content = default_content($file_content, $template_location) file { '/tmp/x': ensure => 'file', content => $config_file_content, } ``` ##### `content` Data type: `Optional[String]` ##### `template_name` Data type: `Optional[String]` The path to an .erb or .epp template file or `undef`. ### extlib::dir_split Type: Puppet Language Use this function when you need to split a absolute path into multiple absolute paths that all descend from the given path. #### Examples ##### calling the function ```puppet extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs'] ``` #### `extlib::dir_split(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs)` Use this function when you need to split a absolute path into multiple absolute paths that all descend from the given path. Returns: `Array[String]` - an array of absolute paths after being cut into individual paths. ##### Examples ###### calling the function ```puppet extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs'] ``` ##### `dirs` Data type: `Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]` - either an absolute path or a array of absolute paths. ### extlib::dump_args Type: Ruby 4.x API Prints the args to STDOUT in Pretty JSON format. Useful for debugging purposes only. Ideally you would use this in conjunction with a rspec-puppet unit test. Otherwise the output will be shown during a puppet run when verbose/debug options are enabled. #### `extlib::dump_args(Any $args)` Prints the args to STDOUT in Pretty JSON format. Useful for debugging purposes only. Ideally you would use this in conjunction with a rspec-puppet unit test. Otherwise the output will be shown during a puppet run when verbose/debug options are enabled. Returns: `Undef` Returns nothing. ##### `args` Data type: `Any` The data you want to dump as pretty JSON. ### extlib::echo Type: Ruby 4.x API This function outputs the variable content and its type to the debug log. It's similiar to the `notice` function but provides a better output format useful to trace variable types and values in the manifests. ``` $v1 = 'test' $v2 = ["1", "2", "3"] $v3 = {"a"=>"1", "b"=>"2"} $v4 = true # $v5 is not defined $v6 = { "b" => { "b" => [1,2,3], "c" => true, "d" => { 'x' => 'y' }}, 'x' => 'y', 'z' => [1,2,3,4,5,6]} $v7 = 12345 echo($v1, 'My string') echo($v2, 'My array') echo($v3, 'My hash') echo($v4, 'My boolean') echo($v5, 'My undef') echo($v6, 'My structure') echo($v7) # no comment here debug log output My string (String) "test" My array (Array) ["1", "2", "3"] My hash (Hash) {"a"=>"1", "b"=>"2"} My boolean (TrueClass) true My undef (String) "" My structure (Hash) {"b"=>{"b"=>["1", "2", "3"], "c"=>true, "d"=>{"x"=>"y"}}, "x"=>"y", "z"=>["1", "2", "3", "4", "5", "6"]} (String) "12345" ``` #### `extlib::echo(Any $value, Optional[String] $comment)` This function outputs the variable content and its type to the debug log. It's similiar to the `notice` function but provides a better output format useful to trace variable types and values in the manifests. ``` $v1 = 'test' $v2 = ["1", "2", "3"] $v3 = {"a"=>"1", "b"=>"2"} $v4 = true # $v5 is not defined $v6 = { "b" => { "b" => [1,2,3], "c" => true, "d" => { 'x' => 'y' }}, 'x' => 'y', 'z' => [1,2,3,4,5,6]} $v7 = 12345 echo($v1, 'My string') echo($v2, 'My array') echo($v3, 'My hash') echo($v4, 'My boolean') echo($v5, 'My undef') echo($v6, 'My structure') echo($v7) # no comment here debug log output My string (String) "test" My array (Array) ["1", "2", "3"] My hash (Hash) {"a"=>"1", "b"=>"2"} My boolean (TrueClass) true My undef (String) "" My structure (Hash) {"b"=>{"b"=>["1", "2", "3"], "c"=>true, "d"=>{"x"=>"y"}}, "x"=>"y", "z"=>["1", "2", "3", "4", "5", "6"]} (String) "12345" ``` Returns: `Undef` Returns nothing. ##### `value` Data type: `Any` The value you want to inspect. ##### `comment` Data type: `Optional[String]` An optional comment to prepend to the debug output. ### extlib::file_separator Type: Puppet Language Returns the os specific file path separator. #### Examples ##### Example of how to use ```puppet extlib::file_separator() => '/' ``` #### `extlib::file_separator()` The extlib::file_separator function. Returns: `String` - The os specific path separator. ##### Examples ###### Example of how to use ```puppet extlib::file_separator() => '/' ``` ### extlib::has_module Type: Ruby 4.x API A function that lets you know whether a specific module is on your modulepath. #### Examples ##### Calling the function ```puppet extlib::has_module('camptocamp/systemd') ``` #### `extlib::has_module(Pattern[/\A\w+[-\/]\w+\z/] $module_name)` A function that lets you know whether a specific module is on your modulepath. Returns: `Boolean` Returns `true` or `false`. ##### Examples ###### Calling the function ```puppet extlib::has_module('camptocamp/systemd') ``` ##### `module_name` Data type: `Pattern[/\A\w+[-\/]\w+\z/]` The full name of the module you want to know exists or not. Namespace and modulename can be separated with either `-` or `/`. ### extlib::ip_to_cron Type: Ruby 4.x API Provides a "random" value to cron based on the last bit of the machine IP address. used to avoid starting a certain cron job at the same time on all servers. Takes the runinterval in seconds as parameter and returns an array of [hour, minute] example usage ``` ip_to_cron(3600) - returns [ '*', one value between 0..59 ] ip_to_cron(1800) - returns [ '*', an array of two values between 0..59 ] ip_to_cron(7200) - returns [ an array of twelve values between 0..23, one value between 0..59 ] ``` #### `extlib::ip_to_cron(Optional[Integer[1]] $runinterval)` Provides a "random" value to cron based on the last bit of the machine IP address. used to avoid starting a certain cron job at the same time on all servers. Takes the runinterval in seconds as parameter and returns an array of [hour, minute] example usage ``` ip_to_cron(3600) - returns [ '*', one value between 0..59 ] ip_to_cron(1800) - returns [ '*', an array of two values between 0..59 ] ip_to_cron(7200) - returns [ an array of twelve values between 0..23, one value between 0..59 ] ``` Returns: `Array` ##### `runinterval` Data type: `Optional[Integer[1]]` The number of seconds to use as the run interval ### extlib::mkdir_p Type: Puppet Language This creates file resources for all directories and utilizes the dir_split() function to get a list of all the descendant directories. You will have no control over any other parameters for the file resource. If you wish to control the file resources you can use the dir_split() function and get an array of directories for use in your own code. Please note this does not use an exec resource. * **Note** splits the given directories into paths that are then created using file resources #### Examples ##### How to use ```puppet extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin'] ``` #### `extlib::mkdir_p(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs)` This creates file resources for all directories and utilizes the dir_split() function to get a list of all the descendant directories. You will have no control over any other parameters for the file resource. If you wish to control the file resources you can use the dir_split() function and get an array of directories for use in your own code. Please note this does not use an exec resource. Returns: `Array[Stdlib::Absolutepath]` ##### Examples ###### How to use ```puppet extlib::mkdir_p('/opt/puppetlabs/bin') => ['/opt', '/opt/puppetlabs', '/opt/puppetlabs/bin'] ``` ##### `dirs` Data type: `Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]` - the path(s) to create ### extlib::path_join Type: Puppet Language Because in how windows uses a different separator this function will format a windows path into a equilivent unix like path. This type of unix like path will work on windows. #### Examples ##### Joining Unix paths to return `/tmp/test/libs` ```puppet extlib::path_join('/tmp', 'test', 'libs') ``` ##### Joining Windows paths to return `/c/test/libs` ```puppet extlib::path_join('c:', 'test', 'libs') ``` #### `extlib::path_join(Array[String] $dirs)` Because in how windows uses a different separator this function will format a windows path into a equilivent unix like path. This type of unix like path will work on windows. Returns: `Stdlib::Absolutepath` The joined path ##### Examples ###### Joining Unix paths to return `/tmp/test/libs` ```puppet extlib::path_join('/tmp', 'test', 'libs') ``` ###### Joining Windows paths to return `/c/test/libs` ```puppet extlib::path_join('c:', 'test', 'libs') ``` ##### `dirs` Data type: `Array[String]` Joins two or more directories by file separator. ### extlib::random_password Type: Ruby 4.x API A function to return a string of arbitrary length that contains randomly selected characters. #### Examples ##### Calling the function ```puppet random_password(42) ``` #### `extlib::random_password(Integer[1] $length)` A function to return a string of arbitrary length that contains randomly selected characters. Returns: `String` The random string returned consists of alphanumeric characters excluding 'look-alike' characters. ##### Examples ###### Calling the function ```puppet random_password(42) ``` ##### `length` Data type: `Integer[1]` The length of random password you want generated. ### extlib::read_url Type: Ruby 4.x API Fetch a string from a URL (should only be used with 'small' remote files). This function should only be used with trusted/internal sources. This is especially important if using it in conjunction with `inline_template` or `inline_epp`. The current implementation is also very basic. No thought has gone into timeouts, support for redirects, CA paths etc. #### Examples ##### Calling the function ```puppet extlib::read_url('https://example.com/sometemplate.epp') ``` #### `extlib::read_url(Stdlib::HTTPUrl $url)` Fetch a string from a URL (should only be used with 'small' remote files). This function should only be used with trusted/internal sources. This is especially important if using it in conjunction with `inline_template` or `inline_epp`. The current implementation is also very basic. No thought has gone into timeouts, support for redirects, CA paths etc. Returns: `String` Returns the contents of the url as a string ##### Examples ###### Calling the function ```puppet extlib::read_url('https://example.com/sometemplate.epp') ``` ##### `url` Data type: `Stdlib::HTTPUrl` The URL to read from ### extlib::resources_deep_merge Type: Ruby 4.x API Deeply merge a "defaults" hash into a "resources" hash like the ones expected by `create_resources()`. Internally calls the puppetlabs-stdlib function `deep_merge()`. In case of duplicate keys the `resources` hash keys win over the `defaults` hash keys. Example ```puppet $defaults_hash = { 'one' => '1', 'two' => '2', 'three' => '3', 'four' => { 'five' => '5', 'six' => '6', 'seven' => '7', } } $numbers_hash = { 'german' => { 'one' => 'eins', 'three' => 'drei', 'four' => { 'six' => 'sechs', }, }, 'french' => { 'one' => 'un', 'two' => 'deux', 'four' => { 'five' => 'cinq', 'seven' => 'sept', }, } } $result_hash = resources_deep_merge($numbers_hash, $defaults_hash) ``` The $result_hash then looks like this: ```puppet $result_hash = { 'german' => { 'one' => 'eins', 'two' => '2', 'three' => 'drei', 'four' => { 'five' => '5', 'six' => 'sechs', 'seven' => '7', } }, 'french' => { 'one' => 'un', 'two' => 'deux', 'three' => '3', 'four' => { 'five' => 'cinq', 'six' => '6', 'seven' => 'sept', } } } ``` #### `extlib::resources_deep_merge(Hash $resources, Hash $defaults)` Deeply merge a "defaults" hash into a "resources" hash like the ones expected by `create_resources()`. Internally calls the puppetlabs-stdlib function `deep_merge()`. In case of duplicate keys the `resources` hash keys win over the `defaults` hash keys. Example ```puppet $defaults_hash = { 'one' => '1', 'two' => '2', 'three' => '3', 'four' => { 'five' => '5', 'six' => '6', 'seven' => '7', } } $numbers_hash = { 'german' => { 'one' => 'eins', 'three' => 'drei', 'four' => { 'six' => 'sechs', }, }, 'french' => { 'one' => 'un', 'two' => 'deux', 'four' => { 'five' => 'cinq', 'seven' => 'sept', }, } } $result_hash = resources_deep_merge($numbers_hash, $defaults_hash) ``` The $result_hash then looks like this: ```puppet $result_hash = { 'german' => { 'one' => 'eins', 'two' => '2', 'three' => 'drei', 'four' => { 'five' => '5', 'six' => 'sechs', 'seven' => '7', } }, 'french' => { 'one' => 'un', 'two' => 'deux', 'three' => '3', 'four' => { 'five' => 'cinq', 'six' => '6', 'seven' => 'sept', } } } ``` Returns: `Hash` Returns the merged hash. ##### `resources` Data type: `Hash` The hash of resources. ##### `defaults` Data type: `Hash` The hash of defaults to merge. ### extlib::sort_by_version Type: Ruby 4.x API A function that sorts an array of version numbers. -## Facts - -### puppet\_config - -This facts exposes some facts from both the main and master section of the puppet agent configueration. The following facts are supported - -``` -{ - main => { - hostpubkey, - hostprivkey, - hostcert, - localcacert, - ssldir, - vardir, - server, - }, - master => { - localcacert, - ssldir, - } -} -``` - #### Examples ##### Calling the function ```puppet extlib::sort_by_version(['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3']) ``` #### `extlib::sort_by_version(Array[String] $versions)` A function that sorts an array of version numbers. Returns: `Array[String]` Returns the sorted array. ##### Examples ###### Calling the function ```puppet extlib::sort_by_version(['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3']) ``` ##### `versions` Data type: `Array[String]` An array of version strings you want sorted. diff --git a/lib/puppet/functions/cache_data.rb b/lib/puppet/functions/cache_data.rb deleted file mode 100644 index 18eb67f..0000000 --- a/lib/puppet/functions/cache_data.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @summary DEPRECATED. Use the namespaced function [`extlib::cache_data`](#extlibcache_data) instead. -# DEPRECATED. Use the namespaced function [`extlib::cache_data`](#extlibcache_data) instead. -Puppet::Functions.create_function(:cache_data) do - dispatch :deprecation_gen do - repeated_param 'Any', :args - end - def deprecation_gen(*args) - call_function('deprecation', 'cache_data', 'This method is deprecated, please use extlib::cache_data instead.') - call_function('extlib::cache_data', *args) - end -end diff --git a/lib/puppet/functions/default_content.rb b/lib/puppet/functions/default_content.rb deleted file mode 100644 index b9c5728..0000000 --- a/lib/puppet/functions/default_content.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @summary DEPRECATED. Use the namespaced function [`extlib::default_content`](#extlibdefault_content) instead. -# DEPRECATED. Use the namespaced function [`extlib::default_content`](#extlibdefault_content) instead. -Puppet::Functions.create_function(:default_content) do - dispatch :deprecation_gen do - repeated_param 'Any', :args - end - def deprecation_gen(*args) - call_function('deprecation', 'default_content', 'This method is deprecated, please use extlib::default_content instead.') - call_function('extlib::default_content', *args) - end -end diff --git a/lib/puppet/functions/dump_args.rb b/lib/puppet/functions/dump_args.rb deleted file mode 100644 index ee2cf06..0000000 --- a/lib/puppet/functions/dump_args.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @summary DEPRECATED. Use the namespaced function [`extlib::dump_args`](#extlibdump_args) instead. -# DEPRECATED. Use the namespaced function [`extlib::dump_args`](#extlibdump_args) instead. -Puppet::Functions.create_function(:dump_args) do - dispatch :deprecation_gen do - repeated_param 'Any', :args - end - def deprecation_gen(*args) - call_function('deprecation', 'dump_args', 'This method is deprecated, please use extlib::dump_args instead.') - call_function('extlib::dump_args', *args) - end -end diff --git a/lib/puppet/functions/echo.rb b/lib/puppet/functions/echo.rb deleted file mode 100644 index 5a0057c..0000000 --- a/lib/puppet/functions/echo.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @summary DEPRECATED. Use the namespaced function [`extlib::echo`](#extlibecho) instead. -# DEPRECATED. Use the namespaced function [`extlib::echo`](#extlibecho) instead. -Puppet::Functions.create_function(:echo) do - dispatch :deprecation_gen do - repeated_param 'Any', :args - end - def deprecation_gen(*args) - call_function('deprecation', 'echo', 'This method is deprecated, please use extlib::echo instead.') - call_function('extlib::echo', *args) - end -end diff --git a/lib/puppet/functions/ip_to_cron.rb b/lib/puppet/functions/ip_to_cron.rb deleted file mode 100644 index bc376a8..0000000 --- a/lib/puppet/functions/ip_to_cron.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @summary DEPRECATED. Use the namespaced function [`extlib::ip_to_cron`](#extlibip_to_cron) instead. -# DEPRECATED. Use the namespaced function [`extlib::ip_to_cron`](#extlibip_to_cron) instead. -Puppet::Functions.create_function(:ip_to_cron) do - dispatch :deprecation_gen do - repeated_param 'Any', :args - end - def deprecation_gen(*args) - call_function('deprecation', 'ip_to_cron', 'This method is deprecated, please use extlib::ip_to_cron instead.') - call_function('extlib::ip_to_cron', *args) - end -end diff --git a/lib/puppet/functions/random_password.rb b/lib/puppet/functions/random_password.rb deleted file mode 100644 index 352cf2f..0000000 --- a/lib/puppet/functions/random_password.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @summary DEPRECATED. Use the namespaced function [`extlib::random_password`](#extlibrandom_password) instead. -# DEPRECATED. Use the namespaced function [`extlib::random_password`](#extlibrandom_password) instead. -Puppet::Functions.create_function(:random_password) do - dispatch :deprecation_gen do - repeated_param 'Any', :args - end - def deprecation_gen(*args) - call_function('deprecation', 'random_password', 'This method is deprecated, please use extlib::random_password instead.') - call_function('extlib::random_password', *args) - end -end diff --git a/lib/puppet/functions/resources_deep_merge.rb b/lib/puppet/functions/resources_deep_merge.rb deleted file mode 100644 index a88fb40..0000000 --- a/lib/puppet/functions/resources_deep_merge.rb +++ /dev/null @@ -1,11 +0,0 @@ -# @summary DEPRECATED. Use the namespaced function [`extlib::resources_deep_merge`](#extlibresources_deep_merge) instead. -# DEPRECATED. Use the namespaced function [`extlib::resources_deep_merge`](#extlibresources_deep_merge) instead. -Puppet::Functions.create_function(:resources_deep_merge) do - dispatch :deprecation_gen do - repeated_param 'Any', :args - end - def deprecation_gen(*args) - call_function('deprecation', 'resources_deep_merge', 'This method is deprecated, please use extlib::resources_deep_merge instead.') - call_function('extlib::resources_deep_merge', *args) - end -end diff --git a/spec/functions/cache_data_spec.rb b/spec/functions/cache_data_spec.rb deleted file mode 100644 index 3c68386..0000000 --- a/spec/functions/cache_data_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe 'cache_data' do - let(:initial_data) { 'original_password' } - let(:data_name) { 'mysql_password' } - let(:namespace) { 'data_cache' } - let(:vardir) { "#{FIXTURES_PATH}/tmpdir" } - - it { expect(subject).not_to eq(nil) } - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params(data_name).and_raise_error(ArgumentError) } - it { is_expected.to run.with_params('', initial_data).and_raise_error(ArgumentError) } - it { is_expected.to run.with_params('', 'mysql_password', initial_data).and_raise_error(ArgumentError) } - - describe 'data caching' do - before do - # Fool rspec-puppet into creating a consistent vardir for these tests! - allow(Dir).to receive(:mktmpdir).and_return("#{FIXTURES_PATH}/tmpdir") - # Stop rspec-puppet from blowing away the vardir between each example. Is unstubbed in the after block. - allow(FileUtils).to receive(:rm_rf).with(vardir).and_return(true) - end - after do - # Since rspec-puppet won't be removing the vardir, we'd better do that ourselves. - FileUtils.rm_rf(vardir) if File.directory?(vardir) - end - - context 'when not in cache' do - it 'returns supplied data' do - is_expected.to run.with_params(namespace, data_name, initial_data).and_return(initial_data) - end - end - - context 'when cached' do - it 'returns cached data' do - is_expected.to run.with_params(namespace, data_name, initial_data).and_return(initial_data) - is_expected.to run.with_params(namespace, data_name, 'new_password').and_return(initial_data) - end - end - end -end diff --git a/spec/functions/default_content_spec.rb b/spec/functions/default_content_spec.rb deleted file mode 100644 index d38f026..0000000 --- a/spec/functions/default_content_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'spec_helper' - -describe 'default_content' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(ArgumentError) } - it { is_expected.to run.with_params(:undef, :undef).and_return(:undef) } - - describe 'signature validation' do - it 'exists' do - is_expected.not_to be_nil - end - end - - context 'should return the correct string for' do - it 'a string' do - is_expected.to run.with_params('a string', :undef).and_return 'a string' - end - - it 'an empty string and an epp template' do - File.open('/tmp/foo.epp', 'w') do |f| - f.write '<% $foo = 2 %>a template string <%= $foo + 1 %>' - end - is_expected.to run.with_params(:undef, '/tmp/foo.epp').and_return 'a template string 3' - end - - it 'an empty string and an erb template' do - File.open('/tmp/foo.erb', 'w') do |f| - f.write '<% @foo = 1 %>a template string <%= @foo + 1 %>' - end - is_expected.to run.with_params(:undef, '/tmp/foo.erb').and_return 'a template string 2' - end - - it 'an empty string and an empty template' do - is_expected.to run.with_params(:undef, :undef).and_return :undef - end - end -end diff --git a/spec/functions/dump_args_spec.rb b/spec/functions/dump_args_spec.rb deleted file mode 100644 index f2485d4..0000000 --- a/spec/functions/dump_args_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' -require 'json' - -describe 'dump_args' do - it 'exists' do - is_expected.not_to be_nil - end - - it 'requires an argument' do - is_expected.to run.with_params.and_raise_error(ArgumentError) - end - - context 'when called with a hash' do - let(:hash) { { 'param_one' => 'value', 'param_two' => 42 } } - - it 'puts pretty JSON' do - allow(STDOUT).to receive(:puts).with(JSON.pretty_generate(hash)) - is_expected.to run.with_params(hash) - end - end - - context 'when called with an integer' do - let(:int) { 42 } - - it 'puts pretty JSON' do - allow(STDOUT).to receive(:puts).with(JSON.pretty_generate(int)) - is_expected.to run.with_params(int) - end - end -end diff --git a/spec/functions/echo_spec.rb b/spec/functions/echo_spec.rb deleted file mode 100644 index b75a114..0000000 --- a/spec/functions/echo_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'spec_helper' - -describe 'echo' do - describe 'signature validation' do - it 'exists' do - is_expected.not_to be_nil - end - it 'requires at least one argument' do - is_expected.to run.with_params.and_raise_error(ArgumentError) - end - end - - context 'should output a correct debug string for' do - it 'a string' do - allow(scope).to receive(:debug).with '(String) "test"' - is_expected.to run.with_params('test') - end - it 'a string with a comment' do - allow(scope).to receive(:debug).with 'My String (String) "test"' - is_expected.to run.with_params('test', 'My String') - end - it 'and array' do - allow(scope).to receive(:debug).with 'My Array (Array) ["1", "2", "3"]' - is_expected.to run.with_params(%w[1 2 3], 'My Array') - end - it 'a hash' do - allow(scope).to receive(:debug).with 'My Hash (Hash) {"a"=>"1"}' - is_expected.to run.with_params({ 'a' => '1' }, 'My Hash') - end - it 'a boolean value' do - allow(scope).to receive(:debug).with 'My Boolean (FalseClass) false' - is_expected.to run.with_params(false, 'My Boolean') - end - it 'an undefind value' do - allow(scope).to receive(:debug).with 'Undefined Value (NilClass) nil' - is_expected.to run.with_params(nil, 'Undefined Value') - end - end -end diff --git a/spec/functions/ip_to_cron_spec.rb b/spec/functions/ip_to_cron_spec.rb deleted file mode 100644 index b62ebd3..0000000 --- a/spec/functions/ip_to_cron_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'spec_helper' - -describe 'ip_to_cron' do - it 'exists' do - is_expected.not_to be_nil - end - - describe 'when runinterval is 1 hour' do - let(:runinterval) { 3600 } - - context 'and IP address is 10.0.0.150' do - let(:facts) { { networking: { ip: '10.0.0.150' } } } - - it { is_expected.to run.with_params(runinterval).and_return(['*', [30]]) } - end - - context 'and IP address is 10.0.0.160' do - let(:facts) { { networking: { ip: '10.0.0.160' } } } - - it { is_expected.to run.with_params(runinterval).and_return(['*', [40]]) } - end - end - - context 'with IP address 10.0.0.1' do - let(:facts) { { networking: { ip: '10.0.0.1' } } } - - describe 'when runinterval is 30 minutes' do - let(:runinterval) { 1800 } - - it { is_expected.to run.with_params(runinterval).and_return(['*', [1, 31]]) } - end - - describe 'when runinterval is 2 hours' do - let(:runinterval) { 7200 } - - it { is_expected.to run.with_params(runinterval).and_return([[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23], 1]) } - end - end - - describe 'when runinterval not specified and IP address is 10.0.0.60' do - let(:facts) { { networking: { ip: '10.0.0.60' } } } - - it { is_expected.to run.and_return(['*', [0, 30]]) } - end -end diff --git a/spec/functions/random_password_spec.rb b/spec/functions/random_password_spec.rb deleted file mode 100644 index 4ee3132..0000000 --- a/spec/functions/random_password_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' - -describe 'random_password' do - it 'exists' do - is_expected.not_to be_nil - end - - context 'when called with no parameters' do - it { is_expected.to run.with_params.and_raise_error(ArgumentError) } - end - - context 'when called with a string' do - it { is_expected.to run.with_params('42').and_raise_error(ArgumentError) } - end - - [4, 32].each do |length| - context "when called with #{length}" do - it "returns a string of length #{length}" do - expect(subject.execute(length)).to be_a String - subject.execute(length).length == length - end - end - end - - context 'when called multiple times with the same argument' do - it 'returns different strings' do - expect(subject.execute(12)).not_to eq(subject.execute(12)) - end - end -end diff --git a/spec/functions/resources_deep_merge_spec.rb b/spec/functions/resources_deep_merge_spec.rb deleted file mode 100644 index fb14aa9..0000000 --- a/spec/functions/resources_deep_merge_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -require 'spec_helper' - -describe 'resources_deep_merge' do - let(:resources) do - { - 'one' => { - 'attributes' => { - 'user' => '1', - 'pass' => '1' - } - }, - 'two' => { - 'attributes' => { - 'user' => '2', - 'pass' => '2' - } - } - } - end - - let(:defaults) do - { - 'ensure' => 'present', - 'attributes' => { - 'type' => 'psql' - } - } - end - - let(:result) do - { - 'one' => { - 'ensure' => 'present', - 'attributes' => { - 'type' => 'psql', - 'user' => '1', - 'pass' => '1' - } - }, - 'two' => { - 'ensure' => 'present', - 'attributes' => { - 'type' => 'psql', - 'user' => '2', - 'pass' => '2' - } - } - } - end - - describe 'signature validation' do - it 'exists' do - is_expected.not_to be_nil - end - - it 'raises an ArgumentError if there is less than 1 arguments' do - is_expected.to run.with_params.and_raise_error ArgumentError - end - - it 'does not compile when 1 argument is passed' do - my_hash = { 'one' => 1 } - is_expected.to run.with_params(my_hash).and_raise_error ArgumentError - end - - it 'requires all parameters are hashes' do - is_expected.to run.with_params({}, '2').and_raise_error ArgumentError - end - end - - describe 'when calling resources_deep_merge on a resource and a defaults hash' do - it 'is able to deep_merge a resource hash and a defaults hash' do - is_expected.to run.with_params(resources, defaults).and_return(result) - end - end -end diff --git a/spec/no_duplicate.rb b/spec/no_duplicate.rb deleted file mode 100755 index 064f9f7..0000000 --- a/spec/no_duplicate.rb +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env ruby - -`git clone https://github.com/puppetlabs/puppetlabs-stdlib stdlib` - -extlib_functions = [] -Dir.glob('lib/puppet/parser/functions/*.rb').each do |path| - extlib_functions << path.split('/')[-1].split('.')[0] -end - -stdlib_functions = [] -Dir.glob('stdlib/lib/puppet/parser/functions/*.rb').each do |path| - stdlib_functions << path.split('/')[-1].split('.')[0] -end - -puts 'Stdlib functions:' -puts stdlib_functions -puts '' - -puts 'Extlib functions:' -puts extlib_functions -puts '' - -duplicate_functions = stdlib_functions & extlib_functions -puts 'Duplicate functions:' -puts duplicate_functions -puts '' - -if !duplicate_functions.length.empty? - puts 'Duplicate function(s) found! Please have unique function names between' - puts 'stdlib and extlib' - puts 'Test failed' - exit 1 -else - puts 'No duplicate functions found' - puts 'Test passed' - exit 0 -end