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/.fixtures.yml b/.fixtures.yml index 90cee1f..7cae334 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,4 @@ fixtures: repositories: - 'stdlib': - repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.6.0' - 'firewall': - repo: 'git://github.com/puppetlabs/puppetlabs-firewall.git' - ref: '1.7.1' - symlinks: - 'monit': "#{source_dir}" + 'stdlib': 'https://github.com/puppetlabs/puppetlabs-stdlib.git' + 'firewall': 'https://github.com/puppetlabs/puppetlabs-firewall.git' diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..6aaa603 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,254 @@ +# Contribution guidelines + +## Table of contents + +* [Contributing](#contributing) +* [Writing proper commits - short version](#writing-proper-commits-short-version) +* [Writing proper commits - long version](#writing-proper-commits-long-version) +* [Dependencies](#dependencies) + * [Note for OS X users](#note-for-os-x-users) +* [The test matrix](#the-test-matrix) +* [Syntax and style](#syntax-and-style) +* [Running the unit tests](#running-the-unit-tests) +* [Unit tests in docker](#unit-tests-in-docker) +* [Integration tests](#integration-tests) + +This module has grown over time based on a range of contributions from +people using it. If you follow these contributing guidelines your patch +will likely make it into a release a little more quickly. + +## Contributing + +Please note that this project is released with a Contributor Code of Conduct. +By participating in this project you agree to abide by its terms. +[Contributor Code of Conduct](https://voxpupuli.org/coc/). + +* Fork the repo. +* Create a separate branch for your change. +* We only take pull requests with passing tests, and documentation. [GitHub Actions](https://docs.github.com/en/actions) run the tests for us. You can also execute them locally. This is explained [in a later section](#the-test-matrix). +* Checkout [our docs](https://voxpupuli.org/docs/reviewing_pr/) we use to review a module and the [official styleguide](https://puppet.com/docs/puppet/6.0/style_guide.html). They provide some guidance for new code that might help you before you submit a pull request. +* Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, please add a test. +* Squash your commits down into logical components. Make sure to rebase against our current master. +* Push the branch to your fork and submit a pull request. + +Please be prepared to repeat some of these steps as our contributors review your code. + +Also consider sending in your profile code that calls this component module as an acceptance test or provide it via an issue. This helps reviewers a lot to test your use case and prevents future regressions! + +## Writing proper commits - short version + +* Make commits of logical units. +* Check for unnecessary whitespace with "git diff --check" before committing. +* Commit using Unix line endings (check the settings around "crlf" in git-config(1)). +* Do not check in commented out code or unneeded files. +* The first line of the commit message should be a short description (50 characters is the soft limit, excluding ticket number(s)), and should skip the full stop. +* Associate the issue in the message. The first line should include the issue number in the form "(#XXXX) Rest of message". +* The body should provide a meaningful commit message, which: + *uses the imperative, present tense: `change`, not `changed` or `changes`. + * includes motivation for the change, and contrasts its implementation with the previous behavior. + * Make sure that you have tests for the bug you are fixing, or feature you are adding. + * Make sure the test suites passes after your commit: + * When introducing a new feature, make sure it is properly documented in the README.md + +## Writing proper commits - long version + + 1. Make separate commits for logically separate changes. + + Please break your commits down into logically consistent units + which include new or changed tests relevant to the rest of the + change. The goal of doing this is to make the diff easier to + read for whoever is reviewing your code. In general, the easier + your diff is to read, the more likely someone will be happy to + review it and get it into the code base. + + If you are going to refactor a piece of code, please do so as a + separate commit from your feature or bug fix changes. + + We also really appreciate changes that include tests to make + sure the bug is not re-introduced, and that the feature is not + accidentally broken. + + Describe the technical detail of the change(s). If your + description starts to get too long, that is a good sign that you + probably need to split up your commit into more finely grained + pieces. + + Commits which plainly describe the things which help + reviewers check the patch and future developers understand the + code are much more likely to be merged in with a minimum of + bike-shedding or requested changes. Ideally, the commit message + would include information, and be in a form suitable for + inclusion in the release notes for the version of Puppet that + includes them. + + Please also check that you are not introducing any trailing + whitespace or other "whitespace errors". You can do this by + running "git diff --check" on your changes before you commit. + + 2. Sending your patches + + To submit your changes via a GitHub pull request, we _highly_ + recommend that you have them on a topic branch, instead of + directly on `master`. + It makes things much easier to keep track of, especially if + you decide to work on another thing before your first change + is merged in. + + GitHub has some pretty good + [general documentation](http://help.github.com/) on using + their site. They also have documentation on + [creating pull requests](http://help.github.com/send-pull-requests/). + + In general, after pushing your topic branch up to your + repository on GitHub, you can switch to the branch in the + GitHub UI and click "Pull Request" towards the top of the page + in order to open a pull request. + + + 3. Update the related GitHub issue. + + If there is a GitHub issue associated with the change you + submitted, then you should update the ticket to include the + location of your branch, along with any other commentary you + may wish to make. + +## Dependencies + +The testing and development tools have a bunch of dependencies, +all managed by [bundler](http://bundler.io/) according to the +[Puppet support matrix](http://docs.puppetlabs.com/guides/platforms.html#ruby-versions). + +By default the tests use a baseline version of Puppet. + +If you have Ruby 2.x or want a specific version of Puppet, +you must set an environment variable such as: + +```sh +export PUPPET_GEM_VERSION="~> 6.1.0" +``` + +You can install all needed gems for spec tests into the modules directory by +running: + +```sh +bundle install --path .vendor/ --without development system_tests release --jobs "$(nproc)" +``` + +If you also want to run acceptance tests: + +```sh +bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)" +``` + +Our all in one solution if you don't know if you need to install or update gems: + +```sh +bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)"; bundle update; bundle clean +``` + +As an alternative to the `--jobs "$(nproc)` parameter, you can set an +environment variable: + +```sh +BUNDLE_JOBS="$(nproc)" +``` + +### Note for OS X users + +`nproc` isn't a valid command under OS x. As an alternative, you can do: + +```sh +--jobs "$(sysctl -n hw.ncpu)" +``` + +## The test matrix + +### Syntax and style + +The test suite will run [Puppet Lint](http://puppet-lint.com/) and +[Puppet Syntax](https://github.com/gds-operations/puppet-syntax) to +check various syntax and style things. You can run these locally with: + +```sh +bundle exec rake lint +bundle exec rake validate +``` + +It will also run some [Rubocop](http://batsov.com/rubocop/) tests +against it. You can run those locally ahead of time with: + +```sh +bundle exec rake rubocop +``` + +### Running the unit tests + +The unit test suite covers most of the code, as mentioned above please +add tests if you're adding new functionality. If you've not used +[rspec-puppet](http://rspec-puppet.com/) before then feel free to ask +about how best to test your new feature. + +To run the linter, the syntax checker and the unit tests: + +```sh +bundle exec rake test +``` + +To run your all the unit tests + +```sh +bundle exec rake spec +``` + +To run a specific spec test set the `SPEC` variable: + +```sh +bundle exec rake spec SPEC=spec/foo_spec.rb +``` + +#### Unit tests in docker + +Some people don't want to run the dependencies locally or don't want to install +ruby. We ship a Dockerfile that enables you to run all unit tests and linting. +You only need to run: + +```sh +docker build . +``` + +Please ensure that a docker daemon is running and that your user has the +permission to talk to it. You can specify a remote docker host by setting the +`DOCKER_HOST` environment variable. it will copy the content of the module into +the docker image. So it will not work if a Gemfile.lock exists. + +### Integration tests + +The unit tests just check the code runs, not that it does exactly what +we want on a real machine. For that we're using +[beaker](https://github.com/puppetlabs/beaker). + +This fires up a new virtual machine (using vagrant) and runs a series of +simple tests against it after applying the module. You can run this +with: + +```sh +BEAKER_PUPPET_COLLECTION=puppet7 BEAKER_setfile=debian11-64 bundle exec rake beaker +``` + +You can replace the string `debian11` with any common operating system. +The following strings are known to work: + +* ubuntu2004 +* ubuntu2204 +* debian11 +* centos7 +* centos8 +* centos9 +* almalinux8 +* almalinux9 +* fedora36 + +For more information and tips & tricks, see [voxpupuli-acceptance's documentation](https://github.com/voxpupuli/voxpupuli-acceptance#running-tests). + +The source of this file is in our [modulesync_config](https://github.com/voxpupuli/modulesync_config/blob/master/moduleroot/.github/CONTRIBUTING.md.erb) +repository. diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..593e7aa --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## Affected Puppet, Ruby, OS and module versions/distributions + +- Puppet: +- Ruby: +- Distribution: +- Module version: + +## How to reproduce (e.g Puppet code you use) + +## What are you seeing + +## What behaviour did you expect instead + +## Output log + +## Any additional information you'd like to impart diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..342807b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,20 @@ + +#### Pull Request (PR) description + + +#### This Pull Request (PR) fixes the following issues + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7216724 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: CI + +on: + pull_request: {} + push: + branches: + - main + - master + +concurrency: + group: ${{ github.ref_name }} + cancel-in-progress: true + +jobs: + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2 + with: + pidfile_workaround: 'false' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..55324aa --- /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@v2 + with: + allowed_owner: 'voxpupuli' + 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 2767022..84fd904 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,23 @@ -.git/ -.*.sw[op] -.metadata -.yardoc -.yardwarns -*.iml -/.bundle/ -/.idea/ -/.vagrant/ -/coverage/ -/bin/ -/doc/ -/Gemfile.local -/Gemfile.lock -/junit/ -/log/ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + /pkg/ +/Gemfile.lock +/Gemfile.local +/vendor/ +/.vendor/ /spec/fixtures/manifests/ /spec/fixtures/modules/ -/tmp/ -/vendor/ -/convert_report.txt -/update_report.txt -.DS_Store -.project -.envrc -/inventory.yaml +/.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..f46ee02 --- /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: '7.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/.pdkignore b/.pdkignore deleted file mode 100644 index e6215cd..0000000 --- a/.pdkignore +++ /dev/null @@ -1,42 +0,0 @@ -.git/ -.*.sw[op] -.metadata -.yardoc -.yardwarns -*.iml -/.bundle/ -/.idea/ -/.vagrant/ -/coverage/ -/bin/ -/doc/ -/Gemfile.local -/Gemfile.lock -/junit/ -/log/ -/pkg/ -/spec/fixtures/manifests/ -/spec/fixtures/modules/ -/tmp/ -/vendor/ -/convert_report.txt -/update_report.txt -.DS_Store -.project -.envrc -/inventory.yaml -/appveyor.yml -/.fixtures.yml -/Gemfile -/.gitattributes -/.gitignore -/.gitlab-ci.yml -/.pdkignore -/Rakefile -/rakelib/ -/.rspec -/.rubocop.yml -/.travis.yml -/.yardopts -/spec/ -/.vscode/ diff --git a/.pmtignore b/.pmtignore index fb58957..10b9830 100644 --- a/.pmtignore +++ b/.pmtignore @@ -1,20 +1,38 @@ -docs/ -pkg/ -Gemfile.lock -Gemfile.local -vendor/ -.vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ -.vagrant/ -.bundle/ -.ruby-version -coverage/ -log/ -.idea/ -.dependencies/ -.librarian/ -Puppetfile.lock +# 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/ +/.yardoc/ +/.yardopts +/Dockerfile +/HISTORY.md diff --git a/.puppet-lint.rc b/.puppet-lint.rc index cc96ece..dd8272c 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,3 @@ ---relative +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/.rspec b/.rspec index 16f9cdb..f634583 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,5 @@ ---color +# 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 5307849..fded90c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,137 +1,7 @@ --- -require: -- rubocop-rspec -- rubocop-i18n -AllCops: - DisplayCopNames: true - TargetRubyVersion: '2.1' - Include: - - "./**/*.rb" - Exclude: - - bin/* - - ".vendor/**/*" - - "**/Gemfile" - - "**/Rakefile" - - pkg/**/* - - spec/fixtures/**/* - - vendor/**/* - - "**/Puppetfile" - - "**/Vagrantfile" - - "**/Guardfile" -Metrics/LineLength: - Description: People have wide screens, use them. - Max: 200 -GetText: - Enabled: false -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false -RSpec/BeforeAfterAll: - Description: Beware of using after(:all) as it may cause state to leak between tests. - A necessary evil in acceptance testing. - Exclude: - - spec/acceptance/**/*.rb -RSpec/HookArgument: - Description: Prefer explicit :each argument, matching existing module's style - EnforcedStyle: each -Style/BlockDelimiters: - Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to - be consistent then. - EnforcedStyle: braces_for_chaining -Style/BracesAroundHashParameters: - Description: Braces are required by Ruby 2.7. Cop removed from RuboCop v0.80.0. - See https://github.com/rubocop-hq/rubocop/pull/7643 - Enabled: true -Style/ClassAndModuleChildren: - Description: Compact style reduces the required amount of indentation. - EnforcedStyle: compact -Style/EmptyElse: - Description: Enforce against empty else clauses, but allow `nil` for clarity. - EnforcedStyle: empty -Style/FormatString: - Description: Following the main puppet project's style, prefer the % format format. - EnforcedStyle: percent -Style/FormatStringToken: - Description: Following the main puppet project's style, prefer the simpler template - tokens over annotated ones. - EnforcedStyle: template -Style/Lambda: - Description: Prefer the keyword for easier discoverability. - EnforcedStyle: literal -Style/RegexpLiteral: - Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 - EnforcedStyle: percent_r -Style/TernaryParentheses: - Description: Checks for use of parentheses around ternary conditions. Enforce parentheses - on complex expressions for better readability, but seriously consider breaking - it up. - EnforcedStyle: require_parentheses_when_complex -Style/TrailingCommaInArguments: - Description: Prefer always trailing comma on multiline argument lists. This makes - diffs, and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/TrailingCommaInLiteral: - Description: Prefer always trailing comma on multiline literals. This makes diffs, - and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/SymbolArray: - Description: Using percent style obscures symbolic intent of array's contents. - EnforcedStyle: brackets -RSpec/MessageSpies: - EnforcedStyle: receive -Style/Documentation: - Exclude: - - lib/puppet/parser/functions/**/* - - spec/**/* -Style/WordArray: - EnforcedStyle: brackets -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -GetText/DecorateFunctionMessage: - Enabled: false -GetText/DecorateStringFormattingUsingInterpolation: - Enabled: false -GetText/DecorateStringFormattingUsingPercent: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/IndentHeredoc: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/MessageExpectation: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/NestedGroups: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/SymbolProc: - Enabled: false +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +inherit_from: .rubocop_todo.yml +inherit_gem: + voxpupuli-test: rubocop.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..6db939c --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,27 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-08-17 21:35:05 UTC using RuboCop version 1.50.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/CommentedKeyword: + Exclude: + - 'spec/classes/init_spec.rb' + - 'spec/defines/check_spec.rb' + +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - 'lib/facter/monit_version.rb' + - 'spec/acceptance/class_spec.rb' + - 'spec/classes/init_spec.rb' + - 'spec/defines/check_spec.rb' + - 'spec/spec_helper_acceptance.rb' + - 'spec/unit/facter/monit_version_spec.rb' diff --git a/.sync.yml b/.sync.yml index d2d11b0..6fd48f8 100644 --- a/.sync.yml +++ b/.sync.yml @@ -20,3 +20,6 @@ appveyor.yml: spec/spec_helper.rb: mock_with: ':rspec' coverage_report: true + +spec/spec_helper_acceptance.rb: + unmanaged: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5388724..0000000 --- a/.travis.yml +++ /dev/null @@ -1,54 +0,0 @@ ---- -os: linux -dist: xenial -language: ruby -cache: bundler -before_install: - - bundle -v - - rm -f Gemfile.lock - - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - - gem --version - - bundle -v -script: - - 'bundle exec rake $CHECK' -bundler_args: --without system_tests -rvm: - - 2.5.7 -stages: - - static - - spec - - acceptance - - - if: tag =~ ^v\d - name: deploy -jobs: - fast_finish: true - include: - - - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" - stage: static - - - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.5 - stage: spec - - - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec - rvm: 2.5.7 - stage: spec - - - env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec - rvm: 2.1.9 - stage: spec - - - env: DEPLOY_TO_FORGE=yes - stage: deploy -branches: - only: - - master - - /^v\d/ - - develop -notifications: - email: false diff --git a/.yardopts b/.yardopts deleted file mode 100644 index 29c933b..0000000 --- a/.yardopts +++ /dev/null @@ -1 +0,0 @@ ---markup markdown 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 8007ad0..a4a3b20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,72 +1,32 @@ -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_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} +source ENV['GEM_SOURCE'] || 'https://rubygems.org' - if place_or_version && (git_url = place_or_version.match(git_url_regex)) - [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact - elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) - ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] - else - [place_or_version, { require: false }] - end +group :test do + gem 'voxpupuli-test', '~> 7.0', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'puppet_metadata', '~> 3.5', :require => false end -ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments -minor_version = ruby_version_segments[0..1].join('.') - group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') - gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - 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 "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem 'guard-rake', :require => false + gem 'overcommit', '>= 0.39.1', :require => false end -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - -gems = {} - -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables - -gems['facter'] = location_for(facter_version) if facter_version -gems['hiera'] = location_for(hiera_version) if hiera_version - -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] +group :system_tests do + gem 'voxpupuli-acceptance', '~> 3.0', :require => false end -gems.each do |gem_name, gem_params| - gem gem_name, *gem_params +group :release do + gem 'voxpupuli-release', '~> 3.0', :require => false end -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] +gem 'rake', :require => false +gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] + +puppetversion = ENV['PUPPET_GEM_VERSION'] || '~> 7.24' +gem 'puppet', puppetversion, :require => false, :groups => [:test] -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end -end # vim: syntax=ruby diff --git a/README.md b/README.md index 83c7c61..1485d4f 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ You can use the module [stahnma-epel](https://forge.puppetlabs.com/stahnma/epel) ### Beginning with monit ```puppet -include ::monit +include monit ``` ## Usage diff --git a/REFERENCE.md b/REFERENCE.md index 08bac43..0c1b25a 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -20,11 +20,11 @@ ### Defined types -* [`monit::check`](#monitcheck): Adds a Monit check. +* [`monit::check`](#monit--check): Adds a Monit check. ## Classes -### `monit` +### `monit` Main class, includes all other classes. @@ -38,9 +38,38 @@ class { 'monit': } #### Parameters -The following parameters are available in the `monit` class. - -##### `alert_emails` +The following parameters are available in the `monit` class: + +* [`alert_emails`](#-monit--alert_emails) +* [`check_interval`](#-monit--check_interval) +* [`config_file`](#-monit--config_file) +* [`config_dir`](#-monit--config_dir) +* [`config_dir_purge`](#-monit--config_dir_purge) +* [`httpd`](#-monit--httpd) +* [`httpd_port`](#-monit--httpd_port) +* [`httpd_address`](#-monit--httpd_address) +* [`httpd_allow`](#-monit--httpd_allow) +* [`httpd_user`](#-monit--httpd_user) +* [`httpd_password`](#-monit--httpd_password) +* [`logfile`](#-monit--logfile) +* [`mailserver`](#-monit--mailserver) +* [`mailformat`](#-monit--mailformat) +* [`manage_firewall`](#-monit--manage_firewall) +* [`mmonit_address`](#-monit--mmonit_address) +* [`mmonit_https`](#-monit--mmonit_https) +* [`mmonit_port`](#-monit--mmonit_port) +* [`mmonit_user`](#-monit--mmonit_user) +* [`mmonit_password`](#-monit--mmonit_password) +* [`mmonit_without_credential`](#-monit--mmonit_without_credential) +* [`package_ensure`](#-monit--package_ensure) +* [`package_name`](#-monit--package_name) +* [`service_ensure`](#-monit--service_ensure) +* [`service_manage`](#-monit--service_manage) +* [`service_name`](#-monit--service_name) +* [`start_delay`](#-monit--start_delay) +* [`service_enable`](#-monit--service_enable) + +##### `alert_emails` Data type: `Array[String]` @@ -48,55 +77,55 @@ Specifies one or more email addresses to send global alerts to. Default value: [ Default value: `$monit::params::alert_emails` -##### `check_interval` +##### `check_interval` -Data type: `Integer[0]` +Data type: `Integer[1]` Specifies the interval between two checks of Monit. Default value: 120 Default value: `$monit::params::check_interval` -##### `config_file` +##### `config_file` -Data type: `String` +Data type: `Stdlib::Absolutepath` Specifies a path to the main config file. Default value: varies with operating system Default value: `$monit::params::config_file` -##### `config_dir` +##### `config_dir` -Data type: `String` +Data type: `Stdlib::Absolutepath` Specifies a path to the config directory. Default value: varies with operating system Default value: `$monit::params::config_dir` -##### `config_dir_purge` +##### `config_dir_purge` -Data type: `Variant[Boolean, Enum['true', 'false']]` +Data type: `Boolean` Specifies if unmanaged files in the config directory should be purged. Default value: 'false' Default value: `$monit::params::config_dir_purge` -##### `httpd` +##### `httpd` -Data type: `Variant[Boolean, Enum['true', 'false']]` +Data type: `Boolean` Specifies whether to enable the Monit Dashboard. Default value: 'false' Default value: `$monit::params::httpd` -##### `httpd_port` +##### `httpd_port` -Data type: `Integer[0, 65535]` +Data type: `Integer[1, 65535]` Specifies the port of the Monit Dashboard. Default value: 2812 Default value: `$monit::params::httpd_port` -##### `httpd_address` +##### `httpd_address` Data type: `String` @@ -104,7 +133,7 @@ Specifies the IP address of the Monit Dashboard. Default value: 'locahost' Default value: `$monit::params::httpd_address` -##### `httpd_allow` +##### `httpd_allow` Data type: `String` @@ -112,7 +141,7 @@ Specifies the allow option of the Monit Dashboard. Default value: '0.0.0.0/0.0.0 Default value: `$monit::params::httpd_allow` -##### `httpd_user` +##### `httpd_user` Data type: `String` @@ -120,7 +149,7 @@ Specifies the user to access the Monit Dashboard. Default value: 'admin' Default value: `$monit::params::httpd_user` -##### `httpd_password` +##### `httpd_password` Data type: `String` @@ -128,16 +157,16 @@ Specifies the password to access the Monit Dashboard. Default value: 'monit' Default value: `$monit::params::httpd_password` -##### `logfile` +##### `logfile` -Data type: `String` +Data type: `Optional[String]` Specifies the logfile directive value. Default value: '/var/log/monit.log' It is possible to use syslog instead of direct file logging. (e.g. 'syslog facility log\_daemon') Default value: `$monit::params::logfile` -##### `mailserver` +##### `mailserver` Data type: `Optional[String]` @@ -146,7 +175,7 @@ For more details, see: https://mmonit.com/monit/documentation/monit.html#Setting Default value: `$monit::params::mailserver` -##### `mailformat` +##### `mailformat` Data type: `Optional[Hash]` @@ -155,42 +184,44 @@ For more details, see: https://mmonit.com/monit/documentation/monit.html#Message Default value: `$monit::params::mailformat` -##### `manage_firewall` +##### `manage_firewall` -Data type: `Variant[Boolean, Enum['true', 'false']]` +Data type: `Boolean` -If true and if puppetlabs-firewall module is present, Puppet manages firewall to allow HTTP access for Monit Dashboard. Default value: 'false' +If true and if puppetlabs-firewall module is present, Puppet manages firewall to allow HTTP access for Monit Dashboard. +Default value: 'false' Default value: `$monit::params::manage_firewall` -##### `mmonit_address` +##### `mmonit_address` Data type: `Optional[String]` *Requires at least Monit 5.0*
-Specifies the remote address of an M/Monit server to be used by Monit agent for report. If set to undef, M/Monit connection is disabled. Default value: undef +Specifies the remote address of an M/Monit server to be used by Monit agent for report. If set to undef, M/Monit connection is disabled. +Default value: undef Default value: `$monit::params::mmonit_address` -##### `mmonit_https` +##### `mmonit_https` -Data type: `Variant[Boolean, Enum['true', 'false']]` +Data type: `Boolean` *Requires at least Monit 5.0*
Specifies wheither the protocol of the M/Monit server is HTTPs. Default value: 'true' Default value: `$monit::params::mmonit_https` -##### `mmonit_port` +##### `mmonit_port` -Data type: `Integer[0, 65535]` +Data type: `Integer[1, 65535]` *Requires at least Monit 5.0*
Specifies the remote port of the M/Monit server. Default value: 8443 Default value: `$monit::params::mmonit_port` -##### `mmonit_user` +##### `mmonit_user` Data type: `String` @@ -200,7 +231,7 @@ If you set both user and password to an empty string, authentication is disabled Default value: `$monit::params::mmonit_user` -##### `mmonit_password` +##### `mmonit_password` Data type: `String` @@ -210,24 +241,28 @@ If you set both user and password to an empty string, authentication is disabled Default value: `$monit::params::mmonit_password` -##### `mmonit_without_credential` +##### `mmonit_without_credential` -Data type: `Variant[Boolean, Enum['true', 'false']]` +Data type: `Boolean` *Requires at least Monit 5.0*
-By default Monit registers credentials with M/Monit so M/Monit can smoothly communicate back to Monit and you don't have to register Monit credentials manually in M/Monit. It is possible to disable credential registration setting this option to 'true'. Default value: 'false' +By default Monit registers credentials with M/Monit so M/Monit can smoothly communicate back to Monit and you don't have to register +Monit credentials manually in M/Monit. It is possible to disable credential registration setting this option to 'true'. +Default value: 'false' Default value: `$monit::params::mmonit_without_credential` -##### `package_ensure` +##### `package_ensure` Data type: `String` -Tells Puppet whether the Monit package should be installed, and what version. Valid options: 'present', 'latest', or a specific version number. Default value: 'present' +Tells Puppet whether the Monit package should be installed, and what version. +Valid options: 'present', 'latest', or a specific version number. +Default value: 'present' Default value: `$monit::params::package_ensure` -##### `package_name` +##### `package_name` Data type: `String` @@ -235,7 +270,7 @@ Tells Puppet what Monit package to manage. Default value: 'monit' Default value: `$monit::params::package_name` -##### `service_ensure` +##### `service_ensure` Data type: `Enum['running', 'stopped']` @@ -243,15 +278,15 @@ Tells Puppet whether the Monit service should be running. Default value: 'runnin Default value: `$monit::params::service_ensure` -##### `service_manage` +##### `service_manage` -Data type: `Variant[Boolean, Enum['true', 'false']]` +Data type: `Boolean` Tells Puppet whether to manage the Monit service. Default value: 'true' Default value: `$monit::params::service_manage` -##### `service_name` +##### `service_name` Data type: `String` @@ -259,18 +294,18 @@ Tells Puppet what Monit service to manage. Default value: 'monit' Default value: `$monit::params::service_name` -##### `start_delay` +##### `start_delay` -Data type: `Integer[0]` +Data type: `Optional[Integer[1]]` *Requires at least Monit 5.0* -If set, Monit will wait the specified time in seconds before it starts checking services. Default value: 0 +If set, Monit will wait the specified time in seconds before it starts checking services. Default value: undef Default value: `$monit::params::start_delay` -##### `service_enable` +##### `service_enable` -Data type: `Variant[Boolean, Enum['true', 'false']]` +Data type: `Boolean` @@ -278,23 +313,27 @@ Default value: `$monit::params::service_enable` ## Defined types -### `monit::check` +### `monit::check` Adds a Monit check. #### Parameters -The following parameters are available in the `monit::check` defined type. +The following parameters are available in the `monit::check` defined type: + +* [`content`](#-monit--check--content) +* [`ensure`](#-monit--check--ensure) +* [`source`](#-monit--check--source) -##### `content` +##### `content` Data type: `Optional[String]` Specifies the content of the configuration file. The `content` and `source` parameters are exclusive of each other. -Default value: ``undef`` +Default value: `undef` -##### `ensure` +##### `ensure` Data type: `Enum['present', 'absent']` @@ -302,11 +341,11 @@ Tells Puppet whether the check should exist. Default value: `present` -##### `source` +##### `source` Data type: `Optional[String]` Tells Puppet what is the path of the configuration file. The `content` and `source` parameters are exclusive of each other. -Default value: ``undef`` +Default value: `undef` diff --git a/Rakefile b/Rakefile index 0a5093b..a9f7934 100644 --- a/Rakefile +++ b/Rakefile @@ -1,87 +1,44 @@ -# frozen_string_literal: true - -require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? -require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? -require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? -require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? - -def changelog_user - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['author'] - raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator user:#{returnVal}" - returnVal -end - -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - - returnVal = nil - returnVal ||= begin - metadata_source = JSON.load(File.read('metadata.json'))['source'] - metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) - - metadata_source_match && metadata_source_match[1] +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +# 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 - - raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? - - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal end -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version'] - raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator future_release:#{returnVal}" - returnVal +# load optional tasks for acceptance +# only available if gem group releases is installed +begin + require 'voxpupuli/acceptance/rake' +rescue LoadError end -PuppetLint.configuration.send('disable_relative') - -if Bundler.rubygems.find_name('github_changelog_generator').any? - GitHubChangelogGenerator::RakeTask.new :changelog do |config| - raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? - config.user = "#{changelog_user}" - config.project = "#{changelog_project}" - config.future_release = "#{changelog_future_release}" - config.exclude_labels = ['maintenance'] - config.header = "# Change log\n\nAll 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)." - config.add_pr_wo_labels = true - config.issues = false - config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB" - config.configure_sections = { - "Changed" => { - "prefix" => "### Changed", - "labels" => ["backwards-incompatible"], - }, - "Added" => { - "prefix" => "### Added", - "labels" => ["enhancement", "feature"], - }, - "Fixed" => { - "prefix" => "### Fixed", - "labels" => ["bug", "documentation", "bugfix"], - }, - } - end +# load optional tasks for releases +# only available if gem group releases is installed +begin + require 'voxpupuli/release/rake_tasks' +rescue LoadError + # voxpupuli-release not present else - desc 'Generate a Changelog from GitHub' - task :changelog do - raise < 1.15' - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')" -EOM + GCGConfig.user = 'voxpupuli' + GCGConfig.project = 'puppet-monit' +end + +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 +# vim: syntax=ruby diff --git a/examples/check.pp b/examples/check.pp index 143b5e1..f0d0943 100644 --- a/examples/check.pp +++ b/examples/check.pp @@ -1,4 +1,4 @@ -include ::monit +include monit monit::check { 'fake': content => 'fake content for the fake service check', diff --git a/examples/init.pp b/examples/init.pp index 06c91bc..ee082d5 100644 --- a/examples/init.pp +++ b/examples/init.pp @@ -9,4 +9,4 @@ # Learn more about module testing here: # http://docs.puppetlabs.com/guides/tests_smoke.html # -include ::monit +include monit diff --git a/manifests/check.pp b/manifests/check.pp index fd52f6c..b416ac9 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -26,7 +26,7 @@ } # - file { "${::monit::config_dir}/${name}": + file { "${monit::config_dir}/${name}": ensure => $ensure, owner => 'root', group => 'root', diff --git a/manifests/config.pp b/manifests/config.pp index b20ba5e..adb5302 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -21,8 +21,8 @@ owner => 'root', group => 'root', mode => '0755', - purge => $monit::config_dir_purge_bool, - recurse => $monit::config_dir_purge_bool, + purge => $monit::config_dir_purge, + recurse => $monit::config_dir_purge, require => Package['monit'], } diff --git a/manifests/firewall.pp b/manifests/firewall.pp index 37a9d2e..86abbc4 100644 --- a/manifests/firewall.pp +++ b/manifests/firewall.pp @@ -8,12 +8,12 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $monit::httpd_bool and $monit::manage_firewall_bool { + if $monit::httpd and $monit::manage_firewall { if defined('::firewall') { firewall { "${monit::httpd_port} allow Monit inbound traffic": - action => 'accept', - dport => $monit::httpd_port, - proto => 'tcp', + jump => 'accept', + dport => $monit::httpd_port, + proto => 'tcp', } } } diff --git a/manifests/init.pp b/manifests/init.pp index 2a850ff..aa8ec20 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -105,10 +105,10 @@ class monit ( Array[String] $alert_emails = $monit::params::alert_emails, Integer[1] $check_interval = $monit::params::check_interval, - String $config_file = $monit::params::config_file, - String $config_dir = $monit::params::config_dir, - Variant[Boolean, Enum['true', 'false']] $config_dir_purge = $monit::params::config_dir_purge, - Variant[Boolean, Enum['true', 'false']] $httpd = $monit::params::httpd, + Stdlib::Absolutepath $config_file = $monit::params::config_file, + Stdlib::Absolutepath $config_dir = $monit::params::config_dir, + Boolean $config_dir_purge = $monit::params::config_dir_purge, + Boolean $httpd = $monit::params::httpd, Integer[1, 65535] $httpd_port = $monit::params::httpd_port, String $httpd_address = $monit::params::httpd_address, String $httpd_allow = $monit::params::httpd_allow, @@ -117,90 +117,37 @@ Optional[String] $logfile = $monit::params::logfile, Optional[String] $mailserver = $monit::params::mailserver, Optional[Hash] $mailformat = $monit::params::mailformat, - Variant[Boolean, Enum['true', 'false']] $manage_firewall = $monit::params::manage_firewall, + Boolean $manage_firewall = $monit::params::manage_firewall, Optional[String] $mmonit_address = $monit::params::mmonit_address, - Variant[Boolean, Enum['true', 'false']] $mmonit_https = $monit::params::mmonit_https, + Boolean $mmonit_https = $monit::params::mmonit_https, Integer[1, 65535] $mmonit_port = $monit::params::mmonit_port, String $mmonit_user = $monit::params::mmonit_user, String $mmonit_password = $monit::params::mmonit_password, - Variant[Boolean, Enum['true', 'false']] $mmonit_without_credential = $monit::params::mmonit_without_credential, + Boolean $mmonit_without_credential = $monit::params::mmonit_without_credential, String $package_ensure = $monit::params::package_ensure, String $package_name = $monit::params::package_name, - Variant[Boolean, Enum['true', 'false']] $service_enable = $monit::params::service_enable, + Boolean $service_enable = $monit::params::service_enable, Enum['running', 'stopped'] $service_ensure = $monit::params::service_ensure, - Variant[Boolean, Enum['true', 'false']] $service_manage = $monit::params::service_manage, + Boolean $service_manage = $monit::params::service_manage, String $service_name = $monit::params::service_name, Optional[Integer[1]] $start_delay = $monit::params::start_delay, ) inherits monit::params { - # - if is_string($httpd) == true { - $httpd_bool = str2bool($httpd) - } else { - $httpd_bool = $httpd - } - - if is_string($manage_firewall) == true { - $manage_firewall_bool = str2bool($manage_firewall) - } else { - $manage_firewall_bool = $manage_firewall - } - - if is_string($service_enable) == true { - $service_enable_bool = str2bool($service_enable) - } else { - $service_enable_bool = $service_enable - } - - if is_string($service_manage) == true { - $service_manage_bool = str2bool($service_manage) - } else { - $service_manage_bool = $service_manage - } - - if is_string($mmonit_https) == true { - $mmonit_https_bool = str2bool($mmonit_https) - } else { - $mmonit_https_bool = $mmonit_https - } - - if is_string($mmonit_without_credential) == true { - $mmonit_without_credential_bool = str2bool($mmonit_without_credential) - } else { - $mmonit_without_credential_bool = $mmonit_without_credential - } - - if is_string($config_dir_purge) == true { - $config_dir_purge_bool = str2bool($config_dir_purge) - } else { - $config_dir_purge_bool = $config_dir_purge - } - # - - # - validate_absolute_path($config_file) - validate_absolute_path($config_dir) - if $logfile and !($logfile =~ /^syslog(\s+facility\s+log_(local[0-7]|daemon))?/) { - validate_absolute_path($logfile) + assert_type(Stdlib::Absolutepath, $logfile) } - # # Use the monit_version fact if available, else use the default for the # platform. - if defined('$::monit_version') and $::monit_version { - $monit_version_real = $::monit_version - } else { - $monit_version_real = $monit::params::monit_version - } + $monit_version_real = pick($facts['monit_version'], $monit::params::monit_version) if($start_delay and $start_delay > 0 and versioncmp($monit_version_real,'5') < 0) { fail("start_delay requires at least Monit 5.0. Detected version is <${monit_version_real}>.") } - anchor { "${module_name}::begin": } - -> class { "${module_name}::install": } - -> class { "${module_name}::config": } - ~> class { "${module_name}::service": } - -> class { "${module_name}::firewall": } - -> anchor { "${module_name}::end": } + contain "${module_name}::install" + contain "${module_name}::config" + contain "${module_name}::service" + contain "${module_name}::firewall" + + Class["${module_name}::install"] -> Class["${module_name}::config"] ~> Class["${module_name}::service"] -> Class["${module_name}::firewall"] } diff --git a/manifests/params.pp b/manifests/params.pp index f238250..2979961 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -30,69 +30,31 @@ $mmonit_password = 'monit' $mmonit_without_credential = false - # - case $::osfamily { + case $facts['os']['family'] { 'Debian': { $config_file = '/etc/monit/monitrc' $config_dir = '/etc/monit/conf.d' $monit_version = '5' - - case $::lsbdistcodename { - 'squeeze', 'lucid': { - $default_file_content = 'startup=1' - $service_hasstatus = false - } - 'wheezy', 'jessie', 'stretch', 'buster', 'precise', 'trusty', 'xenial', 'bionic': { - $default_file_content = 'START=yes' - $service_hasstatus = true - } - default: { - fail("monit supports Debian 6 (squeeze), 7 (wheezy), 8 (jessie), 9 (stretch) and 10 (buster) \ -and Ubuntu 10.04 (lucid), 12.04 (precise), 14.04 (trusty), 16.04 (xenial) and 18.04 (bionic). \ -Detected lsbdistcodename is <${::lsbdistcodename}>.") - } - } + $default_file_content = 'START=yes' + $service_hasstatus = true } 'RedHat': { $config_dir = '/etc/monit.d' $service_hasstatus = true - case $::operatingsystem { + case $facts['os']['name'] { 'Amazon': { - case $::operatingsystemmajrelease { - '2': { - $monit_version = '5' - $config_file = '/etc/monitrc' - } - default: { - fail("monit supports Amazon Linux 2. Detected operatingsystemmajrelease is <${::operatingsystemmajrelease}>.") - } - } + $monit_version = '5' + $config_file = '/etc/monit.conf' } default: { - case $::operatingsystemmajrelease { - '5': { - $monit_version = '4' - $config_file = '/etc/monit.conf' - } - '6': { - $monit_version = '5' - $config_file = '/etc/monit.conf' - } - '7', '8', '9': { - $monit_version = '5' - $config_file = '/etc/monitrc' - } - default: { - fail("monit supports EL 5, 6, 7, 8, and 9. Detected operatingsystemmajrelease is <${::operatingsystemmajrelease}>.") - } - } + $monit_version = '5' + $config_file = '/etc/monitrc' } } } default: { - fail("monit supports osfamilies Debian and RedHat. Detected osfamily is <${::osfamily}>.") + fail("monit supports osfamilies Debian and RedHat. Detected osfamily is <${facts['os']['family']}>.") } } - # } diff --git a/manifests/service.pp b/manifests/service.pp index 1fd8d5a..c76250a 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -8,8 +8,8 @@ fail("Use of private class ${name} by ${caller_module_name}") } - if $monit::service_manage_bool { - if $::osfamily == 'Debian' { + if $monit::service_manage { + if $facts['os']['family'] == 'Debian' { file { '/etc/default/monit': content => $monit::default_file_content, notify => Service[$monit::service_name], diff --git a/metadata.json b/metadata.json index 12c0ccc..4f172fc 100644 --- a/metadata.json +++ b/metadata.json @@ -10,71 +10,74 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.6.0 < 6.0.0" + "version_requirement": ">= 4.6.0 < 10.0.0" }, { "name": "puppetlabs/firewall", - "version_requirement": ">= 1.7.1 < 2.0.0" + "version_requirement": ">= 5.0.0 < 9.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "Amazon", "operatingsystemrelease": [ - "2016", - "2018" + "2023" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ - "6", - "7", - "8", - "9", - "10" + "11", + "12" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "10.04", - "12.04", - "14.04", - "16.04", - "18.04" + "20.04", + "22.04" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ - "5", - "6", - "7" + "7", + "8", + "9" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "5", - "6", "7", - "8" + "8", + "9" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ - "5", - "6", - "7" + "8", + "9" + ] + }, + { + "operatingsystem": "AlmaLinux", + "operatingsystemrelease": [ + "8", + "9" + ] + }, + { + "operatingsystem": "Rocky", + "operatingsystemrelease": [ + "8", + "9" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ - "5", - "6", "7" ] } @@ -82,7 +85,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 3.0.0 < 6.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "tags": [ diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 2141f92..6bf5086 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -5,7 +5,7 @@ # Using puppet_apply as a helper it 'works with no errors' do pp = <<-EOS - include ::monit + include monit EOS # Run it twice and test for idempotency diff --git a/spec/acceptance/nodesets/debian-82-x64.yml b/spec/acceptance/nodesets/debian-82-x64.yml deleted file mode 100644 index 8d9dc06..0000000 --- a/spec/acceptance/nodesets/debian-82-x64.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - debian-82-x64: - roles: - - master - platform: debian-8-amd64 - box : puppetlabs/debian-8.2-64-nocm - box_url : https://vagrantcloud.com/puppetlabs/boxes/debian-8.2-64-nocm - hypervisor : vagrant -CONFIG: - log_level: verbose - type: foss \ No newline at end of file diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 100644 index ce47212..0000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - centos-64-x64: - roles: - - master - platform: el-6-x86_64 - box : centos-64-x64-vbox4210-nocm - box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box - hypervisor : vagrant -CONFIG: - log_level: debug - type: git diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml deleted file mode 100644 index cba1cd0..0000000 --- a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - ubuntu-server-1404-x64: - roles: - - master - platform: ubuntu-14.04-amd64 - box : puppetlabs/ubuntu-14.04-64-nocm - box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm - hypervisor : vagrant -CONFIG: - log_level : debug - type: git diff --git a/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml deleted file mode 100644 index 23d9f70..0000000 --- a/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - ubuntu-server-1604-x64: - roles: - - master - platform: ubuntu-16.04-amd64 - box : puppetlabs/ubuntu-16.04-64-nocm - box_url : https://vagrantcloud.com/puppetlabs/ubuntu-16.04-64-nocm - hypervisor : vagrant -CONFIG: - log_level: debug - type: git diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 9a6e9e2..e6b15f8 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -6,48 +6,23 @@ context "on #{os}" do let(:facts) { facts } - case facts[:osfamily] + case facts[:os]['family'] when 'Debian' config_file = '/etc/monit/monitrc' config_dir = '/etc/monit/conf.d' monit_version = '5' - case facts[:lsbdistcodename] - when 'squeeze', 'lucid' - default_file_content = 'startup=1' - service_hasstatus = false - when 'wheezy', 'jessie', 'stretch', 'buster', 'precise', 'trusty', 'xenial', 'bionic' - default_file_content = 'START=yes' - service_hasstatus = true - else - raise 'unsupported operatingsystemmajrelease detected on Debian osfamily' - end + default_file_content = 'START=yes' + service_hasstatus = true when 'RedHat' config_dir = '/etc/monit.d' service_hasstatus = true - case facts[:operatingsystem] - when 'Amazon' - case facts[:operatingsystemmajrelease] - when '2016', '2018' - monit_version = '5' - config_file = '/etc/monit.conf' - else - raise 'unsupported operatingsystemmajrelease detected on Amazon Linux operating system' - end - else - case facts[:operatingsystemmajrelease] - when '5' - monit_version = '4' - config_file = '/etc/monit.conf' - when '6' - monit_version = '5' - config_file = '/etc/monit.conf' - when '7', '8' - monit_version = '5' - config_file = '/etc/monitrc' - else - raise 'unsupported operatingsystemmajrelease detected on RedHat osfamily' - end - end + monit_version = '5' + config_file = case facts[:os]['name'] + when 'Amazon' + '/etc/monit.conf' + else + '/etc/monitrc' + end else raise 'unsupported osfamily detected' end @@ -89,17 +64,17 @@ end monit_config_fixture = if monit_version == '4' - File.read(fixtures("monitrc.4.#{facts[:osfamily]}")) + File.read(fixtures("monitrc.4.#{facts[:os]['family']}")) else - File.read(fixtures("monitrc.#{facts[:osfamily]}")) + File.read(fixtures("monitrc.#{facts[:os]['family']}")) end it { is_expected.to contain_file('monit_config').with_content(monit_config_fixture) } - if facts[:osfamily] == 'Debian' + if facts[:os]['family'] == 'Debian' it do - is_expected.to contain_file('/etc/default/monit').with('notify' => 'Service[monit]') - .with_content(%r{^#{default_file_content}$}) + is_expected.to contain_file('/etc/default/monit').with('notify' => 'Service[monit]'). + with_content(%r{^#{default_file_content}$}) end else it { is_expected.not_to contain_file('/etc/default/monit') } @@ -128,11 +103,11 @@ context 'when httpd is set to valid bool ' do let(:params) { { httpd: true } } - content = <<-END.gsub(%r{^\s+\|}, '') - |set httpd port 2812 and - | use address localhost - | allow 0.0.0.0/0.0.0.0 - | allow admin:monit + content = <<~END + set httpd port 2812 and + use address localhost + allow 0.0.0.0/0.0.0.0 + allow admin:monit END it { is_expected.to contain_file('monit_config').with_content(%r{#{content}}) } end @@ -149,11 +124,11 @@ } end - content = <<-END.gsub(%r{^\s+\|}, '') - |set httpd port 2420 and - | use address otherhost - | allow 0.0.0.0/0.0.0.0 - | allow tester:Passw0rd + content = <<~END + set httpd port 2420 and + use address otherhost + allow 0.0.0.0/0.0.0.0 + allow tester:Passw0rd END it { is_expected.to contain_file('monit_config').with_content(%r{#{content}}) } end @@ -184,9 +159,9 @@ end it do - is_expected.to contain_firewall('2812 allow Monit inbound traffic').with('action' => 'accept', - 'dport' => '2812', - 'proto' => 'tcp') + is_expected.to contain_firewall('2812 allow Monit inbound traffic').with('jump' => 'accept', + 'dport' => '2812', + 'proto' => 'tcp') end end @@ -256,12 +231,12 @@ } end - content = <<-END.gsub(%r{^\s+\|}, '') - |set mail-format \{ - | from: monit\@test.local - | message: Monit \$ACTION \$SERVICE at \$DATE on \$HOST: \$DESCRIPTION - | subject: spectesting - |\} + content = <<~END + set mail-format { + from: monit@test.local + message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION + subject: spectesting + } END it { is_expected.to contain_file('monit_config').with_content(%r{#{Regexp.escape(content)}}) } end @@ -276,9 +251,9 @@ } end - content = <<-END.gsub(%r{^\s+\|}, '') - |set alert spec@test.local - |set alert tester@test.local + content = <<~END + set alert spec@test.local + set alert tester@test.local END it { is_expected.to contain_file('monit_config').with_content(%r{#{content}}) } end @@ -341,239 +316,4 @@ end end end - - describe 'failures' do - let(:facts) do - { - osfamily: 'Debian', - lsbdistcodename: 'squeeze', - monit_version: '5', - } - end - - [-1, 65_536].each do |value| - context "when httpd_port is set to invalid value <#{value}>" do - let(:params) do - { - httpd: true, - httpd_port: value, - httpd_address: 'otherhost', - httpd_user: 'tester', - httpd_password: 'Passw0rd', - } - end - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::PreformattedError, %r{expects an Integer\[1, 65535\] value}) - end - end - end - - context 'when check_interval is set to invalid value <0>' do - let(:params) { { check_interval: 0 } } - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::PreformattedError, %r{expects an Integer\[1}) - end - end - - context 'when start_delay is set to invalid value <0>' do - let(:params) { { start_delay: 0 } } - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::PreformattedError, %r{expects a value of type Undef or Integer\[1}) - end - end - - context 'when major release of Amazon Linux is unsupported' do - let :facts do - { osfamily: 'RedHat', - operatingsystem: 'Amazon', - operatingsystemmajrelease: '3', - monit_version: '5' } - end - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::Error, %r{monit supports Amazon Linux 2\. Detected operatingsystemmajrelease is <3>}) - end - end - - context 'when major release of EL is unsupported' do - let :facts do - { osfamily: 'RedHat', - operatingsystem: 'CentOS', - operatingsystemmajrelease: '4', - monit_version: '5' } - end - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::Error, %r{monit supports EL 5, 6 and 7\. Detected operatingsystemmajrelease is <4>}) - end - end - - context 'when major release of Debian is unsupported' do - let :facts do - { osfamily: 'Debian', - operatingsystemmajrelease: '4', - lsbdistcodename: 'etch', - monit_version: '5' } - end - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::Error, %r{monit supports Debian 6 \(squeeze\), 7 \(wheezy\), 8 \(jessie\), 9 \(stretch\) and 10 \(buster\) \ -and Ubuntu 10\.04 \(lucid\), 12\.04 \(precise\), 14\.04 \(trusty\), 16\.04 \(xenial\) and 18\.04 \(bionic\)\. \ -Detected lsbdistcodename is \.}) - end - end - - context 'when major release of Ubuntu is unsupported' do - let :facts do - { osfamily: 'Debian', - operatingsystemmajrelease: '8', - lsbdistcodename: 'hardy', - monit_version: '5' } - end - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::Error, %r{monit supports Debian 6 \(squeeze\), 7 \(wheezy\), 8 \(jessie\), 9 \(stretch\) and 10 \(buster\) \ -and Ubuntu 10\.04 \(lucid\), 12\.04 \(precise\), 14\.04 \(trusty\), 16\.04 \(xenial\) and 18\.04 \(bionic\). \ -Detected lsbdistcodename is \.}) - end - end - - context 'when osfamily is unsupported' do - let :facts do - { osfamily: 'Unsupported', - operatingsystemmajrelease: '9', - monit_version: '5' } - end - - it 'fails' do - expect { - is_expected.to contain_class('monit') - }.to raise_error(Puppet::Error, %r{monit supports osfamilies Debian and RedHat\. Detected osfamily is \.}) - end - end - end - - describe 'variable type and content validations' do - # set needed custom facts and variables - let(:facts) do - { - osfamily: 'Debian', - operatingsystemrelease: '6.0', - operatingsystemmajrelease: '6', - lsbdistcodename: 'squeeze', - monit_version: '5', - } - end - let(:validation_params) do - { - #:param => 'value', - } - end - - validations = { - 'absolute_path' => { - name: ['config_file', 'config_dir'], - valid: ['/absolute/filepath', '/absolute/directory/'], - invalid: ['invalid', 3, 2.42, ['array'], { 'ha' => 'sh' }], - message: '(expects a String value|is not an absolute path)', - }, - 'array' => { - name: ['alert_emails'], - valid: [['valid', 'array']], - invalid: ['string', { 'ha' => 'sh' }, 3, 2.42, true], - message: 'expects an Array value', - }, - 'bool_stringified' => { - name: ['httpd', 'manage_firewall', 'service_enable', 'service_manage', 'mmonit_https', 'mmonit_without_credential', 'config_dir_purge'], - valid: [true, 'true', false, 'false'], - invalid: ['invalid', 3, 2.42, ['array'], { 'ha' => 'sh' }, nil], - message: 'expects a value of type Boolean or Enum', - }, - 'integer' => { - name: ['check_interval', 'httpd_port', 'mmonit_port'], - valid: [242], - invalid: [2.42, 'invalid', ['array'], { 'ha' => 'sh ' }, true, false, nil], - message: 'expects an Integer', - }, - 'optional_integer' => { - name: ['start_delay'], - valid: [242], - invalid: [2.42, 'invalid', ['array'], { 'ha' => 'sh ' }, true, false, nil], - message: 'expects a value of type Undef or Integer', - }, - 'optional_logfile' => { - name: ['logfile'], - valid: ['/absolute/filepath', '/absolute/directory/', 'syslog', 'syslog facility log_local0'], - invalid: ['invalid', 3, 2.42, ['array'], { 'ha' => 'sh' }], - message: '(expects a value of type Undef or String|is not an absolute path)', - }, - 'optional_hash' => { - name: ['mailformat'], - valid: [{ 'ha' => 'sh' }], - invalid: ['string', 3, 2.42, ['array'], true, false, nil], - message: 'expects a value of type Undef or Hash', - }, - 'optional_string' => { - name: ['mailserver', 'mmonit_address'], - valid: ['present'], - invalid: [['array'], { 'ha' => 'sh' }], - message: 'expects a value of type Undef or String', - }, - 'string' => { - name: ['httpd_address', 'httpd_allow', 'httpd_user', 'httpd_password', - 'package_ensure', 'package_name', 'service_name', 'mmonit_user', - 'mmonit_password'], - valid: ['present'], - invalid: [['array'], { 'ha' => 'sh' }], - message: 'expects a String value', - }, - 'service_ensure_string' => { - name: ['service_ensure'], - valid: ['running'], - invalid: [['array'], { 'ha' => 'sh' }], - message: 'expects a match for Enum\[\'running\', \'stopped\'\]', - }, - } - - validations.sort.each do |type, var| - var[:name].each do |var_name| - var[:valid].each do |valid| - context "with #{var_name} (#{type}) set to valid #{valid} (as #{valid.class})" do - let(:params) { validation_params.merge(:"#{var_name}" => valid) } - - it { is_expected.to compile } - end - end - - var[:invalid].each do |invalid| - context "with #{var_name} (#{type}) set to invalid #{invalid} (as #{invalid.class})" do - let(:params) { validation_params.merge(:"#{var_name}" => invalid) } - - it 'fails' do - expect { - catalogue - }.to raise_error(Puppet::Error, %r{#{var[:message]}}) - end - end - end - end # var[:name].each - end # validations.sort.each - end # describe 'variable type and content validations' end diff --git a/spec/default_facts.yml b/spec/default_facts.yml deleted file mode 100644 index f777abf..0000000 --- a/spec/default_facts.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Use default_module_facts.yml for module specific facts. -# -# Facts specified here will override the values provided by rspec-puppet-facts. ---- -ipaddress: "172.16.254.254" -ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" -is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/check_spec.rb b/spec/defines/check_spec.rb index 1ec49e5..834fd28 100644 --- a/spec/defines/check_spec.rb +++ b/spec/defines/check_spec.rb @@ -2,171 +2,116 @@ describe 'monit::check' do let :pre_condition do - 'include ::monit' + 'include monit' end let(:title) { 'test' } - let(:facts) do - { - osfamily: 'Debian', - lsbdistcodename: 'squeeze', - monit_version: '5', - } - end - context 'with default values for parameters' do - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_class('monit') } - it do - is_expected.to contain_file('/etc/monit/conf.d/test').with('ensure' => 'present', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'source' => nil, - 'content' => nil, - 'notify' => 'Service[monit]', - 'require' => 'Package[monit]') - end - end - - ['absent', 'present'].each do |value| - context "with ensure set to valid <#{value}>" do - let(:params) do - { - ensure: value, - } + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts end - it do - is_expected.to contain_file('/etc/monit/conf.d/test').with('ensure' => value, - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'source' => nil, - 'content' => nil, - 'notify' => 'Service[monit]', - 'require' => 'Package[monit]') + confdir = if facts[:os]['family'] == 'RedHat' + '/etc/monit.d' + else + '/etc/monit/conf.d' + end + + context 'with default values for parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('monit') } + + it do + is_expected.to contain_file("#{confdir}/test").with('ensure' => 'present', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'source' => nil, + 'content' => nil, + 'notify' => 'Service[monit]', + 'require' => 'Package[monit]') + end end - end - end - context 'with content set to a valid value' do - content = <<-END.gsub(%r{^\s+\|}, '') - |check process ntpd with pidfile /var/run/ntpd.pid - |start program = "/etc/init.d/ntpd start" - |stop program = "/etc/init.d/ntpd stop" - |if failed host 127.0.0.1 port 123 type udp then alert - |if 5 restarts within 5 cycles then timeout - END - let(:params) do - { - content: content, - } - end - - it do - is_expected.to contain_file('/etc/monit/conf.d/test').with('ensure' => 'present', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'source' => nil, - 'content' => content, - 'notify' => 'Service[monit]', - 'require' => 'Package[monit]') - end - end - - context 'with source set to a valid value' do - let(:params) do - { - source: 'puppet:///modules/monit/ntp', - } - end - - it do - is_expected.to contain_file('/etc/monit/conf.d/test').with('ensure' => 'present', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'source' => 'puppet:///modules/monit/ntp', - 'content' => nil, - 'notify' => 'Service[monit]', - 'require' => 'Package[monit]') - end - end - - context 'with content and source set at the same time' do - let(:params) do - { - content: 'content', - source: 'puppet:///modules/subject/test', - } - end + %w[absent present].each do |value| + context "with ensure set to valid <#{value}>" do + let(:params) do + { + ensure: value, + } + end - it 'fails' do - expect { - catalogue - }.to raise_error(Puppet::Error, %r{Parameters source and content are mutually exclusive}) - end - end + it do + is_expected.to contain_file("#{confdir}/test").with('ensure' => value, + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'source' => nil, + 'content' => nil, + 'notify' => 'Service[monit]', + 'require' => 'Package[monit]') + end + end + end - describe 'variable type and content validations' do - # set needed custom facts and variables - let(:facts) do - { - osfamily: 'Debian', - lsbdistcodename: 'squeeze', - monit_version: '5', - } - end - let(:validation_params) do - { - #:param => 'value', - } - end + context 'with content set to a valid value' do + content = <<~END + check process ntpd with pidfile /var/run/ntpd.pid + start program = "/etc/init.d/ntpd start" + stop program = "/etc/init.d/ntpd stop" + if failed host 127.0.0.1 port 123 type udp then alert + if 5 restarts within 5 cycles then timeout + END + let(:params) do + { + content: content, + } + end - validations = { - 'regex_file_ensure' => { - name: ['ensure'], - valid: ['present', 'absent'], - invalid: ['file', 'directory', 'link', ['array'], { 'ha' => 'sh' }, 3, 2.42, true, false, nil], - message: 'match for Enum\[\'absent\', \'present\'\]', - }, - 'string' => { - name: ['content'], - valid: ['string'], - invalid: [['array'], { 'ha' => 'sh' }, 3, 2.42, true, false], - message: 'value of type Undef or String', - }, - 'string_file_source' => { - name: ['source'], - valid: ['puppet:///modules/subject/test'], - invalid: [['array'], { 'ha' => 'sh' }, 3, 2.42, true, false], - message: 'value of type Undef or String', - }, - } + it do + is_expected.to contain_file("#{confdir}/test").with('ensure' => 'present', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'source' => nil, + 'content' => content, + 'notify' => 'Service[monit]', + 'require' => 'Package[monit]') + end + end - validations.sort.each do |type, var| - var[:name].each do |var_name| - var[:valid].each do |valid| - context "with #{var_name} (#{type}) set to valid #{valid} (as #{valid.class})" do - let(:params) { validation_params.merge(:"#{var_name}" => valid) } + context 'with source set to a valid value' do + let(:params) do + { + source: 'puppet:///modules/monit/ntp', + } + end - it { is_expected.to compile } - end + it do + is_expected.to contain_file("#{confdir}/test").with('ensure' => 'present', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'source' => 'puppet:///modules/monit/ntp', + 'content' => nil, + 'notify' => 'Service[monit]', + 'require' => 'Package[monit]') end + end - var[:invalid].each do |invalid| - context "with #{var_name} (#{type}) set to invalid #{invalid} (as #{invalid.class})" do - let(:params) { validation_params.merge(:"#{var_name}" => invalid) } + context 'with content and source set at the same time' do + let(:params) do + { + content: 'content', + source: 'puppet:///modules/subject/test', + } + end - it 'fails' do - expect { - catalogue - }.to raise_error(Puppet::PreformattedError, %r{expects a #{var[:message]}}) - end - end + it 'fails' do + is_expected.to compile.and_raise_error(%r{Parameters source and content are mutually exclusive}) end - end # var[:name].each - end # validations.sort.each - end # describe 'variable type and content validations' + end + end + end end diff --git a/spec/setup_acceptance_node.pp b/spec/setup_acceptance_node.pp new file mode 100644 index 0000000..a620147 --- /dev/null +++ b/spec/setup_acceptance_node.pp @@ -0,0 +1,5 @@ +if $facts['os']['family'] == 'RedHat' { + package {'epel-release': + ensure => installed + } +} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 16764b6..7b6a562 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,62 +1,24 @@ # frozen_string_literal: true +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + RSpec.configure do |c| c.mock_with :rspec end -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' - -require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) - -include RspecPuppetFacts - -default_facts = { - puppetversion: Puppet.version, - facterversion: Facter.version, -} +# 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__)) -default_fact_files = [ - File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), - File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), -] +require 'voxpupuli/test/spec_helper' -default_fact_files.each do |f| - next unless File.exist?(f) && File.readable?(f) && File.size?(f) +add_mocked_facts! - begin - default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e - RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" +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 - -# read default_facts and merge them over what is provided by facterdb -default_facts.each do |fact, value| - add_custom_fact fact, value -end - -RSpec.configure do |c| - c.default_facts = default_facts - c.before :each do - # set to strictest setting for testing - # by default Puppet runs at warning level - Puppet.settings[:strict] = :warning - Puppet.settings[:strict_variables] = true - end - c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] - c.after(:suite) do - RSpec::Puppet::Coverage.report!(0) - end -end - -# Ensures that a module is defined -# @param module_name Name of the module -def ensure_module_defined(module_name) - module_name.split('::').reduce(Object) do |last_module, next_module| - last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) - last_module.const_get(next_module, false) - end -end - -# 'spec_overrides' from sync.yml will appear below this line +Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 21d10c5..2681792 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,22 +1,10 @@ -require 'beaker-rspec' -require 'pry' +# frozen_string_literal: true -hosts.each do |host| - # Install Puppet - on host, install_puppet -end +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -RSpec.configure do |c| - module_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) +require 'voxpupuli/acceptance/spec_helper_acceptance' - c.formatter = :documentation +configure_beaker(modules: :metadata) - # Configure all nodes in nodeset - c.before :suite do - # Install module - puppet_module_install(source: module_root, module_name: 'monit') - hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] - end - end -end +Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } diff --git a/spec/unit/facter/monit_version_spec.rb b/spec/unit/facter/monit_version_spec.rb index 8f64ccf..56ea2c4 100644 --- a/spec/unit/facter/monit_version_spec.rb +++ b/spec/unit/facter/monit_version_spec.rb @@ -1,23 +1,25 @@ require 'spec_helper' describe 'Facter::Util::Fact' do - before(:each) do + before do Facter.clear end context 'with monit v5.14 installed' do - before :each do + before do allow(Facter::Util::Resolution).to receive(:exec).with('monit -V 2>&1').and_return("This is Monit version 5.14\nCopyright (C) 2001-2015 Tildeslash Ltd. All Rights Reserved.") end + it 'returns 5.14' do expect(Facter.fact(:monit_version).value).to eq('5.14') end end context 'with monit not installed' do - before :each do + before do allow(Facter::Util::Resolution).to receive(:exec).with('monit -V 2>&1').and_return(nil) end + it 'is nil' do expect(Facter.fact(:monit_version).value).to be_nil end diff --git a/templates/monitrc.erb b/templates/monitrc.erb index eac9509..6b8a8d6 100644 --- a/templates/monitrc.erb +++ b/templates/monitrc.erb @@ -40,8 +40,8 @@ set httpd port <%= @httpd_port %> and <%- end -%> <%- end -%> <%- if @mmonit_address -%> -set mmonit http<% if @mmonit_https_bool %>s<%- end -%>://<%= @mmonit_user %>:<%= @mmonit_password %>@<%= @mmonit_address %>:<%= @mmonit_port %>/collector -<%- if @mmonit_without_credential_bool -%> and register without credentials<%- end -%> +set mmonit http<% if @mmonit_https %>s<%- end -%>://<%= @mmonit_user %>:<%= @mmonit_password %>@<%= @mmonit_address %>:<%= @mmonit_port %>/collector +<%- if @mmonit_without_credential -%> and register without credentials<%- end -%> <%- end -%> include <%= @config_dir -%>/*