diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2240a97..a6b64e0 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,281 +1,283 @@ # 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. [travis-ci](http://travis-ci.org) runs 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_VERSION="~> 5.5.6" ``` 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 bundle exec rake acceptance ``` This will run the tests on the module's default nodeset. You can override the nodeset used, e.g., ```sh BEAKER_set=centos-7-x64 bundle exec rake acceptance ``` There are default rake tasks for the various acceptance test modules, e.g., ```sh bundle exec rake beaker:centos-7-x64 bundle exec rake beaker:ssh:centos-7-x64 ``` If you don't want to have to recreate the virtual machine every time you can use `BEAKER_destroy=no` and `BEAKER_provision=no`. On the first run you will at least need `BEAKER_provision` set to yes (the default). The Vagrantfile for the created virtual machines will be in `.vagrant/beaker_vagrant_files`. Beaker also supports docker containers. We also use that in our automated CI pipeline at [travis-ci](http://travis-ci.org). To use that instead of Vagrant: ```sh PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian10-64{hypervisor=docker} BEAKER_destroy=yes bundle exec rake beaker ``` You can replace the string `debian10` with any common operating system. The following strings are known to work: * ubuntu1604 * ubuntu1804 * debian8 * debian9 * debian10 * centos6 * centos7 * centos8 The easiest way to debug in a docker container is to open a shell: ```sh docker exec -it -u root ${container_id_or_name} bash ``` 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/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..cacadf2 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Vox Pupuli Security Policy + +Our vulnerabilities reporting process is at https://voxpupuli.org/security/ diff --git a/.msync.yml b/.msync.yml index 8864fc0..4c7999c 100644 --- a/.msync.yml +++ b/.msync.yml @@ -1 +1 @@ -modulesync_config_version: '2.12.0' +modulesync_config_version: '3.0.0' diff --git a/.rubocop.yml b/.rubocop.yml index 0703f3b..c0fd488 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,550 +1,2 @@ -require: rubocop-rspec -AllCops: -# Puppet Server 5 defaults to jruby 1.7 so TargetRubyVersion must stay at 1.9 until we drop support for puppet 5 - TargetRubyVersion: 1.9 - Include: - - ./**/*.rb - Exclude: - - files/**/* - - vendor/**/* - - .vendor/**/* - - pkg/**/* - - spec/fixtures/**/* - - Gemfile - - Rakefile - - Guardfile - - Vagrantfile -Lint/ConditionPosition: - Enabled: True - -Lint/ElseLayout: - Enabled: True - -Lint/UnreachableCode: - Enabled: True - -Lint/UselessComparison: - Enabled: True - -Lint/EnsureReturn: - Enabled: True - -Lint/HandleExceptions: - Enabled: True - -Lint/LiteralInCondition: - Enabled: True - -Lint/ShadowingOuterLocalVariable: - Enabled: True - -Lint/LiteralInInterpolation: - Enabled: True - -Style/HashSyntax: - Enabled: True - -Style/RedundantReturn: - Enabled: True - -Layout/EndOfLine: - Enabled: False - -Lint/AmbiguousOperator: - Enabled: True - -Lint/AssignmentInCondition: - Enabled: True - -Layout/SpaceBeforeComment: - Enabled: True - -Style/AndOr: - Enabled: True - -Style/RedundantSelf: - Enabled: True - -Metrics/BlockLength: - Enabled: False - -# 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/SpaceInsideBrackets: - 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/TrailingCommaInLiteral: - 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/OpMethod: - 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 - -Style/ModuleFunction: - Enabled: True - -Lint/Debugger: - Enabled: True - -Style/IfWithSemicolon: - Enabled: True - -Style/Encoding: - Enabled: True - -Style/BlockDelimiters: - Enabled: True - -Layout/MultilineBlockLayout: - Enabled: True - -# 'Complexity' is very relative -Metrics/AbcSize: - Enabled: False - -# 'Complexity' is very relative -Metrics/PerceivedComplexity: - Enabled: False - -Lint/UselessAssignment: - Enabled: True - -Layout/ClosingParenthesisIndentation: - Enabled: True - -# RSpec - -RSpec/BeforeAfterAll: - Exclude: - - spec/acceptance/**/* - -# 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/NamedSubject: - Enabled: False - -# disabled for now since they cause a lot of issues -# these issues aren't easy to fix -RSpec/RepeatedDescription: - Enabled: False - -RSpec/NestedGroups: - Enabled: False - -# this is broken on ruby1.9 -Layout/IndentHeredoc: - Enabled: False - -# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs -Security/YAMLLoad: - Enabled: false - -# This affects hiera interpolation, as well as some configs that we push. -Style/FormatStringToken: - Enabled: false - -# This is useful, but sometimes a little too picky about where unit tests files -# are located. -RSpec/FilePath: - Enabled: false - -# silence it to support older jruby (<= v1.9) which can not handle e.g. %i[] -Style/WordArray: - Enabled: false +inherit_gem: + voxpupuli-test: rubocop.yml diff --git a/.sync.yml b/.sync.yml index 7b7ea57..ee4d72e 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,15 +1,17 @@ --- .travis.yml: secure: "C+dXd27/doW1JnKqv+UDHL6/HBI5Te+xGsaoPkqhpO4iXfMxJrTi6sBWaEuyNTeHIwN8wOWHaW9qKEqTuYZ0/k+k3SWFmZpi3jSh79Y8WDoYK7+DsbKQ6xZy54Sh56YIYXfkaLQYYYrqKKksZ57h/NYU/hzu9h8oH+PnXfGT6i/KH9C4z8IR9qTxIiErrJHUMni9CryTTbtGV9pIj0QTZP+OQLoE660J8/uMsfTQDK9/NqQ2nsTaQ12SS9xg6MmmOX7W4NhRrOyIi0sd7eR0dRIoVf0TwfYhw8Yi4aDuTZIHNtcHiyfAVsvh3RpAr5d01GjXEr5lj0XyBOu8t1U3BzPU7LrJRrwE+ZmP72L39vrT7rmDRz9pDU7fVIOiRtqRLEJRDIW4I2ISkwBdzFKX8UTozTkPEmt9Iy+uKX5n2y8re2KFaseXWxTeVJbHh+DsJQ/hWsUNrHcl2dKmtgo7xHSonmevnATVV1vUbwvswm1oEiAFRdhF4gNdC8I6OGlVzmzwMbwqiGUk/nRBQeMEbyeRQV54QV3zteuBiHc8neQPR+QiD7diR2d4JhmDbr6xop+Bat2SVQqLg2IdAJ/Qu1Aor7mxhmPqiz35SWkbaaoDJYbWrCBeQ+jos4s2jCDY7OJEXW8ng9gPO71W/lcybMWzihUw6fA9w/riHe37Ez0=" docker_sets: - set: debian8-64 - set: debian9-64 - set: debian10-64 - set: ubuntu1604-64 - set: ubuntu1804-64 - set: centos6-64 - set: centos7-64 Gemfile: optional: ':test': - gem: 'toml' +spec/spec_helper_acceptance.rb: + unmanaged: false diff --git a/.travis.yml b/.travis.yml index a2d892e..4578f0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,103 +1,104 @@ --- -dist: bionic +os: linux +dist: focal language: ruby cache: bundler before_install: - yes | gem update --system - bundle --version script: - 'bundle exec rake $CHECK' -matrix: +jobs: fast_finish: true include: - rvm: 2.4.4 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 5.0" CHECK=test - rvm: 2.5.3 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls - rvm: 2.5.3 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 6.0" CHECK=rubocop - rvm: 2.4.4 bundler_args: --without system_tests development release env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian8-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=debian8-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian8-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=debian8-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=debian9-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=debian9-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian10-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=debian10-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian10-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=debian10-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=ubuntu1604-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu1604-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=ubuntu1804-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu1804-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos6-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=centos6-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos6-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=centos6-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=centos7-64 CHECK=beaker services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=centos7-64 CHECK=beaker services: docker branches: only: - master - /^v\d/ notifications: email: false webhooks: https://voxpupu.li/incoming/travis irc: on_success: always on_failure: always channels: - "chat.freenode.org#voxpupuli-notifications" deploy: provider: puppetforge - user: puppet + username: puppet password: secure: "C+dXd27/doW1JnKqv+UDHL6/HBI5Te+xGsaoPkqhpO4iXfMxJrTi6sBWaEuyNTeHIwN8wOWHaW9qKEqTuYZ0/k+k3SWFmZpi3jSh79Y8WDoYK7+DsbKQ6xZy54Sh56YIYXfkaLQYYYrqKKksZ57h/NYU/hzu9h8oH+PnXfGT6i/KH9C4z8IR9qTxIiErrJHUMni9CryTTbtGV9pIj0QTZP+OQLoE660J8/uMsfTQDK9/NqQ2nsTaQ12SS9xg6MmmOX7W4NhRrOyIi0sd7eR0dRIoVf0TwfYhw8Yi4aDuTZIHNtcHiyfAVsvh3RpAr5d01GjXEr5lj0XyBOu8t1U3BzPU7LrJRrwE+ZmP72L39vrT7rmDRz9pDU7fVIOiRtqRLEJRDIW4I2ISkwBdzFKX8UTozTkPEmt9Iy+uKX5n2y8re2KFaseXWxTeVJbHh+DsJQ/hWsUNrHcl2dKmtgo7xHSonmevnATVV1vUbwvswm1oEiAFRdhF4gNdC8I6OGlVzmzwMbwqiGUk/nRBQeMEbyeRQV54QV3zteuBiHc8neQPR+QiD7diR2d4JhmDbr6xop+Bat2SVQqLg2IdAJ/Qu1Aor7mxhmPqiz35SWkbaaoDJYbWrCBeQ+jos4s2jCDY7OJEXW8ng9gPO71W/lcybMWzihUw6fA9w/riHe37Ez0=" on: tags: true # all_branches is required to use tags all_branches: true # Only publish the build marked with "DEPLOY_TO_FORGE" condition: "$DEPLOY_TO_FORGE = yes" diff --git a/Gemfile b/Gemfile index 2128b39..06972c6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,69 +1,49 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" 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 group :test do - gem 'voxpupuli-test', '>= 1.0.0', :require => false - gem 'coveralls', :require => false - gem 'simplecov-console', :require => false - gem 'toml', :require => false + gem 'voxpupuli-test', '~> 2.1', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'toml', :require => false end group :development do gem 'travis', :require => false gem 'travis-lint', :require => false gem 'guard-rake', :require => false gem 'overcommit', '>= 0.39.1', :require => false end group :system_tests do - gem 'winrm', :require => false - if beaker_version = ENV['BEAKER_VERSION'] - gem 'beaker', *location_for(beaker_version) - else - gem 'beaker', '>= 4.2.0', :require => false - 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 'serverspec', :require => false - gem 'beaker-hostgenerator', '>= 1.1.22', :require => false - gem 'beaker-docker', :require => false - gem 'beaker-puppet', :require => false - gem 'beaker-puppet_install_helper', :require => false - gem 'beaker-module_install_helper', :require => false - gem 'rbnacl', '>= 4', :require => false - gem 'rbnacl-libsodium', :require => false - gem 'bcrypt_pbkdf', :require => false - gem 'ed25519', :require => false + gem 'voxpupuli-acceptance', :require => false end group :release do gem 'github_changelog_generator', :require => false, :git => 'https://github.com/voxpupuli/github-changelog-generator', :branch => 'voxpupuli_essential_fixes' gem 'puppet-blacksmith', :require => false gem 'voxpupuli-release', :require => false gem 'puppet-strings', '>= 2.2', :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] end ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 6.0' : puppetversion = ENV['PUPPET_VERSION'].to_s gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/lib/puppet/type/grafana_ldap_config.rb b/lib/puppet/type/grafana_ldap_config.rb index f007d32..4b54287 100644 --- a/lib/puppet/type/grafana_ldap_config.rb +++ b/lib/puppet/type/grafana_ldap_config.rb @@ -1,184 +1,184 @@ require 'toml' Puppet::Type.newtype(:grafana_ldap_config) do @doc = 'Manage Grafana LDAP configuration' @toml_header = <<-EOF # # Grafana LDAP configuration # # generated by Puppet module puppet-grafana # https://github.com/voxpupuli/puppet-grafana # # *** Edit at your own peril *** # # ############################################# # EOF # currently not ensurable as we are not parsing the LDAP toml config. # ensurable newparam(:title, namevar: true) do desc 'Path to ldap.toml' validate do |value| raise ArgumentError, _('name/title must be a String') unless value.is_a?(String) end end newparam(:owner) do desc 'Owner of the LDAP configuration-file either as String or Integer (default: root)' defaultto 'root' validate do |value| raise ArgumentError, _('owner must be a String or Integer') unless value.is_a?(String) || value.is_a?(Integer) end end newparam(:group) do desc 'Group of the LDAP configuration file either as String or Integer (default: grafana)' defaultto 'grafana' validate do |value| raise ArgumentError, _('group must be a String or Integer') unless value.is_a?(String) || value.is_a?(Integer) end end newparam(:mode) do desc 'File-permissions mode of the LDAP configuration file as String' defaultto '0440' validate do |value| raise ArgumentError, _('file-permissions must be a String') unless value.is_a?(String) raise ArgumentError, _('file-permissions must be a String') if value.empty? # regex-pattern stolen from here - all credis to them! # https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/types/filemode.pp # currently disabled, as it fails when implicitly called. # # raise ArgumentError, _('file-permissions is not valid') unless value.to_s.match(%r{/\A(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))\z/}) end end newparam(:replace, boolean: true, parent: Puppet::Parameter::Boolean) do desc 'Replace existing files' defaultto true end newparam(:backup, boolean: true, parent: Puppet::Parameter::Boolean) do desc 'Backup existing files before replacing them into the file-bucket' defaultto false end newparam(:validate_cmd) do desc 'A command to validate the new Grafana LDAP configuration before actually replacing it' validate do |value| raise ArgumentError, _('validate_cmd must be a String or undef') unless value.nil? || value.is_a?(String) end end def ldap_servers catalog.resources.each_with_object({}) do |resource, memo| next unless resource.is_a?(Puppet::Type.type(:grafana_ldap_server)) next unless resource[:name].is_a?(String) memo[resource[:name]] = resource memo end end def should_content return @generated_config if @generated_config @generated_config = {} ldap_servers.each do |server_k, server_v| # convert symbols to strings server_params = Hash[server_v.original_parameters.map { |k, v| [k.to_s, v] }] server_attributes = server_params['attributes'] server_params.delete('attributes') # grafana-syntax for multiple hosts is a space-separate list. server_params['host'] = server_params['hosts'].join(' ') server_params.delete('hosts') server_group_mappings = server_v.group_mappings server_block = { 'servers' => [server_params], 'servers.attributes' => server_attributes, 'servers.group_mappings' => server_group_mappings }.compact @generated_config[server_k] = server_block end @generated_config.compact end def generate file_opts = {} # currently not ensurable # file_opts = { # ensure: (self[:ensure] == :absent) ? :absent : :file, # } [:name, :owner, :group, :mode, :replace, :backup, # this we have currently not implemented # :selinux_ignore_defaults, # :selrange, # :selrole, # :seltype, # :seluser, # :show_diff, :validate_cmd].each do |param| file_opts[param] = self[param] unless self[param].nil? end metaparams = Puppet::Type.metaparams - excluded_metaparams = ['before', 'notify', 'require', 'subscribe', 'tag'] + excluded_metaparams = %w[before notify require subscribe tag] metaparams.reject! { |param| excluded_metaparams.include? param } metaparams.each do |metaparam| file_opts[metaparam] = self[metaparam] unless self[metaparam].nil? end [Puppet::Type.type(:file).new(file_opts)] end def eval_generate ldap_servers = should_content if !ldap_servers.nil? && !ldap_servers.empty? toml_contents = [] toml_contents << @toml_header toml_contents << ldap_servers.map do |k, v| str = [] str << "\n\n" str << <<-EOF # # #{k} # EOF str << TOML::Generator.new(v).body str.join end catalog.resource("File[#{self[:name]}]")[:content] = toml_contents.join end [catalog.resource("File[#{self[:name]}]")] end autonotify(:class) do 'grafana::service' end end diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index cc512af..9cabed9 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,142 +1,145 @@ require 'spec_helper_acceptance' describe 'grafana class' do # Create dummy module directorty shell('mkdir -p /etc/puppetlabs/code/environments/production/modules/my_custom_module/files/dashboards') context 'default parameters' do + before do + install_module_from_forge('puppetlabs/apt', '>= 7.5.0 < 8.0.0') + end # Using puppet_apply as a helper it 'works idempotently with no errors' do pp = <<-EOS class { 'grafana': } EOS # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe package('grafana') do it { is_expected.to be_installed } end describe service('grafana-server') do it { is_expected.to be_enabled } it { is_expected.to be_running } end end context 'with fancy dashboard config' do it 'works idempotently with no errors' do pp = <<-EOS class { 'grafana': provisioning_datasources => { apiVersion => 1, datasources => [ { name => 'Prometheus', type => 'prometheus', access => 'proxy', url => 'http://localhost:9090/prometheus', isDefault => false, }, ], }, provisioning_dashboards => { apiVersion => 1, providers => [ { name => 'default', orgId => 1, folder => '', type => 'file', disableDeletion => true, options => { path => '/var/lib/grafana/dashboards', puppetsource => 'puppet:///modules/my_custom_module/dashboards', }, }, ], } } EOS # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end end context 'with fancy dashboard config and custom target file' do it 'works idempotently with no errors' do pp = <<-EOS class { 'grafana': provisioning_datasources => { apiVersion => 1, datasources => [ { name => 'Prometheus', type => 'prometheus', access => 'proxy', url => 'http://localhost:9090/prometheus', isDefault => false, }, ], }, provisioning_dashboards => { apiVersion => 1, providers => [ { name => 'default', orgId => 1, folder => '', type => 'file', disableDeletion => true, options => { path => '/var/lib/grafana/dashboards', puppetsource => 'puppet:///modules/my_custom_module/dashboards', }, }, ], }, provisioning_dashboards_file => '/etc/grafana/provisioning/dashboards/dashboard.yaml', provisioning_datasources_file => '/etc/grafana/provisioning/datasources/datasources.yaml' } EOS # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end end context 'beta release' do it 'works idempotently with no errors' do case fact('os.family') when 'Debian' pp = <<-EOS class { 'grafana': version => '6.0.0-beta3', repo_name => 'beta', } EOS when 'RedHat' pp = <<-EOS class { 'grafana': version => '6.0.0', rpm_iteration => 'beta3', repo_name => 'beta', } EOS end # Run it twice and test for idempotency apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe package('grafana') do it { is_expected.to be_installed } end end end diff --git a/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml b/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml deleted file mode 100644 index 19dd43e..0000000 --- a/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -# -# Additional ~/.fog config file with AWS EC2 credentials -# required. -# -# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md -# -# Amazon Linux is not a RHEL clone. -# -HOSTS: - amazonlinux-2016091-x64: - roles: - - master - platform: centos-6-x86_64 - hypervisor: ec2 - # refers to image_tempaltes.yaml AMI[vmname] entry: - vmname: amazonlinux-2016091-eu-central-1 - # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: - snapshot: aio - # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): - amisize: t2.micro - # required so that beaker sanitizes sshd_config and root authorized_keys: - user: ec2-user -CONFIG: - type: aio - :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml -... -# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/image_templates.yaml b/spec/acceptance/nodesets/ec2/image_templates.yaml deleted file mode 100644 index e50593e..0000000 --- a/spec/acceptance/nodesets/ec2/image_templates.yaml +++ /dev/null @@ -1,34 +0,0 @@ -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -# -# see also: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md -# -# Hint: image IDs (ami-*) for the same image are different per location. -# -AMI: - # Amazon Linux AMI 2016.09.1 (HVM), SSD Volume Type - amazonlinux-2016091-eu-central-1: - :image: - :aio: ami-af0fc0c0 - :region: eu-central-1 - # Red Hat Enterprise Linux 7.3 (HVM), SSD Volume Type - rhel-73-eu-central-1: - :image: - :aio: ami-e4c63e8b - :region: eu-central-1 - # SUSE Linux Enterprise Server 12 SP2 (HVM), SSD Volume Type - sles-12sp2-eu-central-1: - :image: - :aio: ami-c425e4ab - :region: eu-central-1 - # Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ubuntu-1604-eu-central-1: - :image: - :aio: ami-fe408091 - :region: eu-central-1 - # Microsoft Windows Server 2016 Base - windows-2016-base-eu-central-1: - :image: - :aio: ami-88ec20e7 - :region: eu-central-1 diff --git a/spec/acceptance/nodesets/ec2/rhel-73-x64.yml b/spec/acceptance/nodesets/ec2/rhel-73-x64.yml deleted file mode 100644 index 7fac823..0000000 --- a/spec/acceptance/nodesets/ec2/rhel-73-x64.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -# -# Additional ~/.fog config file with AWS EC2 credentials -# required. -# -# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md -# -HOSTS: - rhel-73-x64: - roles: - - master - platform: el-7-x86_64 - hypervisor: ec2 - # refers to image_tempaltes.yaml AMI[vmname] entry: - vmname: rhel-73-eu-central-1 - # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: - snapshot: aio - # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): - amisize: t2.micro - # required so that beaker sanitizes sshd_config and root authorized_keys: - user: ec2-user -CONFIG: - type: aio - :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml -... -# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml b/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml deleted file mode 100644 index 8542154..0000000 --- a/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -# -# Additional ~/.fog config file with AWS EC2 credentials -# required. -# -# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md -# -HOSTS: - sles-12sp2-x64: - roles: - - master - platform: sles-12-x86_64 - hypervisor: ec2 - # refers to image_tempaltes.yaml AMI[vmname] entry: - vmname: sles-12sp2-eu-central-1 - # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: - snapshot: aio - # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): - amisize: t2.micro - # required so that beaker sanitizes sshd_config and root authorized_keys: - user: ec2-user -CONFIG: - type: aio - :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml -... -# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml b/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml deleted file mode 100644 index 9cf59d5..0000000 --- a/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -# -# Additional ~/.fog config file with AWS EC2 credentials -# required. -# -# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md -# -HOSTS: - ubuntu-1604-x64: - roles: - - master - platform: ubuntu-16.04-amd64 - hypervisor: ec2 - # refers to image_tempaltes.yaml AMI[vmname] entry: - vmname: ubuntu-1604-eu-central-1 - # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: - snapshot: aio - # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): - amisize: t2.micro - # required so that beaker sanitizes sshd_config and root authorized_keys: - user: ubuntu -CONFIG: - type: aio - :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml -... -# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml b/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml deleted file mode 100644 index 0932e29..0000000 --- a/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -# This file is managed via modulesync -# https://github.com/voxpupuli/modulesync -# https://github.com/voxpupuli/modulesync_config -# -# Additional ~/.fog config file with AWS EC2 credentials -# required. -# -# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md -# -HOSTS: - windows-2016-base-x64: - roles: - - master - platform: windows-2016-64 - hypervisor: ec2 - # refers to image_tempaltes.yaml AMI[vmname] entry: - vmname: windows-2016-base-eu-central-1 - # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: - snapshot: aio - # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): - amisize: t2.micro - # required so that beaker sanitizes sshd_config and root authorized_keys: - user: ec2-user -CONFIG: - type: aio - :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml -... -# vim: syntax=yaml diff --git a/spec/grafana_dashboard_permission_type_spec.rb b/spec/grafana_dashboard_permission_type_spec.rb index 0341a88..5e45622 100644 --- a/spec/grafana_dashboard_permission_type_spec.rb +++ b/spec/grafana_dashboard_permission_type_spec.rb @@ -1,62 +1,60 @@ require 'spec_helper' describe Puppet::Type.type(:grafana_dashboard_permission) do let(:gpermission) do described_class.new( title: 'foo_title', grafana_url: 'http://example.com/', grafana_api_path: '/api', user: 'foo_user', dashboard: 'foo_dashboard', permission: 'View', ensure: :present ) end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new title: 'foo_title', name: 'foo', grafana_url: 'example.com', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid URL}) end it "fails if grafana_api_path isn't properly formed" do expect do described_class.new title: 'foo_title', grafana_url: 'http://example.com', grafana_api_path: '/invalidpath', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid API path}) end it 'fails if both user and team set' do expect do described_class.new title: 'foo title', user: 'foo_user', team: 'foo_team' end.to raise_error(Puppet::Error, %r{Only user or team can be set, not both}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gpermission[:user]).to eq('foo_user') expect(gpermission[:grafana_api_path]).to eq('/api') expect(gpermission[:grafana_url]).to eq('http://example.com/') expect(gpermission[:dashboard]).to eq('foo_dashboard') end # rubocop:enable RSpec/MultipleExpectations it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gpermission relationship = gpermission.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gpermission.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gpermission expect(gpermission.autorequire).to be_empty end end end diff --git a/spec/grafana_membership_type_spec.rb b/spec/grafana_membership_type_spec.rb index 31ded64..b0ef316 100644 --- a/spec/grafana_membership_type_spec.rb +++ b/spec/grafana_membership_type_spec.rb @@ -1,64 +1,62 @@ require 'spec_helper' describe Puppet::Type.type(:grafana_membership) do let(:gmembership) do described_class.new( title: 'foo_title', user_name: 'foo_user', target_name: 'foo_target', grafana_url: 'http://example.com/', grafana_api_path: '/api', membership_type: 'organization', role: 'Viewer', ensure: :present ) end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new title: 'foo_title', name: 'foo', grafana_url: 'example.com', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid URL}) end it "fails if grafana_api_path isn't properly formed" do expect do described_class.new title: 'foo_title', grafana_url: 'http://example.com', grafana_api_path: '/invalidpath', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid API path}) end it 'fails if membership type not valid' do expect do described_class.new title: 'foo title', membership_type: 'foo' end.to raise_error(Puppet::Error, %r{Invalid value "foo"}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gmembership[:user_name]).to eq('foo_user') expect(gmembership[:target_name]).to eq('foo_target') expect(gmembership[:grafana_api_path]).to eq('/api') expect(gmembership[:grafana_url]).to eq('http://example.com/') expect(gmembership[:membership_type]).to eq(:organization) end # rubocop:enable RSpec/MultipleExpectations it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gmembership relationship = gmembership.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gmembership.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gmembership expect(gmembership.autorequire).to be_empty end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b2b2704..d266f6b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,18 @@ # This file is managed via modulesync # https://github.com/voxpupuli/modulesync # https://github.com/voxpupuli/modulesync_config # 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', __FILE__)) require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) - facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml'))) + facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) if facts facts.each do |name, value| add_custom_fact name.to_sym, value end end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index d2d9537..bec34fd 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,24 +1,6 @@ -require 'beaker-rspec' -require 'beaker-puppet' -require 'beaker/puppet_install_helper' -require 'beaker/module_install_helper' +# This file is completely managed via modulesync +require 'voxpupuli/acceptance/spec_helper_acceptance' -run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' +configure_beaker -RSpec.configure do |c| - # Readable test descriptions - c.formatter = :documentation - - # Configure all nodes in nodeset - c.before :suite do - install_module - install_module_dependencies - - hosts.each do |host| - if fact_on(host, 'osfamily') == 'Debian' - # Install additional modules for soft deps - install_module_from_forge('puppetlabs-apt', '>= 4.1.0 < 8.0.0') - end - end - end -end +Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } diff --git a/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb b/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb index a2a59fb..68c52a9 100644 --- a/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb +++ b/spec/unit/puppet/provider/grafana_plugin/grafana_cli_spec.rb @@ -1,74 +1,73 @@ require 'spec_helper' provider_class = Puppet::Type.type(:grafana_plugin).provider(:grafana_cli) describe provider_class do let(:resource) do Puppet::Type::Grafana_plugin.new( name: 'grafana-wizzle' ) end let(:provider) { provider_class.new(resource) } describe '#instances' do let(:plugins_ls_two) do # rubocop:disable Layout/TrailingWhitespace <<-PLUGINS installed plugins: grafana-simple-json-datasource @ 1.3.4 jdbranham-diagram-panel @ 1.4.0 Restart grafana after installing plugins . PLUGINS # rubocop:enable Layout/TrailingWhitespace end let(:plugins_ls_none) do <<-PLUGINS Restart grafana after installing plugins . PLUGINS end - # rubocop:disable RSpec/MultipleExpectations it 'has the correct names' do allow(provider_class).to receive(:grafana_cli).with('plugins', 'ls').and_return(plugins_ls_two) expect(provider_class.instances.map(&:name)).to match_array(['grafana-simple-json-datasource', 'jdbranham-diagram-panel']) expect(provider_class).to have_received(:grafana_cli) end it 'does not match if there are no plugins' do allow(provider_class).to receive(:grafana_cli).with('plugins', 'ls').and_return(plugins_ls_none) expect(provider_class.instances.size).to eq(0) expect(provider.exists?).to eq(false) expect(provider_class).to have_received(:grafana_cli) end # rubocop:enable RSpec/MultipleExpectations end it '#create' do allow(provider).to receive(:grafana_cli) provider.create expect(provider).to have_received(:grafana_cli).with('plugins', 'install', 'grafana-wizzle') end it '#destroy' do allow(provider).to receive(:grafana_cli) provider.destroy expect(provider).to have_received(:grafana_cli).with('plugins', 'uninstall', 'grafana-wizzle') end describe 'create with repo' do let(:resource) do Puppet::Type::Grafana_plugin.new( name: 'grafana-plugin', repo: 'https://nexus.company.com/grafana/plugins' ) end it '#create with repo' do allow(provider).to receive(:grafana_cli) provider.create expect(provider).to have_received(:grafana_cli).with('--repo https://nexus.company.com/grafana/plugins', 'plugins', 'install', 'grafana-plugin') end end end diff --git a/spec/unit/puppet/type/grafana_dashboard_type_spec.rb b/spec/unit/puppet/type/grafana_dashboard_type_spec.rb index 18f9a88..a59d53e 100644 --- a/spec/unit/puppet/type/grafana_dashboard_type_spec.rb +++ b/spec/unit/puppet/type/grafana_dashboard_type_spec.rb @@ -1,63 +1,61 @@ # Copyright 2015 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'spec_helper' describe Puppet::Type.type(:grafana_dashboard) do let(:gdashboard) do described_class.new name: 'foo', grafana_url: 'http://example.com/', content: '{}', ensure: :present end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new name: 'foo', grafana_url: 'example.com', content: '{}', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid URL}) end it "fails if content isn't provided" do expect do described_class.new name: 'foo', grafana_url: 'http://example.com', ensure: :present end.to raise_error(Puppet::Error, %r{content is required}) end it "fails if content isn't JSON" do expect do described_class.new name: 'foo', grafana_url: 'http://example.com/', content: '{invalid', ensure: :present end.to raise_error(Puppet::Error, %r{Invalid JSON}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gdashboard[:name]).to eq('foo') expect(gdashboard[:grafana_url]).to eq('http://example.com/') expect(gdashboard[:content]).to eq({}) end it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gdashboard relationship = gdashboard.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gdashboard.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gdashboard expect(gdashboard.autorequire).to be_empty end end end diff --git a/spec/unit/puppet/type/grafana_datasource_type_spec.rb b/spec/unit/puppet/type/grafana_datasource_type_spec.rb index 1bad7e8..80f75e3 100644 --- a/spec/unit/puppet/type/grafana_datasource_type_spec.rb +++ b/spec/unit/puppet/type/grafana_datasource_type_spec.rb @@ -1,95 +1,94 @@ # Copyright 2015 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'spec_helper' describe Puppet::Type.type(:grafana_datasource) do let(:gdatasource) do described_class.new( name: 'foo', grafana_url: 'http://example.com', url: 'http://es.example.com', type: 'elasticsearch', organization: 'test_org', access_mode: 'proxy', is_default: true, basic_auth: true, basic_auth_user: 'user', basic_auth_password: 'password', with_credentials: true, database: 'test_db', user: 'db_user', password: 'db_password', json_data: { esVersion: 5, timeField: '@timestamp', timeInterval: '1m' }, secure_json_data: { password: '5ecretPassw0rd' } ) end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new name: 'foo', grafana_url: 'example.com', content: '{}', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid URL}) end it "fails if json_data isn't valid" do expect do described_class.new name: 'foo', grafana_url: 'http://example.com', json_data: 'invalid', ensure: :present end.to raise_error(Puppet::Error, %r{json_data should be a Hash}) end it "fails if secure_json_data isn't valid" do expect do described_class.new name: 'foo', grafana_url: 'http://example.com', secure_json_data: 'invalid', ensure: :present end.to raise_error(Puppet::Error, %r{json_data should be a Hash}) end - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gdatasource[:name]).to eq('foo') expect(gdatasource[:grafana_url]).to eq('http://example.com') expect(gdatasource[:url]).to eq('http://es.example.com') expect(gdatasource[:type]).to eq('elasticsearch') expect(gdatasource[:organization]).to eq('test_org') expect(gdatasource[:access_mode]).to eq(:proxy) expect(gdatasource[:is_default]).to eq(:true) expect(gdatasource[:basic_auth]).to eq(:true) expect(gdatasource[:basic_auth_user]).to eq('user') expect(gdatasource[:basic_auth_password]).to eq('password') expect(gdatasource[:with_credentials]).to eq(:true) expect(gdatasource[:database]).to eq('test_db') expect(gdatasource[:user]).to eq('db_user') expect(gdatasource[:password]).to eq('db_password') expect(gdatasource[:json_data]).to eq(esVersion: 5, timeField: '@timestamp', timeInterval: '1m') expect(gdatasource[:secure_json_data]).to eq(password: '5ecretPassw0rd') end # rubocop:enable RSpec/MultipleExpectations it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gdatasource relationship = gdatasource.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gdatasource.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gdatasource expect(gdatasource.autorequire).to be_empty end end end diff --git a/spec/unit/puppet/type/grafana_folder_type_spec.rb b/spec/unit/puppet/type/grafana_folder_type_spec.rb index bb26999..7d01ac1 100644 --- a/spec/unit/puppet/type/grafana_folder_type_spec.rb +++ b/spec/unit/puppet/type/grafana_folder_type_spec.rb @@ -1,56 +1,54 @@ # Copyright 2015 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'spec_helper' describe Puppet::Type.type(:grafana_folder) do let(:gfolder) do described_class.new name: 'foo', grafana_url: 'http://example.com/', ensure: :present end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new name: 'foo', grafana_url: 'example.com', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid URL}) end it "fails if grafana_api_path isn't properly formed" do expect do described_class.new name: 'foo', grafana_url: 'http://example.com', grafana_api_path: '/invalidpath', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid API path}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gfolder[:name]).to eq('foo') expect(gfolder[:grafana_url]).to eq('http://example.com/') end it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gfolder relationship = gfolder.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gfolder.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gfolder expect(gfolder.autorequire).to be_empty end end end diff --git a/spec/unit/puppet/type/grafana_ldap_config_spec.rb b/spec/unit/puppet/type/grafana_ldap_config_spec.rb index e8a32ed..c917c28 100644 --- a/spec/unit/puppet/type/grafana_ldap_config_spec.rb +++ b/spec/unit/puppet/type/grafana_ldap_config_spec.rb @@ -1,164 +1,164 @@ # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'spec_helper' - +# rubocop:disable RSpec/VoidExpect describe Puppet::Type.type(:grafana_ldap_config) do # resource title context 'validate resource title' do it 'fails if title is not set' do expect do described_class.new name: nil end.to raise_error(Puppet::Error, %r{Title or name must be provided}) end it 'fails if title is not a string' do expect do described_class.new name: 123 end.to raise_error(Puppet::ResourceError, %r{must be a String}) end end # owner context 'validate owner' do it 'fails if owner is wrong type' do expect do described_class.new name: 'foo_bar', owner: true end.to raise_error(Puppet::ResourceError, %r{must be a String or Integer}) end it 'succeeds if owner is string' do expect do described_class.new name: 'foo_bar', owner: 'foo' end end it 'succeeds if owner is numeric' do expect do described_class.new name: 'foo_bar', owner: 111 end end end # group context 'validate group' do it 'fails if group is wrong type' do expect do described_class.new name: 'foo_bar', group: true end.to raise_error(Puppet::ResourceError, %r{must be a String or Integer}) end it 'succeeds if group is string' do expect do described_class.new name: 'foo_bar', group: 'foo' end end it 'succeeds if group is numeric' do expect do described_class.new name: 'foo_bar', owner: 111 end end end # mode context 'validate mode' do it 'fails if mode is wrong type' do expect do described_class.new name: 'foo_bar', mode: 123 end.to raise_error(Puppet::ResourceError, %r{must be a String}) end it 'fails if mode is empty' do expect do described_class.new name: 'foo_bar', mode: '' end.to raise_error(Puppet::ResourceError, %r{must be a String}) end # currently disabled # it 'fails if mode is invalid' do # expect do # described_class.new name: 'foo_bar', mode: 'abcd' # end.to raise_error(Puppet::ResourceError, %r{is not valid}) # end it 'succeeds if mode is string' do expect do described_class.new name: 'foo_bar', mode: '0755' end end end # replace context 'validate replace' do it 'fails if replace is not a boolean' do expect do described_class.new name: 'foo_bar', replace: 'bla' end.to raise_error(Puppet::ResourceError, %r{Valid values are}) end it 'succeeds if replace' do expect do described_class.new name: 'foo_bar', replace: true end end end # backup context 'validate backup' do it 'fails if backup is not a boolean' do expect do described_class.new name: 'foo_bar', backup: 'bla' end.to raise_error(Puppet::ResourceError, %r{Valid values are}) end it 'succeeds if backup' do expect do described_class.new name: 'foo_bar', backup: true end end end # validate_cmd context 'validate validate_cmd' do it 'fails if validate_cmd is wrong type' do expect do described_class.new name: 'foo_bar', validate_cmd: 123 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if group is string' do expect do described_class.new name: 'foo_bar', validate_cmd: '0755' end end end # ldap_servers context 'validate ldap_servers' do it 'correctly returns the declared LDAP servers' do catalog = Puppet::Resource::Catalog.new server = Puppet::Type.type(:grafana_ldap_server).new( name: 'ldap.example.com', hosts: ['ldap.example.com'], search_base_dns: ['ou=auth'] ) config = Puppet::Type.type(:grafana_ldap_config).new name: 'ldap1' catalog.add_resource server catalog.add_resource config expect(config.ldap_servers.keys).to include('ldap.example.com') end end end diff --git a/spec/unit/puppet/type/grafana_ldap_group_mapping_spec.rb b/spec/unit/puppet/type/grafana_ldap_group_mapping_spec.rb index 410be52..81d33b4 100644 --- a/spec/unit/puppet/type/grafana_ldap_group_mapping_spec.rb +++ b/spec/unit/puppet/type/grafana_ldap_group_mapping_spec.rb @@ -1,151 +1,151 @@ # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'spec_helper' - +# rubocop:disable RSpec/VoidExpect describe Puppet::Type.type(:grafana_ldap_group_mapping) do # resource title context 'validate resource title' do it 'fails if title is not set' do expect do described_class.new name: nil end.to raise_error(Puppet::Error, %r{Title or name must be provided}) end it 'fails if title is empty' do expect do described_class.new name: '' end.to raise_error(RuntimeError, %r{needs to be a non-empty string}) end it 'fails if title is not a string' do expect do described_class.new name: 123 end.to raise_error(Puppet::ResourceError, %r{must be a String}) end end # ldap_server_name context 'validate ldap_server_name' do it 'fails if ldap_server_name is not set' do expect do described_class.new name: 'foo_bar', ldap_server_name: nil, group_dn: 'bar' end.to raise_error(Puppet::Error, %r{Got nil value for}) end it 'fails if ldap_server_name is empty' do expect do described_class.new name: 'foo_bar', ldap_server_name: '', group_dn: 'bar' end.to raise_error(RuntimeError, %r{needs to be a non-empty string}) end it 'fails if ldap_server_name is not a string' do expect do described_class.new name: '123_bar', ldap_server_name: 123, group_dn: 'bar' end.to raise_error(Puppet::ResourceError, %r{must be a String}) end end # group_dn context 'validate group_dn' do it 'fails if group_dn is not set' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: nil end.to raise_error(Puppet::Error, %r{Got nil value for}) end it 'fails if group_dn is empty' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: '' end.to raise_error(RuntimeError, %r{needs to be a non-empty string}) end it 'fails if group_dn is not a string' do expect do described_class.new name: 'foo_123', ldap_server_name: 'foo', group_dn: 123 end.to raise_error(Puppet::ResourceError, %r{must be a String}) end end # org_role context 'validate org_role' do it 'fails if org_role is not set' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: nil end.to raise_error(Puppet::Error, %r{Got nil value for}) end it 'fails if org_role is not a string' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 123 end.to raise_error(Puppet::ResourceError, %r{Valid values are}) end it 'fails if org_role is an unknown role' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 'bla' end.to raise_error(Puppet::Error, %r{Valid values are}) end it 'succeeds if all is correct' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 'Editor' end end end # grafana_admin context 'validate grafana_admin' do it 'fails if org_role is not a boolean' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 'Admin', grafana_admin: 'bla' end.to raise_error(Puppet::ResourceError, %r{Valid values are}) end it 'succeeds if grafana_admin' do expect do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 'Admin', grafana_admin: true end end end context 'valid viewer' do let(:group_mapping) do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 'Viewer', grafana_admin: false end it 'given all parameters' do expect(group_mapping[:org_role]).to eq(:Viewer) end end context 'valid editor' do let(:group_mapping) do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 'Editor', grafana_admin: false end it 'given all parameters' do expect(group_mapping[:org_role]).to eq(:Editor) end end context 'valid admin' do let(:group_mapping) do described_class.new name: 'foo_bar', ldap_server_name: 'foo', group_dn: 'bar', org_role: 'Admin', grafana_admin: true end it 'given all parameters' do expect(group_mapping[:org_role]).to eq(:Admin) end end end diff --git a/spec/unit/puppet/type/grafana_ldap_server_spec.rb b/spec/unit/puppet/type/grafana_ldap_server_spec.rb index 0706c0d..8cff019 100644 --- a/spec/unit/puppet/type/grafana_ldap_server_spec.rb +++ b/spec/unit/puppet/type/grafana_ldap_server_spec.rb @@ -1,337 +1,337 @@ # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'spec_helper' - +# rubocop:disable RSpec/VoidExpect describe Puppet::Type.type(:grafana_ldap_server) do # resource title context 'validate resource title' do it 'fails if title is not set' do expect do described_class.new name: nil end.to raise_error(Puppet::Error, %r{Title or name must be provided}) end it 'fails if title is empty' do expect do described_class.new name: '' end.to raise_error(RuntimeError, %r{must not be empty}) end it 'fails if title is not a string' do expect do described_class.new name: 123 end.to raise_error(Puppet::ResourceError, %r{must be a String}) end end # hosts context 'validate hosts' do it 'fails if hosts is not set' do expect do described_class.new name: 'server1', hosts: nil end.to raise_error(Puppet::Error, %r{Got nil value for}) end it 'fails if hosts is not an array' do expect do described_class.new name: 'server1', hosts: '' end.to raise_error(RuntimeError, %r{must be an Array}) end it 'fails if hosts is empty' do expect do described_class.new name: 'server1', hosts: [] end.to raise_error(RuntimeError, %r{must not be empty}) end end # port context 'validate port' do it 'fails if port is empty' do expect do described_class.new name: 'server1', hosts: ['server1'], port: 0 end.to raise_error(RuntimeError, %r{must be an Integer within}) end it 'fails if port is a string' do expect do described_class.new name: 'server1', hosts: ['server1'], port: '123' end.to raise_error(Puppet::ResourceError, %r{must be an Integer within}) end it 'fails if port is greater than 65535' do expect do described_class.new name: 'server1', hosts: ['server1'], port: 123_456 end.to raise_error(Puppet::ResourceError, %r{must be an Integer within}) end end # use_ssl context 'validate use_ssl' do it 'fails if use_ssl is not boolean' do expect do described_class.new name: 'server1', hosts: ['server1'], use_ssl: 'foobar' end.to raise_error(Puppet::Error, %r{Valid values are true}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], use_ssl: true end end end # start_tls context 'validate start_tls' do it 'fails if start_tls is not boolean' do expect do described_class.new name: 'server1', hosts: ['server1'], start_tls: 'foobar' end.to raise_error(Puppet::Error, %r{Valid values are true}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], start_tls: true end end end # ssl_skip_verify context 'validate ssl_skip_verify' do it 'fails if ssl_skip_verify is not boolean' do expect do described_class.new name: 'server1', hosts: ['server1'], ssl_skip_verify: 'foobar' end.to raise_error(Puppet::Error, %r{Valid values are true}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], ssl_skip_verify: true end end end # root_ca_cert context 'validate root_ca_cert' do it 'fails if root_ca_cert is empty' do expect do described_class.new name: 'server1', hosts: ['server1'], root_ca_cert: '' end.to raise_error(RuntimeError, %r{must be set when SSL}) end it 'fails if root_ca_cert is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], root_ca_cert: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], root_ca_cert: '/etc/ssl/certs/ca-certificate.crt' end end end # client_cert context 'validate client_cert' do it 'fails if client_cert is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], client_cert: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], client_cert: '/etc/ssl/host.crt' end end end # client_key context 'validate client_key' do it 'fails if client_key is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], client_key: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], client_key: '/etc/ssl/certs/ca-certificate.crt' end end end # bind_dn context 'validate bind_dn' do it 'fails if bind_dn is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], bind_dn: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], bind_dn: 'cn=Admin', search_base_dns: ['ou=users'] end end end # bind_password context 'validate bind_password' do it 'fails if bind_password is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], bind_password: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], bind_password: 'foobar', search_base_dns: ['ou=users'] end end end # search_filter context 'validate search_filter' do it 'fails if search_filter is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], search_filter: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], search_filter: 'uid=%u', search_base_dns: ['ou=users'] end end end # search_base_dns context 'validate search_base_dns' do it 'fails if search_base_dns is not an array' do expect do described_class.new name: 'server1', hosts: ['server1'], search_base_dns: 12_345 end.to raise_error(Puppet::Error, %r{must be an Array}) end it 'fails if search_base_dns array members are not strings' do expect do described_class.new name: 'server1', hosts: ['server1'], search_base_dns: [12_345] end.to raise_error(Puppet::Error, %r{must be a String}) end it 'fails if search_base_dns array is empty' do expect do described_class.new name: 'server1', hosts: ['server1'], search_base_dns: [] end.to raise_error(RuntimeError, %r{needs to contain at least one LDAP base-dn}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], search_base_dns: ['ou=users'] end end end # group_search_filter context 'validate group_search_filter' do it 'fails if group_search_filter is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_filter: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_filter: 'cn=adminsgroup', search_base_dns: ['ou=users'] end end end # group_search_filter_user_attribute context 'validate group_search_filter_user_attribute' do it 'fails if group_search_filter_user_attribute is not a string' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_filter_user_attribute: 12_345 end.to raise_error(Puppet::Error, %r{must be a String}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_filter_user_attribute: 'dn', search_base_dns: ['ou=users'] end end end # group_search_base_dns context 'validate group_search_base_dns' do it 'fails if group_search_base_dns is not an array' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_base_dns: 12_345 end.to raise_error(Puppet::Error, %r{must be an Array}) end it 'fails if group_search_base_dns array members are not strings' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_base_dns: [12_345] end.to raise_error(Puppet::Error, %r{must be a String}) end it 'fails if group_search_base_dns array is empty' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_base_dns: [], search_base_dns: ['ou=auth'] end.to raise_error(RuntimeError, %r{needs to contain at least one LDAP base-dn}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], group_search_base_dns: ['ou=users'] end end end # attributes context 'validate attributes' do it 'fails if attributes is not a hash' do expect do described_class.new name: 'server1', hosts: ['server1'], attributes: [12_345] end.to raise_error(Puppet::Error, %r{must be a Hash}) end it 'fails if unknown attribute' do expect do described_class.new name: 'server1', hosts: ['server1'], attributes: { 'foo' => 'bar' } end.to raise_error(Puppet::Error, %r{contains an unknown key}) end it 'fails if wrong key type' do expect do described_class.new name: 'server1', hosts: ['server1'], attributes: { 12_345 => 'bar' } end.to raise_error(Puppet::Error, %r{must be Strings}) end it 'fails if wrong value type' do expect do described_class.new name: 'server1', hosts: ['server1'], attributes: { 'surname' => {} } end.to raise_error(Puppet::Error, %r{must be Strings}) end it 'succeeds if all is correct' do expect do described_class.new name: 'server1', hosts: ['server1'], attributes: { 'username' => 'uid' } end end end end diff --git a/spec/unit/puppet/type/grafana_notification_type_spec.rb b/spec/unit/puppet/type/grafana_notification_type_spec.rb index d85489b..e1b9953 100644 --- a/spec/unit/puppet/type/grafana_notification_type_spec.rb +++ b/spec/unit/puppet/type/grafana_notification_type_spec.rb @@ -1,72 +1,70 @@ # Copyright 2015 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'spec_helper' describe Puppet::Type.type(:grafana_notification) do let(:gnotification) do described_class.new( name: 'foo', grafana_url: 'http://example.com', type: 'email', is_default: true, send_reminder: true, frequency: '20m', settings: { adresses: 'test@example.com' } ) end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new name: 'foo', grafana_url: 'example.com', content: '{}' end.to raise_error(Puppet::Error, %r{not a valid URL}) end it "fails if settings isn't valid" do expect do described_class.new name: 'foo', grafana_url: 'http://example.com', settings: 'invalid' end.to raise_error(Puppet::Error, %r{settings should be a Hash}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gnotification[:name]).to eq('foo') expect(gnotification[:grafana_url]).to eq('http://example.com') expect(gnotification[:type]).to eq('email') expect(gnotification[:is_default]).to eq(:true) expect(gnotification[:send_reminder]).to eq(:true) expect(gnotification[:frequency]).to eq('20m') expect(gnotification[:settings]).to eq(adresses: 'test@example.com') end # rubocop:enable RSpec/MultipleExpectations it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gnotification relationship = gnotification.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gnotification.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gnotification expect(gnotification.autorequire).to be_empty end end end diff --git a/spec/unit/puppet/type/grafana_organization_type_spec.rb b/spec/unit/puppet/type/grafana_organization_type_spec.rb index 522ec0e..9fb7dd6 100644 --- a/spec/unit/puppet/type/grafana_organization_type_spec.rb +++ b/spec/unit/puppet/type/grafana_organization_type_spec.rb @@ -1,55 +1,53 @@ require 'spec_helper' describe Puppet::Type.type(:grafana_organization) do let(:gorganization) do described_class.new( name: 'foo', grafana_url: 'http://example.com', grafana_user: 'admin', grafana_password: 'admin', address: { address1: 'test address1', address2: 'test address2', city: 'CityName', state: 'NewState', zipcode: '12345', country: 'USA' } ) end context 'when setting parameters' do it "fails if json_data isn't valid" do expect do described_class.new name: 'foo', address: 'invalid address' end.to raise_error(Puppet::Error, %r{address should be a Hash!}) end it "fails if grafana_url isn't HTTP-based" do expect do described_class.new name: 'foo', grafana_url: 'example.com', content: '{}', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid URL}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gorganization[:name]).to eq('foo') expect(gorganization[:grafana_user]).to eq('admin') expect(gorganization[:grafana_password]).to eq('admin') expect(gorganization[:grafana_url]).to eq('http://example.com') expect(gorganization[:address]).to eq(address1: 'test address1', address2: 'test address2', city: 'CityName', state: 'NewState', zipcode: '12345', country: 'USA') end # rubocop:enable RSpec/MultipleExpectations it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gorganization relationship = gorganization.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gorganization.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gorganization expect(gorganization.autorequire).to be_empty end end end diff --git a/spec/unit/puppet/type/grafana_team_type_spec.rb b/spec/unit/puppet/type/grafana_team_type_spec.rb index 0f01c1b..f2e2f77 100644 --- a/spec/unit/puppet/type/grafana_team_type_spec.rb +++ b/spec/unit/puppet/type/grafana_team_type_spec.rb @@ -1,51 +1,49 @@ require 'spec_helper' describe Puppet::Type.type(:grafana_team) do let(:gteam) do described_class.new( name: 'foo', grafana_url: 'http://example.com', grafana_user: 'admin', grafana_password: 'admin', home_dashboard: 'foo_dashboard', organization: 'foo_organization' ) end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new name: 'foo', grafana_url: 'example.com', content: '{}', ensure: :present end.to raise_error(Puppet::Error, %r{not a valid URL}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(gteam[:name]).to eq('foo') expect(gteam[:grafana_user]).to eq('admin') expect(gteam[:grafana_password]).to eq('admin') expect(gteam[:grafana_url]).to eq('http://example.com') expect(gteam[:home_dashboard]).to eq('foo_dashboard') expect(gteam[:organization]).to eq('foo_organization') end # rubocop:enable RSpec/MultipleExpectations it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource gteam relationship = gteam.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gteam.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource gteam expect(gteam.autorequire).to be_empty end end end diff --git a/spec/unit/puppet/type/grafana_user_type_spec.rb b/spec/unit/puppet/type/grafana_user_type_spec.rb index f8f63b9..0e0f0a7 100644 --- a/spec/unit/puppet/type/grafana_user_type_spec.rb +++ b/spec/unit/puppet/type/grafana_user_type_spec.rb @@ -1,50 +1,48 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'spec_helper' describe Puppet::Type.type(:grafana_user) do let(:guser) do described_class.new name: 'test', full_name: 'Mr tester', password: 't3st', grafana_url: 'http://example.com/' end context 'when setting parameters' do it "fails if grafana_url isn't HTTP-based" do expect do described_class.new name: 'test', grafana_url: 'example.com' end.to raise_error(Puppet::Error, %r{not a valid URL}) end - - # rubocop:disable RSpec/MultipleExpectations it 'accepts valid parameters' do expect(guser[:name]).to eq('test') expect(guser[:full_name]).to eq('Mr tester') expect(guser[:password]).to eq('t3st') expect(guser[:grafana_url]).to eq('http://example.com/') end it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new service = Puppet::Type.type(:service).new(name: 'grafana-server') catalog.add_resource service catalog.add_resource guser relationship = guser.autorequire.find do |rel| (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == guser.to_s) end expect(relationship).to be_a Puppet::Relationship end it 'does not autorequire the service it is not managed' do catalog = Puppet::Resource::Catalog.new catalog.add_resource guser expect(guser.autorequire).to be_empty end end end