From e881718572e17b1a82703505a40141bb2e1e1b83 Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 09:02:56 +0100 Subject: [PATCH 01/10] Update based on voxpupuli/modulesync_config 0.16.3 --- .github/CONTRIBUTING.md | 100 ++++ .github/ISSUE_TEMPLATE.md | 25 + .github/PULL_REQUEST_TEMPLATE.md | 7 + .gitignore | 28 +- .msync.yml | 1 + .rspec | 2 + .rubocop.yml | 512 ++++++++++++++++++ .sync.yml | 7 + .travis.yml | 78 +-- .yardopts | 1 + Gemfile | 76 ++- Rakefile | 74 +-- spec/acceptance/nodesets/centos-511-x64.yml | 15 + spec/acceptance/nodesets/centos-64-x64.yml | 11 - spec/acceptance/nodesets/centos-66-x64-pe.yml | 17 + spec/acceptance/nodesets/centos-66-x64.yml | 15 + spec/acceptance/nodesets/centos-72-x64.yml | 15 + spec/acceptance/nodesets/debian-78-x64.yml | 15 + spec/acceptance/nodesets/debian-82-x64.yml | 15 + spec/acceptance/nodesets/default.yml | 12 - spec/acceptance/nodesets/docker/centos-5.yml | 19 + spec/acceptance/nodesets/docker/centos-6.yml | 20 + spec/acceptance/nodesets/docker/centos-7.yml | 18 + spec/acceptance/nodesets/docker/debian-7.yml | 19 + spec/acceptance/nodesets/docker/debian-8.yml | 20 + .../nodesets/docker/ubuntu-12.04.yml | 19 + .../nodesets/docker/ubuntu-14.04.yml | 21 + .../nodesets/docker/ubuntu-16.04.yml | 19 + .../nodesets/ubuntu-server-1204-x64.yml | 15 + .../nodesets/ubuntu-server-12042-x64.yml | 12 - .../nodesets/ubuntu-server-1404-x64.yml | 15 + .../nodesets/ubuntu-server-1604-x64.yml | 15 + spec/classes/coverage_spec.rb | 3 + spec/default_facts.yml | 6 + spec/spec_helper.rb | 31 ++ 35 files changed, 1134 insertions(+), 144 deletions(-) create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .msync.yml create mode 100644 .rspec create mode 100644 .rubocop.yml create mode 100644 .sync.yml create mode 100644 .yardopts create mode 100644 spec/acceptance/nodesets/centos-511-x64.yml delete mode 100644 spec/acceptance/nodesets/centos-64-x64.yml create mode 100644 spec/acceptance/nodesets/centos-66-x64-pe.yml create mode 100644 spec/acceptance/nodesets/centos-66-x64.yml create mode 100644 spec/acceptance/nodesets/centos-72-x64.yml create mode 100644 spec/acceptance/nodesets/debian-78-x64.yml create mode 100644 spec/acceptance/nodesets/debian-82-x64.yml delete mode 100644 spec/acceptance/nodesets/default.yml create mode 100644 spec/acceptance/nodesets/docker/centos-5.yml create mode 100644 spec/acceptance/nodesets/docker/centos-6.yml create mode 100644 spec/acceptance/nodesets/docker/centos-7.yml create mode 100644 spec/acceptance/nodesets/docker/debian-7.yml create mode 100644 spec/acceptance/nodesets/docker/debian-8.yml create mode 100644 spec/acceptance/nodesets/docker/ubuntu-12.04.yml create mode 100644 spec/acceptance/nodesets/docker/ubuntu-14.04.yml create mode 100644 spec/acceptance/nodesets/docker/ubuntu-16.04.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1204-x64.yml delete mode 100644 spec/acceptance/nodesets/ubuntu-server-12042-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1404-x64.yml create mode 100644 spec/acceptance/nodesets/ubuntu-server-1604-x64.yml create mode 100644 spec/default_facts.yml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 000000000..5574191a6 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,100 @@ +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 quicker. + +## 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/). + +1. Fork the repo. + +1. Create a separate branch for your change. + +1. Run the tests. We only take pull requests with passing tests, and + documentation. + +1. 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. + +1. Squash your commits down into logical components. Make sure to rebase + against the current master. + +1. 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. + +## 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: + + export PUPPET_VERSION="~> 4.2.0" + +Install the dependencies like so... + + bundle install + +## 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: + + 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: + + 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 your all the unit tests + + bundle exec rake spec SPEC_OPTS='--format documentation' + +To run a specific spec test set the `SPEC` variable: + + bundle exec rake spec SPEC=spec/foo_spec.rb + +To run the linter, the syntax checker and the unit tests: + + bundle exec rake test + +## 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: + + bundle exec rake acceptance + +This will run the tests on an Ubuntu 12.04 virtual machine. You can also +run the integration tests against Centos 6.6 with. + + BEAKER_set=centos-66-x64 bundle exec rake acceptances + +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_fies`. diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..f6f4f86e7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,25 @@ + + +## 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 000000000..92f2e5983 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,7 @@ + diff --git a/.gitignore b/.gitignore index 98cbccbb1..82426da6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,15 @@ -.*.sw? -pkg -spec/fixtures -.rspec_system -.vagrant -log/ - -# for a library or gem, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: +pkg/ Gemfile.lock -.ruby-version -.ruby-gemset - -# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: -.rvmrc +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ +.bundle/ +coverage/ +log/ +.idea/ +*.iml +.*.sw? +.yardoc/ diff --git a/.msync.yml b/.msync.yml new file mode 100644 index 000000000..a7e7e88a6 --- /dev/null +++ b/.msync.yml @@ -0,0 +1 @@ +modulesync_config_version: '0.16.3' diff --git a/.rspec b/.rspec new file mode 100644 index 000000000..8c18f1abd --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..f703c727c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,512 @@ +require: rubocop-rspec +AllCops: + TargetRubyVersion: 1.9 + Include: + - ./**/*.rb + Exclude: + - files/**/* + - vendor/**/* + - .vendor/**/* + - pkg/**/* + - spec/fixtures/**/* +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 + +Lint/AmbiguousOperator: + Enabled: True + +Lint/AssignmentInCondition: + Enabled: True + +Style/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 + +Lint/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 + +Style/AccessModifierIndentation: + Enabled: True + +Style/AccessorMethodName: + Enabled: True + +Style/Alias: + Enabled: True + +Style/AlignArray: + Enabled: True + +Style/AlignHash: + Enabled: True + +Style/AlignParameters: + Enabled: True + +Metrics/BlockNesting: + Enabled: True + +Style/AsciiComments: + Enabled: True + +Style/Attr: + Enabled: True + +Style/BracesAroundHashParameters: + Enabled: True + +Style/CaseEquality: + Enabled: True + +Style/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 + +Style/Tab: + Enabled: True + +Style/SpaceBeforeSemicolon: + Enabled: True + +Style/TrailingBlankLines: + Enabled: True + +Style/SpaceInsideBlockBraces: + Enabled: True + +Style/SpaceInsideBrackets: + Enabled: True + +Style/SpaceInsideHashLiteralBraces: + Enabled: True + +Style/SpaceInsideParens: + Enabled: True + +Style/LeadingCommentSpace: + Enabled: True + +Style/SpaceBeforeFirstArg: + Enabled: True + +Style/SpaceAfterColon: + Enabled: True + +Style/SpaceAfterComma: + Enabled: True + +Style/SpaceAfterMethodName: + Enabled: True + +Style/SpaceAfterNot: + Enabled: True + +Style/SpaceAfterSemicolon: + Enabled: True + +Style/SpaceAroundEqualsInParameterDefault: + Enabled: True + +Style/SpaceAroundOperators: + Enabled: True + +Style/SpaceBeforeBlockBraces: + Enabled: True + +Style/SpaceBeforeComma: + Enabled: True + +Style/CollectionMethods: + Enabled: True + +Style/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 + +Style/DotPosition: + EnforcedStyle: trailing + +Style/DoubleNegation: + Enabled: True + +Style/EachWithObject: + Enabled: True + +Style/EmptyLineBetweenDefs: + Enabled: True + +Style/IndentArray: + Enabled: True + +Style/IndentHash: + Enabled: True + +Style/IndentationConsistency: + Enabled: True + +Style/IndentationWidth: + Enabled: True + +Style/EmptyLines: + Enabled: True + +Style/EmptyLinesAroundAccessModifier: + Enabled: True + +Style/EmptyLiteral: + Enabled: True + +# Configuration parameters: AllowURI, URISchemes. +Metrics/LineLength: + Enabled: False + +Style/MethodCallParentheses: + Enabled: True + +Style/MethodDefParentheses: + Enabled: True + +Style/LineEndConcatenation: + Enabled: True + +Style/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/SpaceBeforeFirstArg: + Enabled: True + +Style/ModuleFunction: + Enabled: True + +Lint/Debugger: + Enabled: True + +Style/IfWithSemicolon: + Enabled: True + +Style/Encoding: + Enabled: True + +Style/BlockDelimiters: + Enabled: True + +Style/MultilineBlockLayout: + Enabled: True + +# 'Complexity' is very relative +Metrics/AbcSize: + Enabled: False + +# 'Complexity' is very relative +Metrics/PerceivedComplexity: + Enabled: False + +Lint/UselessAssignment: + Enabled: True + +Style/ClosingParenthesisIndentation: + Enabled: True + +# RSpec + +# We don't use rspec in this way +RSpec/DescribeClass: + Enabled: False + +# Example length is not necessarily an indicator of code quality +RSpec/ExampleLength: + Enabled: False + +RSpec/NamedSubject: + Enabled: False diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 000000000..928d81f77 --- /dev/null +++ b/.sync.yml @@ -0,0 +1,7 @@ +--- +.travis.yml: + secure: "qtLA1TPKaVgd9rvi0kkF2v0CP0QLls//lFHJ9IowTYNi5O+0dx7OxZCK3g4nkNWWbsujS464/YFJqVRWoXIeLIyFtfMKkaRAiuaukxOQqnzD+BsnpYYeo2zeZPCvMbB94+7G7JQ+jpuzlsHX6j+H6LQEj6+kXzd8NAj8rlygrL8XcFN3bA8XM/unCvqn2b2sduShExVl0mnNMIvZMHCbdrEzByXkz+FmyGYCay+feDIYbIbhzYLNnh6BcDkq24TxRmVOdEnUkPG6ZU0UJlNqBZB++zAIazR25NyX+b22/CFp6D6YJKkJvBNnywGUNNF21s4a6kPoEnUVBEO6yg5sDkKgp8nAvsmUnI8A1tfRFWKejxHZN3YqveY60xiNIUEHJU4MjEE6VVi9WpNW8CpJbfP/z3RtlU5n4ckSER7mb/ApxspUPJRzyMKjobDP12WU/bgXinzdNMu6PH9H56WkDpRNtIYnNhIAuirdfDr2Ok5z9/9yObUt/OQddM4wrOnMG7lyyUIzAO2OOJbIcOaZBedTKccpCu6k2mOkUHhMutf1D0bde5IGhrs7E54V2ZNxX5Dopv5eOrmVN2OxdcB9g8nmISxX6Tty/BNrTBvt7urthGjUJrjlnNE/K1595KmcWa6PGWUcYZyzdKeWqiA3+iWKSmnx1Ri0lsml5Z/a4QM=" +Gemfile: + optional: + ':test': + - gem: 'toml' diff --git a/.travis.yml b/.travis.yml index 74842aa2d..613b2c3c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,34 +1,50 @@ -language: ruby +--- sudo: false -bundler_args: --without development -before_install: rm Gemfile.lock || true -rvm: - - 1.8.7 - - 1.9.3 - - 2.0.0 - - 2.1.0 -script: bundle exec rake test -env: - - PUPPET_GEM_VERSION="~> 2.7.0" - - PUPPET_GEM_VERSION="~> 3.2.0" - - PUPPET_GEM_VERSION="~> 3.3.0" - - PUPPET_GEM_VERSION="~> 3.4.0" - - PUPPET_GEM_VERSION="~> 3.5.0" - - PUPPET_GEM_VERSION="~> 3.6.0" - - PUPPET_GEM_VERSION="~> 3.7.0" +language: ruby +cache: bundler +bundler_args: --without system_tests development +before_install: + - bundle -v + - rm Gemfile.lock || true + - gem update --system + - gem update bundler + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' matrix: - allow_failures: - - rvm: 1.8.7 - exclude: + fast_finish: true + include: - rvm: 1.9.3 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.0.0 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 2.7.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 3.2.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 3.3.0" - - rvm: 2.1.0 - env: PUPPET_VERSION="~> 3.4.0" + env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test + - rvm: 1.9.3 + env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" CHECK=test + - rvm: 2.1.9 + env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test + - rvm: 2.1.9 + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.2.6 + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.3.3 + env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes + - rvm: 2.3.3 + env: PUPPET_VERSION="~> 4.0" CHECK=rubocop + - rvm: 2.3.3 + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.4.0-preview3 + env: PUPPET_VERSION="~> 4.0" CHECK=test + allow_failures: + - rvm: 2.4.0-preview3 +notifications: + email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "qtLA1TPKaVgd9rvi0kkF2v0CP0QLls//lFHJ9IowTYNi5O+0dx7OxZCK3g4nkNWWbsujS464/YFJqVRWoXIeLIyFtfMKkaRAiuaukxOQqnzD+BsnpYYeo2zeZPCvMbB94+7G7JQ+jpuzlsHX6j+H6LQEj6+kXzd8NAj8rlygrL8XcFN3bA8XM/unCvqn2b2sduShExVl0mnNMIvZMHCbdrEzByXkz+FmyGYCay+feDIYbIbhzYLNnh6BcDkq24TxRmVOdEnUkPG6ZU0UJlNqBZB++zAIazR25NyX+b22/CFp6D6YJKkJvBNnywGUNNF21s4a6kPoEnUVBEO6yg5sDkKgp8nAvsmUnI8A1tfRFWKejxHZN3YqveY60xiNIUEHJU4MjEE6VVi9WpNW8CpJbfP/z3RtlU5n4ckSER7mb/ApxspUPJRzyMKjobDP12WU/bgXinzdNMu6PH9H56WkDpRNtIYnNhIAuirdfDr2Ok5z9/9yObUt/OQddM4wrOnMG7lyyUIzAO2OOJbIcOaZBedTKccpCu6k2mOkUHhMutf1D0bde5IGhrs7E54V2ZNxX5Dopv5eOrmVN2OxdcB9g8nmISxX6Tty/BNrTBvt7urthGjUJrjlnNE/K1595KmcWa6PGWUcYZyzdKeWqiA3+iWKSmnx1Ri0lsml5Z/a4QM=" + 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/.yardopts b/.yardopts new file mode 100644 index 000000000..29c933bcf --- /dev/null +++ b/.yardopts @@ -0,0 +1 @@ +--markup markdown diff --git a/Gemfile b/Gemfile index d469af991..e3785e25d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,21 +1,67 @@ -source "https://rubygems.org" +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 "rake" - gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.6.0' - gem 'metadata-json-lint' - gem "puppet-lint" - gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git' - gem "puppet-syntax" - gem "puppetlabs_spec_helper" - gem "toml" + gem 'puppetlabs_spec_helper', '~> 1.2.2', :require => false + gem 'rspec-puppet', '~> 2.5', :require => false + gem 'rspec-puppet-facts', :require => false + gem 'rspec-puppet-utils', :require => false + gem 'puppet-lint-absolute_classname-check', :require => false + gem 'puppet-lint-leading_zero-check', :require => false + gem 'puppet-lint-trailing_comma-check', :require => false + gem 'puppet-lint-version_comparison-check', :require => false + gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false + gem 'puppet-lint-unquoted_string-check', :require => false + gem 'puppet-lint-variable_contains_upcase', :require => false + gem 'metadata-json-lint', :require => false + gem 'puppet-blacksmith', :require => false + gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem.git' + gem 'puppet-strings', '~> 0.99.0', :require => false + gem 'rubocop-rspec', '~> 1.6', :require => false if RUBY_VERSION >= '2.3.0' + gem 'json_pure', '<= 2.0.1', :require => false if RUBY_VERSION < '2.0.0' + gem 'mocha', '>= 1.2.1', :require => false + gem 'coveralls', :require => false if RUBY_VERSION >= '2.0.0' + gem 'simplecov-console', :require => false if RUBY_VERSION >= '2.0.0' + gem 'toml', :require => false end group :development do - gem "travis" - gem "travis-lint" - gem "beaker" - gem "beaker-rspec" - gem "puppet-blacksmith" - gem "guard-rake" + gem 'travis', :require => false + gem 'travis-lint', :require => false + gem 'guard-rake', :require => false +end + +group :system_tests do + if beaker_version = ENV['BEAKER_VERSION'] + gem 'beaker', *location_for(beaker_version) + end + if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end + gem 'serverspec', :require => false + gem 'beaker-puppet_install_helper', :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 = '~> 4.0' : puppetversion = ENV['PUPPET_VERSION'].to_s +gem 'puppet', puppetversion, :require => false, :groups => [:test] + +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index c94da6371..d00f2470a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,57 +1,33 @@ require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' -require 'puppet-syntax/tasks/puppet-syntax' - -# These two gems aren't always present, for instance -# on Travis with --without development -begin - require 'puppet_blacksmith/rake_tasks' -rescue LoadError -end - -exclude_paths = [ - "pkg/**/*", - "vendor/**/*", - "spec/**/*", -] - -Rake::Task[:lint].clear -PuppetLint::RakeTask.new :lint do |config| - # Pattern of files to ignore - config.ignore_paths = exclude_paths - - # List of checks to disable - config.disable_checks = [ - '80chars', - 'autoloader_layout', - 'class_parameter_defaults', - 'class_inherits_from_params_class' - ] - - # Should the task fail if there were any warnings, defaults to false - config.fail_on_warnings = true - - # Print out the context for the problem, defaults to false - config.with_context = true - - # Format string for puppet-lint's output (see the puppet-lint help output - # for details - config.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" - - # Compare module layout relative to the module root - # config.relative = true -end - +require 'puppet_blacksmith/rake_tasks' +require 'voxpupuli/release/rake_tasks' +require 'puppet-strings/tasks' + +PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.send('relative') +PuppetLint.configuration.send('disable_140chars') +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +PuppetLint.configuration.send('disable_documentation') +PuppetLint.configuration.send('disable_single_quote_string_with_variables') + +exclude_paths = %w( + pkg/**/* + vendor/**/* + .vendor/**/* + spec/**/* +) +PuppetLint.configuration.ignore_paths = exclude_paths PuppetSyntax.exclude_paths = exclude_paths -desc "Run acceptance tests" +desc 'Run acceptance tests' RSpec::Core::RakeTask.new(:acceptance) do |t| t.pattern = 'spec/acceptance' end -desc "Run syntax, lint, and spec tests." -task :test => [ - :syntax, - :lint, - :spec, +desc 'Run tests metadata_lint, release_checks' +task test: [ + :metadata_lint, + :release_checks, ] +# vim: syntax=ruby diff --git a/spec/acceptance/nodesets/centos-511-x64.yml b/spec/acceptance/nodesets/centos-511-x64.yml new file mode 100644 index 000000000..089d646a5 --- /dev/null +++ b/spec/acceptance/nodesets/centos-511-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-511-x64: + roles: + - master + platform: el-5-x86_64 + box: puppetlabs/centos-5.11-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-64-x64.yml b/spec/acceptance/nodesets/centos-64-x64.yml deleted file mode 100644 index d19aa6951..000000000 --- a/spec/acceptance/nodesets/centos-64-x64.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: verbose - type: foss diff --git a/spec/acceptance/nodesets/centos-66-x64-pe.yml b/spec/acceptance/nodesets/centos-66-x64-pe.yml new file mode 100644 index 000000000..1e7aea6d4 --- /dev/null +++ b/spec/acceptance/nodesets/centos-66-x64-pe.yml @@ -0,0 +1,17 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-66-x64: + roles: + - master + - database + - dashboard + platform: el-6-x86_64 + box: puppetlabs/centos-6.6-64-puppet-enterprise + hypervisor: vagrant +CONFIG: + type: pe +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-66-x64.yml b/spec/acceptance/nodesets/centos-66-x64.yml new file mode 100644 index 000000000..42455e7ae --- /dev/null +++ b/spec/acceptance/nodesets/centos-66-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-66-x64: + roles: + - master + platform: el-6-x86_64 + box: puppetlabs/centos-6.6-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/centos-72-x64.yml b/spec/acceptance/nodesets/centos-72-x64.yml new file mode 100644 index 000000000..85af89d3f --- /dev/null +++ b/spec/acceptance/nodesets/centos-72-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-72-x64: + roles: + - master + platform: el-7-x86_64 + box: puppetlabs/centos-7.2-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/debian-78-x64.yml b/spec/acceptance/nodesets/debian-78-x64.yml new file mode 100644 index 000000000..6ef6de8c8 --- /dev/null +++ b/spec/acceptance/nodesets/debian-78-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-78-x64: + roles: + - master + platform: debian-7-amd64 + box: puppetlabs/debian-7.8-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/debian-82-x64.yml b/spec/acceptance/nodesets/debian-82-x64.yml new file mode 100644 index 000000000..9897a8fc7 --- /dev/null +++ b/spec/acceptance/nodesets/debian-82-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-82-x64: + roles: + - master + platform: debian-8-amd64 + box: puppetlabs/debian-8.2-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 100644 index b392dab75..000000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - ubuntu-server-12042-x64: - roles: - - master - platform: ubuntu-server-12.04-amd64 - box: ubuntu-server-12042-x64-vbox4210-nocm - box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/docker/centos-5.yml b/spec/acceptance/nodesets/docker/centos-5.yml new file mode 100644 index 000000000..c17bc3d00 --- /dev/null +++ b/spec/acceptance/nodesets/docker/centos-5.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-5-x64: + platform: el-5-x86_64 + hypervisor: docker + image: centos:5 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'yum install -y crontabs initscripts iproute openssl sysvinit-tools tar wget which' + - 'sed -i -e "/mingetty/d" /etc/inittab' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/centos-6.yml b/spec/acceptance/nodesets/docker/centos-6.yml new file mode 100644 index 000000000..d93f884cb --- /dev/null +++ b/spec/acceptance/nodesets/docker/centos-6.yml @@ -0,0 +1,20 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-6-x64: + platform: el-6-x86_64 + hypervisor: docker + image: centos:6 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'rm -rf /var/run/network/*' + - 'yum install -y crontabs initscripts iproute openssl sysvinit-tools tar wget which' + - 'rm /etc/init/tty.conf' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/centos-7.yml b/spec/acceptance/nodesets/docker/centos-7.yml new file mode 100644 index 000000000..886b1eeb3 --- /dev/null +++ b/spec/acceptance/nodesets/docker/centos-7.yml @@ -0,0 +1,18 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + centos-7-x64: + platform: el-7-x86_64 + hypervisor: docker + image: centos:7 + docker_preserve_image: true + docker_cmd: '["/usr/sbin/init"]' + docker_image_commands: + - 'yum install -y crontabs initscripts iproute openssl sysvinit-tools tar wget which' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/debian-7.yml b/spec/acceptance/nodesets/docker/debian-7.yml new file mode 100644 index 000000000..071acbf90 --- /dev/null +++ b/spec/acceptance/nodesets/docker/debian-7.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-7-x64: + platform: debian-7-amd64 + hypervisor: docker + image: debian:7 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'echo deb http://ftp.debian.org/debian wheezy-backports main >> /etc/apt/sources.list' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/debian-8.yml b/spec/acceptance/nodesets/docker/debian-8.yml new file mode 100644 index 000000000..500bee522 --- /dev/null +++ b/spec/acceptance/nodesets/docker/debian-8.yml @@ -0,0 +1,20 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + debian-8-x64: + platform: debian-8-amd64 + hypervisor: docker + image: debian:8 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'echo deb http://ftp.debian.org/debian jessie-backports main >> /etc/apt/sources.list' + - 'apt-get update && apt-get install -y cron locales-all net-tools wget' + - 'rm -f /usr/sbin/policy-rc.d' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/ubuntu-12.04.yml b/spec/acceptance/nodesets/docker/ubuntu-12.04.yml new file mode 100644 index 000000000..ab77cda48 --- /dev/null +++ b/spec/acceptance/nodesets/docker/ubuntu-12.04.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-1204-x64: + platform: ubuntu-12.04-amd64 + hypervisor: docker + image: ubuntu:12.04 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'apt-get install -y net-tools wget' + - 'locale-gen en_US.UTF-8' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/ubuntu-14.04.yml b/spec/acceptance/nodesets/docker/ubuntu-14.04.yml new file mode 100644 index 000000000..54d5e5a5b --- /dev/null +++ b/spec/acceptance/nodesets/docker/ubuntu-14.04.yml @@ -0,0 +1,21 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-1404-x64: + platform: ubuntu-14.04-amd64 + hypervisor: docker + image: ubuntu:14.04 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'rm /usr/sbin/policy-rc.d' + - 'rm /sbin/initctl; dpkg-divert --rename --remove /sbin/initctl' + - 'apt-get install -y net-tools wget' + - 'locale-gen en_US.UTF-8' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/docker/ubuntu-16.04.yml b/spec/acceptance/nodesets/docker/ubuntu-16.04.yml new file mode 100644 index 000000000..92a93cb73 --- /dev/null +++ b/spec/acceptance/nodesets/docker/ubuntu-16.04.yml @@ -0,0 +1,19 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-1604-x64: + platform: ubuntu-16.04-amd64 + hypervisor: docker + image: ubuntu:16.04 + docker_preserve_image: true + docker_cmd: '["/sbin/init"]' + docker_image_commands: + - 'apt-get install -y net-tools wget' + - 'locale-gen en_US.UTF-8' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml new file mode 100644 index 000000000..29102c565 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1204-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-server-1204-x64: + roles: + - master + platform: ubuntu-12.04-amd64 + box: puppetlabs/ubuntu-12.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml deleted file mode 100644 index b392dab75..000000000 --- a/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - ubuntu-server-12042-x64: - roles: - - master - platform: ubuntu-server-12.04-amd64 - box: ubuntu-server-12042-x64-vbox4210-nocm - box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 000000000..054e65880 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-server-1404-x64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml new file mode 100644 index 000000000..bc85e0e84 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1604-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + ubuntu-server-1604-x64: + roles: + - master + platform: ubuntu-16.04-amd64 + box: puppetlabs/ubuntu-16.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss +... +# vim: syntax=yaml diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb index 12513b83c..de446548b 100644 --- a/spec/classes/coverage_spec.rb +++ b/spec/classes/coverage_spec.rb @@ -1 +1,4 @@ +require 'rspec-puppet' + at_exit { RSpec::Puppet::Coverage.report! } +# vim: syntax=ruby diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 000000000..a3f52bfda --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,6 @@ +--- +concat_basedir: "/tmp" +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" +selinux_config_mode: "disabled" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f56649..32709c814 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,32 @@ require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts + +if Dir.exist?(File.expand_path('../../lib', __FILE__)) && RUBY_VERSION !~ %r{^1.9} + require 'coveralls' + require 'simplecov' + require 'simplecov-console' + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, + Coveralls::SimpleCov::Formatter + ] + SimpleCov.start do + track_files 'lib/**/*.rb' + add_filter '/spec' + add_filter '/vendor' + add_filter '/.vendor' + end +end + +RSpec.configure do |c| + default_facts = { + puppetversion: Puppet.version, + facterversion: Facter.version + } + default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__)) + default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__)) + c.default_facts = default_facts +end + +# vim: syntax=ruby From 2a5da8d6debc0493d427a08a84a40af7201445a1 Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 09:06:02 +0100 Subject: [PATCH 02/10] Fix several Lint issues --- manifests/config.pp | 8 ++++---- manifests/init.pp | 10 +++++----- manifests/install.pp | 32 ++++++++++++++++---------------- manifests/service.pp | 8 ++++---- tests/init.pp | 2 +- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 6974bb5c4..fa61d8f6d 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -9,7 +9,7 @@ $cfg = $::grafana::cfg file { $::grafana::cfg_location: - ensure => present, + ensure => file, content => template('grafana/config.ini.erb'), } } @@ -18,7 +18,7 @@ $cfg = $::grafana::cfg file { $::grafana::cfg_location: - ensure => present, + ensure => file, content => template('grafana/config.ini.erb'), } } @@ -26,7 +26,7 @@ $cfg = $::grafana::cfg file { "${::grafana::install_dir}/conf/custom.ini": - ensure => present, + ensure => file, content => template('grafana/config.ini.erb'), } } @@ -38,7 +38,7 @@ if $::grafana::ldap_cfg { $ldap_cfg = $::grafana::ldap_cfg file { '/etc/grafana/ldap.toml': - ensure => present, + ensure => file, content => inline_template("<%= require 'toml'; TOML::Generator.new(@ldap_cfg).body %>\n"), } } diff --git a/manifests/init.pp b/manifests/init.pp index ba14e9dd1..6b94aa0be 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -92,12 +92,12 @@ fail('cfg parameter must be a hash') } - class { 'grafana::install': } -> - class { 'grafana::config': } ~> - class { 'grafana::service': } + class { '::grafana::install': } -> + class { '::grafana::config': } ~> + class { '::grafana::service': } - contain 'grafana::install' - contain 'grafana::service' + contain '::grafana::install' + contain '::grafana::service' #Class['grafana'] } diff --git a/manifests/install.pp b/manifests/install.pp index e986b61e8..809b19230 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -18,43 +18,43 @@ default => $real_archive_source, } } - + case $::grafana::install_method { 'docker': { docker::image { 'grafana/grafana': image_tag => $::grafana::version, - require => Class['docker'] + require => Class['docker'], } } 'package': { case $::osfamily { 'Debian': { package { 'libfontconfig1': - ensure => present + ensure => present, } wget::fetch { 'grafana': source => $real_package_source, - destination => '/tmp/grafana.deb' + destination => '/tmp/grafana.deb', } package { $::grafana::package_name: ensure => present, provider => 'dpkg', source => '/tmp/grafana.deb', - require => [Wget::Fetch['grafana'],Package['libfontconfig1']] + require => [Wget::Fetch['grafana'],Package['libfontconfig1']], } } 'RedHat': { package { 'fontconfig': - ensure => present + ensure => present, } package { $::grafana::package_name: ensure => present, provider => 'rpm', source => $real_package_source, - require => Package['fontconfig'] + require => Package['fontconfig'], } } default: { @@ -66,12 +66,12 @@ case $::osfamily { 'Debian': { package { 'libfontconfig1': - ensure => present + ensure => present, } if ( $::grafana::manage_package_repo ){ if !defined( Class['apt'] ) { - class { 'apt': } + class { '::apt': } } apt::source { 'grafana': location => "https://packagecloud.io/grafana/${::grafana::repo_name}/debian", @@ -79,7 +79,7 @@ repos => 'main', key => { 'id' => '418A7F2FB0E1E6E7EABF6FE8C2E73424D59097AB', - 'source' => 'https://packagecloud.io/gpg.key' + 'source' => 'https://packagecloud.io/gpg.key', }, before => Package[$::grafana::package_name], } @@ -88,12 +88,12 @@ package { $::grafana::package_name: ensure => $::grafana::version, - require => Package['libfontconfig1'] + require => Package['libfontconfig1'], } } 'RedHat': { package { 'fontconfig': - ensure => present + ensure => present, } if ( $::grafana::manage_package_repo ){ @@ -109,7 +109,7 @@ package { $::grafana::package_name: ensure => "${::grafana::version}-${::grafana::rpm_iteration}", - require => Package['fontconfig'] + require => Package['fontconfig'], } } default: { @@ -123,7 +123,7 @@ if !defined(User['grafana']){ user { 'grafana': ensure => present, - home => $::grafana::install_dir + home => $::grafana::install_dir, } } @@ -131,7 +131,7 @@ ensure => directory, group => 'grafana', owner => 'grafana', - require => User['grafana'] + require => User['grafana'], } archive { '/tmp/grafana.tar.gz': @@ -143,7 +143,7 @@ user => 'grafana', group => 'grafana', cleanup => true, - require => File[$::grafana::install_dir] + require => File[$::grafana::install_dir], } } diff --git a/manifests/service.pp b/manifests/service.pp index 1a517c227..6b1b991c1 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -7,12 +7,12 @@ case $::grafana::install_method { 'docker': { $container = { - 'grafana' => $::grafana::container_params + 'grafana' => $::grafana::container_params, } $defaults = { image => "${::grafana::params::docker_image}:${::grafana::version}", - ports => $::grafana::params::docker_ports + ports => $::grafana::params::docker_ports, } create_resources(docker::run, $container, $defaults) @@ -21,7 +21,7 @@ service { $::grafana::service_name: ensure => running, enable => true, - subscribe => Package[$::grafana::package_name] + subscribe => Package[$::grafana::package_name], } } 'archive': { @@ -35,7 +35,7 @@ binary => "su - grafana -c '${service_path} -config=${service_config} -homepath=${::grafana::install_dir} web &'", hasrestart => false, hasstatus => false, - status => "ps -ef | grep ${::grafana::service_name} | grep -v grep" + status => "ps -ef | grep ${::grafana::service_name} | grep -v grep", } } } diff --git a/tests/init.pp b/tests/init.pp index 8043c17d1..ddf3cc944 100644 --- a/tests/init.pp +++ b/tests/init.pp @@ -9,4 +9,4 @@ # Learn more about module testing here: # http://docs.puppetlabs.com/guides/tests_smoke.html # -include grafana +include ::grafana From 5a12d93e0d64adea9d37b78c983d22c33a58fa12 Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 10:03:02 +0100 Subject: [PATCH 03/10] Fix several Rubocop issues --- lib/puppet/provider/grafana.rb | 111 +++--- .../provider/grafana_dashboard/grafana.rb | 143 ++++---- .../provider/grafana_datasource/grafana.rb | 324 +++++++++--------- lib/puppet/type/grafana_dashboard.rb | 95 ++--- lib/puppet/type/grafana_datasource.rb | 134 ++++---- spec/acceptance/class_spec.rb | 13 +- spec/classes/grafana_spec.rb | 317 ++++++++++------- spec/spec_helper_acceptance.rb | 6 +- .../type/grafana_dashboard_type_spec.rb | 44 +-- .../type/grafana_datasource_type_spec.rb | 36 +- 10 files changed, 628 insertions(+), 595 deletions(-) diff --git a/lib/puppet/provider/grafana.rb b/lib/puppet/provider/grafana.rb index d1cfc47ab..2229f852b 100644 --- a/lib/puppet/provider/grafana.rb +++ b/lib/puppet/provider/grafana.rb @@ -17,72 +17,65 @@ require 'net/http' class Puppet::Provider::Grafana < Puppet::Provider - # Helper methods - def grafana_host - unless @grafana_host - @grafana_host = URI.parse(resource[:grafana_url]).host - end - @grafana_host - end + # Helper methods + def grafana_host + @grafana_host = URI.parse(resource[:grafana_url]).host unless @grafana_host + @grafana_host + end - def grafana_port - unless @grafana_port - @grafana_port = URI.parse(resource[:grafana_url]).port - end - @grafana_port - end + def grafana_port + @grafana_port = URI.parse(resource[:grafana_url]).port unless @grafana_port + @grafana_port + end - def grafana_scheme - unless @grafana_scheme - @grafana_scheme = URI.parse(resource[:grafana_url]).scheme - end - @grafana_scheme + def grafana_scheme + unless @grafana_scheme + @grafana_scheme = URI.parse(resource[:grafana_url]).scheme end + @grafana_scheme + end - # Return a Net::HTTP::Response object - def send_request(operation="GET", path="", data=nil, search_path={}) - request = nil - encoded_search = "" + # Return a Net::HTTP::Response object + def send_request(operation = 'GET', path = '', data = nil, search_path = {}) + request = nil + encoded_search = '' - if URI.respond_to?(:encode_www_form) - encoded_search = URI.encode_www_form(search_path) - else - # Ideally we would have use URI.encode_www_form but it isn't - # available with Ruby 1.8.x that ships with CentOS 6.5. - encoded_search = search_path.to_a.map do |x| - x.map{|y| CGI.escape(y.to_s)}.join('=') - end - encoded_search = encoded_search.join('&') - end - uri = URI.parse("%s://%s:%d%s?%s" % [ - self.grafana_scheme, self.grafana_host, self.grafana_port, - path, encoded_search]) + if URI.respond_to?(:encode_www_form) + encoded_search = URI.encode_www_form(search_path) + else + # Ideally we would have use URI.encode_www_form but it isn't + # available with Ruby 1.8.x that ships with CentOS 6.5. + encoded_search = search_path.to_a.map do |x| + x.map { |y| CGI.escape(y.to_s) }.join('=') + end + encoded_search = encoded_search.join('&') + end + uri = URI.parse format('%s://%s:%d%s?%s', grafana_scheme, grafana_host, grafana_port, path, encoded_search) - case operation.upcase - when 'POST' - request = Net::HTTP::Post.new(uri.request_uri) - request.body = data.to_json() - when 'PUT' - request = Net::HTTP::Put.new(uri.request_uri) - request.body = data.to_json() - when 'GET' - request = Net::HTTP::Get.new(uri.request_uri) - when 'DELETE' - request = Net::HTTP::Delete.new(uri.request_uri) - else - raise Puppet::Error, "Unsupported HTTP operation '%s'" % operation - end + case operation.upcase + when 'POST' + request = Net::HTTP::Post.new(uri.request_uri) + request.body = data.to_json + when 'PUT' + request = Net::HTTP::Put.new(uri.request_uri) + request.body = data.to_json + when 'GET' + request = Net::HTTP::Get.new(uri.request_uri) + when 'DELETE' + request = Net::HTTP::Delete.new(uri.request_uri) + else + raise Puppet::Error, format('Unsupported HTTP operation %s', operation) + end - request.content_type = 'application/json' - if resource[:grafana_user] and resource[:grafana_user] - request.basic_auth resource[:grafana_user], resource[:grafana_password] - end + request.content_type = 'application/json' + if resource[:grafana_user] && resource[:grafana_user] + request.basic_auth resource[:grafana_user], resource[:grafana_password] + end - return Net::HTTP.start(self.grafana_host, self.grafana_port, - :use_ssl => self.grafana_scheme == 'https', - :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http| - http.request(request) - end + Net::HTTP.start(grafana_host, grafana_port, + use_ssl: grafana_scheme == 'https', + verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http| + http.request(request) end + end end - diff --git a/lib/puppet/provider/grafana_dashboard/grafana.rb b/lib/puppet/provider/grafana_dashboard/grafana.rb index 30599b2fe..7f3157724 100644 --- a/lib/puppet/provider/grafana_dashboard/grafana.rb +++ b/lib/puppet/provider/grafana_dashboard/grafana.rb @@ -18,92 +18,79 @@ # Note: this class doesn't implement the self.instances and self.prefetch # methods because the Grafana API doesn't allow to retrieve the dashboards and # all their properties in a single call. -Puppet::Type.type(:grafana_dashboard).provide(:grafana, :parent => Puppet::Provider::Grafana) do - desc "Support for Grafana dashboards stored into Grafana" - - defaultfor :kernel => 'Linux' - - # Return the list of dashboards - def dashboards - response = self.send_request('GET', '/api/search', nil, {:q => '', :starred => false}) - if response.code != '200' - fail("Fail to retrieve the dashboards (HTTP response: %s/%s)" % - [response.code, response.body]) - end - - begin - JSON.parse(response.body) - rescue JSON::ParserError - fail("Fail to parse dashboards (HTTP response: %s/%s)" % - [response_code, response.body]) - end - end - - # Return the dashboard matching with the resource's title - def find_dashboard - if not self.dashboards.find{ |x| x['title'] == resource[:title] } - return - end - - response = self.send_request('GET', '/api/dashboards/db/%s' % self.slug) - if response.code != '200' - fail("Fail to retrieve dashboard '%s' (HTTP response: %s/%s)" % - [resource[:title], response.code, response.body]) - end - - begin - # Cache the dashboard's content - @dashboard = JSON.parse(response.body)["dashboard"] - rescue JSON::ParserError - fail("Fail to parse dashboard '%s': %s" % - [resource[:title], response.body]) - end - end - - def save_dashboard(dashboard) - data = { - :dashboard => dashboard.merge({ - 'title' => resource[:title], - 'id' => @dashboard ? @dashboard['id'] : nil, - 'version' => @dashboard ? @dashboard['version'] + 1 : 0 - }), - :overwrite => @dashboard != nil - } - - response = self.send_request('POST', '/api/dashboards/db', data) - if response.code != '200' - fail("Fail to save dashboard '%s' (HTTP response: %s/%s)" % - [resource[:name], response.code, response.body]) - end - end - - def slug - resource[:title].downcase.gsub(/[^\w\- ]/, '').gsub(/ +/, '-') - end +Puppet::Type.type(:grafana_dashboard).provide(:grafana, parent: Puppet::Provider::Grafana) do + desc 'Support for Grafana dashboards stored into Grafana' - def content - @dashboard - end + defaultfor kernel: 'Linux' - def content=(value) - self.save_dashboard(value) + # Return the list of dashboards + def dashboards + response = send_request('GET', '/api/search', nil, q: '', starred: false) + if response.code != '200' + raise format('Fail to retrieve the dashboards (HTTP response: %s/%s)', response.code, response.body) end - def create - self.save_dashboard(resource[:content]) + begin + JSON.parse(response.body) + rescue JSON::ParserError + raise format('Fail to parse dashboards (HTTP response: %s/%s)', response.code, response.body) end + end - def destroy - response = self.send_request('DELETE', '/api/dashboards/db/%s' % self.slug) + # Return the dashboard matching with the resource's title + def find_dashboard + return unless dashboards.find { |x| x['title'] == resource[:title] } - if response.code != '200' - raise Puppet::Error, "Failed to delete dashboard '%s' (HTTP "\ - "response: %s/'%s')" % [resource[:title], response.code, - response.body] - end + response = send_request format('GET, /api/dashboards/db/%s', slug) + if response.code != '200' + raise format('Fail to retrieve dashboard %s (HTTP response: %s/%s)', resource[:title], response.code, response.body) end - def exists? - self.find_dashboard() + begin + # Cache the dashboard's content + @dashboard = JSON.parse(response.body)['dashboard'] + rescue JSON::ParserError + raise format('Fail to parse dashboard %s: %s', resource[:title], response.body) end + end + + def save_dashboard(dashboard) + data = { + dashboard: dashboard.merge('title' => resource[:title], + 'id' => @dashboard ? @dashboard['id'] : nil, + 'version' => @dashboard ? @dashboard['version'] + 1 : 0), + overwrite: !@dashboard.nil? + } + + response = send_request('POST', '/api/dashboards/db', data) + return unless response.code != '200' + raise format('Fail to save dashboard %s (HTTP response: %s/%s', resource[:name], response.code, response.body) + end + + def slug + resource[:title].downcase.gsub(%r{[^\w\- ]}, '').gsub(%r{ +}, '-') + end + + def content + @dashboard + end + + def content=(value) + save_dashboard(value) + end + + def create + save_dashboard(resource[:content]) + end + + def destroy + response = send_request format('DELETE, /api/dashboards/db/%s', slug) + + return unless response.code != '200' + raise Puppet::Error, format('Failed to delete dashboard %s (HTTP response: %s/%s', resource[:title], response.code, response.body) + end + + def exists? + find_dashboard + end end diff --git a/lib/puppet/provider/grafana_datasource/grafana.rb b/lib/puppet/provider/grafana_datasource/grafana.rb index 1e08b8805..94a74f4b5 100644 --- a/lib/puppet/provider/grafana_datasource/grafana.rb +++ b/lib/puppet/provider/grafana_datasource/grafana.rb @@ -16,177 +16,171 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'grafana')) -Puppet::Type.type(:grafana_datasource).provide(:grafana, :parent => Puppet::Provider::Grafana) do - desc "Support for Grafana datasources" +Puppet::Type.type(:grafana_datasource).provide(:grafana, parent: Puppet::Provider::Grafana) do + desc 'Support for Grafana datasources' - defaultfor :kernel => 'Linux' + defaultfor kernel: 'Linux' - def datasources - response = self.send_request('GET', '/api/datasources') - if response.code != '200' - fail("Fail to retrieve datasources (HTTP response: %s/%s)" % - [response.code, response.body]) - end - - begin - datasources = JSON.parse(response.body) - - datasources.collect{|x| x["id"]}.collect do |id| - response = self.send_request('GET', '/api/datasources/%s' % id) - if response.code != '200' - fail("Fail to retrieve datasource %d (HTTP response: %s/%s)" % - [id, response.code, response.body]) - end - - datasource = JSON.parse(response.body) - - { - :id => datasource["id"], - :name => datasource["name"], - :url => datasource["url"], - :type => datasource["type"], - :user => datasource["user"], - :password => datasource["password"], - :database => datasource["database"], - :access_mode => datasource["access"], - :is_default => datasource["isDefault"] ? :true : :false, - :json_data => datasource["jsonData"] - } - end - rescue JSON::ParserError - fail("Fail to parse response: %s" % response.body) - end - end - - def datasource - unless @datasource - @datasource = self.datasources.find { |x| x[:name] == resource[:name] } - end - @datasource - end - - def datasource=(value) - @datasource = value - end - - def type - self.datasource[:type] - end - - def type=(value) - resource[:type] = value - self.save_datasource() - end - - def url - self.datasource[:url] - end - - def url=(value) - resource[:url] = value - self.save_datasource() - end - - def access_mode - self.datasource[:access_mode] - end - - def access_mode=(value) - self.resource[:access_mode] = value - self.save_datasource() - end - - def database - self.datasource[:database] - end - - def database=(value) - resource[:database] = value - self.save_datasource() - end - - def user - self.datasource[:user] - end - - def user=(value) - resource[:user] = value - self.save_datasource() - end - - def password - self.datasource[:password] - end - - def password=(value) - resource[:password] = value - self.save_datasource() - end - - def is_default - self.datasource[:is_default] - end - - def is_default=(value) - resource[:is_default] = value - self.save_datasource() - end - - def json_data - self.datasource[:json_data] - end - - def json_data=(value) - resource[:json_data] = value - self.save_datasource() - end - - def save_datasource - data = { - :name => resource[:name], - :type => resource[:type], - :url => resource[:url], - :access => resource[:access_mode], - :database => resource[:database], - :user => resource[:user], - :password => resource[:password], - :isDefault => (resource[:is_default] == :true), - :jsonData => resource[:json_data], - } - - if self.datasource.nil? - response = self.send_request('POST', '/api/datasources', data) - else - data[:id] = self.datasource[:id] - response = self.send_request('PUT', '/api/datasources/%s' % self.datasource[:id], data) - end - - if response.code != '200' - fail("Failed to create save '%s' (HTTP response: %s/'%s')" % - [resource[:name], response.code, response.body]) - end - self.datasource = nil + def datasources + response = send_request('GET', '/api/datasources') + if response.code != '200' + raise format('Fail to retrieve datasources (HTTP response: %s/%s)', response.code, response.body) end - def delete_datasource - response = self.send_request('DELETE', '/api/datasources/%s' % self.datasource[:id]) + begin + datasources = JSON.parse(response.body) + datasources.map { |x| x['id'] }.map do |id| + response = send_request format('GET, /api/datasources/%s', id) if response.code != '200' - fail("Failed to delete datasource '%s' (HTTP response: %s/'%s')" % - [resource[:name], response.code, response.body]) + raise format('Fail to retrieve datasource %d (HTTP response: %s/%s)', id, response.code, response.body) end - self.datasource = nil - end - - def create - self.save_datasource() - end - def destroy - self.delete_datasource() - end - - def exists? - self.datasource - end + datasource = JSON.parse(response.body) + + { + id: datasource['id'], + name: datasource['name'], + url: datasource['url'], + type: datasource['type'], + user: datasource['user'], + password: datasource['password'], + database: datasource['database'], + access_mode: datasource['access'], + is_default: datasource['isDefault'] ? :true : :false, + json_data: datasource['jsonData'] + } + end + rescue JSON::ParserError + raise format('Fail to parse response: %s', response.body) + end + end + + def datasource + unless @datasource + @datasource = datasources.find { |x| x[:name] == resource[:name] } + end + @datasource + end + + attr_writer :datasource + + def type + datasource[:type] + end + + def type=(value) + resource[:type] = value + save_datasource + end + + def url + datasource[:url] + end + + def url=(value) + resource[:url] = value + save_datasource + end + + def access_mode + datasource[:access_mode] + end + + def access_mode=(value) + resource[:access_mode] = value + save_datasource + end + + def database + datasource[:database] + end + + def database=(value) + resource[:database] = value + save_datasource + end + + def user + datasource[:user] + end + + def user=(value) + resource[:user] = value + save_datasource + end + + def password + datasource[:password] + end + + def password=(value) + resource[:password] = value + save_datasource + end + + def default? + datasource[:is_default] + end + + def default=(value) + resource[:is_default] = value + save_datasource + end + + def json_data + datasource[:json_data] + end + + def json_data=(value) + resource[:json_data] = value + save_datasource + end + + def save_datasource + data = { + name: resource[:name], + type: resource[:type], + url: resource[:url], + access: resource[:access_mode], + database: resource[:database], + user: resource[:user], + password: resource[:password], + isDefault: (resource[:is_default] == :true), + jsonData: resource[:json_data] + } + + if datasource.nil? + response = send_request('POST', '/api/datasources', data) + else + data[:id] = datasource[:id] + response = send_request format('PUT, /api/datasources/%s', datasource[:id]) + end + + if response.code != '200' + raise format('Failed to create save %s (HTTP response: %s/%s)', resource[:name], response.code, response.body) + end + self.datasource = nil + end + + def delete_datasource + response = send_request format('DELETE, /api/datasources/%s', datasource[:id]) + + if response.code != '200' + raise format('Failed to delete datasource %s (HTTP response: %s/%s', resource[:name], response.code, response.body) + end + self.datasource = nil + end + + def create + save_datasource + end + + def destroy + delete_datasource + end + + def exists? + datasource + end end diff --git a/lib/puppet/type/grafana_dashboard.rb b/lib/puppet/type/grafana_dashboard.rb index 51e2d2475..fceadb24d 100644 --- a/lib/puppet/type/grafana_dashboard.rb +++ b/lib/puppet/type/grafana_dashboard.rb @@ -14,65 +14,66 @@ require 'json' Puppet::Type.newtype(:grafana_dashboard) do - @doc = "Manage dashboards in Grafana" + @doc = 'Manage dashboards in Grafana' - ensurable + ensurable - newparam(:title, :namevar => true) do - desc "The title of the dashboard." - end + newparam(:title, namevar: true) do + desc 'The title of the dashboard.' + end - newproperty(:content) do - desc "The JSON representation of the dashboard." + newproperty(:content) do + desc 'The JSON representation of the dashboard.' - validate do |value| - begin - JSON.parse(value) - rescue JSON::ParserError - raise ArgumentError , "Invalid JSON string for content" - end - end + validate do |value| + begin + JSON.parse(value) + rescue JSON::ParserError + raise ArgumentError, 'Invalid JSON string for content' + end + end - munge do |value| - JSON.parse(value) - end + munge do |value| + JSON.parse(value) + end - def should_to_s(value) - if value.length > 12 - "#{value.to_s.slice(0,12)}..." - else - value - end - end + def should_to_s(value) + if value.length > 12 + "#{value.to_s.slice(0, 12)}..." + else + value + end + end - def is_to_s(value) - should_to_s(value) - end + def to_s(value) + should_to_s(value) end + end - newparam(:grafana_url) do - desc "The URL of the Grafana server" - defaultto "" + newparam(:grafana_url) do + desc 'The URL of the Grafana server' + defaultto '' - validate do |value| - unless value =~ /^https?:\/\// - raise ArgumentError , "'%s' is not a valid URL" % value - end - end + validate do |value| + unless value =~ %r{^https?://} + raise ArgumentError, format('%s is not a valid URL', value) + end end + end - newparam(:grafana_user) do - desc "The username for the Grafana server (optional)" - end + newparam(:grafana_user) do + desc 'The username for the Grafana server (optional)' + end - newparam(:grafana_password) do - desc "The password for the Grafana server (optional)" - end + newparam(:grafana_password) do + desc 'The password for the Grafana server (optional)' + end - validate do - fail('content is required when ensure is present') if self[:ensure] == :present and self[:content].nil? - end - autorequire(:service) do - 'grafana-server' - end + # rubocop:disable Style/SignalException + validate do + fail('content is required when ensure is present') if self[:ensure] == :present && self[:content].nil? + end + autorequire(:service) do + 'grafana-server' + end end diff --git a/lib/puppet/type/grafana_datasource.rb b/lib/puppet/type/grafana_datasource.rb index 4c4779afa..086386d35 100644 --- a/lib/puppet/type/grafana_datasource.rb +++ b/lib/puppet/type/grafana_datasource.rb @@ -13,82 +13,82 @@ # under the License. # Puppet::Type.newtype(:grafana_datasource) do - @doc = "Manage datasources in Grafana" + @doc = 'Manage datasources in Grafana' - ensurable + ensurable - newparam(:name, :namevar => true) do - desc "The name of the datasource." - end - - newparam(:grafana_url) do - desc "The URL of the Grafana server" - defaultto "" - - validate do |value| - unless value =~ /^https?:\/\// - raise ArgumentError , "'%s' is not a valid URL" % value - end - end - end - - newparam(:grafana_user) do - desc "The username for the Grafana server" - end - - newparam(:grafana_password) do - desc "The password for the Grafana server" - end - - newproperty(:url) do - desc "The URL of the datasource" + newparam(:name, namevar: true) do + desc 'The name of the datasource.' + end - validate do |value| - unless value =~ /^https?:\/\// - raise ArgumentError , "'%s' is not a valid URL" % value - end - end - end + newparam(:grafana_url) do + desc 'The URL of the Grafana server' + defaultto '' - newproperty(:type) do - desc "The datasource type" - newvalues(:influxdb, :elasticsearch, :graphite, :kairosdb, :opentsdb, :prometheus) + validate do |value| + unless value =~ %r{^https?://} + raise ArgumentError, format('%s is not a valid URL', value) + end end + end - newproperty(:user) do - desc "The username for the datasource (optional)" - end + newparam(:grafana_user) do + desc 'The username for the Grafana server' + end - newproperty(:password) do - desc "The password for the datasource (optional)" - end - - newproperty(:database) do - desc "The name of the database (optional)" - end - - newproperty(:access_mode) do - desc "Whether the datasource is accessed directly or not by the clients" - newvalues(:direct, :proxy) - defaultto :direct - end - - newproperty(:is_default) do - desc "Whether the datasource is the default one" - newvalues(:true, :false) - defaultto :false - end + newparam(:grafana_password) do + desc 'The password for the Grafana server' + end - newproperty(:json_data) do - desc "Additional JSON data to configure the datasource (optional)" + newproperty(:url) do + desc 'The URL of the datasource' - validate do |value| - unless value.nil? or value.is_a?(Hash) then - raise ArgumentError , "json_data should be a Hash!" - end - end + validate do |value| + unless value =~ %r{^https?://} + raise ArgumentError, format('%s is not a valid URL', value) + end end - autorequire(:service) do - 'grafana-server' + end + + newproperty(:type) do + desc 'The datasource type' + newvalues(:influxdb, :elasticsearch, :graphite, :kairosdb, :opentsdb, :prometheus) + end + + newproperty(:user) do + desc 'The username for the datasource (optional)' + end + + newproperty(:password) do + desc 'The password for the datasource (optional)' + end + + newproperty(:database) do + desc 'The name of the database (optional)' + end + + newproperty(:access_mode) do + desc 'Whether the datasource is accessed directly or not by the clients' + newvalues(:direct, :proxy) + defaultto :direct + end + + newproperty(:is_default) do + desc 'Whether the datasource is the default one' + newvalues(:true, :false) + defaultto :false + end + + newproperty(:json_data) do + desc 'Additional JSON data to configure the datasource (optional)' + + validate do |value| + unless value.nil? || value.is_a?(Hash) + raise ArgumentError, 'json_data should be a Hash!' + end end + end + autorequire(:service) do + 'grafana-server' + end end diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 1c5ad99af..759ad09f3 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,26 +1,25 @@ require 'spec_helper_acceptance' describe 'grafana class' do - context 'default parameters' do # Using puppet_apply as a helper - it 'should work idempotently with no errors' do + 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) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end describe package('grafana') do - it { should be_installed } + it { is_expected.to be_installed } end describe service('grafana') do - it { should be_enabled } - it { should be_running } + it { is_expected.to be_enabled } + it { is_expected.to be_running } end end end diff --git a/spec/classes/grafana_spec.rb b/spec/classes/grafana_spec.rb index 2f369c242..2790c6eea 100644 --- a/spec/classes/grafana_spec.rb +++ b/spec/classes/grafana_spec.rb @@ -2,271 +2,330 @@ describe 'grafana' do context 'supported operating systems' do - ['Debian', 'RedHat'].each do |osfamily| + %w(Debian RedHat).each do |osfamily| describe "grafana class without any parameters on #{osfamily}" do - let(:params) {{ }} - let(:facts) {{ - :osfamily => osfamily, - }} - - it { should contain_class('grafana::params') } - it { should contain_class('grafana::install').that_comes_before('grafana::config') } - it { should contain_class('grafana::config') } - it { should contain_class('grafana::service').that_subscribes_to('grafana::config') } - - it { should contain_service('grafana-server').with_ensure('running').with_enable(true) } - it { should contain_package('grafana').with_ensure('present') } + let(:params) { {} } + let(:facts) do + { + osfamily: osfamily + } + end + + it { is_expected.to contain_class('grafana::params') } + it { is_expected.to contain_class('grafana::install').that_comes_before('grafana::config') } + it { is_expected.to contain_class('grafana::config') } + it { is_expected.to contain_class('grafana::service').that_subscribes_to('grafana::config') } + + it { is_expected.to contain_service('grafana-server').with_ensure('running').with_enable(true) } + it { is_expected.to contain_package('grafana').with_ensure('present') } end end end context 'unsupported operating system' do describe 'grafana class without any parameters on Solaris/Nexenta' do - let(:facts) {{ - :osfamily => 'Solaris', - :operatingsystem => 'Nexenta', - }} + let(:facts) do + { + osfamily: 'Solaris', + operatingsystem: 'Nexenta' + } + end - it { expect { should contain_package('grafana') }.to raise_error(Puppet::Error, /Nexenta not supported/) } + it { expect { is_expected.to contain_package('grafana') }.to raise_error(Puppet::Error, %r{Nexenta not supported}) } end end context 'package install method' do context 'debian' do - let(:facts) {{ - :osfamily => 'Debian' - }} + let(:facts) do + { + osfamily: 'Debian' + } + end download_location = '/tmp/grafana.deb' describe 'use wget to fetch the package to a temporary location' do - it { should contain_wget__fetch('grafana').with_destination(download_location) } - it { should contain_wget__fetch('grafana').that_comes_before('Package[grafana]') } + it { is_expected.to contain_wget__fetch('grafana').with_destination(download_location) } + it { is_expected.to contain_wget__fetch('grafana').that_comes_before('Package[grafana]') } end describe 'install dependencies first' do - it { should contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } + it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } end describe 'install the package' do - it { should contain_package('grafana').with_provider('dpkg') } - it { should contain_package('grafana').with_source(download_location) } + it { is_expected.to contain_package('grafana').with_provider('dpkg') } + it { is_expected.to contain_package('grafana').with_source(download_location) } end end context 'redhat' do - let(:facts) {{ - :osfamily => 'RedHat' - }} + let(:facts) do + { + osfamily: 'RedHat' + } + end describe 'install dependencies first' do - it { should contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } + it { is_expected.to contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } end describe 'install the package' do - it { should contain_package('grafana').with_provider('rpm') } + it { is_expected.to contain_package('grafana').with_provider('rpm') } end end end context 'repo install method' do - let(:params) {{ - :install_method => 'repo', - :manage_package_repo => true - }} + let(:params) do + { + install_method: 'repo', + manage_package_repo: true + } + end context 'debian' do - let(:facts) {{ - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu' - }} + let(:facts) do + { + osfamily: 'Debian', + lsbdistid: 'Ubuntu' + } + end describe 'install apt repo dependencies first' do - it { should contain_class('apt') } - it { should contain_apt__source('grafana').with(:release => 'wheezy', :repos => 'main', :location => 'https://packagecloud.io/grafana/stable/debian') } - it { should contain_apt__source('grafana').that_comes_before('Package[grafana]') } + it { is_expected.to contain_class('apt') } + it { is_expected.to contain_apt__source('grafana').with(release: 'wheezy', repos: 'main', location: 'https://packagecloud.io/grafana/stable/debian') } + it { is_expected.to contain_apt__source('grafana').that_comes_before('Package[grafana]') } end describe 'install dependencies first' do - it { should contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } + it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } end describe 'install the package' do - it { should contain_package('grafana').with_ensure('2.5.0') } + it { is_expected.to contain_package('grafana').with_ensure('2.5.0') } end end context 'redhat' do - let(:facts) {{ - :osfamily => 'RedHat' - }} + let(:facts) do + { + osfamily: 'RedHat' + } + end describe 'yum repo dependencies first' do - it { should contain_yumrepo('grafana').with(:baseurl => 'https://packagecloud.io/grafana/stable/el/6/$basearch', :gpgkey => 'https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana', :enabled => 1) } - it { should contain_yumrepo('grafana').that_comes_before('Package[grafana]') } + it { is_expected.to contain_yumrepo('grafana').with(baseurl: 'https://packagecloud.io/grafana/stable/el/6/$basearch', gpgkey: 'https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana', enabled: 1) } + it { is_expected.to contain_yumrepo('grafana').that_comes_before('Package[grafana]') } end describe 'install dependencies first' do - it { should contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } + it { is_expected.to contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } end describe 'install the package' do - it { should contain_package('grafana').with_ensure('2.5.0-1') } + it { is_expected.to contain_package('grafana').with_ensure('2.5.0-1') } end end end context 'repo install method without managing the package repo' do - let(:params) {{ - :install_method => 'repo', - :manage_package_repo => false, - :version => 'present' - }} + let(:params) do + { + install_method: 'repo', + manage_package_repo: false, + version: 'present' + } + end context 'debian' do - let(:facts) {{ - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu' - }} + let(:facts) do + { + osfamily: 'Debian', + lsbdistid: 'Ubuntu' + } + end - it { should compile.with_all_deps } + it { is_expected.to compile.with_all_deps } describe 'install dependencies first' do - it { should contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } + it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } end describe 'install the package' do - it { should contain_package('grafana').with_ensure('present') } + it { is_expected.to contain_package('grafana').with_ensure('present') } end end end context 'archive install method' do - let(:params) {{ - :install_method => 'archive' - }} + let(:params) do + { + install_method: 'archive' + } + end install_dir = '/usr/share/grafana' service_config = '/usr/share/grafana/conf/custom.ini' archive_source = 'https://grafanarel.s3.amazonaws.com/builds/grafana-2.5.0.linux-x64.tar.gz' describe 'extract archive to install_dir' do - it { should contain_archive('/tmp/grafana.tar.gz').with_ensure('present') } - it { should contain_archive('/tmp/grafana.tar.gz').with_source(archive_source) } - it { should contain_archive('/tmp/grafana.tar.gz').with_extract_path(install_dir) } + it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_ensure('present') } + it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_source(archive_source) } + it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_extract_path(install_dir) } end describe 'create grafana user' do - it { should contain_user('grafana').with_ensure('present').with_home(install_dir) } - it { should contain_user('grafana').that_comes_before('File[/usr/share/grafana]') } + it { is_expected.to contain_user('grafana').with_ensure('present').with_home(install_dir) } + it { is_expected.to contain_user('grafana').that_comes_before('File[/usr/share/grafana]') } end describe 'manage install_dir' do - it { should contain_file(install_dir).with_ensure('directory') } - it { should contain_file(install_dir).with_group('grafana').with_owner('grafana') } + it { is_expected.to contain_file(install_dir).with_ensure('directory') } + it { is_expected.to contain_file(install_dir).with_group('grafana').with_owner('grafana') } end describe 'configure grafana' do - it { should contain_file(service_config).with_ensure('present') } + it { is_expected.to contain_file(service_config).with_ensure('present') } end describe 'run grafana as service' do - it { should contain_service('grafana-server').with_ensure('running').with_provider('base') } - it { should contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } + it { is_expected.to contain_service('grafana-server').with_ensure('running').with_provider('base') } + it { is_expected.to contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } end context 'when user already defined' do - let(:pre_condition) { + let(:pre_condition) do 'user{"grafana": ensure => present, }' - } + end describe 'do NOT create grafana user' do - it { should_not contain_user('grafana').with_ensure('present').with_home(install_dir) } + it { is_expected.not_to contain_user('grafana').with_ensure('present').with_home(install_dir) } end end context 'when service already defined' do - let(:pre_condition) { + let(:pre_condition) do 'service{"grafana-server": ensure => running, hasrestart => true, hasstatus => true, }' - } + end # let(:params) {{ :service_name => 'grafana-server'}} describe 'do NOT run service' do - it { should_not contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } + it { is_expected.not_to contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } end end end context 'invalid parameters' do context 'cfg' do - let(:facts) {{ - :osfamily => 'Debian', - }} + let(:facts) do + { + osfamily: 'Debian' + } + end describe 'should raise an error when cfg parameter is not a hash' do - let(:params) {{ - :cfg => [], - }} + let(:params) do + { + cfg: [] + } + end - it { expect { should contain_package('grafana') }.to raise_error(Puppet::Error, /cfg parameter must be a hash/) } + it { expect { is_expected.to contain_package('grafana') }.to raise_error(Puppet::Error, %r{cfg parameter must be a hash}) } end describe 'should not raise an error when cfg parameter is a hash' do - let(:params) {{ - :cfg => {}, - }} + let(:params) do + { + cfg: {} + } + end - it { should contain_package('grafana') } + it { is_expected.to contain_package('grafana') } end end end context 'configuration file' do - let(:facts) {{ - :osfamily => 'Debian', - }} + let(:facts) do + { + osfamily: 'Debian' + } + end describe 'should not contain any configuration when cfg param is empty' do - it { should contain_file('/etc/grafana/grafana.ini').with_content("# This file is managed by Puppet, any changes will be overwritten\n\n") } + it { is_expected.to contain_file('/etc/grafana/grafana.ini').with_content("# This file is managed by Puppet, any changes will be overwritten\n\n") } end describe 'should correctly transform cfg param entries to Grafana configuration' do - let(:params) {{ - :cfg => { - 'app_mode' => 'production', - 'section' => { - 'string' => 'production', - 'number' => 8080, - 'boolean' => false, - 'empty' => '', + let(:params) do + { + cfg: { + 'app_mode' => 'production', + 'section' => { + 'string' => 'production', + 'number' => 8080, + 'boolean' => false, + 'empty' => '' + describe 'should correctly transform cfg param entries to Grafana configuration' do + let(:params) do + { + cfg: { + 'app_mode' => 'production', + 'section' => { + 'string' => 'production', + 'number' => 8080, + 'boolean' => false, + 'empty' => '' + } + }, + ldap_cfg: { + 'servers' => [ + { 'host' => 'server1', + 'use_ssl' => true, + 'search_filter' => '(sAMAccountName=%s)', + 'search_base_dns' => ['dc=domain1,dc=com'] }, + { 'host' => 'server2', + 'use_ssl' => true, + 'search_filter' => '(sAMAccountName=%s)', + 'search_base_dns' => ['dc=domain2,dc=com'] } + ], + 'servers.attributes' => { + 'name' => 'givenName', + 'surname' => 'sn', + 'username' => 'sAMAccountName', + 'member_of' => 'memberOf', + 'email' => 'email' + } + } + } }, - }, - :ldap_cfg => { - 'servers' => [ - { 'host' => 'server1', - 'use_ssl' => true, - 'search_filter' => '(sAMAccountName=%s)', - 'search_base_dns' => [ 'dc=domain1,dc=com' ], - }, - { 'host' => 'server2', - 'use_ssl' => true, - 'search_filter' => '(sAMAccountName=%s)', - 'search_base_dns' => [ 'dc=domain2,dc=com' ], - }, - ], - 'servers.attributes' => { - 'name' => 'givenName', - 'surname' => 'sn', - 'username' => 'sAMAccountName', - 'member_of' => 'memberOf', - 'email' => 'email', + ldap_cfg: { + 'servers' => [ + { 'host' => 'server1', + 'use_ssl' => true, + 'search_filter' => '(sAMAccountName=%s)', + 'search_base_dns' => ['dc=domain1,dc=com'] }, + { 'host' => 'server2', + 'use_ssl' => true, + 'search_filter' => '(sAMAccountName=%s)', + 'search_base_dns' => ['dc=domain2,dc=com'] } + ], + 'servers.attributes' => { + 'name' => 'givenName', + 'surname' => 'sn', + 'username' => 'sAMAccountName', + 'member_of' => 'memberOf', + 'email' => 'email' + } } - }, - }} + } + end expected = "# This file is managed by Puppet, any changes will be overwritten\n\n"\ "app_mode = production\n\n"\ @@ -276,7 +335,7 @@ "number = 8080\n"\ "string = production\n" - it { should contain_file('/etc/grafana/grafana.ini').with_content(expected) } + it { is_expected.to contain_file('/etc/grafana/grafana.ini').with_content(expected) } ldap_expected = "\n[[servers]]\n"\ "host = \"server1\"\n"\ @@ -298,7 +357,7 @@ "username = \"sAMAccountName\"\n"\ "\n" - it { should contain_file('/etc/grafana/ldap.toml').with_content(ldap_expected) } + it { is_expected.to contain_file('/etc/grafana/ldap.toml').with_content(ldap_expected) } end end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 5c8573286..3d18c478b 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,7 +1,7 @@ require 'beaker-rspec/spec_helper' require 'beaker-rspec/helpers/serverspec' -hosts.each do |host| +hosts.each do |_host| # Install Puppet install_puppet end @@ -16,9 +16,9 @@ # Configure all nodes in nodeset c.before :suite do # Install module and dependencies - puppet_module_install(:source => proj_root, :module_name => 'grafana') + puppet_module_install(source: proj_root, module_name: 'grafana') hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } + on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] 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 de1325ab6..dc60cb3ae 100644 --- a/spec/unit/puppet/type/grafana_dashboard_type_spec.rb +++ b/spec/unit/puppet/type/grafana_dashboard_type_spec.rb @@ -14,46 +14,46 @@ require 'spec_helper' describe Puppet::Type.type(:grafana_dashboard) do - let(:gdashboard) { - described_class.new :name => "foo", :grafana_url => "http://example.com/", :content => "{}", :ensure => :present - } - context "when setting parameters" do - - it "should fail if grafana_url isn't HTTP-based" do - expect { - described_class.new :name => "foo", :grafana_url => "example.com", :content => "{}", :ensure => :present - }.to raise_error(Puppet::Error, /not a valid URL/) + 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 "should fail if content isn't provided" do - expect { - described_class.new :name => "foo", :grafana_url => "http://example.com", :ensure => :present - }.to raise_error(Puppet::Error, /content is required/) + 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 "should fail if content isn't JSON" do - expect { - described_class.new :name => "foo", :grafana_url => "http://example.com/", :content => "{invalid", :ensure => :present - }.to raise_error(Puppet::Error, /Invalid JSON/) + 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 - it "should accept valid parameters" do + # 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 "should autorequire the grafana-server for proper ordering" do + it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new - service = Puppet::Type.type(:service).new(:name => "grafana-server") + 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]") and (rel.target.to_s == gdashboard.to_s) + (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gdashboard.to_s) end expect(relationship).to be_a Puppet::Relationship end - it "should not autorequire the service it is not managed" do + 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 diff --git a/spec/unit/puppet/type/grafana_datasource_type_spec.rb b/spec/unit/puppet/type/grafana_datasource_type_spec.rb index 708d7c750..76397c748 100644 --- a/spec/unit/puppet/type/grafana_datasource_type_spec.rb +++ b/spec/unit/puppet/type/grafana_datasource_type_spec.rb @@ -14,40 +14,40 @@ require 'spec_helper' describe Puppet::Type.type(:grafana_datasource) do - let(:gdatasource) { - described_class.new :name => "foo", :grafana_url => "http://example.com", :url => 'http://influx.example.com' - } - context "when setting parameters" do - - it "should fail if grafana_url isn't HTTP-based" do - expect { - described_class.new :name => "foo", :grafana_url => "example.com", :content => "{}", :ensure => :present - }.to raise_error(Puppet::Error, /not a valid URL/) + let(:gdatasource) do + described_class.new name: 'foo', grafana_url: 'http://example.com', url: 'http://influx.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: '{}', ensure: :present + end.to raise_error(Puppet::Error, %r{not a valid URL}) end - it "should fail if json_data isn't valid" do - expect { - described_class.new :name => "foo", :grafana_url => "http://example.com", :json_data => "invalid", :ensure => :present - }.to raise_error(Puppet::Error, /json_data should be a Hash/) + 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 "should accept valid parameters" do + # 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://influx.example.com') end - it "should autorequire the grafana-server for proper ordering" do + it 'autorequires the grafana-server for proper ordering' do catalog = Puppet::Resource::Catalog.new - service = Puppet::Type.type(:service).new(:name => "grafana-server") + 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]") and (rel.target.to_s == gdatasource.to_s) + (rel.source.to_s == 'Service[grafana-server]') && (rel.target.to_s == gdatasource.to_s) end expect(relationship).to be_a Puppet::Relationship end - it "should not autorequire the service it is not managed" do + 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 From c4686125c46f25d3c2c6413479e5dc2fb4512a0f Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 10:15:37 +0100 Subject: [PATCH 04/10] Fix open ended dependency for puppet/archive --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 2473131b2..73cb8c293 100644 --- a/metadata.json +++ b/metadata.json @@ -44,7 +44,7 @@ "dependencies": [ { "name": "puppet/archive", - "version_requirement": ">= 0.5.1" + "version_requirement": ">= 0.5.1 <2.0.0" }, { "name": "garethr/docker", From e4e15574a2679cee7c97686811fbf3753e21fbc9 Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 12:06:36 +0100 Subject: [PATCH 05/10] Rename directory tests to examples --- {tests => examples}/init.pp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {tests => examples}/init.pp (100%) diff --git a/tests/init.pp b/examples/init.pp similarity index 100% rename from tests/init.pp rename to examples/init.pp From 3c9cefc3de69e5e78e7693fed9189a3427d13dad Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 15:58:34 +0100 Subject: [PATCH 06/10] Fix several Markdown issues --- README.md | 215 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 138 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index c556d45c9..e8b46b9b6 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,42 @@ -#grafana +# grafana [![Puppet Forge](http://img.shields.io/puppetforge/v/bfraser/grafana.svg)](https://forge.puppetlabs.com/bfraser/grafana) [![Build Status](http://img.shields.io/travis/bfraser/puppet-grafana.svg)](http://travis-ci.org/bfraser/puppet-grafana) -####Table of Contents +#### Table of Contents 1. [Overview](#overview) -2. [Module Description](#module-description) -3. [Setup](#setup) +1. [Module Description](#module-description) +1. [Setup](#setup) * [Beginning with Grafana](#beginning-with-grafana) -4. [Usage](#usage) +1. [Usage](#usage) * [Classes and Defined Types](#classes-and-defined-types) -5. [Limitations](#limitations) -6. [Copyright and License](#copyright-and-license) + * [Advanced usage](#advanced-usage) +1. [Limitations](#limitations) +1. [Copyright and License](#copyright-and-license) -##Overview +## Overview -This module installs Grafana, a dashboard and graph editor for Graphite, InfluxDB and OpenTSDB. +This module installs Grafana, a dashboard and graph editor for Graphite, +InfluxDB and OpenTSDB. -##Module Description +## Module Description -Version 2.x of this module is designed to work with version 2.x of Grafana. If you would like to continue to use Grafana 1.x, please use version 1.x of this module. +Version 2.x of this module is designed to work with version 2.x of Grafana. +If you would like to continue to use Grafana 1.x, please use version 1.x of +this module. -##Setup +## Setup This module will: -* Install Grafana using your preferred method: package (default), Docker container, or tar archive -* Allow you to override the version of Grafana to be installed, and / or the package source +* Install Grafana using your preferred method: package (default), Docker + container, or tar archive +* Allow you to override the version of Grafana to be installed, and / or the + package source * Perform basic configuration of Grafana -###Beginning with Grafana +### Beginning with Grafana To install Grafana with the default parameters: @@ -38,7 +44,8 @@ To install Grafana with the default parameters: class { 'grafana': } ``` -This assumes that you want to install Grafana using the 'package' method. To establish customized parameters: +This assumes that you want to install Grafana using the 'package' method. To +establish customized parameters: ```puppet class { 'grafana': @@ -46,32 +53,41 @@ This assumes that you want to install Grafana using the 'package' method. To est } ``` -##Usage +## Usage -###Classes and Defined Types +### Classes and Defined Types -####Class: `grafana` +#### Class: `grafana` -The Grafana module's primary class, `grafana`, guides the basic setup of Grafana on your system. +The Grafana module's primary class, `grafana`, guides the basic setup of Grafana +on your system. ```puppet class { 'grafana': } ``` + **Parameters within `grafana`:** -#####`archive_source` +##### `archive_source` -The download location of a tarball to use with the 'archive' install method. Defaults to the URL of the latest version of Grafana available at the time of module release. +The download location of a tarball to use with the 'archive' install method. +Defaults to the URL of the latest version of Grafana available at the time of +module release. -#####`cfg_location` +##### `cfg_location` -Configures the location to which the Grafana configuration is written. The default location is '/etc/grafana/grafana.ini'. +Configures the location to which the Grafana configuration is written. The +default location is '/etc/grafana/grafana.ini'. -#####`cfg` +##### `cfg` -Manages the Grafana configuration file. Grafana comes with its own default settings in a different configuration file (/opt/grafana/current/conf/defaults.ini), therefore this module does not supply any defaults. +Manages the Grafana configuration file. Grafana comes with its own default +settings in a different configuration file (/opt/grafana/current/conf/defaults.ini), +therefore this module does not supply any defaults. -This parameter only accepts a hash as its value. Keys with hashes as values will generate sections, any other values are just plain values. The example below will result in... +This parameter only accepts a hash as its value. Keys with hashes as values will +generate sections, any other values are just plain values. The example below will +result in... ```puppet class { 'grafana': @@ -117,14 +133,23 @@ allow_sign_up = false Some minor notes: - - If you want empty values, just use an empty string. - - Keys that contains dots (like auth.google) need to be quoted. - - The order of the keys in this hash is the same as they will be written to the configuration file. So settings that do not fall under a section will have to come before any sections in the hash. +* If you want empty values, just use an empty string. +* Keys that contains dots (like auth.google) need to be quoted. +* The order of the keys in this hash is the same as they will be written to the + configuration file. So settings that do not fall under a section will have to + come before any sections in the hash. + +#### `ldap_cfg` + +##### TOML note -####`ldap_cfg` +This option **requires** the [toml](https://github.com/toml-lang/toml) gem. Either +install the gem using puppet's native gem provider, +[puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/puppetserver_gem), +[pe_gem](https://forge.puppetlabs.com/puppetlabs/pe_gem), +[pe_puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/pe_puppetserver_gem), +or manually using one of the following: -#####TOML note -This option **requires** the [toml](https://github.com/toml-lang/toml) gem. Either install the gem using puppet's native gem provider, [puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/puppetserver_gem), [pe_gem](https://forge.puppetlabs.com/puppetlabs/pe_gem), [pe_puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/pe_puppetserver_gem), or manually using one of the following: ``` # apply or puppet-master gem install toml @@ -134,8 +159,10 @@ This option **requires** the [toml](https://github.com/toml-lang/toml) gem. Eith /opt/puppet/bin/puppetserver gem install toml ``` -#####cfg note -This option by itself is not sufficient to enable LDAP configuration as it must be enabled in the main configuration file. Enable it in cfg with: +##### cfg note + +This option by itself is not sufficient to enable LDAP configuration as it must +be enabled in the main configuration file. Enable it in cfg with: ``` 'auth.ldap' => { @@ -144,19 +171,25 @@ This option by itself is not sufficient to enable LDAP configuration as it must }, ``` -####Integer note -Puppet may convert integers into strings while parsing the hash and converting into toml. This can be worked around by appending 0 to an integer. +#### Integer note + +Puppet may convert integers into strings while parsing the hash and converting +into toml. This can be worked around by appending 0 to an integer. Example: + ``` port => 636+0, ``` -Manages the Grafana LDAP configuration file. This hash is directly translated into the corresponding TOML file, allowing for full flexibility in generating the configuration. +Manages the Grafana LDAP configuration file. This hash is directly translated +into the corresponding TOML file, allowing for full flexibility in generating +the configuration. -See the [LDAP documentation](http://docs.grafana.org/v2.1/installation/ldap/) for more information. +See the [LDAP documentation](http://docs.grafana.org/v2.1/installation/ldap/) +for more information. -####Example LDAP config +#### Example LDAP config ``` ldap_cfg => { @@ -180,14 +213,18 @@ ldap_cfg => { }, ``` +##### `container_cfg` -#####`container_cfg` - -Boolean to control whether a configuration file should be generated when using the 'docker' install method. If 'true', use the 'cfg' and 'cfg_location' parameters to control creation of the file. Defaults to false. +Boolean to control whether a configuration file should be generated when using +the 'docker' install method. If 'true', use the 'cfg' and 'cfg_location' +parameters to control creation of the file. Defaults to false. -#####`container_params` +##### `container_params` -A hash of parameters to use when creating the Docker container. For use with the 'docker' install method. Refer to documentation of the 'docker::run' resource in the [garethr-docker](https://github.com/garethr/garethr-docker) module for details of available parameters. Defaults to: +A hash of parameters to use when creating the Docker container. For use with the +'docker' install method. Refer to documentation of the 'docker::run' resource in +the [garethr-docker](https://github.com/garethr/garethr-docker) module for details +of available parameters. Defaults to: ```puppet container_params => { @@ -196,49 +233,69 @@ container_params => { } ``` -#####`data_dir` +##### `data_dir` The directory Grafana will use for storing its data. Defaults to '/var/lib/grafana'. -#####`install_dir` +##### `install_dir` -The installation directory to be used with the 'archive' install method. Defaults to '/usr/share/grafana'. +The installation directory to be used with the 'archive' install method. Defaults +to '/usr/share/grafana'. -#####`install_method` +##### `install_method` -Controls which method to use for installing Grafana. Valid options are: 'archive', 'docker', 'repo' and 'package'. The default is 'package'. If you wish to use the 'docker' installation method, you will need to include the 'docker' class in your node's manifest / profile. If you wish to use the 'repo' installation method, you can control whether the official Grafana repositories will be used. See `manage_package_repo` below for details. +Controls which method to use for installing Grafana. Valid options are: 'archive', +'docker', 'repo' and 'package'. The default is 'package'. If you wish to use the +'docker' installation method, you will need to include the 'docker' class in your +node's manifest / profile. If you wish to use the 'repo' installation method, you +can control whether the official Grafana repositories will be used. See +`manage_package_repo` below for details. -#####`manage_package_repo` +##### `manage_package_repo` -Boolean. When using the 'repo' installation method, controls whether the official Grafana repositories are enabled on your host. If true, the official Grafana repositories will be enabled. If false, the module assumes you are managing your own package repository and will not set one up for you. Defaults to true. +Boolean. When using the 'repo' installation method, controls whether the official +Grafana repositories are enabled on your host. If true, the official Grafana +repositories will be enabled. If false, the module assumes you are managing your +own package repository and will not set one up for you. Defaults to true. -#####`package_name` +##### `package_name` -The name of the package managed with the 'package' install method. Defaults to 'grafana'. +The name of the package managed with the 'package' install method. Defaults to +'grafana'. -#####`package_source` +##### `package_source` -The download location of a package to be used with the 'package' install method. Defaults to the URL of the latest version of Grafana available at the time of module release. +The download location of a package to be used with the 'package' install method. +Defaults to the URL of the latest version of Grafana available at the time of +module release. -#####`rpm_iteration` +##### `rpm_iteration` -Used when installing Grafana from package ('package' or 'repo' install methods) on Red Hat based systems. Defaults to '1'. It should not be necessary to change this in most cases. +Used when installing Grafana from package ('package' or 'repo' install methods) +on Red Hat based systems. Defaults to '1'. It should not be necessary to change +this in most cases. -#####`service_name` +##### `service_name` -The name of the service managed with the 'archive' and 'package' install methods. Defaults to 'grafana-server'. +The name of the service managed with the 'archive' and 'package' install methods. +Defaults to 'grafana-server'. -#####`version` +##### `version` -The version of Grafana to install and manage. Defaults to the latest version of Grafana available at the time of module release. +The version of Grafana to install and manage. Defaults to the latest version of +Grafana available at the time of module release. -##Advanced usage: +### Advanced usage -The archive install method will create the user and a "command line" service by default. -There are no extra parameters to manage user/service for archive. However, both check to see if they are defined before defining. This way you can create your own user and service with your own specifications. (sort of overriding) -The service can be a bit tricky, in this example below, the class sensu_install::grafana::service creates a startup script and a service{'grafana-server':} +The archive install method will create the user and a "command line" service by +default. There are no extra parameters to manage user/service for archive. +However, both check to see if they are defined before defining. This way you can +create your own user and service with your own specifications. (sort of overriding) +The service can be a bit tricky, in this example below, the class +sensu_install::grafana::service creates a startup script and a service{'grafana-server':} Example: + ```puppet user { 'grafana': ensure => present, @@ -260,11 +317,11 @@ Example: ``` -####Custom Types and Providers +#### Custom Types and Providers The module includes two custom types: `grafana_dashboard` and `grafana_datasource` -#####`grafana_dashboard` +##### `grafana_dashboard` In order to use the dashboard resource, add the following to your manifest: @@ -278,9 +335,10 @@ grafana_dashboard { 'example_dashboard': ``` `content` must be valid JSON, and is parsed before imported. -`grafana_user` and `grafana_password` are optional, and required when authentication is enabled in Grafana. +`grafana_user` and `grafana_password` are optional, and required when +authentication is enabled in Grafana. -#####`grafana_datasource` +##### `grafana_datasource` In order to use the datasource resource, add the following to your manifest: @@ -302,16 +360,19 @@ grafana_datasource { 'influxdb': Available types are: influxdb, elasticsearch, graphite, kairosdb, opentsdb, prometheus -Access mode determines how Grafana connects to the datasource, either `direct` from the browser, or `proxy` to send requests via grafana. - -Authentication is optional, as is `database`; additional `json_data` can be provided to allow custom configuration options. +Access mode determines how Grafana connects to the datasource, either `direct` +from the browser, or `proxy` to send requests via grafana. +Authentication is optional, as is `database`; additional `json_data` can be +provided to allow custom configuration options. -##Limitations +## Limitations -This module has been tested on Ubuntu 14.04, using each of the 'archive', docker' and 'package' installation methods. Other configurations should work with minimal, if any, additional effort. +This module has been tested on Ubuntu 14.04, using each of the 'archive', 'docker' +and 'package' installation methods. Other configurations should work with minimal, +if any, additional effort. -##Copyright and License +## Copyright and License Copyright (C) 2015 Bill Fraser @@ -321,7 +382,7 @@ 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, From ee195967a099d3a235a61d2eb0d125f15ec416bf Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 16:04:43 +0100 Subject: [PATCH 07/10] Fix namespace --- README.md | 8 +++-- metadata.json | 87 ++++++++++++++++++++++++++++----------------------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index e8b46b9b6..362c70c09 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ # grafana -[![Puppet Forge](http://img.shields.io/puppetforge/v/bfraser/grafana.svg)](https://forge.puppetlabs.com/bfraser/grafana) -[![Build Status](http://img.shields.io/travis/bfraser/puppet-grafana.svg)](http://travis-ci.org/bfraser/puppet-grafana) +[![Build Status](https://travis-ci.org/voxpupuli/puppet-grafana.png?branch=master)](https://travis-ci.org/voxpupuli/puppet-grafana) +[![Code Coverage](https://coveralls.io/repos/github/voxpupuli/puppet-grafana/badge.svg?branch=master)](https://coveralls.io/github/voxpupuli/puppet-grafana) +[![Puppet Forge](https://img.shields.io/puppetforge/v/puppet/grafana.svg)](https://forge.puppetlabs.com/puppet/grafana) +[![Puppet Forge - downloads](https://img.shields.io/puppetforge/dt/puppet/grafana.svg)](https://forge.puppetlabs.com/puppet/grafana) +[![Puppet Forge - endorsement](https://img.shields.io/puppetforge/e/puppet/grafana.svg)](https://forge.puppetlabs.com/puppet/grafana) +[![Puppet Forge - scores](https://img.shields.io/puppetforge/f/puppet/grafana.svg)](https://forge.puppetlabs.com/puppet/grafana) #### Table of Contents diff --git a/metadata.json b/metadata.json index 73cb8c293..13d407ce1 100644 --- a/metadata.json +++ b/metadata.json @@ -1,67 +1,74 @@ { - "name": "bfraser-grafana", + "name": "puppet-grafana", "version": "2.5.0", - "author": "bfraser", + "author": "Vox Pupuli", "summary": "This module provides Grafana, a dashboard and graph editor for Graphite and InfluxDB.", "license": "Apache-2.0", - "source": "https://github.com/bfraser/puppet-grafana.git", - "project_page": "https://github.com/bfraser/puppet-grafana", - "issues_url": "https://github.com/bfraser/puppet-grafana/issues", - "tags": [ - "grafana", - "graphite", - "influxdb", - "monitoring" - ], - "operatingsystem_support": [ + "source": "https://github.com/voxpupuli/puppet-grafana.git", + "project_page": "https://github.com/voxpupuli/puppet-grafana", + "issue_url": "https://github.com/voxpupuli/puppet-grafana/issues", + "dependencies": [ { - "operatingsystem": "RedHat", - "operatingsystemrelease": [ "6.0" ] + "name": "garethr/docker", + "version_requirement": ">= 3.5.0 <6.0.0" }, { - "operatingsystem": "CentOS", - "operatingsystemrelease": [ "6.0" ] + "name": "maestrodev/wget", + "version_requirement": ">= 1.6.0 <2.0.0" }, { - "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ "14.04" ] + "name": "puppet/archive", + "version_requirement": ">= 0.5.1 <2.0.0" }, { - "operatingsystem": "Debian", - "operatingsystemrelease": [ "7.0" ] - } - ], - "requirements": [ - { - "name": "pe", - "version_requirement": ">= 3.2.0" + "name": "puppetlabs/apt", + "version_requirement": ">=2.0.0 <3.0.0" }, { - "name": "puppet", - "version_requirement": ">= 3.4.0" + "name": "puppetlabs/stdlib", + "version_requirement": ">=3.2.0 <5.0.0" } ], - "dependencies": [ + "operatingsystem_support": [ { - "name": "puppet/archive", - "version_requirement": ">= 0.5.1 <2.0.0" + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "7" + ] }, { - "name": "garethr/docker", - "version_requirement": ">= 3.5.0 <6.0.0" + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "14.04" + ] }, { - "name": "maestrodev/wget", - "version_requirement": ">= 1.6.0 <2.0.0" + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "6" + ] }, { - "name": "puppetlabs-stdlib", - "version_requirement": ">=3.2.0 <5.0.0" + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "6" + ] + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": ">= 3.2.0" }, { - "name": "puppetlabs-apt", - "version_requirement": ">=2.0.0 <3.0.0" + "name": "puppet", + "version_requirement": ">= 3.4.0" } - + ], + "tags": [ + "grafana", + "graphite", + "influxdb", + "monitoring" ] } From 0ccaac83c2430b3e52e40c6743418a1847416d86 Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 17:49:57 +0100 Subject: [PATCH 08/10] Add support for rspec-puppet-facts --- spec/classes/grafana_spec.rb | 499 +++++++++++++++-------------------- 1 file changed, 206 insertions(+), 293 deletions(-) diff --git a/spec/classes/grafana_spec.rb b/spec/classes/grafana_spec.rb index 2790c6eea..8d9b2ea72 100644 --- a/spec/classes/grafana_spec.rb +++ b/spec/classes/grafana_spec.rb @@ -1,277 +1,209 @@ require 'spec_helper' describe 'grafana' do - context 'supported operating systems' do - %w(Debian RedHat).each do |osfamily| - describe "grafana class without any parameters on #{osfamily}" do - let(:params) { {} } - let(:facts) do - { - osfamily: osfamily - } - end - - it { is_expected.to contain_class('grafana::params') } - it { is_expected.to contain_class('grafana::install').that_comes_before('grafana::config') } - it { is_expected.to contain_class('grafana::config') } - it { is_expected.to contain_class('grafana::service').that_subscribes_to('grafana::config') } - - it { is_expected.to contain_service('grafana-server').with_ensure('running').with_enable(true) } - it { is_expected.to contain_package('grafana').with_ensure('present') } - end - end - end - - context 'unsupported operating system' do - describe 'grafana class without any parameters on Solaris/Nexenta' do + on_supported_os.each do |os, facts| + context "on #{os}" do let(:facts) do - { - osfamily: 'Solaris', - operatingsystem: 'Nexenta' - } + facts end - it { expect { is_expected.to contain_package('grafana') }.to raise_error(Puppet::Error, %r{Nexenta not supported}) } - end - end - - context 'package install method' do - context 'debian' do - let(:facts) do - { - osfamily: 'Debian' - } - end - - download_location = '/tmp/grafana.deb' - - describe 'use wget to fetch the package to a temporary location' do - it { is_expected.to contain_wget__fetch('grafana').with_destination(download_location) } - it { is_expected.to contain_wget__fetch('grafana').that_comes_before('Package[grafana]') } - end - - describe 'install dependencies first' do - it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } - end - - describe 'install the package' do - it { is_expected.to contain_package('grafana').with_provider('dpkg') } - it { is_expected.to contain_package('grafana').with_source(download_location) } - end - end - - context 'redhat' do - let(:facts) do - { - osfamily: 'RedHat' - } - end - - describe 'install dependencies first' do - it { is_expected.to contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } + context 'with default values' do + it { is_expected.to compile } + it { is_expected.to contain_anchor('grafana::begin') } + it { is_expected.to contain_class('grafana::params') } + it { is_expected.to contain_class('grafana::install') } + it { is_expected.to contain_class('grafana::config') } + it { is_expected.to contain_class('grafana::service') } + it { is_expected.to contain_anchor('grafana::end') } end - describe 'install the package' do - it { is_expected.to contain_package('grafana').with_provider('rpm') } + context 'with parameter install_method is set to package' do + case facts[:osfamily] + when 'Debian' + download_location = '/tmp/grafana.deb' + + describe 'use wget to fetch the package to a temporary location' do + it { is_expected.to contain_wget__fetch('grafana').with_destination(download_location) } + it { is_expected.to contain_wget__fetch('grafana').that_comes_before('Package[grafana]') } + end + + describe 'install dependencies first' do + it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } + end + + describe 'install the package' do + it { is_expected.to contain_package('grafana').with_provider('dpkg') } + it { is_expected.to contain_package('grafana').with_source(download_location) } + end + when 'RedHat' + describe 'install dependencies first' do + it { is_expected.to contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } + end + + describe 'install the package' do + it { is_expected.to contain_package('grafana').with_provider('rpm') } + end + end end - end - end - context 'repo install method' do - let(:params) do - { - install_method: 'repo', - manage_package_repo: true - } - end - - context 'debian' do - let(:facts) do - { - osfamily: 'Debian', - lsbdistid: 'Ubuntu' - } - end + context 'with parameter install_method is set to repo' do + let(:params) do + { + install_method: 'repo' + } + end - describe 'install apt repo dependencies first' do - it { is_expected.to contain_class('apt') } - it { is_expected.to contain_apt__source('grafana').with(release: 'wheezy', repos: 'main', location: 'https://packagecloud.io/grafana/stable/debian') } - it { is_expected.to contain_apt__source('grafana').that_comes_before('Package[grafana]') } + case facts[:osfamily] + when 'Debian' + describe 'install apt repo dependencies first' do + it { is_expected.to contain_class('apt') } + it { is_expected.to contain_apt__source('grafana').with(release: 'wheezy', repos: 'main', location: 'https://packagecloud.io/grafana/stable/debian') } + it { is_expected.to contain_apt__source('grafana').that_comes_before('Package[grafana]') } + end + + describe 'install dependencies first' do + it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } + end + + describe 'install the package' do + it { is_expected.to contain_package('grafana').with_ensure('2.5.0') } + end + when 'RedHat' + describe 'yum repo dependencies first' do + it { is_expected.to contain_yumrepo('grafana').with(baseurl: 'https://packagecloud.io/grafana/stable/el/6/$basearch', gpgkey: 'https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana', enabled: 1) } + it { is_expected.to contain_yumrepo('grafana').that_comes_before('Package[grafana]') } + end + + describe 'install dependencies first' do + it { is_expected.to contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } + end + + describe 'install the package' do + it { is_expected.to contain_package('grafana').with_ensure('2.5.0-1') } + end + end end - describe 'install dependencies first' do - it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } - end + context 'with parameter install_method is set to repo and manage_package_repo is set to false' do + let(:params) do + { + install_method: 'repo', + manage_package_repo: false, + version: 'present' + } + end - describe 'install the package' do - it { is_expected.to contain_package('grafana').with_ensure('2.5.0') } + case facts[:osfamily] + when 'Debian' + describe 'install dependencies first' do + it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } + end + + describe 'install the package' do + it { is_expected.to contain_package('grafana').with_ensure('present') } + end + when 'RedHat' + describe 'install dependencies first' do + it { is_expected.to contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } + end + + describe 'install the package' do + it { is_expected.to contain_package('grafana').with_ensure('present') } + end + end end - end - context 'redhat' do - let(:facts) do - { - osfamily: 'RedHat' - } - end + context 'with parameter install_method is set to archive' do + let(:params) do + { + install_method: 'archive' + } + end - describe 'yum repo dependencies first' do - it { is_expected.to contain_yumrepo('grafana').with(baseurl: 'https://packagecloud.io/grafana/stable/el/6/$basearch', gpgkey: 'https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana', enabled: 1) } - it { is_expected.to contain_yumrepo('grafana').that_comes_before('Package[grafana]') } - end + install_dir = '/usr/share/grafana' + service_config = '/usr/share/grafana/conf/custom.ini' + archive_source = 'https://grafanarel.s3.amazonaws.com/builds/grafana-2.5.0.linux-x64.tar.gz' - describe 'install dependencies first' do - it { is_expected.to contain_package('fontconfig').with_ensure('present').that_comes_before('Package[grafana]') } - end + describe 'extract archive to install_dir' do + it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_ensure('present') } + it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_source(archive_source) } + it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_extract_path(install_dir) } + end - describe 'install the package' do - it { is_expected.to contain_package('grafana').with_ensure('2.5.0-1') } - end - end - end + describe 'create grafana user' do + it { is_expected.to contain_user('grafana').with_ensure('present').with_home(install_dir) } + it { is_expected.to contain_user('grafana').that_comes_before('File[/usr/share/grafana]') } + end - context 'repo install method without managing the package repo' do - let(:params) do - { - install_method: 'repo', - manage_package_repo: false, - version: 'present' - } - end + describe 'manage install_dir' do + it { is_expected.to contain_file(install_dir).with_ensure('directory') } + it { is_expected.to contain_file(install_dir).with_group('grafana').with_owner('grafana') } + end - context 'debian' do - let(:facts) do - { - osfamily: 'Debian', - lsbdistid: 'Ubuntu' - } - end + describe 'configure grafana' do + it { is_expected.to contain_file(service_config).with_ensure('file') } + end - it { is_expected.to compile.with_all_deps } + describe 'run grafana as service' do + it { is_expected.to contain_service('grafana-server').with_ensure('running').with_provider('base') } + it { is_expected.to contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } + end - describe 'install dependencies first' do - it { is_expected.to contain_package('libfontconfig1').with_ensure('present').that_comes_before('Package[grafana]') } - end + context 'when user already defined' do + let(:pre_condition) do + 'user{"grafana": + ensure => present, + }' + end + describe 'do NOT create grafana user' do + it { is_expected.not_to contain_user('grafana').with_ensure('present').with_home(install_dir) } + end + end - describe 'install the package' do - it { is_expected.to contain_package('grafana').with_ensure('present') } + context 'when service already defined' do + let(:pre_condition) do + 'service{"grafana-server": + ensure => running, + hasrestart => true, + hasstatus => true, + }' + end + # let(:params) {{ :service_name => 'grafana-server'}} + describe 'do NOT run service' do + it { is_expected.not_to contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } + end + end end - end - end - context 'archive install method' do - let(:params) do - { - install_method: 'archive' - } - end - - install_dir = '/usr/share/grafana' - service_config = '/usr/share/grafana/conf/custom.ini' - archive_source = 'https://grafanarel.s3.amazonaws.com/builds/grafana-2.5.0.linux-x64.tar.gz' - - describe 'extract archive to install_dir' do - it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_ensure('present') } - it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_source(archive_source) } - it { is_expected.to contain_archive('/tmp/grafana.tar.gz').with_extract_path(install_dir) } - end - - describe 'create grafana user' do - it { is_expected.to contain_user('grafana').with_ensure('present').with_home(install_dir) } - it { is_expected.to contain_user('grafana').that_comes_before('File[/usr/share/grafana]') } - end - - describe 'manage install_dir' do - it { is_expected.to contain_file(install_dir).with_ensure('directory') } - it { is_expected.to contain_file(install_dir).with_group('grafana').with_owner('grafana') } - end - - describe 'configure grafana' do - it { is_expected.to contain_file(service_config).with_ensure('present') } - end - - describe 'run grafana as service' do - it { is_expected.to contain_service('grafana-server').with_ensure('running').with_provider('base') } - it { is_expected.to contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } - end - - context 'when user already defined' do - let(:pre_condition) do - 'user{"grafana": - ensure => present, - }' - end - describe 'do NOT create grafana user' do - it { is_expected.not_to contain_user('grafana').with_ensure('present').with_home(install_dir) } - end - end + context 'invalid parameters' do + context 'cfg' do + describe 'should raise an error when cfg parameter is not a hash' do + let(:params) do + { + cfg: [] + } + end - context 'when service already defined' do - let(:pre_condition) do - 'service{"grafana-server": - ensure => running, - hasrestart => true, - hasstatus => true, - }' - end - # let(:params) {{ :service_name => 'grafana-server'}} - describe 'do NOT run service' do - it { is_expected.not_to contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) } - end - end - end + it { expect { is_expected.to contain_package('grafana') }.to raise_error(Puppet::Error, %r{cfg parameter must be a hash}) } + end - context 'invalid parameters' do - context 'cfg' do - let(:facts) do - { - osfamily: 'Debian' - } - end + describe 'should not raise an error when cfg parameter is a hash' do + let(:params) do + { + cfg: {} + } + end - describe 'should raise an error when cfg parameter is not a hash' do - let(:params) do - { - cfg: [] - } + it { is_expected.to contain_package('grafana') } + end end - - it { expect { is_expected.to contain_package('grafana') }.to raise_error(Puppet::Error, %r{cfg parameter must be a hash}) } end - describe 'should not raise an error when cfg parameter is a hash' do - let(:params) do - { - cfg: {} - } + context 'configuration file' do + describe 'should not contain any configuration when cfg param is empty' do + it { is_expected.to contain_file('/etc/grafana/grafana.ini').with_content("# This file is managed by Puppet, any changes will be overwritten\n\n") } end - it { is_expected.to contain_package('grafana') } - end - end - end - - context 'configuration file' do - let(:facts) do - { - osfamily: 'Debian' - } - end - - describe 'should not contain any configuration when cfg param is empty' do - it { is_expected.to contain_file('/etc/grafana/grafana.ini').with_content("# This file is managed by Puppet, any changes will be overwritten\n\n") } - end - - describe 'should correctly transform cfg param entries to Grafana configuration' do - let(:params) do - { - cfg: { - 'app_mode' => 'production', - 'section' => { - 'string' => 'production', - 'number' => 8080, - 'boolean' => false, - 'empty' => '' describe 'should correctly transform cfg param entries to Grafana configuration' do let(:params) do { @@ -304,60 +236,41 @@ } } } - }, - ldap_cfg: { - 'servers' => [ - { 'host' => 'server1', - 'use_ssl' => true, - 'search_filter' => '(sAMAccountName=%s)', - 'search_base_dns' => ['dc=domain1,dc=com'] }, - { 'host' => 'server2', - 'use_ssl' => true, - 'search_filter' => '(sAMAccountName=%s)', - 'search_base_dns' => ['dc=domain2,dc=com'] } - ], - 'servers.attributes' => { - 'name' => 'givenName', - 'surname' => 'sn', - 'username' => 'sAMAccountName', - 'member_of' => 'memberOf', - 'email' => 'email' - } - } - } + end + + expected = "# This file is managed by Puppet, any changes will be overwritten\n\n"\ + "app_mode = production\n\n"\ + "[section]\n"\ + "boolean = false\n"\ + "empty = \n"\ + "number = 8080\n"\ + "string = production\n" + + it { is_expected.to contain_file('/etc/grafana/grafana.ini').with_content(expected) } + + ldap_expected = "\n[[servers]]\n"\ + "host = \"server1\"\n"\ + "search_base_dns = [\"dc=domain1,dc=com\"]\n"\ + "search_filter = \"(sAMAccountName=%s)\"\n"\ + "use_ssl = true\n"\ + "\n"\ + "[[servers]]\n"\ + "host = \"server2\"\n"\ + "search_base_dns = [\"dc=domain2,dc=com\"]\n"\ + "search_filter = \"(sAMAccountName=%s)\"\n"\ + "use_ssl = true\n"\ + "\n"\ + "[servers.attributes]\n"\ + "email = \"email\"\n"\ + "member_of = \"memberOf\"\n"\ + "name = \"givenName\"\n"\ + "surname = \"sn\"\n"\ + "username = \"sAMAccountName\"\n"\ + "\n" + + it { is_expected.to contain_file('/etc/grafana/ldap.toml').with_content(ldap_expected) } + end end - - expected = "# This file is managed by Puppet, any changes will be overwritten\n\n"\ - "app_mode = production\n\n"\ - "[section]\n"\ - "boolean = false\n"\ - "empty = \n"\ - "number = 8080\n"\ - "string = production\n" - - it { is_expected.to contain_file('/etc/grafana/grafana.ini').with_content(expected) } - - ldap_expected = "\n[[servers]]\n"\ - "host = \"server1\"\n"\ - "search_base_dns = [\"dc=domain1,dc=com\"]\n"\ - "search_filter = \"(sAMAccountName=%s)\"\n"\ - "use_ssl = true\n"\ - "\n"\ - "[[servers]]\n"\ - "host = \"server2\"\n"\ - "search_base_dns = [\"dc=domain2,dc=com\"]\n"\ - "search_filter = \"(sAMAccountName=%s)\"\n"\ - "use_ssl = true\n"\ - "\n"\ - "[servers.attributes]\n"\ - "email = \"email\"\n"\ - "member_of = \"memberOf\"\n"\ - "name = \"givenName\"\n"\ - "surname = \"sn\"\n"\ - "username = \"sAMAccountName\"\n"\ - "\n" - - it { is_expected.to contain_file('/etc/grafana/ldap.toml').with_content(ldap_expected) } end end end From 1f3d0efcd673194c7f8b21d96fe228aa0f36670f Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 18:47:33 +0100 Subject: [PATCH 09/10] Fix issue regarding non numeric versions --- manifests/install.pp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/manifests/install.pp b/manifests/install.pp index 809b19230..8ab4b1e30 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -107,8 +107,14 @@ } } + if $::grafana::version =~ /(installed|latest|present)/ { + $real_version = $::grafana::version + } else { + $real_version = "${::grafana::version}-${::grafana::rpm_iteration}" + } + package { $::grafana::package_name: - ensure => "${::grafana::version}-${::grafana::rpm_iteration}", + ensure => $real_version, require => Package['fontconfig'], } } From 27f9cb89f93a7084d747d768b94b27e15a3e4d4e Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Wed, 7 Dec 2016 19:05:40 +0100 Subject: [PATCH 10/10] Add support for anchor pattern --- manifests/init.pp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 6b94aa0be..c2a5a51af 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -92,12 +92,9 @@ fail('cfg parameter must be a hash') } + anchor { 'grafana::begin': } -> class { '::grafana::install': } -> class { '::grafana::config': } ~> - class { '::grafana::service': } - - contain '::grafana::install' - contain '::grafana::service' - - #Class['grafana'] + class { '::grafana::service': } -> + anchor { 'grafana::end': } }