diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ecb10a8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# editorconfig.org + +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +tab_width = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8a07791 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: CI + +on: pull_request + +concurrency: + group: ${{ github.ref_name }} + cancel-in-progress: true + +jobs: + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v1 + with: + pidfile_workaround: 'false' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0fc788e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,22 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: Release + +on: + push: + tags: + - '*' + +jobs: + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1 + with: + allowed_owner: 'saz' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.gitignore b/.gitignore index 606b5e4..9b95224 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,23 @@ -# Default .gitignore for Ruby -*.gem -*.rbc -.bundle -.config -coverage -InstalledFiles -lib/bundler/man -pkg -rdoc -spec/reports -test/tmp -test/version_tmp -tmp -vendor/ - -# YARD artifacts -.yardoc -_yardoc -doc/ - -# Vim -*.swp - -# Eclipse -.project +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -# OS X -.DS_Store - -# Puppet -coverage/ -spec/fixtures/manifests/* -spec/fixtures/modules/* +pkg/ Gemfile.lock -.forge-releng/ +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.librarian/ +Puppetfile.lock +*.iml +.*.sw? +.yardoc/ +Guardfile diff --git a/.msync.yml b/.msync.yml new file mode 100644 index 0000000..0235385 --- /dev/null +++ b/.msync.yml @@ -0,0 +1,5 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +modulesync_config_version: '5.3.0' diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..d367ada --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,65 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ +# +# Hooks are only enabled if you take action. +# +# To enable the hooks run: +# +# ``` +# bundle exec overcommit --install +# # ensure .overcommit.yml does not harm to you and then +# bundle exec overcommit --sign +# ``` +# +# (it will manage the .git/hooks directory): +# +# Examples howto skip a test for a commit or push: +# +# ``` +# SKIP=RuboCop git commit +# SKIP=PuppetLint git commit +# SKIP=RakeTask git push +# ``` +# +# Don't invoke overcommit at all: +# +# ``` +# OVERCOMMIT_DISABLE=1 git commit +# ``` +# +# Read more about overcommit: https://github.com/brigade/overcommit +# +# To manage this config yourself in your module add +# +# ``` +# .overcommit.yml: +# unmanaged: true +# ``` +# +# to your modules .sync.yml config +--- +PreCommit: + RuboCop: + enabled: true + description: 'Runs rubocop on modified files only' + command: ['bundle', 'exec', 'rubocop'] + PuppetLint: + enabled: true + description: 'Runs puppet-lint on modified files only' + command: ['bundle', 'exec', 'puppet-lint'] + YamlSyntax: + enabled: true + JsonSyntax: + enabled: true + TrailingWhitespace: + enabled: true + +PrePush: + RakeTarget: + enabled: true + description: 'Run rake targets' + targets: + - 'validate' + - 'test' + - 'rubocop' + command: ['bundle', 'exec', 'rake'] diff --git a/.pmtignore b/.pmtignore new file mode 100644 index 0000000..65f5051 --- /dev/null +++ b/.pmtignore @@ -0,0 +1,37 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +docs/ +pkg/ +Gemfile +Gemfile.lock +Gemfile.local +vendor/ +.vendor/ +spec/ +Rakefile +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.github/ +.librarian/ +Puppetfile.lock +*.iml +.editorconfig +.fixtures.yml +.gitignore +.msync.yml +.overcommit.yml +.pmtignore +.rspec +.rspec_parallel +.rubocop.yml +.sync.yml +.*.sw? +.yardoc/ +.yardopts +Dockerfile diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..dd8272c --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,3 @@ +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..f634583 --- /dev/null +++ b/.rspec @@ -0,0 +1,5 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +--format documentation +--color diff --git a/.rspec_parallel b/.rspec_parallel new file mode 100644 index 0000000..a9a84f8 --- /dev/null +++ b/.rspec_parallel @@ -0,0 +1,4 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +--format progress diff --git a/.rubocop.yml b/.rubocop.yml index fd9fe74..53ac189 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,508 +1,6 @@ -require: rubocop-rspec -AllCops: - TargetRubyVersion: 2.2 - Include: - - ./**/*.rb - Exclude: - - files/**/* - - vendor/**/* - - Gemfile - - Rakefile - - .vendor/**/* - - pkg/**/* - - spec/fixtures/**/* - - Gemfile - - Rakefile -Lint/ConditionPosition: - Enabled: true +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -Lint/ElseLayout: - Enabled: true - -Lint/UnreachableCode: - Enabled: true - -Lint/UselessComparison: - Enabled: true - -Lint/EnsureReturn: - Enabled: true - -Lint/HandleExceptions: - Enabled: true - -Lint/ShadowingOuterLocalVariable: - Enabled: true - -Lint/LiteralInInterpolation: - Enabled: true - -Style/HashSyntax: - Enabled: false - -Style/RedundantReturn: - Enabled: true - -Lint/AmbiguousOperator: - Enabled: true - -Lint/AssignmentInCondition: - Enabled: true - -Layout/SpaceBeforeComment: - Enabled: true - -Style/AndOr: - Enabled: true - -Style/RedundantSelf: - Enabled: true - -# Method length is not necessarily an indicator of code quality -Metrics/MethodLength: - Enabled: false - -# Module length is not necessarily an indicator of code quality -Metrics/ModuleLength: - Enabled: false - -Style/WhileUntilModifier: - Enabled: true - -Lint/AmbiguousRegexpLiteral: - Enabled: true - -Security/Eval: - Enabled: true - -Lint/BlockAlignment: - Enabled: true - -Lint/DefEndAlignment: - Enabled: true - -Lint/EndAlignment: - Enabled: true - -Lint/DeprecatedClassMethods: - Enabled: true - -Lint/Loop: - Enabled: true - -Lint/ParenthesesAsGroupedExpression: - Enabled: true - -Lint/RescueException: - Enabled: true - -Lint/StringConversionInInterpolation: - Enabled: true - -Lint/UnusedBlockArgument: - Enabled: true - -Lint/UnusedMethodArgument: - Enabled: true - -Lint/UselessAccessModifier: - Enabled: true - -Lint/UselessAssignment: - Enabled: true - -Lint/Void: - Enabled: true - -Layout/AccessModifierIndentation: - Enabled: true - -Style/AccessorMethodName: - Enabled: true - -Style/Alias: - Enabled: true - -Layout/AlignArray: - Enabled: true - -Layout/AlignHash: - Enabled: true - -Layout/AlignParameters: - Enabled: true - -Metrics/BlockNesting: - Enabled: true - -Style/AsciiComments: - Enabled: true - -Style/Attr: - Enabled: true - -Style/BracesAroundHashParameters: - Enabled: true - -Style/CaseEquality: - Enabled: true - -Layout/CaseIndentation: - Enabled: true - -Style/CharacterLiteral: - Enabled: true - -Style/ClassAndModuleCamelCase: - Enabled: true - -Style/ClassAndModuleChildren: - Enabled: false - -Style/ClassCheck: - Enabled: true - -# Class length is not necessarily an indicator of code quality -Metrics/ClassLength: - Enabled: false - -Style/ClassMethods: - Enabled: true - -Style/ClassVars: - Enabled: true - -Style/WhenThen: - Enabled: true - -Style/WordArray: - Enabled: true - -Style/UnneededPercentQ: - Enabled: true - -Layout/Tab: - Enabled: true - -Layout/SpaceBeforeSemicolon: - Enabled: true - -Layout/TrailingBlankLines: - Enabled: true - -Layout/SpaceInsideBlockBraces: - Enabled: true - -Layout/SpaceInsideHashLiteralBraces: - Enabled: true - -Layout/SpaceInsideParens: - Enabled: true - -Layout/LeadingCommentSpace: - Enabled: true - -Layout/SpaceBeforeFirstArg: - Enabled: true - -Layout/SpaceAfterColon: - Enabled: true - -Layout/SpaceAfterComma: - Enabled: true - -Layout/SpaceAfterMethodName: - Enabled: true - -Layout/SpaceAfterNot: - Enabled: true - -Layout/SpaceAfterSemicolon: - Enabled: true - -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: true - -Layout/SpaceAroundOperators: - Enabled: true - -Layout/SpaceBeforeBlockBraces: - Enabled: true - -Layout/SpaceBeforeComma: - Enabled: true - -Style/CollectionMethods: - Enabled: true - -Layout/CommentIndentation: - Enabled: true - -Style/ColonMethodCall: - Enabled: true - -Style/CommentAnnotation: - Enabled: true - -# 'Complexity' is very relative -Metrics/CyclomaticComplexity: - Enabled: false - -Style/ConstantName: - Enabled: true - -Style/Documentation: - Enabled: false - -Style/DefWithParentheses: - Enabled: true - -Style/PreferredHashMethods: - Enabled: true - -Layout/DotPosition: - EnforcedStyle: trailing - -Style/DoubleNegation: - Enabled: true - -Style/EachWithObject: - Enabled: true - -Layout/EmptyLineBetweenDefs: - Enabled: true - -Layout/IndentArray: - Enabled: true - -Layout/IndentHash: - Enabled: true - -Layout/IndentationConsistency: - Enabled: true - -Layout/IndentationWidth: - Enabled: true - -Layout/EmptyLines: - Enabled: true - -Layout/EmptyLinesAroundAccessModifier: - Enabled: true - -Style/EmptyLiteral: - Enabled: true - -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Enabled: false - -Style/MethodCallWithoutArgsParentheses: - Enabled: true - -Style/MethodDefParentheses: - Enabled: true - -Style/LineEndConcatenation: - Enabled: true - -Layout/TrailingWhitespace: - Enabled: true - -Style/StringLiterals: - Enabled: true - -Style/TrailingCommaInArguments: - Enabled: true - -Style/GlobalVars: - Enabled: true - -Style/GuardClause: - Enabled: true - -Style/IfUnlessModifier: - Enabled: true - -Style/MultilineIfThen: - Enabled: true - -Style/NegatedIf: - Enabled: true - -Style/NegatedWhile: - Enabled: true - -Style/Next: - Enabled: true - -Style/SingleLineBlockParams: - Enabled: true - -Style/SingleLineMethods: - Enabled: true - -Style/SpecialGlobalVars: - Enabled: true - -Style/TrivialAccessors: - Enabled: true - -Style/UnlessElse: - Enabled: true - -Style/VariableInterpolation: - Enabled: true - -Style/VariableName: - Enabled: true - -Style/WhileUntilDo: - Enabled: true - -Style/EvenOdd: - Enabled: true - -Style/FileName: - Enabled: true - -Style/For: - Enabled: true - -Style/Lambda: - Enabled: true - -Style/MethodName: - Enabled: true - -Style/MultilineTernaryOperator: - Enabled: true - -Style/NestedTernaryOperator: - Enabled: true - -Style/NilComparison: - Enabled: true - -Style/FormatString: - Enabled: true - -Style/MultilineBlockChain: - Enabled: true - -Style/Semicolon: - Enabled: true - -Style/SignalException: - Enabled: true - -Style/NonNilCheck: - Enabled: true - -Style/Not: - Enabled: true - -Style/NumericLiterals: - Enabled: true - -Style/OneLineConditional: - Enabled: true - -Style/ParenthesesAroundCondition: - Enabled: true - -Style/PercentLiteralDelimiters: - Enabled: true - -Style/PerlBackrefs: - Enabled: true - -Style/PredicateName: - Enabled: true - -Style/RedundantException: - Enabled: true - -Style/SelfAssignment: - Enabled: true - -Style/Proc: - Enabled: true - -Style/RaiseArgs: - Enabled: true - -Style/RedundantBegin: - Enabled: true - -Style/RescueModifier: - Enabled: true - -# based on https://github.com/voxpupuli/modulesync_config/issues/168 -Style/RegexpLiteral: - EnforcedStyle: percent_r - Enabled: true - -Lint/UnderscorePrefixedVariableName: - Enabled: true - -Metrics/ParameterLists: - Enabled: false - -Lint/RequireParentheses: - Enabled: true - -Layout/SpaceBeforeFirstArg: - Enabled: true - -Style/ModuleFunction: - Enabled: true - -Lint/Debugger: - Enabled: true - -Style/IfWithSemicolon: - Enabled: true - -Style/Encoding: - Enabled: true - -Style/BlockDelimiters: - Enabled: true - -Style/FormatStringToken: - Enabled: false - -Layout/MultilineBlockLayout: - Enabled: true - -# 'Complexity' is very relative -Metrics/AbcSize: - Enabled: False - -Metrics/BlockLength: - Enabled: False - -# 'Complexity' is very relative -Metrics/PerceivedComplexity: - Enabled: False - -Lint/UselessAssignment: - Enabled: true - -Layout/ClosingParenthesisIndentation: - Enabled: false - -# RSpec - -# We don't use rspec in this way -RSpec/DescribeClass: - Enabled: False - -# Example length is not necessarily an indicator of code quality -RSpec/ExampleLength: - Enabled: False -RSpec/NestedGroups: - Max: 5 -RSpec/MultipleExpectations: - Max: 3 +inherit_gem: + voxpupuli-test: rubocop.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5f956b1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -sudo: false -language: ruby -cache: bundler -bundler_args: "--without system_tests development" -before_install: -- bundle -v -- rm Gemfile.lock || true -- gem update --system -- gem update bundler -- gem --version -- bundle -v -script: -- bundle exec rake $CHECK -matrix: - fast_finish: true - include: - - rvm: 2.3.1 - env: PUPPET_VERSION="~> 4.0" STRICT_VARIABLES="yes" CHECK=test - - rvm: 2.3.1 - env: PUPPET_VERSION="~> 4.0" STRICT_VARIABLES="yes" CHECK=rubocop - - rvm: 2.3.1 - env: PUPPET_VERSION="~> 4.0" STRICT_VARIABLES="yes" CHECK=build FORGEDEPLOY=true - - rvm: 2.3.1 - env: PUPPET_VERSION="~> 5.0" STRICT_VARIABLES="yes" CHECK=test - - rvm: 2.3.1 - env: PUPPET_VERSION="~> 5.0" STRICT_VARIABLES="yes" CHECK=rubocop - - rvm: 2.5.3 - env: PUPPET_VERSION="~> 6.1" STRICT_VARIABLES="yes" CHECK=test - - rvm: 2.5.3 - env: PUPPET_VERSION="~> 6.1" STRICT_VARIABLES="yes" CHECK=rubocop -notifications: - email: false -deploy: - provider: puppetforge - user: saz - password: - secure: EB6NYFhMlNUGTg4rGsy5h+7gMp+1F0eyXOJwq4TgT2XZMYGv0j/CFkUyOkTKuMV6h9iGDnUH1jdMlFHztWbgymXm4k7ETNtcA2F/1QRlanAe6zUuYZ96/vc1X5+ER8v22iY6YlofGAOCl23MYHSDSHBlMreAnFFWCRJxpB/RjDg= - on: - tags: true - all_branches: true - rvm: 2.3.1 - condition: "$FORGEDEPLOY = true" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8dd82d6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# MANAGED BY MODULESYNC +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +FROM ruby:2.7 + +WORKDIR /opt/puppet + +# https://github.com/puppetlabs/puppet/blob/06ad255754a38f22fb3a22c7c4f1e2ce453d01cb/lib/puppet/provider/service/runit.rb#L39 +RUN mkdir -p /etc/sv + +ARG PUPPET_GEM_VERSION="~> 6.0" +ARG PARALLEL_TEST_PROCESSORS=4 + +# Cache gems +COPY Gemfile . +RUN bundle install --without system_tests development release --path=${BUNDLE_PATH:-vendor/bundle} + +COPY . . + +RUN bundle install +RUN bundle exec rake release_checks + +# Container should not saved +RUN exit 1 diff --git a/Gemfile b/Gemfile index a4a9c22..07209b7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,62 +1,34 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -def location_for(place, fake_version = nil) - if place =~ /^(git[:@][^#]*)#(.*)/ - [fake_version, { git: $1, branch: $2, require: false }].compact - elsif place =~ /^file:\/\/(.*)/ - ['>= 0', { path: File.expand_path($1), require: false }] - else - [place, { require: false }] - end -end +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'puppetlabs_spec_helper', require: false - gem 'rspec-puppet', require: false - gem 'rspec-puppet-facts', require: false - gem 'rspec-puppet-utils', require: false - gem 'puppet-lint-absolute_classname-check', require: false - gem 'puppet-lint-leading_zero-check', require: false - gem 'puppet-lint-trailing_comma-check', require: false - gem 'puppet-lint-version_comparison-check', require: false - gem 'puppet-lint-classes_and_types_beginning_with_digits-check', require: false - gem 'puppet-lint-unquoted_string-check', require: false - gem 'puppet-lint-variable_contains_upcase', require: false - gem 'metadata-json-lint', require: false - gem 'puppet-blacksmith', require: false - gem 'voxpupuli-release', require: false, git: 'https://github.com/voxpupuli/voxpupuli-release-gem.git' - gem 'rubocop', '~> 0.49.1', require: false - gem 'rubocop-rspec', require: false - gem 'rspec-its', require: false + gem 'voxpupuli-test', '~> 5.4', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'puppet_metadata', '~> 1.0', :require => false end group :development do - gem 'travis', require: false - gem 'travis-lint', require: false - gem 'guard-rake', require: false + gem 'guard-rake', :require => false + gem 'overcommit', '>= 0.39.1', :require => false end group :system_tests do - if (beaker_version = ENV['BEAKER_VERSION']) - gem 'beaker', *location_for(beaker_version) - end - if (beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']) - gem 'beaker-rspec', *location_for(beaker_rspec_version) - else - gem 'beaker-rspec', require: false - end - gem 'beaker-puppet_install_helper', require: false + gem 'voxpupuli-acceptance', '~> 1.0', :require => false end - - -if (facterversion = ENV['FACTER_GEM_VERSION']) - gem 'facter', facterversion.to_s, require: false, groups: [:test] -else - gem 'facter', require: false, groups: [:test] +group :release do + gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' + gem 'voxpupuli-release', '>= 1.2.0', :require => false + gem 'puppet-strings', '>= 2.2', :require => false end -ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 4.0' : puppetversion = ENV['PUPPET_VERSION'].to_s -gem 'puppet', puppetversion, require: false, groups: [:test] +gem 'rake', :require => false +gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] + +puppetversion = ENV['PUPPET_GEM_VERSION'] || '>= 6.0' +gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 5c10c3f..f92f051 100644 --- a/Rakefile +++ b/Rakefile @@ -1,42 +1,72 @@ -require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet_blacksmith/rake_tasks' -require 'voxpupuli/release/rake_tasks' +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -if RUBY_VERSION >= '2.2.0' - require 'rubocop/rake_task' +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), +# otherwise attempt to load it directly. +begin + require 'voxpupuli/test/rake' +rescue LoadError + begin + require 'puppetlabs_spec_helper/rake_tasks' + rescue LoadError + end +end + +# load optional tasks for acceptance +# only available if gem group releases is installed +begin + require 'voxpupuli/acceptance/rake' +rescue LoadError +end + +# load optional tasks for releases +# only available if gem group releases is installed +begin + require 'voxpupuli/release/rake_tasks' +rescue LoadError +end - RuboCop::RakeTask.new(:rubocop) do |task| - # These make the rubocop experience maybe slightly less terrible - task.options = ['-D', '-S', '-E'] +desc "Run main 'test' task and report merged results to coveralls" +task test_with_coveralls: [:test] do + if Dir.exist?(File.expand_path('../lib', __FILE__)) + require 'coveralls/rake/task' + Coveralls::RakeTask.new + Rake::Task['coveralls:push'].invoke + else + puts 'Skipping reporting to coveralls. Module has no lib dir' end end -PuppetLint.configuration.fail_on_warnings = true -PuppetLint.configuration.send('relative') -PuppetLint.configuration.send('disable_140chars') -PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send('disable_documentation') -PuppetLint.configuration.send('disable_single_quote_string_with_variables') - -exclude_paths = %w( - pkg/**/* - vendor/**/* - .vendor/**/* - spec/**/* -) -PuppetLint.configuration.ignore_paths = exclude_paths -PuppetSyntax.exclude_paths = exclude_paths - -desc 'Run acceptance tests' -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' +desc 'Generate REFERENCE.md' +task :reference, [:debug, :backtrace] do |t, args| + patterns = '' + Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) end -desc 'Run tests metadata_lint, lint, syntax, spec' -task test: [ - :metadata_lint, - :lint, - :syntax, - :spec, -] +begin + require 'github_changelog_generator/task' + require 'puppet_blacksmith' + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + metadata = Blacksmith::Modulefile.new + config.future_release = "v#{metadata.version}" if metadata.version =~ /^\d+\.\d+.\d+$/ + config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." + config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} + config.user = 'voxpupuli' + config.project = metadata.metadata['name'] + end + + # Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715 + require 'rbconfig' + if RbConfig::CONFIG['host_os'] =~ /linux/ + task :changelog do + puts 'Fixing line endings...' + changelog_file = File.join(__dir__, 'CHANGELOG.md') + changelog_txt = File.read(changelog_file) + new_contents = changelog_txt.gsub(%r{\r\n}, "\n") + File.open(changelog_file, "w") {|file| file.puts new_contents } + end + end + +rescue LoadError +end # vim: syntax=ruby diff --git a/manifests/init.pp b/manifests/init.pp index 6e31082..e1e6c24 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -6,7 +6,6 @@ Boolean $manage_limits_d_dir, Boolean $purge_limits_d_dir, ) { - if $manage_limits_d_dir { file { $limits_dir: ensure => 'directory', @@ -18,12 +17,9 @@ } } - ### Create instances for integration with Hiera - $entries.each | String $e_name, Hash $e_params | { limits::limits { $e_name: * => $e_params, } } - } diff --git a/manifests/limits.pp b/manifests/limits.pp index 6e663f1..03242d0 100644 --- a/manifests/limits.pp +++ b/manifests/limits.pp @@ -17,7 +17,7 @@ # # Manages: # limit file in limits.d with the values provided -define limits::limits( +define limits::limits ( Enum['absent', 'present'] $ensure = present, Optional[String] $user = undef, Optional[String] $limit_type = undef, @@ -25,15 +25,16 @@ Variant[Integer,String,Undef] $soft = undef, Variant[Integer,String,Undef] $both = undef, ) { - - include ::limits + include limits # minimal validation if $ensure == 'present' { unless $hard or $soft or $both { fail('$hard, $soft or $both is required') } } unless $title =~ /\// { - unless $user and $limit_type { fail('when not using the title pattern, $user and $limit_type are required') } + unless $user and $limit_type { + fail('when not using the title pattern, $user and $limit_type are required') + } } $key = split($title, '/') diff --git a/metadata.json b/metadata.json index fcd80dc..a9b72a5 100644 --- a/metadata.json +++ b/metadata.json @@ -10,19 +10,39 @@ "issues_url": "https://github.com/saz/puppet-limits/issues", "operatingsystem_support": [ { - "operatingsystem": "RedHat" + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "7", + "8", + "9" + ] }, { "operatingsystem": "Amazon" }, { - "operatingsystem": "CentOS" + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "7", + "8", + "9" + ] }, { - "operatingsystem": "Debian" + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "9", + "10", + "11" + ] }, { - "operatingsystem": "Ubuntu" + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "18.04", + "20.04", + "22.04" + ] }, { "operatingsystem": "Gentoo" @@ -34,7 +54,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 4.0.0 < 8.0.0" + "version_requirement": ">= 6.0.0 < 8.0.0" } ], "dependencies": [ diff --git a/spec/acceptance/init_spec.rb b/spec/acceptance/init_spec.rb new file mode 100644 index 0000000..350cf12 --- /dev/null +++ b/spec/acceptance/init_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper_acceptance' + +describe 'limits' do + context 'with all defaults' do + let(:pp) do + 'include limits' + end + + it 'works idempotently with no errors' do + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + end +end diff --git a/spec/acceptance/limits_spec.rb b/spec/acceptance/limits_spec.rb new file mode 100644 index 0000000..5a699aa --- /dev/null +++ b/spec/acceptance/limits_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper_acceptance' + +describe 'limits::limits define' do + context 'with default parameters' do + it 'works with no errors' do + pp = <<-PP + limits::limits { '*/nofile': + hard => 12345, + soft => 1234, + } + PP + + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) + end + end + + context 'with ignore and suffix specified managed file' do + it 'create a puppet managed file' do + pp = <<-PP + limits::limits { 'item': + user => 'user', + limit_type => 'nofile', + both => 12345 + } + PP + + # Run it twice and test for idempotency + apply_manifest(pp, catch_failures: true) + expect(apply_manifest(pp, catch_failures: true).exit_code).to be_zero + end + + describe file('/etc/security/limits.d/user_nofile.conf') do + it { is_expected.to be_file } + it { is_expected.to contain 'user - nofile 12345' } + end + end +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..4c65432 --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'limits' do + let :node do + 'rspec.puppet.com' + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts + end + + context 'with all defaults' do + it { is_expected.to compile.with_all_deps } + + it do + is_expected.to contain_file('/etc/security/limits.d').with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'force' => true, + 'recurse' => true, + 'purge' => true + ) + end + end + + describe 'with purge_limits_d_dir set to false' do + let :params do + { + purge_limits_d_dir: false + } + end + + it do + is_expected.to contain_file('/etc/security/limits.d').with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'force' => true, + 'recurse' => true, + 'purge' => false + ) + end + end + + describe 'with manage_limits_d_dir set to false' do + let :params do + { + manage_limits_d_dir: false + } + end + + it { is_expected.not_to contain_file('/etc/security/limits.d') } + end + end + end +end diff --git a/spec/classes/limits_spec.rb b/spec/classes/limits_spec.rb deleted file mode 100644 index c94f9ac..0000000 --- a/spec/classes/limits_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'spec_helper' -describe 'limits' do - let :default_params do - { - :manage_limits_d_dir => true, - :purge_limits_d_dir => true - } - end - - [{}, - { - :purge_limits_d_dir => false - }, - { - :manage_limits_d_dir => false - }].each do |param_set| - describe "when #{param_set == {} ? 'using default' : "specifying #{param_set}"} class parameters" do - let :param_hash do - default_params.merge(param_set) - end - - let :params do - param_set - end - - %w[Debian Gentoo RedHat Suse].each do |osfamily| - let :facts do - { - :osfamily => osfamily - } - end - - describe "on supported osfamily: #{osfamily}" do - it do - if params[:manage_limits_d_dir] == false - is_expected.not_to contain_file('/etc/security/limits.d') - else - is_expected.to contain_file('/etc/security/limits.d').with( - 'ensure' => 'directory', - 'owner' => 'root', - 'group' => 'root', - 'force' => true, - 'recurse' => true, - 'purge' => param_hash[:purge_limits_d_dir] -) - end - end - end - end - end - end -end diff --git a/spec/defines/limits_spec.rb b/spec/defines/limits_spec.rb index 21e90fe..18275d5 100644 --- a/spec/defines/limits_spec.rb +++ b/spec/defines/limits_spec.rb @@ -1,182 +1,215 @@ -require 'spec_helper' -describe 'limits::limits', :type => :define do - let(:filename) { '/etc/security/limits.d/username_nofile.conf' } - - let :facts do - { - :osfamily => 'Debian' - } - end - - context 'default' do - let(:title) { 'username_nofile' } - let :params do - { - :user => 'username', - :limit_type => 'nofile', - :ensure => 'present', - :hard => 16_384, - :soft => 16_384 - } - end - - describe 'when creating a limits entry not ending in .conf' do - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_class('limits') } - it { - is_expected.to contain_limits__limits('username_nofile').with(:user => 'username', - :limit_type => 'nofile', - :ensure => 'present', - :hard => 16_384, - :soft => 16_384) - } - it { - is_expected.to contain_file(filename).with('ensure' => 'present', - 'content' => "# Managed by Puppet\n\n# \nusername hard nofile 16384\nusername soft nofile 16384\n", - 'owner' => 'root', - 'group' => 'root') - } - end - - describe 'when creating a limits entry ending in .conf' do - let(:title) { 'username_nofile.conf' } - - it { - is_expected.to contain_limits__limits('username_nofile.conf').with(:user => 'username', - :limit_type => 'nofile', - :ensure => 'present', - :hard => 16_384, - :soft => 16_384) - } - it { - is_expected.to contain_file(filename).with('ensure' => 'present', - 'content' => "# Managed by Puppet\n\n# \nusername hard nofile 16384\nusername soft nofile 16384\n", - 'owner' => 'root', - 'group' => 'root') - } - end - - describe 'when removing an limits entry' do - let :params do - { - :user => 'username', - :limit_type => 'nofile', - :ensure => 'absent', - :hard => 16_384, - :soft => 16_384 - } - end - - it { - is_expected.to contain_file(filename).with('ensure' => 'absent', - 'owner' => 'root', - 'group' => 'root') - } - end - - describe 'when removing an limits entry without hard or soft set' do - let :params do - { - :user => 'username', - :limit_type => 'nofile', - :ensure => 'absent' - } - end +# frozen_string_literal: true - it { - is_expected.to contain_file(filename).with('ensure' => 'absent', - 'owner' => 'root', - 'group' => 'root') - } - end +require 'spec_helper' - context 'when creating a limits entry setting both limits' do - let :params do - { - :user => 'username', - :limit_type => 'nofile', - :ensure => 'present', - :both => 16_384 - } +describe 'limits::limits', type: :define do + on_supported_os.each do |os, facts| + context "on #{os}" do + let :facts do + facts end - let(:title) { 'username_nofile.conf' } - - it { - is_expected.to contain_limits__limits('username_nofile.conf').with(:user => 'username', - :limit_type => 'nofile', - :ensure => 'present', - :both => 16_384) - } - it { - is_expected.to contain_file(filename).with('ensure' => 'present', - 'content' => "# Managed by Puppet\n\n# \nusername - nofile 16384\n", - 'owner' => 'root', - 'group' => 'root') - } - end - end - context 'title pattern' do - describe 'default/nofile' do - let(:title) { '*/nofile' } - let :params do - { - :both => 16_384 - } - end - - it { is_expected.to compile.with_all_deps } - it { - is_expected.to contain_file('/etc/security/limits.d/default_nofile.conf').with('ensure' => 'present', - 'content' => "# Managed by Puppet\n\n# \n* - nofile 16384\n", - 'owner' => 'root', - 'group' => 'root') - } - end - describe 'root/nofile' do - let(:title) { 'root/nofile' } - let :params do - { - :hard => 12_345 - } + let(:filename) { '/etc/security/limits.d/username_nofile.conf' } + + context 'default' do + let(:title) { 'username_nofile' } + let :params do + { + user: 'username', + limit_type: 'nofile', + ensure: 'present', + hard: 16_384, + soft: 16_384 + } + end + + describe 'when creating a limits entry not ending in .conf' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('limits') } + + it { + is_expected.to contain_limits__limits('username_nofile').with( + user: 'username', + limit_type: 'nofile', + ensure: 'present', + hard: 16_384, + soft: 16_384 + ) + } + + it { + is_expected.to contain_file(filename).with( + 'ensure' => 'present', + 'content' => "# Managed by Puppet\n\n# \nusername hard nofile 16384\nusername soft nofile 16384\n", + 'owner' => 'root', + 'group' => 'root' + ) + } + end + + describe 'when creating a limits entry ending in .conf' do + let(:title) { 'username_nofile.conf' } + + it { + is_expected.to contain_limits__limits('username_nofile.conf').with( + user: 'username', + limit_type: 'nofile', + ensure: 'present', + hard: 16_384, + soft: 16_384 + ) + } + + it { + is_expected.to contain_file(filename).with( + 'ensure' => 'present', + 'content' => "# Managed by Puppet\n\n# \nusername hard nofile 16384\nusername soft nofile 16384\n", + 'owner' => 'root', + 'group' => 'root' + ) + } + end + + describe 'when removing an limits entry' do + let :params do + { + user: 'username', + limit_type: 'nofile', + ensure: 'absent', + hard: 16_384, + soft: 16_384 + } + end + + it { + is_expected.to contain_file(filename).with( + 'ensure' => 'absent', + 'owner' => 'root', + 'group' => 'root' + ) + } + end + + describe 'when removing an limits entry without hard or soft set' do + let :params do + { + user: 'username', + limit_type: 'nofile', + ensure: 'absent' + } + end + + it { + is_expected.to contain_file(filename).with( + 'ensure' => 'absent', + 'owner' => 'root', + 'group' => 'root' + ) + } + end + + context 'when creating a limits entry setting both limits' do + let(:title) { 'username_nofile.conf' } + let :params do + { + user: 'username', + limit_type: 'nofile', + ensure: 'present', + both: 16_384 + } + end + + it { + is_expected.to contain_limits__limits('username_nofile.conf').with( + user: 'username', + limit_type: 'nofile', + ensure: 'present', + both: 16_384 + ) + } + + it { + is_expected.to contain_file(filename).with( + 'ensure' => 'present', + 'content' => "# Managed by Puppet\n\n# \nusername - nofile 16384\n", + 'owner' => 'root', + 'group' => 'root' + ) + } + end end - it { - is_expected.to contain_file('/etc/security/limits.d/root_nofile.conf').with('ensure' => 'present', - 'content' => "# Managed by Puppet\n\n# \nroot hard nofile 12345\n", - 'owner' => 'root', - 'group' => 'root') - } - end - end - - context 'validation' do - describe 'missing user' do - let(:title) { 'nofile' } - let :params do - { - :limit_type => 'nofile', - :both => 16_384 - } + context 'title pattern' do + describe 'default/nofile' do + let(:title) { '*/nofile' } + let :params do + { + both: 16_384 + } + end + + it { is_expected.to compile.with_all_deps } + + it { + is_expected.to contain_file('/etc/security/limits.d/default_nofile.conf').with( + 'ensure' => 'present', + 'content' => "# Managed by Puppet\n\n# \n* - nofile 16384\n", + 'owner' => 'root', + 'group' => 'root' + ) + } + end + + describe 'root/nofile' do + let(:title) { 'root/nofile' } + let :params do + { + hard: 12_345 + } + end + + it { + is_expected.to contain_file('/etc/security/limits.d/root_nofile.conf').with( + 'ensure' => 'present', + 'content' => "# Managed by Puppet\n\n# \nroot hard nofile 12345\n", + 'owner' => 'root', + 'group' => 'root' + ) + } + end end - it { is_expected.to compile.and_raise_error(%r{when not using the title pattern}) } - end - describe 'missing type' do - let(:title) { 'nofile.conf' } - let :params do - { - :user => 'foo', - :both => 16_384 - } + context 'validation' do + describe 'missing user' do + let(:title) { 'nofile' } + let :params do + { + limit_type: 'nofile', + both: 16_384 + } + end + + it { is_expected.to compile.and_raise_error(%r{when not using the title pattern}) } + end + + describe 'missing type' do + let(:title) { 'nofile.conf' } + let :params do + { + user: 'foo', + both: 16_384 + } + end + + it { is_expected.to compile.and_raise_error(%r{when not using the title pattern}) } + end + + describe 'missing limit' do + let(:title) { 'root/nofile' } + + it { is_expected.to compile.and_raise_error(%r{\$hard, \$soft or \$both is required}) } + end end - - it { is_expected.to compile.and_raise_error(%r{when not using the title pattern}) } - end - describe 'missing limit' do - let(:title) { 'root/nofile' } - - it { is_expected.to compile.and_raise_error(%r{\$hard, \$soft or \$both is required}) } end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..4d617f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,17 @@ -require 'puppetlabs_spec_helper/module_spec_helper' +# frozen_string_literal: true + +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +# puppetlabs_spec_helper will set up coverage if the env variable is set. +# We want to do this if lib exists and it hasn't been explicitly set. +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) + +require 'voxpupuli/test/spec_helper' + +if File.exist?(File.join(__dir__, 'default_module_facts.yml')) + facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) + facts&.each do |name, value| + add_custom_fact name.to_sym, value + end +end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..b79530e --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +# This file is completely based on voxpupuli/modulesync_config +require 'voxpupuli/acceptance/spec_helper_acceptance' + +configure_beaker diff --git a/tests/init.pp b/tests/init.pp deleted file mode 100644 index 98d263d..0000000 --- a/tests/init.pp +++ /dev/null @@ -1 +0,0 @@ -include ::limits