diff --git a/.fixtures.yml b/.fixtures.yml index cf4ff2d7b..b25e8c459 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,9 +1,7 @@ fixtures: repositories: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' - puppet_agent: - repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.13.0 + puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' provision: 'https://github.com/puppetlabs/provision.git' symlinks: stdlib: "#{source_dir}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b0e39c35..2cdfc30f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,6 @@ jobs: Acceptance: needs: Spec uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" - secrets: "inherit" with: - runs_on: "ubuntu-20.04" + flags: "--nightly" + secrets: "inherit" diff --git a/.github/workflows/labeller.yml b/.github/workflows/labeller.yml deleted file mode 100644 index ee149bf52..000000000 --- a/.github/workflows/labeller.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Labeller - -on: - issues: - types: - - opened - - labeled - - unlabeled - pull_request_target: - types: - - opened - - labeled - - unlabeled - -jobs: - label: - runs-on: ubuntu-latest - steps: - - - uses: puppetlabs/community-labeller@v1.0.1 - name: Label issues or pull requests - with: - label_name: community - label_color: '5319e7' - org_membership: puppetlabs - fail_if_member: 'true' - token: ${{ secrets.IAC_COMMUNITY_LABELER }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index aaa4967f9..5a39a47c7 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -13,6 +13,6 @@ jobs: Acceptance: needs: Spec uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main" - secrets: "inherit" with: - runs_on: "ubuntu-20.04" + flags: "--nightly" + secrets: "inherit" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b7b8a05d..4b3b80fc8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: "Publish module" on: workflow_dispatch: - + jobs: release: uses: "puppetlabs/cat-github-actions/.github/workflows/module_release.yml@main" diff --git a/.gitignore b/.gitignore index 3f1551212..2803e566b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ /spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -26,3 +27,9 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log diff --git a/.pdkignore b/.pdkignore index 862847a72..84684be63 100644 --- a/.pdkignore +++ b/.pdkignore @@ -19,6 +19,7 @@ /spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store @@ -26,6 +27,12 @@ .envrc /inventory.yaml /spec/fixtures/litmus_inventory.yaml +.resource_types +.modules +.task_cache.json +.plan_cache.json +.rerun.json +bolt-debug.log /.fixtures.yml /Gemfile /.gitattributes diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece05..9e15c6e01 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,9 @@ +--fail-on-warnings --relative +--no-80chars-check +--no-140chars-check +--no-class_inherits_from_params_class-check +--no-autoloader_layout-check +--no-documentation-check +--no-single_quote_string_with_variables-check +--ignore-paths=.vendor/**/*.pp,.bundle/**/*.pp,pkg/**/*.pp,spec/**/*.pp,tests/**/*.pp,types/**/*.pp,vendor/**/*.pp diff --git a/.rubocop.yml b/.rubocop.yml index 7a66e0833..47b1aadbe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: AllCops: NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.7' + TargetRubyVersion: 3.1 Include: - "**/*.rb" Exclude: @@ -529,6 +529,8 @@ Lint/DuplicateBranch: Enabled: false Lint/DuplicateMagicComment: Enabled: false +Lint/DuplicateMatchPattern: + Enabled: false Lint/DuplicateRegexpCharacterClassElement: Enabled: false Lint/EmptyBlock: @@ -645,6 +647,8 @@ Style/ComparableClamp: Enabled: false Style/ConcatArrayLiterals: Enabled: false +Style/DataInheritance: + Enabled: false Style/DirEmpty: Enabled: false Style/DocumentDynamicEvalDefinition: @@ -713,6 +717,8 @@ Style/RedundantHeredocDelimiterQuotes: Enabled: false Style/RedundantInitialize: Enabled: false +Style/RedundantLineContinuation: + Enabled: false Style/RedundantSelfAssignmentBranch: Enabled: false Style/RedundantStringEscape: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 2f1e4f73a..6da8d472f 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,6 @@ { "recommendations": [ "puppet.puppet-vscode", - "rebornix.Ruby" + "Shopify.ruby-lsp" ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 7178301e3..6f650b7a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,45 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). -## [v9.4.1](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.4.1) - 2023-11-08 +## [v9.7.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.7.0) - 2024-12-17 + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v9.6.0...v9.7.0) + +### Added + +- (CAT-2119) Add Ubuntu 24.04 support [#1440](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1440) ([shubhamshinde360](https://github.com/shubhamshinde360)) +- (CAT-2101) Add support for Debian-12 [#1439](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1439) ([skyamgarp](https://github.com/skyamgarp)) +- Support for Amazon linux 2 and 2023 [#1427](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1427) ([h0tw1r3](https://github.com/h0tw1r3)) + +### Fixed + +- (CAT-2180) Upgrade rexml to address CVE-2024-49761 [#1443](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1443) ([amitkarsale](https://github.com/amitkarsale)) + +## [v9.6.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.6.0) - 2024-04-03 + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v9.5.0...v9.6.0) + +### Added + +- Allow usage of file templates with stdlib::manage [#1422](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1422) ([tuxmea](https://github.com/tuxmea)) + +## [v9.5.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.5.0) - 2024-03-11 + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v9.4.1...v9.5.0) + +### Added + +- Add function stdlib::sort_by [#1384](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1384) ([XMol](https://github.com/XMol)) + +### Fixed + +- (#1389) - pw_hash with bcrypt not working on puppet master [#1410](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1410) ([TuningYourCode](https://github.com/TuningYourCode)) + +### Other + +- Deprecate `time` function [#1417](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1417) ([alexjfisher](https://github.com/alexjfisher)) + +## [v9.4.1](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.4.1) - 2023-11-09 [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v9.4.0...v9.4.1) @@ -21,10 +59,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Modernise `fqdn_rotate` function [#1341](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1341) ([alexjfisher](https://github.com/alexjfisher)) -### Other - -- Remove unused parser deprecation function [#1392](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1392) ([ekohl](https://github.com/ekohl)) - ## [v9.3.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v9.3.0) - 2023-08-01 [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v9.2.0...v9.3.0) @@ -68,12 +102,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v8.6.0...v9.0.0) -### Added - -- Namespace Puppet 4.x functions [#1356](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1356) ([smortex](https://github.com/smortex)) -- Add a function to update / regenerate deprecated shims [#1349](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1349) ([smortex](https://github.com/smortex)) - ### Changed + - Deprecate the `validate_legacy()` function [#1353](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1353) ([smortex](https://github.com/smortex)) - Remove deprecated functions [#1352](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1352) ([smortex](https://github.com/smortex)) - Rewrite validate_email_address() as a Puppet 4.x function [#1350](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1350) ([smortex](https://github.com/smortex)) @@ -108,6 +138,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Remove deprecated type and type3x functions [#1309](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1309) ([MartyEwings](https://github.com/MartyEwings)) - (CONT-801) Puppet 8 support / Drop Puppet 6 support [#1307](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1307) ([LukasAud](https://github.com/LukasAud)) +### Added + +- Namespace Puppet 4.x functions [#1356](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1356) ([smortex](https://github.com/smortex)) +- Add a function to update / regenerate deprecated shims [#1349](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1349) ([smortex](https://github.com/smortex)) + ### Fixed - Remove deprecated File.exists? [#1357](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1357) ([ekohl](https://github.com/ekohl)) @@ -226,18 +261,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v7.1.0...v8.0.0) +### Changed + +- Flip installed and present in Function ensure_packages [#1196](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1196) ([cocker-cc](https://github.com/cocker-cc)) + ### Added - New function to_python() / to_ruby() [#1200](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1200) ([smortex](https://github.com/smortex)) - pdksync - (IAC-1709) - Add Support for Debian 11 [#1199](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1199) ([david22swan](https://github.com/david22swan)) - Stdlib::Http::Method: Add new type for http methods [#1192](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1192) ([b4ldr](https://github.com/b4ldr)) -### Changed -- Flip installed and present in Function ensure_packages [#1196](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1196) ([cocker-cc](https://github.com/cocker-cc)) - ### Fixed -- (MODULES-11099) Make merge parameter data types actually backwards compatible [#1191](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1191) ([SimonPe](https://github.com/SimonPe)) +- (MODULES-11099) Make merge parameter data types actually backwards compatible [#1191](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1191) ([LadyNamedLaura](https://github.com/LadyNamedLaura)) ## [v7.1.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/v7.1.0) - 2021-05-17 @@ -259,13 +295,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/v6.6.0...v7.0.0) +### Changed + +- pdksync - Remove Puppet 5 from testing and bump minimal version to 6.0.0 [#1164](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1164) ([carabasdaniel](https://github.com/carabasdaniel)) + ### Added - Stdlib::Email type [#1160](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1160) ([b4ldr](https://github.com/b4ldr)) -### Changed -- pdksync - Remove Puppet 5 from testing and bump minimal version to 6.0.0 [#1164](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1164) ([carabasdaniel](https://github.com/carabasdaniel)) - ### Fixed - (bugfix) Setting stricter email validation [#1163](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1163) ([pmcmaw](https://github.com/pmcmaw)) @@ -367,14 +404,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/5.2.0...v6.0.0) +### Changed + +- pdksync - (MODULES-8444) - Raise lower Puppet bound [#1011](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1011) ([david22swan](https://github.com/david22swan)) + ### Added - (MODULES-8760) Add iterative feature to merge() function [#1008](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1008) ([hlindberg](https://github.com/hlindberg)) - Add a stdlib::ip_in_range() function [#1003](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1003) ([iglov](https://github.com/iglov)) -### Changed -- pdksync - (MODULES-8444) - Raise lower Puppet bound [#1011](https://github.com/puppetlabs/puppetlabs-stdlib/pull/1011) ([david22swan](https://github.com/david22swan)) - ## [5.2.0](https://github.com/puppetlabs/puppetlabs-stdlib/tree/5.2.0) - 2019-01-18 [Full Changelog](https://github.com/puppetlabs/puppetlabs-stdlib/compare/5.1.0...5.2.0) diff --git a/Gemfile b/Gemfile index ca0e773ec..6dd3b77cc 100644 --- a/Gemfile +++ b/Gemfile @@ -14,50 +14,55 @@ def location_for(place_or_version, fake_version = nil) end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "deep_merge", '~> 1.2.2', require: false gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false - gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '~> 3.0', require: false - gem "puppetlabs_spec_helper", '~> 6.0', require: false - gem "rspec-puppet-facts", '~> 2.0', require: false - gem "codecov", '~> 0.2', require: false + gem "facterdb", '~> 2.1', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "facterdb", '~> 3.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "metadata-json-lint", '~> 4.0', require: false + gem "json-schema", '< 5.1.1', require: false + gem "rspec-puppet-facts", '~> 4.0', require: false if Gem::Requirement.create(['< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "rspec-puppet-facts", '~> 5.0', require: false if Gem::Requirement.create(['>= 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "dependency_checker", '~> 1.0.0', require: false gem "parallel_tests", '= 3.12.1', require: false gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.5', require: false - gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.48.1', require: false + gem "simplecov-console", '~> 0.9', require: false + gem "puppet-debugger", '~> 1.6', require: false + gem "rubocop", '~> 1.50.0', require: false gem "rubocop-performance", '= 1.16.0', require: false gem "rubocop-rspec", '= 2.19.0', require: false - gem "puppet-strings", '~> 4.0', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "bigdecimal", '< 3.2.2', require: false, platforms: [:mswin, :mingw, :x64_mingw] end -group :system_tests do - gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] - gem "serverspec", '~> 2.41', require: false -end -group :release_prep do +group :development, :release_prep do gem "puppet-strings", '~> 4.0', require: false - gem "puppetlabs_spec_helper", '~> 6.0', require: false + gem "puppetlabs_spec_helper", '~> 8.0', require: false + gem "puppet-blacksmith", '~> 7.0', require: false +end +group :system_tests do + gem "puppet_litmus", '~> 2.0', require: false, platforms: [:ruby, :x64_mingw] if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? + gem "puppet_litmus", '~> 1.0', require: false, platforms: [:ruby, :x64_mingw] if ENV['PUPPET_FORGE_TOKEN'].to_s.empty? + gem "CFPropertyList", '< 3.0.7', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end - -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] gems = {} +puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil) +facter_version = ENV.fetch('FACTER_GEM_VERSION', nil) +hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil) -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables +# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet +# Otherwise, do as before and use location_for to fetch gems from the default source +if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty? + gems['puppet'] = ['~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] + gems['facter'] = ['~> 4.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }] +else + gems['puppet'] = location_for(puppet_version) + gems['facter'] = location_for(facter_version) if facter_version +end -gems['facter'] = location_for(facter_version) if facter_version gems['hiera'] = location_for(hiera_version) if hiera_version gems.each do |gem_name, gem_params| diff --git a/REFERENCE.md b/REFERENCE.md index 5e97d1ac8..a472419bc 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -63,9 +63,8 @@ environment. * [`grep`](#grep): This function searches through an array and returns any elements that match the provided regular expression. * [`has_interface_with`](#has_interface_with): DEPRECATED. Use the namespaced function [`stdlib::has_interface_with`](#stdlibhas_interface_with) instead. -* [`has_interface_with`](#has_interface_with): Returns boolean based on kind and value. -* [`has_ip_address`](#has_ip_address): Returns true if the client has the requested IP address on some interface. -* [`has_ip_network`](#has_ip_network): Returns true if the client has an IP address within the requested network. +* [`has_ip_address`](#has_ip_address): DEPRECATED. Use the namespaced function [`stdlib::has_ip_address`](#stdlibhas_ip_address) instead. +* [`has_ip_network`](#has_ip_network): DEPRECATED. Use the namespaced function [`stdlib::has_ip_network`](#stdlibhas_ip_network) instead. * [`intersection`](#intersection): This function returns an array of the intersection of two. * [`is_a`](#is_a): Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks. @@ -126,6 +125,8 @@ optional seed for repeatable randomness. * [`stdlib::fqdn_rotate`](#stdlib--fqdn_rotate): Rotates an array or string a random number of times, combining the `fqdn` fact and an optional seed for repeatable randomness. * [`stdlib::has_function`](#stdlib--has_function): Returns whether the Puppet runtime has access to a given function. * [`stdlib::has_interface_with`](#stdlib--has_interface_with): Returns boolean based on network interfaces present and their attribute values. +* [`stdlib::has_ip_address`](#stdlib--has_ip_address): Returns true if the client has the requested IPv4 address on some interface. +* [`stdlib::has_ip_network`](#stdlib--has_ip_network): Returns true if the client has the requested IPv4 network on some interface. * [`stdlib::ip_in_range`](#stdlib--ip_in_range): Returns true if the ipaddress is within the given CIDRs * [`stdlib::merge`](#stdlib--merge): Merges two or more hashes together or hashes resulting from iteration, and returns the resulting hash. @@ -139,6 +140,7 @@ Puppet structure * [`stdlib::seeded_rand_string`](#stdlib--seeded_rand_string): Generates a consistent random string of specific length based on provided seed. * [`stdlib::sha256`](#stdlib--sha256): Run a SHA256 calculation against a given value. * [`stdlib::shell_escape`](#stdlib--shell_escape): Escapes a string so that it can be safely used in a Bourne shell command line. +* [`stdlib::sort_by`](#stdlib--sort_by): Sort an Array, Hash or String by mapping values through a given block. * [`stdlib::start_with`](#stdlib--start_with): Returns true if str starts with one of the prefixes given. Each of the prefixes should be a String. * [`stdlib::str2resource`](#stdlib--str2resource): This converts a string to a puppet resource. * [`stdlib::time`](#stdlib--time): This function is deprecated. It implements the functionality of the original non-namespaced stdlib `time` function. @@ -265,20 +267,33 @@ and `subscribe`. ```puppet class { 'stdlib::manage': - 'create_resources' => { - 'file' => { - '/etc/motd.d/hello' => { - 'content' => 'I say Hi', - 'notify' => 'Service[sshd]', + 'create_resources' => { + 'file' => { + '/etc/motd.d/hello' => { + 'content' => 'I say Hi', + 'notify' => 'Service[sshd]', + }, + '/etc/motd' => { + 'ensure' => 'file', + 'epp' => { + 'template' => 'profile/motd.epp', } }, - 'package' => { - 'example' => { - 'ensure' => 'installed', - 'subscribe' => ['Service[sshd]', 'Exec[something]'], + '/etc/information' => { + 'ensure' => 'file', + 'erb' => { + 'template' => 'profile/informaiton.erb', } } + }, + 'package' => { + 'example' => { + 'ensure' => 'installed', + 'subscribe' => ['Service[sshd]', 'Exec[something]'], + } } + } +} ``` ##### @@ -289,6 +304,15 @@ stdlib::manage::create_resources: '/etc/motd.d/hello': content: I say Hi notify: 'Service[sshd]' + '/etc/motd': + ensure: 'file' + epp: + template: 'profile/motd.epp' + context: {} + '/etc/information': + ensure: 'file' + erb: + template: 'profile/information.erb' package: example: ensure: installed @@ -308,7 +332,8 @@ The following parameters are available in the `stdlib::manage` class: Data type: `Hash[String, Hash]` A hash of resources to create -NOTE: functions, such as `template` or `epp`, are not evaluated. +NOTE: functions, such as `template` or `epp`, are not directly evaluated + but processed as Puppet code based on epp and erb hash keys. Default value: `{}` @@ -2028,75 +2053,41 @@ Data type: `Any` -### `has_interface_with` - -Type: Ruby 3.x API - -Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`. - -#### Examples - -##### **Usage** - -```puppet -has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false` -has_interface_with("ipaddress", "127.0.0.1") # Returns `true` -``` - -##### If no "kind" is given, then the presence of the interface is checked: - -```puppet -has_interface_with("lo") # Returns `true` -``` - -#### `has_interface_with()` +### `has_ip_address` -Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`. +Type: Ruby 4.x API -Returns: `Any` boolean values `true` or `false` +DEPRECATED. Use the namespaced function [`stdlib::has_ip_address`](#stdlibhas_ip_address) instead. -##### Examples +#### `has_ip_address(Any *$args)` -###### **Usage** +The has_ip_address function. -```puppet -has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false` -has_interface_with("ipaddress", "127.0.0.1") # Returns `true` -``` +Returns: `Any` -###### If no "kind" is given, then the presence of the interface is checked: +##### `*args` -```puppet -has_interface_with("lo") # Returns `true` -``` +Data type: `Any` -### `has_ip_address` -Type: Ruby 3.x API -This function iterates through the 'interfaces' fact and checks the -'ipaddress_IFACE' facts, performing a simple string comparison. +### `has_ip_network` -#### `has_ip_address()` +Type: Ruby 4.x API -This function iterates through the 'interfaces' fact and checks the -'ipaddress_IFACE' facts, performing a simple string comparison. +DEPRECATED. Use the namespaced function [`stdlib::has_ip_network`](#stdlibhas_ip_network) instead. -Returns: `Boolean` `true` or `false` +#### `has_ip_network(Any *$args)` -### `has_ip_network` +The has_ip_network function. -Type: Ruby 3.x API +Returns: `Any` -This function iterates through the 'interfaces' fact and checks the -'network_IFACE' facts, performing a simple string comparision. +##### `*args` -#### `has_ip_network()` +Data type: `Any` -This function iterates through the 'interfaces' fact and checks the -'network_IFACE' facts, performing a simple string comparision. -Returns: `Any` Boolean value, `true` if the client has an IP address within the requested network. ### `intersection` @@ -3551,6 +3542,42 @@ Data type: `String[1]` The value of the attribute +### `stdlib::has_ip_address` + +Type: Puppet Language + +Returns true if the client has the requested IPv4 address on some interface. + +#### `stdlib::has_ip_address(Stdlib::IP::Address::V4::Nosubnet $ip_address)` + +The stdlib::has_ip_address function. + +Returns: `Boolean` Returns `true` if the requested IP address exists on any interface. + +##### `ip_address` + +Data type: `Stdlib::IP::Address::V4::Nosubnet` + +The IPv4 address you want to check the existence of + +### `stdlib::has_ip_network` + +Type: Puppet Language + +Returns true if the client has the requested IPv4 network on some interface. + +#### `stdlib::has_ip_network(Stdlib::IP::Address::V4::Nosubnet $ip_network)` + +The stdlib::has_ip_network function. + +Returns: `Boolean` Returns `true` if the requested IP network exists on any interface. + +##### `ip_network` + +Data type: `Stdlib::IP::Address::V4::Nosubnet` + +The IPv4 network you want to check the existence of + ### `stdlib::ip_in_range` Type: Ruby 4.x API @@ -4003,6 +4030,75 @@ Data type: `Any` The string to escape +### `stdlib::sort_by` + +Type: Ruby 4.x API + +Sort an Array, Hash or String by mapping values through a given block. + +#### Examples + +##### Sort local devices according to their used space. + +```puppet +$facts['mountpoints'].stdlib::sort_by |$m| { $m.dig(1, 'used_bytes') } +``` + +#### `stdlib::sort_by(Array $ary, Callable[1,1] &$block)` + +The stdlib::sort_by function. + +Returns: `Array` Returns an ordered copy of ary. + +##### `ary` + +Data type: `Array` + +The Array to sort. + +##### `&block` + +Data type: `Callable[1,1]` + +The block for transforming elements of ary. + +#### `stdlib::sort_by(String $str, Callable[1,1] &$block)` + +The stdlib::sort_by function. + +Returns: `String` Returns an ordered copy of str. + +##### `str` + +Data type: `String` + +The String to sort. + +##### `&block` + +Data type: `Callable[1,1]` + +The block for transforming elements of str. + +#### `stdlib::sort_by(Hash $hsh, Variant[Callable[1,1], Callable[2,2]] &$block)` + +The stdlib::sort_by function. + +Returns: `Hash` Returns an ordered copy of hsh. + +##### `hsh` + +Data type: `Hash` + +The Hash to sort. + +##### `&block` + +Data type: `Variant[Callable[1,1], Callable[2,2]]` + +The block for transforming elements of hsh. +The block may have arity of one or two. + ### `stdlib::start_with` Type: Ruby 4.x API diff --git a/Rakefile b/Rakefile index 77590fe6f..31b593053 100644 --- a/Rakefile +++ b/Rakefile @@ -7,3 +7,12 @@ require 'puppet-syntax/tasks/puppet-syntax' require 'puppet-strings/tasks' if Gem.loaded_specs.key? 'puppet-strings' PuppetLint.configuration.send('disable_relative') +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.ignore_paths = [".vendor/**/*.pp", ".bundle/**/*.pp", "pkg/**/*.pp", "spec/**/*.pp", "tests/**/*.pp", "types/**/*.pp", "vendor/**/*.pp"] + diff --git a/functions/has_ip_address.pp b/functions/has_ip_address.pp new file mode 100644 index 000000000..d8d7e6a79 --- /dev/null +++ b/functions/has_ip_address.pp @@ -0,0 +1,10 @@ +# @summary Returns true if the client has the requested IPv4 address on some interface. +# +# @param ip_address +# The IPv4 address you want to check the existence of +# @return [Boolean] Returns `true` if the requested IP address exists on any interface. +function stdlib::has_ip_address( + Stdlib::IP::Address::V4::Nosubnet $ip_address, +) >> Boolean { + stdlib::has_interface_with('ipaddress', $ip_address) +} diff --git a/functions/has_ip_network.pp b/functions/has_ip_network.pp new file mode 100644 index 000000000..b6b9cb0f8 --- /dev/null +++ b/functions/has_ip_network.pp @@ -0,0 +1,10 @@ +# @summary Returns true if the client has the requested IPv4 network on some interface. +# +# @param ip_network +# The IPv4 network you want to check the existence of +# @return [Boolean] Returns `true` if the requested IP network exists on any interface. +function stdlib::has_ip_network( + Stdlib::IP::Address::V4::Nosubnet $ip_network, +) >> Boolean { + stdlib::has_interface_with('network', $ip_network) +} diff --git a/lib/puppet/functions/has_ip_address.rb b/lib/puppet/functions/has_ip_address.rb new file mode 100644 index 000000000..392d5c550 --- /dev/null +++ b/lib/puppet/functions/has_ip_address.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` + +# @summary DEPRECATED. Use the namespaced function [`stdlib::has_ip_address`](#stdlibhas_ip_address) instead. +Puppet::Functions.create_function(:has_ip_address) do + dispatch :deprecation_gen do + repeated_param 'Any', :args + end + def deprecation_gen(*args) + call_function('deprecation', 'has_ip_address', 'This function is deprecated, please use stdlib::has_ip_address instead.', false) + call_function('stdlib::has_ip_address', *args) + end +end diff --git a/lib/puppet/functions/has_ip_network.rb b/lib/puppet/functions/has_ip_network.rb new file mode 100644 index 000000000..b0219b671 --- /dev/null +++ b/lib/puppet/functions/has_ip_network.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims` + +# @summary DEPRECATED. Use the namespaced function [`stdlib::has_ip_network`](#stdlibhas_ip_network) instead. +Puppet::Functions.create_function(:has_ip_network) do + dispatch :deprecation_gen do + repeated_param 'Any', :args + end + def deprecation_gen(*args) + call_function('deprecation', 'has_ip_network', 'This function is deprecated, please use stdlib::has_ip_network instead.', false) + call_function('stdlib::has_ip_network', *args) + end +end diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb deleted file mode 100644 index b78029d08..000000000 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ /dev/null @@ -1,68 +0,0 @@ -# frozen_string_literal: true - -# -# has_interface_with -# -module Puppet::Parser::Functions - newfunction(:has_interface_with, type: :rvalue, doc: <<-DOC - @summary - Returns boolean based on kind and value. - - @return - boolean values `true` or `false` - - Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`. - - @example **Usage** - has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false` - has_interface_with("ipaddress", "127.0.0.1") # Returns `true` - - @example If no "kind" is given, then the presence of the interface is checked: - has_interface_with("lo") # Returns `true` - DOC - ) do |args| - raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments given (#{args.size} for 1 or 2)") if args.empty? || args.size > 2 - - interfaces = lookupvar('interfaces') - - # If we do not have any interfaces, then there are no requested attributes - return false if interfaces == :undefined || interfaces.nil? - - interfaces = interfaces.split(',') - - return interfaces.member?(args[0]) if args.size == 1 - - kind, value = args - - # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable - # https://tickets.puppetlabs.com/browse/PUP-3597 - factval = nil - begin - catch :undefined_variable do - factval = lookupvar(kind) - end - rescue Puppet::ParseError - end - return true if factval == value - - result = false - interfaces.each do |iface| - iface.downcase! - factval = nil - begin - # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable - # https://tickets.puppetlabs.com/browse/PUP-3597 - catch :undefined_variable do - factval = lookupvar("#{kind}_#{iface}") - end - rescue Puppet::ParseError - end - if value == factval - result = true - break - end - end - - result - end -end diff --git a/lib/puppet/parser/functions/has_ip_address.rb b/lib/puppet/parser/functions/has_ip_address.rb deleted file mode 100644 index 763813c22..000000000 --- a/lib/puppet/parser/functions/has_ip_address.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -# -# has_ip_address -# -module Puppet::Parser::Functions - newfunction(:has_ip_address, type: :rvalue, doc: <<-DOC - @summary - Returns true if the client has the requested IP address on some interface. - - @return [Boolean] - `true` or `false` - - This function iterates through the 'interfaces' fact and checks the - 'ipaddress_IFACE' facts, performing a simple string comparison. - DOC - ) do |args| - raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 - - Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ - unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) - - function_has_interface_with(['ipaddress', args[0]]) - end -end - -# vim:sts=2 sw=2 diff --git a/lib/puppet/parser/functions/has_ip_network.rb b/lib/puppet/parser/functions/has_ip_network.rb deleted file mode 100644 index b556d97c0..000000000 --- a/lib/puppet/parser/functions/has_ip_network.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -# -# has_ip_network -# -module Puppet::Parser::Functions - newfunction(:has_ip_network, type: :rvalue, doc: <<-DOC - @summary - Returns true if the client has an IP address within the requested network. - - @return - Boolean value, `true` if the client has an IP address within the requested network. - - This function iterates through the 'interfaces' fact and checks the - 'network_IFACE' facts, performing a simple string comparision. - DOC - ) do |args| - raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 - - Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ - unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) - - function_has_interface_with(['network', args[0]]) - end -end - -# vim:sts=2 sw=2 diff --git a/lib/puppet/parser/functions/parseyaml.rb b/lib/puppet/parser/functions/parseyaml.rb index e1036386a..014c12d26 100644 --- a/lib/puppet/parser/functions/parseyaml.rb +++ b/lib/puppet/parser/functions/parseyaml.rb @@ -22,7 +22,7 @@ module Puppet::Parser::Functions require 'yaml' begin - YAML.load(arguments[0]) || arguments[1] # rubocop:disable Security/YAMLLoad : using YAML.safe_load causes the code to break + YAML.load(arguments[0]) || arguments[1] # : using YAML.safe_load causes the code to break # in ruby 1.9.3 Psych::SyntaxError is a RuntimeException # this still needs to catch that and work also on rubies that # do not have Psych available. diff --git a/lib/puppet/parser/functions/validate_augeas.rb b/lib/puppet/parser/functions/validate_augeas.rb index 8d89b1e7d..31df4cd66 100644 --- a/lib/puppet/parser/functions/validate_augeas.rb +++ b/lib/puppet/parser/functions/validate_augeas.rb @@ -67,7 +67,7 @@ module Puppet::Parser::Functions # Check for syntax lens = args[1] aug.transform( - lens: lens, + lens:, name: 'Validate_augeas', incl: tmpfile.path, ) diff --git a/manifests/manage.pp b/manifests/manage.pp index 1324187a7..82c39bc8d 100644 --- a/manifests/manage.pp +++ b/manifests/manage.pp @@ -10,24 +10,38 @@ # # @param create_resources # A hash of resources to create -# NOTE: functions, such as `template` or `epp`, are not evaluated. +# NOTE: functions, such as `template` or `epp`, are not directly evaluated +# but processed as Puppet code based on epp and erb hash keys. # # @example # class { 'stdlib::manage': -# 'create_resources' => { -# 'file' => { -# '/etc/motd.d/hello' => { -# 'content' => 'I say Hi', -# 'notify' => 'Service[sshd]', +# 'create_resources' => { +# 'file' => { +# '/etc/motd.d/hello' => { +# 'content' => 'I say Hi', +# 'notify' => 'Service[sshd]', +# }, +# '/etc/motd' => { +# 'ensure' => 'file', +# 'epp' => { +# 'template' => 'profile/motd.epp', # } # }, -# 'package' => { -# 'example' => { -# 'ensure' => 'installed', -# 'subscribe' => ['Service[sshd]', 'Exec[something]'], +# '/etc/information' => { +# 'ensure' => 'file', +# 'erb' => { +# 'template' => 'profile/informaiton.erb', # } # } +# }, +# 'package' => { +# 'example' => { +# 'ensure' => 'installed', +# 'subscribe' => ['Service[sshd]', 'Exec[something]'], +# } # } +# } +# } # # @example # stdlib::manage::create_resources: @@ -35,6 +49,15 @@ # '/etc/motd.d/hello': # content: I say Hi # notify: 'Service[sshd]' +# '/etc/motd': +# ensure: 'file' +# epp: +# template: 'profile/motd.epp' +# context: {} +# '/etc/information': +# ensure: 'file' +# erb: +# template: 'profile/information.erb' # package: # example: # ensure: installed @@ -46,7 +69,50 @@ ) { $create_resources.each |$type, $resources| { $resources.each |$title, $attributes| { - create_resources($type, { $title => $attributes }) + case $type { + 'file': { + # sanity checks + # epp, erb and content are exclusive + if 'epp' in $attributes and 'content' in $attributes { + fail("You can not set 'epp' and 'content' for file ${title}") + } + if 'erb' in $attributes and 'content' in $attributes { + fail("You can not set 'erb' and 'content' for file ${title}") + } + if 'erb' in $attributes and 'epp' in $attributes { + fail("You can not set 'erb' and 'epp' for file ${title}") + } + + if 'epp' in $attributes { + if 'template' in $attributes['epp'] { + if 'context' in $attributes['epp'] { + $content = epp($attributes['epp']['template'], $attributes['epp']['context']) + } else { + $content = epp($attributes['epp']['template']) + } + } else { + fail("No template configured for epp for file ${title}") + } + } elsif 'erb' in $attributes { + if 'template' in $attributes['erb'] { + $content = template($attributes['erb']['template']) + } else { + fail("No template configured for erb for file ${title}") + } + } elsif 'content' in $attributes { + $content = $attributes['content'] + } else { + $content = undef + } + file { $title: + * => $attributes - 'erb' - 'epp' - 'content', + content => $content, + } + } + default: { + create_resources($type, { $title => $attributes }) + } + } } } } diff --git a/metadata.json b/metadata.json index ad43452cf..c997c0457 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-stdlib", - "version": "9.4.1", + "version": "9.7.0", "author": "puppetlabs", "summary": "Standard library of resources for Puppet modules.", "license": "Apache-2.0", @@ -49,7 +49,8 @@ "operatingsystem": "Debian", "operatingsystemrelease": [ "10", - "11" + "11", + "12" ] }, { @@ -57,7 +58,8 @@ "operatingsystemrelease": [ "18.04", "20.04", - "22.04" + "22.04", + "24.04" ] }, { @@ -95,16 +97,23 @@ "operatingsystemrelease": [ "8" ] + }, + { + "operatingsystem": "AmazonLinux", + "operatingsystemrelease": [ + "2", + "2023" + ] } ], "requirements": [ { "name": "puppet", - "version_requirement": ">= 7.0.0 < 9.0.0" + "version_requirement": ">= 8.0.0 < 9.0.0" } ], "description": "Standard Library for Puppet Modules", - "pdk-version": "3.0.0", + "pdk-version": "3.5.0", "template-url": "https://github.com/puppetlabs/pdk-templates#main", - "template-ref": "heads/main-0-g79a2f93" + "template-ref": "heads/main-0-g11c0f3d" } diff --git a/spec/classes/manage_spec.rb b/spec/classes/manage_spec.rb index a34fc7296..ce78ec2f0 100644 --- a/spec/classes/manage_spec.rb +++ b/spec/classes/manage_spec.rb @@ -25,6 +25,16 @@ '/etc/motd.d/hello' => { 'content' => 'I say Hi', 'notify' => 'Service[sshd]' + }, + '/etc/motd' => { + 'epp' => { + 'template' => 'profile/motd.epp' + } + }, + '/etc/information' => { + 'erb' => { + 'template' => 'profile/information.erb' + } } }, 'package' => { @@ -37,8 +47,17 @@ } end + Puppet::Functions.create_function(:epp) do + return 'I am an epp template' + end + Puppet::Functions.create_function(:template) do + return 'I am an erb template' + end + it { is_expected.to compile } it { is_expected.to contain_file('/etc/motd.d/hello').with_content('I say Hi').with_notify('Service[sshd]') } + it { is_expected.to contain_file('/etc/motd').with_content(%r{I am an epp template}) } + it { is_expected.to contain_file('/etc/information').with_content(%r{I am an erb template}) } it { is_expected.to contain_package('example').with_ensure('installed').that_subscribes_to(['Service[sshd]', 'File[/etc/motd.d]']) } end end diff --git a/spec/functions/has_ip_address_spec.rb b/spec/functions/has_ip_address_spec.rb index 5b787d693..7256e7518 100644 --- a/spec/functions/has_ip_address_spec.rb +++ b/spec/functions/has_ip_address_spec.rb @@ -4,22 +4,29 @@ describe 'has_ip_address' do it { is_expected.not_to be_nil } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'stdlib::has_ip_address' expects 1 argument, got none}) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError, %r{'stdlib::has_ip_address' expects 1 argument, got 2}) } context 'when on Linux Systems' do let(:facts) do { - interfaces: 'eth0,lo', - ipaddress: '10.0.0.1', - ipaddress_lo: '127.0.0.1', - ipaddress_eth0: '10.0.0.1' + networking: { + 'interfaces' => { + 'eth0' => { + 'ip' => '10.0.0.1', + }, + 'lo' => { + 'ip' => '127.0.0.1', + }, + }, + 'ip' => '10.0.0.1', + }, } end it { is_expected.to run.with_params('127.0.0.1').and_return(true) } it { is_expected.to run.with_params('10.0.0.1').and_return(true) } it { is_expected.to run.with_params('8.8.8.8').and_return(false) } - it { is_expected.to run.with_params('invalid').and_return(false) } + it { is_expected.to run.with_params('invalid').and_raise_error(ArgumentError, %r{parameter 'ip_address' expects a match}) } end end diff --git a/spec/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb index 22564bb71..c8352272e 100644 --- a/spec/functions/has_ip_network_spec.rb +++ b/spec/functions/has_ip_network_spec.rb @@ -4,21 +4,28 @@ describe 'has_ip_network' do it { is_expected.not_to be_nil } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } + it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'stdlib::has_ip_network' expects 1 argument, got none}) } + it { is_expected.to run.with_params('one', 'two').and_raise_error(ArgumentError, %r{'stdlib::has_ip_network' expects 1 argument, got 2}) } context 'when on Linux Systems' do let(:facts) do { - interfaces: 'eth0,lo', - network_lo: '127.0.0.0', - network_eth0: '10.0.0.0' + networking: { + 'interfaces' => { + 'eth0' => { + 'network' => '10.0.0.0', + }, + 'lo' => { + 'network' => '127.0.0.0', + }, + }, + }, } end it { is_expected.to run.with_params('127.0.0.0').and_return(true) } it { is_expected.to run.with_params('10.0.0.0').and_return(true) } it { is_expected.to run.with_params('8.8.8.0').and_return(false) } - it { is_expected.to run.with_params('invalid').and_return(false) } + it { is_expected.to run.with_params('invalid').and_raise_error(ArgumentError, %r{parameter 'ip_network' expects a match}) } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6820cebee..ae7c1f681 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,7 +25,8 @@ next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin - default_facts.merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) + require 'deep_merge' + default_facts.deep_merge!(YAML.safe_load(File.read(f), permitted_classes: [], permitted_symbols: [], aliases: true)) rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end @@ -33,7 +34,7 @@ # read default_facts and merge them over what is provided by facterdb default_facts.each do |fact, value| - add_custom_fact fact, value + add_custom_fact fact, value, merge_facts: true end RSpec.configure do |c| diff --git a/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb b/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb index 8b10a413c..310ac5c97 100644 --- a/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_alter_spec.rb @@ -172,8 +172,8 @@ name: 'foo', path: tmpfile, line: 'inserted = line', - after: after, - match: match, + after:, + match:, ) end end