diff --git a/.fixtures.yml b/.fixtures.yml index 56424bd..990960b 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,3 +1,10 @@ fixtures: symlinks: cassandra: "#{source_dir}" + repositories: + apt: + repo: "git://github.com/puppetlabs/puppetlabs-apt" + ref: "2.4.0" + firewall: "git://github.com/puppetlabs/puppetlabs-firewall" + inifile: "git://github.com/puppetlabs/puppetlabs-inifile" + stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib" diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..602f324 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,104 @@ +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`. + +The easiest way to debug in a docker container is to open a shell: + + docker exec -it -u root ${container_id_or_name} bash diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..593e7aa --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## Affected Puppet, Ruby, OS and module versions/distributions + +- Puppet: +- Ruby: +- Distribution: +- Module version: + +## How to reproduce (e.g Puppet code you use) + +## What are you seeing + +## What behaviour did you expect instead + +## Output log + +## Any additional information you'd like to impart diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..66f8044 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,8 @@ + diff --git a/.gitignore b/.gitignore index 35438db..e9b3cf4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,20 @@ +pkg/ +Gemfile.lock +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ .bundle/ +.ruby-version coverage/ -doc/ -Gemfile.lock +log/ .idea/ -*.iml +.dependencies/ .librarian/ -log/ -pkg/ -.project Puppetfile.lock -spec/fixtures/ -*.swn -*.swo -*.swp -.vagrant/ -vagrant/modules/ -vendor/ +*.iml +.*.sw? .yardoc/ -/.vagrant/ -/vagrant/modules/ +Guardfile diff --git a/.msync.yml b/.msync.yml new file mode 100644 index 0000000..0a4a57d --- /dev/null +++ b/.msync.yml @@ -0,0 +1 @@ +modulesync_config_version: '1.1.0' diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..31699e7 --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,63 @@ +# Managed by https://github.com/voxpupuli/modulesync_configs +# +# Hooks are only enabled if you take action. +# +# To enable the hooks run: +# +# ``` +# bundle exec overcommit --install +# # ensure .overcommit.yml does not harm to you and then +# bundle exec overcommit --sign +# ``` +# +# (it will manage the .git/hooks directory): +# +# Examples howto skip a test for a commit or push: +# +# ``` +# SKIP=RuboCop git commit +# SKIP=PuppetLint git commit +# SKIP=RakeTask git push +# ``` +# +# Don't invoke overcommit at all: +# +# ``` +# OVERCOMMIT_DISABLE=1 git commit +# ``` +# +# Read more about overcommit: https://github.com/brigade/overcommit +# +# To manage this config yourself in your module add +# +# ``` +# .overcommit.yml: +# unmanaged: true +# ``` +# +# to your modules .sync.yml config +--- +PreCommit: + RuboCop: + enabled: true + description: 'Runs rubocop on modified files only' + command: ['bundle', 'exec', 'rubocop'] + PuppetLint: + enabled: true + description: 'Runs puppet-lint on modified files only' + command: ['bundle', 'exec', 'puppet-lint'] + YamlSyntax: + enabled: true + JsonSyntax: + enabled: true + TrailingWhitespace: + enabled: true + +PrePush: + RakeTarget: + enabled: true + description: 'Run rake targets' + targets: + - 'test' + - 'rubocop' + command: [ 'bundle', 'exec', 'rake' ] diff --git a/.pmtignore b/.pmtignore new file mode 100644 index 0000000..fb58957 --- /dev/null +++ b/.pmtignore @@ -0,0 +1,20 @@ +docs/ +pkg/ +Gemfile.lock +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.librarian/ +Puppetfile.lock +*.iml +.*.sw? +.yardoc/ diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..8c18f1a --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.rspec_parallel b/.rspec_parallel new file mode 100644 index 0000000..e4d136b --- /dev/null +++ b/.rspec_parallel @@ -0,0 +1 @@ +--format progress diff --git a/.rubocop.yml b/.rubocop.yml index be2408d..9288153 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,17 +1,538 @@ ---- +require: rubocop-rspec AllCops: + TargetRubyVersion: 1.9 + Include: + - ./**/*.rb Exclude: - - 'vagrant/modules/*/Gemfile' - - 'vagrant/modules/*/Rakefile' - - 'vagrant/modules/**/*' - - 'vendor/**/*' + - files/**/* + - vendor/**/* + - .vendor/**/* + - pkg/**/* + - spec/fixtures/**/* + - Gemfile + - Rakefile + - Guardfile +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 + +Layout/SpaceBeforeComment: + Enabled: True + +Style/AndOr: + Enabled: True + +Style/RedundantSelf: + Enabled: True + Metrics/BlockLength: - Enabled: false + Enabled: False + +# Method length is not necessarily an indicator of code quality +Metrics/MethodLength: + Enabled: False + +# Module length is not necessarily an indicator of code quality +Metrics/ModuleLength: + Enabled: False + +Style/WhileUntilModifier: + Enabled: True + +Lint/AmbiguousRegexpLiteral: + Enabled: True + +Security/Eval: + Enabled: True + +Lint/BlockAlignment: + Enabled: True + +Lint/DefEndAlignment: + Enabled: True + +Lint/EndAlignment: + Enabled: True + +Lint/DeprecatedClassMethods: + Enabled: True + +Lint/Loop: + Enabled: True + +Lint/ParenthesesAsGroupedExpression: + Enabled: True + +Lint/RescueException: + Enabled: True + +Lint/StringConversionInInterpolation: + Enabled: True + +Lint/UnusedBlockArgument: + Enabled: True + +Lint/UnusedMethodArgument: + Enabled: True + +Lint/UselessAccessModifier: + Enabled: True + +Lint/UselessAssignment: + Enabled: True + +Lint/Void: + Enabled: True + +Layout/AccessModifierIndentation: + Enabled: True + +Style/AccessorMethodName: + Enabled: True + +Style/Alias: + Enabled: True + +Layout/AlignArray: + Enabled: True + +Layout/AlignHash: + Enabled: True + +Layout/AlignParameters: + Enabled: True + +Metrics/BlockNesting: + Enabled: True + +Style/AsciiComments: + Enabled: True + +Style/Attr: + Enabled: True + +Style/BracesAroundHashParameters: + Enabled: True + +Style/CaseEquality: + Enabled: True + +Layout/CaseIndentation: + Enabled: True + +Style/CharacterLiteral: + Enabled: True + +Style/ClassAndModuleCamelCase: + Enabled: True + +Style/ClassAndModuleChildren: + Enabled: False + +Style/ClassCheck: + Enabled: True + +# Class length is not necessarily an indicator of code quality Metrics/ClassLength: - Enabled: false + Enabled: False + +Style/ClassMethods: + Enabled: True + +Style/ClassVars: + Enabled: True + +Style/WhenThen: + Enabled: True + +Style/WordArray: + Enabled: True + +Style/UnneededPercentQ: + Enabled: True + +Layout/Tab: + Enabled: True + +Layout/SpaceBeforeSemicolon: + Enabled: True + +Layout/TrailingBlankLines: + Enabled: True + +Layout/SpaceInsideBlockBraces: + Enabled: True + +Layout/SpaceInsideBrackets: + Enabled: True + +Layout/SpaceInsideHashLiteralBraces: + Enabled: True + +Layout/SpaceInsideParens: + Enabled: True + +Layout/LeadingCommentSpace: + Enabled: True + +Layout/SpaceBeforeFirstArg: + Enabled: True + +Layout/SpaceAfterColon: + Enabled: True + +Layout/SpaceAfterComma: + Enabled: True + +Layout/SpaceAfterMethodName: + Enabled: True + +Layout/SpaceAfterNot: + Enabled: True + +Layout/SpaceAfterSemicolon: + Enabled: True + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: True + +Layout/SpaceAroundOperators: + Enabled: True + +Layout/SpaceBeforeBlockBraces: + Enabled: True + +Layout/SpaceBeforeComma: + Enabled: True + +Style/CollectionMethods: + Enabled: True + +Layout/CommentIndentation: + Enabled: True + +Style/ColonMethodCall: + Enabled: True + +Style/CommentAnnotation: + Enabled: True + +# 'Complexity' is very relative +Metrics/CyclomaticComplexity: + Enabled: False + +Style/ConstantName: + Enabled: True + +Style/Documentation: + Enabled: False + +Style/DefWithParentheses: + Enabled: True + +Style/PreferredHashMethods: + Enabled: True + +Layout/DotPosition: + EnforcedStyle: trailing + +Style/DoubleNegation: + Enabled: True + +Style/EachWithObject: + Enabled: True + +Layout/EmptyLineBetweenDefs: + Enabled: True + +Layout/IndentArray: + Enabled: True + +Layout/IndentHash: + Enabled: True + +Layout/IndentationConsistency: + Enabled: True + +Layout/IndentationWidth: + Enabled: True + +Layout/EmptyLines: + Enabled: True + +Layout/EmptyLinesAroundAccessModifier: + Enabled: True + +Style/EmptyLiteral: + Enabled: True + +# Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: + Enabled: False + +Style/MethodCallWithoutArgsParentheses: + Enabled: True + +Style/MethodDefParentheses: + Enabled: True + +Style/LineEndConcatenation: + Enabled: True + +Layout/TrailingWhitespace: + Enabled: True + +Style/StringLiterals: + Enabled: True + +Style/TrailingCommaInArguments: + Enabled: True + +Style/TrailingCommaInLiteral: + Enabled: True + +Style/GlobalVars: + Enabled: True + +Style/GuardClause: + Enabled: True + +Style/IfUnlessModifier: + Enabled: True + +Style/MultilineIfThen: + Enabled: True + +Style/NegatedIf: + Enabled: True + +Style/NegatedWhile: + Enabled: True + +Style/Next: + Enabled: True + +Style/SingleLineBlockParams: + Enabled: True + +Style/SingleLineMethods: + Enabled: True + +Style/SpecialGlobalVars: + Enabled: True + +Style/TrivialAccessors: + Enabled: True + +Style/UnlessElse: + Enabled: True + +Style/VariableInterpolation: + Enabled: True + +Style/VariableName: + Enabled: True + +Style/WhileUntilDo: + Enabled: True + +Style/EvenOdd: + Enabled: True + +Style/FileName: + Enabled: True + +Style/For: + Enabled: True + +Style/Lambda: + Enabled: True + +Style/MethodName: + Enabled: True + +Style/MultilineTernaryOperator: + Enabled: True + +Style/NestedTernaryOperator: + Enabled: True + +Style/NilComparison: + Enabled: True + +Style/FormatString: + Enabled: True + +Style/MultilineBlockChain: + Enabled: True + +Style/Semicolon: + Enabled: True + +Style/SignalException: + Enabled: True + +Style/NonNilCheck: + Enabled: True + +Style/Not: + Enabled: True + +Style/NumericLiterals: + Enabled: True + +Style/OneLineConditional: + Enabled: True + +Style/OpMethod: + Enabled: True + +Style/ParenthesesAroundCondition: + Enabled: True + +Style/PercentLiteralDelimiters: + Enabled: True + +Style/PerlBackrefs: + Enabled: True + +Style/PredicateName: + Enabled: True + +Style/RedundantException: + Enabled: True + +Style/SelfAssignment: + Enabled: True + +Style/Proc: + Enabled: True + +Style/RaiseArgs: + Enabled: True + +Style/RedundantBegin: + Enabled: True + +Style/RescueModifier: + Enabled: True + +# based on https://github.com/voxpupuli/modulesync_config/issues/168 +Style/RegexpLiteral: + EnforcedStyle: percent_r + Enabled: True + +Lint/UnderscorePrefixedVariableName: + Enabled: True + +Metrics/ParameterLists: + Enabled: False + +Lint/RequireParentheses: + Enabled: True + +Style/ModuleFunction: + Enabled: True + +Lint/Debugger: + Enabled: True + +Style/IfWithSemicolon: + Enabled: True + +Style/Encoding: + Enabled: True + +Style/BlockDelimiters: + Enabled: True + +Layout/MultilineBlockLayout: + Enabled: True + +# 'Complexity' is very relative +Metrics/AbcSize: + Enabled: False + +# 'Complexity' is very relative +Metrics/PerceivedComplexity: + Enabled: False + +Lint/UselessAssignment: + Enabled: True + +Layout/ClosingParenthesisIndentation: + Enabled: True + +# RSpec + +RSpec/BeforeAfterAll: + Exclude: + - spec/acceptance/**/* + +# We don't use rspec in this way +RSpec/DescribeClass: + Enabled: False + +# Example length is not necessarily an indicator of code quality +RSpec/ExampleLength: + Enabled: False + +RSpec/NamedSubject: + Enabled: False + +# disabled for now since they cause a lot of issues +# these issues aren't easy to fix +RSpec/RepeatedDescription: + Enabled: False + +RSpec/NestedGroups: + Enabled: False + +# this is broken on ruby1.9 +Layout/IndentHeredoc: + Enabled: False + +# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs +Security/YAMLLoad: Enabled: false -Metrics/MethodLength: + +# This affects hiera interpolation, as well as some configs that we push. +Style/FormatStringToken: Enabled: false Style/FormatStringToken: Enabled: false diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..9468f8c --- /dev/null +++ b/.sync.yml @@ -0,0 +1,3 @@ +--- +.travis.yml: + secret: "I/IK9bG88UOVll0hpuxluGp6IY5gicLaDHug/jGwfuWlN4R3coPAqWO/sGOyaEMbc9V5/Fw0H0ThQdYY3eI3rW5M4a1r9TSg/Z9d46JximPat/XvcpLvUc0G+QxCVhTRmYqD7u0wuX5VSric0PQU6KSjH84ZbKgAA8l04NGObgUI6ugjaNBhkaoIP3glYcHY1fgn5vwER2T/iiXZ5q3qDtYboR2GWLUODLWSpXWZRy7oYvp/RGTSe1fKjDwkbtrZiFvRoyzQvDhEAr+0MFDxJiOLdoKJFeBs6BrF2lyUJ6udlOmEYV94DfKoxEhhlZbxkPCh4SedT79i3c3xkKlf9wfAsEyGSTfc9OtyYBfoHcE9GMRZIvLf2Jn2mpHMO2694Fil4d7JdhLYQ/9Gv9VgFrYosQdVlDh+RxE2CXzrO39LhA1GeOY/n1r+DdvuCJs1fZfBZ1ORb7eQNp1BknurJ8FoYCKlEgihS223IJEnGueDdYkchMSRjS6C3a/HIzBz0RvEDGXD3WgrY5edRIaGziSoSr5eXzumK7N1FFBlpfY/7j38zI1ibWN4PRakmZppeeWOb1xiuVS5JkngCLoYerxLJEEjt8+klXhwnqqJukFuObaVsyprSWp+aAu/UHD/4w/6/lC6Elv+VzccLpITOR5b7VdAuCttQ5PGse6fits=" diff --git a/.travis.yml b/.travis.yml index 63e34f8..3e42137 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,46 @@ --- -env: - - "PUPPET_VERSION='~> 4.5' BEAKER_set=centos6_2" - - "PUPPET_VERSION='~> 4.5' BEAKER_set=centos6_3" - - "PUPPET_VERSION='~> 4.5' BEAKER_set=centos7" - - "PUPPET_VERSION='~> 4.5' BEAKER_set=debian7" - - "PUPPET_VERSION='~> 4.5' BEAKER_set=debian8" - - "PUPPET_VERSION='~> 4.5' BEAKER_set=ubuntu1204" - - "PUPPET_VERSION='~> 4.5' BEAKER_set=ubuntu1404" - - "PUPPET_VERSION='~> 4.5' BEAKER_set=ubuntu1604" +sudo: false +dist: trusty language: ruby -rvm: - - 2.3.1 cache: bundler -before_install: rm Gemfile.lock || true -bundler_args: --without development -dist: trusty -sudo: required -script: - - "bundle exec puppet --version" - - "bundle exec rake metadata_lint" - - "bundle exec rubocop" - - "bundle exec rake lint" - - "bundle exec rake validate" - - "bundle exec rake spec SPEC_OPTS='--format documentation'" - - "bundle exec rake acceptance" +before_install: + - bundle -v + - rm Gemfile.lock || true + - gem update --system + - gem update bundler + - gem --version + - bundle -v +script: + - 'bundle exec rake $CHECK' +matrix: + fast_finish: true + include: + - rvm: 2.1.9 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 4.0" CHECK=test + - rvm: 2.4.1 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 5.0" CHECK=test_with_coveralls + - rvm: 2.4.1 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 5.0" CHECK=rubocop + - rvm: 2.4.1 + bundler_args: --without system_tests development + env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes +branches: + only: + - master + - /^v\d/ notifications: email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "" + 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 index b6bedde..3687f51 100644 --- a/.yardopts +++ b/.yardopts @@ -1,4 +1,2 @@ --markup markdown ---tag caveats:"Caveats:" ---tag resolution:"Resolution:" -- CONTRIBUTING.md LICENSE README.md +--output-dir docs/ diff --git a/Gemfile b/Gemfile index c0c1d54..483f05a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,52 +1,73 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' -puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['~> 4.0'] +source ENV['GEM_SOURCE'] || "https://rubygems.org" -# github_changelog_generator must be 1.13.0 for ruby < 2.2.2 -github_changelog_generator_version = RUBY_VERSION < '2.2.2' ? '~> 1.13.0' : '>= 1.13.0' - -# github_changelog_generator must be 1.13.0 for ruby < 2.2.2 -github_changelog_generator_version = RUBY_VERSION < '2.2.2' ? '~> 1.13.0' : '>= 1.13.0' +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 'coveralls', require: false - gem 'facter', '>= 1.7.0' - gem 'git', '1.3.0' - gem 'github_changelog_generator', github_changelog_generator_version - gem 'hiera', require: false - gem 'httparty', require: false - gem 'metadata-json-lint', require: false - gem 'puppet', puppetversion - gem 'puppet-blacksmith', require: false - gem 'puppet-lint', require: false - gem 'puppet-strings', require: false - gem 'puppetlabs_spec_helper', require: false - gem 'rack', '~> 1.0', require: false if RUBY_VERSION < '2.2.2' - gem 'rspec-puppet', '>= 2.3.2' - gem 'rspec-puppet-utils', require: false - gem 'rspec_junit_formatter', require: false - gem 'rubocop-rspec', '1.4.1' if RUBY_VERSION < '2.2.0' - gem 'semantic_puppet', require: false - gem 'travis', require: false - gem 'travis-lint', require: false - gem 'yard', require: false + gem 'puppetlabs_spec_helper', '~> 2.2.0', :require => false + gem 'rspec-puppet', '~> 2.5', :require => false + gem 'rspec-puppet-facts', :require => false + gem 'rspec-puppet-utils', :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' + gem 'puppet-strings', '~> 1.0', :require => false + gem 'redcarpet', :require => false + gem 'rubocop', '~> 0.49.1', :require => false if RUBY_VERSION >= '2.3.0' + gem 'rubocop-rspec', '~> 1.15.0', :require => false if RUBY_VERSION >= '2.3.0' + gem 'mocha', '>= 1.2.1', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'github_changelog_generator', '~> 1.13.0', :require => false if RUBY_VERSION < '2.2.2' + gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2' + gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2' + gem 'parallel_tests', :require => false end -group :acceptance do - gem 'beaker' - gem 'beaker-puppet_install_helper' - gem 'beaker-rspec' - gem 'pry' +group :development do + gem 'travis', :require => false + gem 'travis-lint', :require => false + gem 'guard-rake', :require => false + gem 'overcommit', '>= 0.39.1', :require => false end -group :development do - gem 'notes', '~> 0.1.2' +group :system_tests do + gem 'winrm', :require => false + 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 + gem 'beaker-module_install_helper', :require => false end -# rspec must be v2 for ruby 1.8.7 -if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' - gem 'rake', '~> 10.0' - gem 'rspec', '~> 2.0' + + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion.to_s, :require => false, :groups => [:test] else - # rubocop requires ruby >= 1.9 - gem 'rubocop' + gem 'facter', :require => false, :groups => [:test] end + +ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 5.0' : puppetversion = ENV['PUPPET_VERSION'].to_s +gem 'puppet', puppetversion, :require => false, :groups => [:test] + +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 151dc85..174c72a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,31 +1,56 @@ -require 'github_changelog_generator/task' -require 'metadata-json-lint/rake_task' +require 'puppetlabs_spec_helper/rake_tasks' require 'puppet_blacksmith/rake_tasks' +require 'voxpupuli/release/rake_tasks' require 'puppet-strings/tasks' -require 'puppetlabs_spec_helper/rake_tasks' -require 'rubocop/rake_task' if RUBY_VERSION >= '2.0.0' -require 'rubygems' -# TravisCI does not require the extra module tasks. -require_relative 'rake/rake_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 -# Use a custom pattern with git tag. %s is replaced with the version number. -Blacksmith::RakeTask.new do |t| - t.tag_pattern = '%s' +desc 'Run acceptance tests' +RSpec::Core::RakeTask.new(:acceptance) do |t| + t.pattern = 'spec/acceptance' end -exclude_paths = [ - 'vagrant/**/*', - 'vendor/bundle/**/*' +desc 'Run tests metadata_lint, release_checks' +task test: [ + :metadata_lint, + :release_checks, ] -PuppetLint.configuration.ignore_paths = exclude_paths -PuppetSyntax.exclude_paths = exclude_paths +desc "Run main 'test' task and report merged results to coveralls" +task test_with_coveralls: [:test] do + if Dir.exist?(File.expand_path('../lib', __FILE__)) + require 'coveralls/rake/task' + Coveralls::RakeTask.new + Rake::Task['coveralls:push'].invoke + else + puts 'Skipping reporting to coveralls. Module has no lib dir' + end +end -GitHubChangelogGenerator::RakeTask.new :changelog do |config| - version = Blacksmith::Modulefile.new.version - config.future_release = version.to_s - config.unreleased_only = true - config.user = 'locp' - config.project = 'cassandra' +begin + require 'github_changelog_generator/task' + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + version = (Blacksmith::Modulefile.new).version + config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/ + config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\nEach new release typically also includes the latest modulesync defaults.\nThese should not affect the functionality of the module." + config.exclude_labels = %w{duplicate question invalid wontfix wont-fix modulesync skip-changelog} + config.user = 'voxpupuli' + end +rescue LoadError end +# vim: syntax=ruby diff --git a/Vagrantfile b/Vagrantfile index a95e7ba..8ba94d1 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,59 +1,60 @@ +# rubocop:disable Style/FileName # TODO: Find out why cassandra::params not working with vagrant and CentOS 6.2 # TODO: Find out why cassandra::params not working with vagrant and CentOS 7.0 # TODO: Find out why cassandra::params not working with vagrant and Ubuntu 12.04. Vagrant.configure('2') do |config| # config.vm.box = 'puppetlabs/centos-6.6-64-puppet' # config.vm.box = 'puppetlabs/centos-7.0-64-puppet' # config.vm.box = 'puppetlabs/debian-7.8-64-puppet' # config.vm.box = 'puppetlabs/debian-8.2-64-puppet' # config.vm.box = "puppetlabs/ubuntu-12.04-64-puppet" config.vm.box = 'puppetlabs/ubuntu-14.04-64-puppet' # config.vm.box = "puppetlabs/ubuntu-16.04-64-puppet" config.vm.provider 'virtualbox' do |vm| vm.memory = 2048 vm.cpus = 2 end puppet_environment = 'vagrant' puppet_environment_path_on_guest = "/etc/puppetlabs/code/environments/#{puppet_environment}" module_path_on_guest = "#{puppet_environment_path_on_guest}/modules" config.vm.synced_folder './vagrant', '/etc/puppetlabs/code/environments/vagrant' config.vm.synced_folder '.', '/etc/puppetlabs/code/environments/vagrant/modules/cassandra' config.vm.synced_folder './spec/acceptance/hieradata', '/etc/puppetlabs/code/environments/vagrant/hieradata' metadata_json_file = "#{File.dirname(__FILE__)}/metadata.json" config.vm.provision :shell, inline: "test -d #{module_path_on_guest}/ || mkdir #{puppet_environment_path_on_guest}" if File.exist?(metadata_json_file) JSON.parse(File.read(metadata_json_file))['dependencies'].each do |key, _value| module_name = key['name'].to_s short_name = module_name.split('-')[1] config.vm.provision :shell, inline: "test -d #{module_path_on_guest}/#{short_name} || puppet module install #{module_name} --environment=#{puppet_environment}" end else puts 'metadata.json not found; skipping install of dependencies' end config.vm.provision :puppet do |puppet| puppet.options = ENV['PUPPET_OPTS'].split(' ') if ENV.key?('PUPPET_OPTS') # See http://stackoverflow.com/a/27540417/224334 puppet.options = '--verbose --debug' if ENV['PUPPET_VERBOSE'] puppet.hiera_config_path = 'vagrant/hiera.yaml' puppet.environment = puppet_environment puppet.environment_path = './' puppet.manifests_path = "#{puppet_environment}/manifests" puppet.manifest_file = 'site.pp' puppet.facter = { project_name: 'ENGLISH NAME Of PROJECT', # EDIT THIS LINE } end config.vm.network :forwarded_port, guest: 22, host: 2223, auto_correct: true, id: 'ssh' # config.vm.network :forwarded_port, guest: 3000, host: 3000 end diff --git a/examples/system_settings.pp b/examples/system_settings.pp index 1cdbe3e..11047c0 100644 --- a/examples/system_settings.pp +++ b/examples/system_settings.pp @@ -1,26 +1,26 @@ # Cassandra pre-requisites require cassandra::datastax_repo require cassandra::system::transparent_hugepage case "${::operatingsystem}-${operatingsystemmajrelease}" { 'CentOS-6': { $device = '/dev/mapper/VolGroup-lv_swap' $sysctl_args = '-e -p' } 'CentOS-7': { $device = '/dev/mapper/centos-swap' } default: {} } class { 'cassandra::system::swapoff': - device => $device + device => $device, } if $sysctl_args { class { 'cassandra::system::sysctl': sysctl_args => $sysctl_args, } } else { require cassandra::system::sysctl } diff --git a/lib/facter/cassandrarelease.rb b/lib/facter/cassandrarelease.rb index 78ba9f9..13bf139 100644 --- a/lib/facter/cassandrarelease.rb +++ b/lib/facter/cassandrarelease.rb @@ -1,14 +1,14 @@ # Extract the release string from the running Cassandra instance. # # @resolution # Runs the command "nodetool version". # @caveats # The Cassandra service needs to be running, otherwise the fact will be # undefined. # @return [string] The version string (e.g. 3.0.1). Facter.add('cassandrarelease') do setcode do version = Facter::Util::Resolution.exec('nodetool version') - version.match(/\d+\.\d+\.\d+/).to_s if version && version != '' + version.match(%r{\d+\.\d+\.\d+}).to_s if version && version != '' end end diff --git a/manifests/datastax_agent.pp b/manifests/datastax_agent.pp index ed20add..5c19a58 100644 --- a/manifests/datastax_agent.pp +++ b/manifests/datastax_agent.pp @@ -1,120 +1,122 @@ # A class for installing the DataStax Agent and to point it at an OpsCenter # instance. # # @param address_config_file The full path to the address config file. # @param defaults_file The full path name to the file where `java_home` is set. # @param java_home If the value of this variable is left as *undef*, no # action is taken. Otherwise the value is set as JAVA_HOME in # `defaults_file`. # @param package_ensure Is passed to the package reference. Valid values are # **present** or a version number. # @param package_name Is passed to the package reference. # @param service_ensure Is passed to the service reference. # @param service_enable Is passed to the service reference. # @param service_name Is passed to the service reference. # @param service_provider The name of the provider that runs the service. # If left as *undef* then the OS family specific default will be used, # otherwise the specified value will be used instead. # @param settings A hash that is passed to # [create_ini_settings] # (https://github.com/puppetlabs/puppetlabs-inifile#function-create_ini_settings) # with the following additional defaults: # # ```puppet # { # path => $address_config_file, # key_val_separator => ': ', # require => Package[$package_name], # notify => Service['datastax-agent'], # } # ``` # # @example Set agent_alias to foobar, stomp_interface to localhost and ensure that async_pool_size is absent from the file. # class { 'cassandra::datastax_agent': # settings => { # 'agent_alias' => { # 'setting' => 'agent_alias', # 'value' => 'foobar', # }, # 'stomp_interface' => { # 'setting' => 'stomp_interface', # 'value' => 'localhost', # }, # 'async_pool_size' => { # 'ensure' => absent, # }, # }, # } class cassandra::datastax_agent ( $address_config_file = '/var/lib/datastax-agent/conf/address.yaml', $defaults_file = '/etc/default/datastax-agent', $java_home = undef, $package_ensure = 'present', $package_name = 'datastax-agent', $service_ensure = 'running', $service_enable = true, $service_name = 'datastax-agent', $service_provider = undef, $settings = {}, ) inherits cassandra::params { + require '::cassandra' + if $service_provider != undef { System { provider => $service_provider, } } package { $package_name: ensure => $package_ensure, require => Class['cassandra'], notify => Exec['datastax_agent_reload_systemctl'], } exec { 'datastax_agent_reload_systemctl': command => "${::cassandra::params::systemctl} daemon-reload", onlyif => "test -x ${::cassandra::params::systemctl}", path => ['/usr/bin', '/bin'], refreshonly => true, notify => Service['datastax-agent'], } file { $address_config_file: owner => 'cassandra', group => 'cassandra', mode => '0644', require => Package[$package_name], } if $java_home != undef { ini_setting { 'java_home': ensure => present, path => $defaults_file, section => '', key_val_separator => '=', setting => 'JAVA_HOME', value => $java_home, notify => Service['datastax-agent'], } } service { 'datastax-agent': ensure => $service_ensure, enable => $service_enable, name => $service_name, } if $settings { $defaults = { path => $address_config_file, key_val_separator => ': ', require => Package[$package_name], notify => Service['datastax-agent'], } $full_settings = { '' => $settings, } validate_hash($full_settings) create_ini_settings($full_settings, $defaults) } } diff --git a/manifests/init.pp b/manifests/init.pp index 91f0cc9..288430f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,382 +1,382 @@ # A class for installing the Cassandra package and manipulate settings in the # configuration file. # # @param baseline_settings [hash] If set, this is a baseline of settings that # are merged with the `settings` hash. The values of the `settings` # hash overriding the values in this hash. This is most useful when used # with hiera. # @param cassandra_2356_sleep_seconds [boolean] # This will provide a workaround for # [CASSANDRA-2356](https://issues.apache.org/jira/browse/CASSANDRA-2356) by # sleeping for the specifed number of seconds after an event involving the # Cassandra package. This option is silently ignored on the Red Hat family # of operating systems as this bug only affects Debian systems. # @param cassandra_9822 [boolean] If set to true, this will apply a patch to the init # file for the Cassandra service as a workaround for # [CASSANDRA-9822](https://issues.apache.org/jira/browse/CASSANDRA-9822). # This this bug only affects Debian systems. # @param cassandra_yaml_tmpl [string] The path to the Puppet template for the # Cassandra configuration file. This allows the user to supply their own # customized template.` # @param commitlog_directory [string] The path to the commitlog directory. # If set, the directory will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. # @param commitlog_directory_mode [string] The mode for the # `commitlog_directory` is ignored unless `commitlog_directory` is # specified. # @param config_file_mode [string] The permissions mode of the cassandra configuration # file. # @param config_path [string] The path to the cassandra configuration file. # @param data_file_directories [array] The path(s) to the date directory or # directories. # If set, the directories will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. # @param data_file_directories_mode [string] The mode for the # `data_file_directories` is ignored unless `data_file_directories` is # specified. # @param dc [string] Sets the value for dc in *config_path*/*snitch_properties_file* # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. # @param dc_suffix [string] Sets the value for dc_suffix in # *config_path*/*snitch_properties_file* see # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. If the value is *undef* then no change will be made to # the snitch properties file for this setting. # @param fail_on_non_supported_os [boolean] A flag that dictates if the module should # fail if it is not RedHat or Debian. If you set this option to false then # you must also at least set the `config_path` attribute as well. # @param hints_directory [string] The path to the hints directory. # If set, the directory will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. Do not set this option in Cassandra versions before 3.0.0. # @param hints_directory_mode [string] The mode for the # `hints_directory` is ignored unless `hints_directory` is # specified. # @param package_ensure [present|latest|string] The status of the package specified in # **package_name**. Can be *present*, *latest* or a specific version # number. # @param package_name [string] The name of the Cassandra package which must be available # from a repository. # @param prefer_local [boolean] Sets the value for prefer_local in # *config_path*/*snitch_properties_file* see # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. Valid values are true, false or *undef*. If the value # is *undef* then change will be made to the snitch properties file for # this setting. # @param rack [string] Sets the value for rack in # *config_path*/*snitch_properties_file* see # http://docs.datastax.com/en/cassandra/2.1/cassandra/architecture/architectureSnitchesAbout_c.html # for more details. # @param rackdc_tmpl [string] The template for creating the snitch properties file. # @param saved_caches_directory [string] The path to the saved caches directory. # If set, the directory will be managed as a Puppet resource. Do not # specify a value here and in the `settings` hash as they are mutually # exclusive. # @param saved_caches_directory_mode [string] The mode for the # `saved_caches_directory` is ignored unless `saved_caches_directory` is # specified. # @param service_enable [boolean] enable the Cassandra service to start at boot time. # @param service_ensure [string] Ensure the Cassandra service is running. Valid values # are running or stopped. # @param service_name [string] The name of the service that runs the Cassandra software. # @param service_provider [string] The name of the provider that runs the service. # If left as *undef* then the OS family specific default will # be used, otherwise the specified value will be used instead. # @param service_refresh [boolean] If set to true, changes to the Cassandra config file # or the data directories will ensure that Cassandra service is refreshed # after the changes. Setting this flag to false will disable this # behaviour, therefore allowing the changes to be made but allow the user # to control when the service is restarted. # @param settings [hash] A hash that is passed to `to_yaml` which dumps the results # to the Cassandra configuring file. The minimum required settings for # Cassandra 2.X are as follows: # # ```puppet # { # 'authenticator' => 'PasswordAuthenticator', # 'cluster_name' => 'MyCassandraCluster', # 'commitlog_directory' => '/var/lib/cassandra/commitlog', # 'commitlog_sync' => 'periodic', # 'commitlog_sync_period_in_ms' => 10000, # 'data_file_directories' => ['/var/lib/cassandra/data'], # 'endpoint_snitch' => 'GossipingPropertyFileSnitch', # 'listen_address' => $::ipaddress, # 'partitioner' => 'org.apache.cassandra.dht.Murmur3Partitioner', # 'saved_caches_directory' => '/var/lib/cassandra/saved_caches', # 'seed_provider' => [ # { # 'class_name' => 'org.apache.cassandra.locator.SimpleSeedProvider', # 'parameters' => [ # { # 'seeds' => $::ipaddress, # }, # ], # }, # ], # 'start_native_transport' => true, # } # ``` # For Cassandra 3.X you will also need to specify the `hints_directory` # attribute. # @param snitch_properties_file [string] The name of the snitch properties file. The # full path name would be *config_path*/*snitch_properties_file*. # @param systemctl [string] The full path to the systemctl command. Only # needed when the package is installed. Will silently continue if the # executable does not exist. class cassandra ( $baseline_settings = {}, $cassandra_2356_sleep_seconds = 5, $cassandra_9822 = false, $cassandra_yaml_tmpl = 'cassandra/cassandra.yaml.erb', $commitlog_directory = undef, $commitlog_directory_mode = '0750', $config_file_mode = '0644', $config_path = $::cassandra::params::config_path, $data_file_directories = undef, $data_file_directories_mode = '0750', $dc = 'DC1', $dc_suffix = undef, $fail_on_non_supported_os = true, $hints_directory = undef, $hints_directory_mode = '0750', $package_ensure = 'present', $package_name = $::cassandra::params::cassandra_pkg, $prefer_local = undef, $rack = 'RAC1', $rackdc_tmpl = 'cassandra/cassandra-rackdc.properties.erb', $saved_caches_directory = undef, $saved_caches_directory_mode = '0750', $service_enable = true, $service_ensure = undef, $service_name = 'cassandra', $service_provider = undef, $service_refresh = true, $settings = {}, $snitch_properties_file = 'cassandra-rackdc.properties', $systemctl = $::cassandra::params::systemctl, ) inherits cassandra::params { if $service_provider != undef { Service { provider => $service_provider, } } $config_file = "${config_path}/cassandra.yaml" $dc_rack_properties_file = "${config_path}/${snitch_properties_file}" case $::osfamily { 'RedHat': { $config_file_require = Package['cassandra'] $config_file_before = [] $config_path_require = Package['cassandra'] $dc_rack_properties_file_require = Package['cassandra'] $dc_rack_properties_file_before = [] $data_dir_require = Package['cassandra'] $data_dir_before = [] - if $::operatingsystemmajrelease == 7 and $::cassandra::service_provider == 'init' { + if $::operatingsystemmajrelease == '7' and $::cassandra::service_provider == 'init' { exec { "/sbin/chkconfig --add ${service_name}": unless => "/sbin/chkconfig --list ${service_name}", require => Package['cassandra'], before => Service['cassandra'], } } } 'Debian': { $config_file_require = [ User['cassandra'], File[$config_path] ] $config_file_before = Package['cassandra'] $config_path_require = [] $dc_rack_properties_file_require = [ User['cassandra'], File[$config_path] ] $dc_rack_properties_file_before = Package['cassandra'] $data_dir_require = File[$config_file] $data_dir_before = Package['cassandra'] if $cassandra_9822 { file { '/etc/init.d/cassandra': source => 'puppet:///modules/cassandra/CASSANDRA-9822/cassandra', mode => '0555', before => Package['cassandra'], } } # Sleep after package install and before service resource to prevent # possible duplicate processes arising from CASSANDRA-2356. exec { 'CASSANDRA-2356 sleep': command => "/bin/sleep ${cassandra_2356_sleep_seconds}", refreshonly => true, user => 'root', subscribe => Package['cassandra'], before => Service['cassandra'], } group { 'cassandra': ensure => present, } $user = 'cassandra' user { $user: ensure => present, comment => 'Cassandra database,,,', gid => 'cassandra', home => '/var/lib/cassandra', shell => '/bin/false', managehome => true, require => Group['cassandra'], } # End of CASSANDRA-2356 specific resources. } default: { - $config_file_before = [] - $config_file_require = [ User['cassandra'], File[$config_path] ] + $config_file_before = [ Package['cassandra'] ] + $config_file_require = [] $config_path_require = [] $dc_rack_properties_file_require = Package['cassandra'] $dc_rack_properties_file_before = [] if $fail_on_non_supported_os { fail("OS family ${::osfamily} not supported") } else { warning("OS family ${::osfamily} not supported") } } } package { 'cassandra': ensure => $package_ensure, name => $package_name, notify => Exec['cassandra_reload_systemctl'], } exec { 'cassandra_reload_systemctl': command => "${systemctl} daemon-reload", onlyif => "test -x ${systemctl}", path => ['/usr/bin', '/bin'], refreshonly => true, } file { $config_path: ensure => directory, group => 'cassandra', owner => 'cassandra', mode => '0755', require => $config_path_require, } if $commitlog_directory { file { $commitlog_directory: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $commitlog_directory_mode, require => $data_dir_require, before => $data_dir_before, } $commitlog_directory_settings = merge($settings, { 'commitlog_directory' => $commitlog_directory, }) } else { $commitlog_directory_settings = $settings } if is_array($data_file_directories) { file { $data_file_directories: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $data_file_directories_mode, require => $data_dir_require, before => $data_dir_before, } $data_file_directories_settings = merge($settings, { 'data_file_directories' => $data_file_directories, }) } else { $data_file_directories_settings = $settings } if $hints_directory { file { $hints_directory: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $hints_directory_mode, require => $data_dir_require, before => $data_dir_before, } $hints_directory_settings = merge($settings, { 'hints_directory' => $hints_directory, }) } else { $hints_directory_settings = $settings } if $saved_caches_directory { file { $saved_caches_directory: ensure => directory, owner => 'cassandra', group => 'cassandra', mode => $saved_caches_directory_mode, require => $data_dir_require, before => $data_dir_before, } $saved_caches_directory_settings = merge($settings, { 'saved_caches_directory' => $saved_caches_directory, }) } else { $saved_caches_directory_settings = $settings } $merged_settings = merge($baseline_settings, $settings, $commitlog_directory_settings, $data_file_directories_settings, $hints_directory_settings, $saved_caches_directory_settings) file { $config_file: ensure => present, owner => 'cassandra', group => 'cassandra', content => template($cassandra_yaml_tmpl), mode => $config_file_mode, require => $config_file_require, before => $config_file_before, } file { $dc_rack_properties_file: ensure => file, content => template($rackdc_tmpl), owner => 'cassandra', group => 'cassandra', mode => '0644', require => $dc_rack_properties_file_require, before => $dc_rack_properties_file_before, } if $package_ensure != 'absent' and $package_ensure != 'purged' { if $service_refresh { service { 'cassandra': ensure => $service_ensure, name => $service_name, enable => $service_enable, subscribe => [ File[$config_file], File[$dc_rack_properties_file], Package['cassandra'], ], } } else { service { 'cassandra': ensure => $service_ensure, name => $service_name, enable => $service_enable, require => [ File[$config_file], File[$dc_rack_properties_file], Package['cassandra'], ], } } } } diff --git a/manifests/optutils.pp b/manifests/optutils.pp index de4e83a..275fa8b 100644 --- a/manifests/optutils.pp +++ b/manifests/optutils.pp @@ -1,14 +1,16 @@ # A class to install the optional Cassandra tools package. # @param package_ensure [string] Can be `present`, `latest` or a specific # version number. # @param package_name [string] The name of the optional utilities package to # be installed. class cassandra::optutils ( $package_ensure = 'present', $package_name = $::cassandra::params::optutils_package_name, ) inherits cassandra::params { + include '::cassandra' + package { $package_name: ensure => $package_ensure, require => Class['cassandra'], } } diff --git a/rake/rake_tasks.rb b/rake/rake_tasks.rb deleted file mode 100644 index 9c8cddc..0000000 --- a/rake/rake_tasks.rb +++ /dev/null @@ -1,48 +0,0 @@ -############################################################################# -# Some module specific rake tasks. -############################################################################# -require 'fileutils' -require_relative 'tasks/deploy' - -desc '[CI Only] Run beaker, but only for pull requests or for release branches.' -task :acceptance do - travis_pull_request = ENV['TRAVIS_PULL_REQUEST'] - - if travis_pull_request.nil? || (travis_pull_request == 'false') - puts 'Skipping acceptance tests.' - exit(0) - else - Rake::Task['beaker'].invoke - end -end - -desc '[CI Only] Tag, build and push the module to PuppetForge.' -task :deploy do - abort('Only deploy from master.') unless ENV['CIRCLE_BRANCH'] == 'master' - - # Find out what the local version of the module is. - file = File.read('metadata.json') - data_hash = JSON.parse(file) - local_version = data_hash['version'] - abort('Unable to find local module version.') unless local_version - puts "Module version (local): #{local_version}" - - Rake::Task['deploy:tag'].invoke(local_version) - Rake::Task['deploy:forge'].invoke(local_version) -end - -desc 'Run metadata_lint, rubocop, lint, validate and spec.' -task test: %i[ - metadata_lint - rubocop - lint - validate - spec -] - -desc 'Clean up after a vagrant run.' -task :vagrant_clean do - module_root = File.expand_path(File.join(__FILE__, '..', '..')) - directory = File.expand_path(File.join(module_root, 'vagrant', 'modules')) - FileUtils.rm_r directory if File.directory?(directory) -end diff --git a/rake/tasks/deploy.rb b/rake/tasks/deploy.rb deleted file mode 100644 index ac1c7e0..0000000 --- a/rake/tasks/deploy.rb +++ /dev/null @@ -1,2 +0,0 @@ -require_relative 'deploy/forge' -require_relative 'deploy/tag' diff --git a/rake/tasks/deploy/forge.rb b/rake/tasks/deploy/forge.rb deleted file mode 100644 index e436fd3..0000000 --- a/rake/tasks/deploy/forge.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'httparty' -require 'json' -require 'yaml' - -namespace :deploy do - desc 'Deploy module to Puppet Forge if required.' - task :forge, [:version] do |_t, args| - local_version = args[:version] - - # Find out what the forge version of the module is. - response = HTTParty.get('https://forgeapi.puppetlabs.com/v3/modules/locp-cassandra') - data_hash = JSON.parse(response.body) - forge_version = data_hash['current_release']['version'] - abort('Unable to find out the forge version.') unless forge_version - puts "Module version (forge): #{forge_version}" - exit 0 unless local_version != forge_version - - # Build the module. - puts "Build and deploy version #{local_version}." - Rake::Task['module:clean'].invoke - Rake::Task['build'].invoke - - # Now see if we can push this baby to the forge. - PUPPET_FORGE_CREDENTIALS_FILE = ENV['HOME'] + '/' + '.puppetforge.yml' - username = ENV['CIRCLE_PROJECT_USERNAME'] - password = ENV['PUPPET_FORGE_PASSWORD'] - abort("Not enough data to populate #{PUPPET_FORGE_CREDENTIALS_FILE}") unless username && password - puts "Populating #{PUPPET_FORGE_CREDENTIALS_FILE}" - credentials = { 'username' => username, 'password' => password } - File.open(PUPPET_FORGE_CREDENTIALS_FILE, 'w') { |f| f.write credentials.to_yaml } - Rake::Task['module:push'].invoke - end -end diff --git a/rake/tasks/deploy/tag.rb b/rake/tasks/deploy/tag.rb deleted file mode 100644 index 7c48fcc..0000000 --- a/rake/tasks/deploy/tag.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'git' - -namespace :deploy do - desc 'Deploy tag for the module' - task :tag, [:version] do |_t, args| - tagname = args[:version] - # Find out if a tag is available for this version. - log = Logger.new(STDOUT) - log.level = Logger::WARN - git = Git.open('.', log: log) - - begin - git.tag(tagname) - rescue Git::GitTagNameDoesNotExist - puts "Creating tag: #{tagname}" - git.add_tag(tagname, 'master', message: 'tagged by RubyAutoDeployTest', f: true) - git.push('origin', "refs/tags/#{tagname}", f: true) - else - puts "Tag: #{tagname} already exists." - end - end -end diff --git a/spec/acceptance/cassandra_spec.rb b/spec/acceptance/cassandra_spec.rb index 14ec230..d7f4716 100644 --- a/spec/acceptance/cassandra_spec.rb +++ b/spec/acceptance/cassandra_spec.rb @@ -1,128 +1,128 @@ require 'spec_helper_acceptance' describe 'cassandra' do roles = hosts[0]['roles'] versions = [] versions.push(2.1) if roles.include? 'cassandra2' versions.push(2.2) if roles.include? 'cassandra2' versions.push(3.0) if roles.include? 'cassandra3' versions.each do |version| t = TestManifests.new(roles, version, fact('operatingsystemmajrelease')) describe "Cassandra #{version} installation." do # firewall_pp = t.firewall_pp() cassandra_install_pp = t.cassandra_install_pp - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(cassandra_install_pp, catch_failures: true) end it 'check code is idempotent' do expect(apply_manifest(cassandra_install_pp, catch_failures: true).exit_code).to be_zero end end describe service('cassandra') do it "check Cassandra-#{version} is running and enabled" do is_expected.to be_running is_expected.to be_enabled end end if fact('osfamily') == 'RedHat' describe service('datastax-agent') do it 'check service status' do is_expected.to be_running is_expected.to be_enabled end end end describe "Create schema for #{version}." do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.schema_create_pp, catch_failures: true) end if version != 2.1 it 'check code is idempotent' do expect(apply_manifest(t.schema_create_pp, catch_failures: true).exit_code).to be_zero end end end describe "Schema drop type for #{version}." do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.schema_drop_type_pp, catch_failures: true) end it 'check code is idempotent' do expect(apply_manifest(t.schema_drop_type_pp, catch_failures: true).exit_code).to be_zero end end describe "Revoke permissions for #{version}." do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.permissions_revoke_pp, catch_failures: true) end it 'check code is idempotent' do expect(apply_manifest(t.permissions_revoke_pp, catch_failures: true).exit_code).to be_zero end end describe "Drop user for #{version}" do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.schema_drop_user_pp, catch_failures: true) end it 'check code is idempotent' do expect(apply_manifest(t.schema_drop_user_pp, catch_failures: true).exit_code).to be_zero end end describe "Drop index for #{version}" do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.schema_drop_index_pp, catch_failures: true) end it 'check code is idempotent' do expect(apply_manifest(t.schema_drop_index_pp, catch_failures: true).exit_code).to be_zero end end describe "Drop table for #{version}" do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.schema_drop_table_pp, catch_failures: true) end it 'check code is idempotent' do expect(apply_manifest(t.schema_drop_table_pp, catch_failures: true).exit_code).to be_zero end end describe "Drop keyspace for #{version}" do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.schema_drop_keyspace_pp, catch_failures: true) end it 'check code is idempotent' do expect(apply_manifest(t.schema_drop_keyspace_pp, catch_failures: true).exit_code).to be_zero end end describe "Facts Tests for #{version}" do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.facts_testing_pp, catch_failures: true) end end next unless version != 3.0 describe "Uninstall #{version}." do - it 'should work with no errors' do + it 'works with no errors' do apply_manifest(t.cassandra_uninstall_pp, catch_failures: true) end end end end diff --git a/spec/acceptance/nodesets/archlinux-2-x64.yml b/spec/acceptance/nodesets/archlinux-2-x64.yml new file mode 100644 index 0000000..89b6300 --- /dev/null +++ b/spec/acceptance/nodesets/archlinux-2-x64.yml @@ -0,0 +1,13 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + archlinux-2-x64: + roles: + - master + platform: archlinux-2-x64 + box: archlinux/archlinux + hypervisor: vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/centos-511-x64.yml b/spec/acceptance/nodesets/centos-511-x64.yml new file mode 100644 index 0000000..089d646 --- /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-6-x64.yml b/spec/acceptance/nodesets/centos-6-x64.yml new file mode 100644 index 0000000..16abc8f --- /dev/null +++ b/spec/acceptance/nodesets/centos-6-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-6-x64: + roles: + - master + platform: el-6-x86_64 + box: centos/6 + hypervisor: vagrant +CONFIG: + type: aio +... +# vim: syntax=yaml 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 0000000..1e7aea6 --- /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-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml new file mode 100644 index 0000000..e05a3ae --- /dev/null +++ b/spec/acceptance/nodesets/centos-7-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-7-x64: + roles: + - master + platform: el-7-x86_64 + box: centos/7 + hypervisor: vagrant +CONFIG: + type: aio +... +# 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 0000000..6ef6de8 --- /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 0000000..9897a8f --- /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/docker/centos-5.yml b/spec/acceptance/nodesets/docker/centos-5.yml new file mode 100644 index 0000000..c17bc3d --- /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 0000000..d93f884 --- /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 0000000..41e924b --- /dev/null +++ b/spec/acceptance/nodesets/docker/centos-7.yml @@ -0,0 +1,19 @@ +--- +# 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 ss' + - 'systemctl mask getty@tty1.service' +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 0000000..071acbf --- /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 0000000..7a1f35c --- /dev/null +++ b/spec/acceptance/nodesets/docker/debian-8.yml @@ -0,0 +1,21 @@ +--- +# 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' + - 'systemctl mask getty@tty1.service getty-static.service' +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 0000000..ab77cda --- /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 0000000..ae45304 --- /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 apt-transport-https' + - '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 0000000..2d173c5 --- /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 locales apt-transport-https' + - 'locale-gen en_US.UTF-8' +CONFIG: + trace_limit: 200 + masterless: true +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml b/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml new file mode 100644 index 0000000..19dd43e --- /dev/null +++ b/spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml @@ -0,0 +1,31 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +# Amazon Linux is not a RHEL clone. +# +HOSTS: + amazonlinux-2016091-x64: + roles: + - master + platform: centos-6-x86_64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: amazonlinux-2016091-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/image_templates.yaml b/spec/acceptance/nodesets/ec2/image_templates.yaml new file mode 100644 index 0000000..e50593e --- /dev/null +++ b/spec/acceptance/nodesets/ec2/image_templates.yaml @@ -0,0 +1,34 @@ +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# see also: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +# Hint: image IDs (ami-*) for the same image are different per location. +# +AMI: + # Amazon Linux AMI 2016.09.1 (HVM), SSD Volume Type + amazonlinux-2016091-eu-central-1: + :image: + :aio: ami-af0fc0c0 + :region: eu-central-1 + # Red Hat Enterprise Linux 7.3 (HVM), SSD Volume Type + rhel-73-eu-central-1: + :image: + :aio: ami-e4c63e8b + :region: eu-central-1 + # SUSE Linux Enterprise Server 12 SP2 (HVM), SSD Volume Type + sles-12sp2-eu-central-1: + :image: + :aio: ami-c425e4ab + :region: eu-central-1 + # Ubuntu Server 16.04 LTS (HVM), SSD Volume Type + ubuntu-1604-eu-central-1: + :image: + :aio: ami-fe408091 + :region: eu-central-1 + # Microsoft Windows Server 2016 Base + windows-2016-base-eu-central-1: + :image: + :aio: ami-88ec20e7 + :region: eu-central-1 diff --git a/spec/acceptance/nodesets/ec2/rhel-73-x64.yml b/spec/acceptance/nodesets/ec2/rhel-73-x64.yml new file mode 100644 index 0000000..7fac823 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/rhel-73-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + rhel-73-x64: + roles: + - master + platform: el-7-x86_64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: rhel-73-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml b/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml new file mode 100644 index 0000000..8542154 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + sles-12sp2-x64: + roles: + - master + platform: sles-12-x86_64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: sles-12sp2-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml b/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml new file mode 100644 index 0000000..9cf59d5 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + ubuntu-1604-x64: + roles: + - master + platform: ubuntu-16.04-amd64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: ubuntu-1604-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ubuntu +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml b/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml new file mode 100644 index 0000000..0932e29 --- /dev/null +++ b/spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml @@ -0,0 +1,29 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# Additional ~/.fog config file with AWS EC2 credentials +# required. +# +# see: https://github.com/puppetlabs/beaker/blob/master/docs/how_to/hypervisors/ec2.md +# +HOSTS: + windows-2016-base-x64: + roles: + - master + platform: windows-2016-64 + hypervisor: ec2 + # refers to image_tempaltes.yaml AMI[vmname] entry: + vmname: windows-2016-base-eu-central-1 + # refers to image_tempaltes.yaml entry inside AMI[vmname][:image]: + snapshot: aio + # t2.micro is free tier eligible (https://aws.amazon.com/en/free/): + amisize: t2.micro + # required so that beaker sanitizes sshd_config and root authorized_keys: + user: ec2-user +CONFIG: + type: aio + :ec2_yaml: spec/acceptance/nodesets/ec2/image_templates.yaml +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/fedora-24-x64.yml b/spec/acceptance/nodesets/fedora-24-x64.yml new file mode 100644 index 0000000..820b62d --- /dev/null +++ b/spec/acceptance/nodesets/fedora-24-x64.yml @@ -0,0 +1,15 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +HOSTS: + fedora-24-x64: + roles: + - master + platform: fedora-24-x86_64 + box: fedora/24-cloud-base + hypervisor: vagrant +CONFIG: + type: aio +... +# vim: syntax=yaml diff --git a/spec/acceptance/nodesets/fedora-25-x64.yml b/spec/acceptance/nodesets/fedora-25-x64.yml new file mode 100644 index 0000000..60ae011 --- /dev/null +++ b/spec/acceptance/nodesets/fedora-25-x64.yml @@ -0,0 +1,18 @@ +--- +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# platform is fedora 24 because there is no +# puppet-agent for fedora 25 by 2016-12-30 +HOSTS: + fedora-25-x64: + roles: + - master + platform: fedora-25-x86_64 + box: fedora/25-cloud-base + hypervisor: vagrant +CONFIG: + type: aio +... +# 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 0000000..29102c5 --- /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-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..054e658 --- /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 0000000..bc85e0e --- /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/apache_repo_spec.rb b/spec/classes/apache_repo_spec.rb index 7d46212..5b5e662 100644 --- a/spec/classes/apache_repo_spec.rb +++ b/spec/classes/apache_repo_spec.rb @@ -1,78 +1,69 @@ require 'spec_helper' describe 'cassandra::apache_repo' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $source) {}', - 'define apt::source ($location, $comment, $release, $include) {}' - ] - end - context 'On a RedHat OS with defaults for all parameters' do let :facts do { osfamily: 'RedHat' } end let :params do { release: '311x' } end it do - should have_resource_count(1) + is_expected.to have_resource_count(1) - should contain_class('cassandra::apache_repo').only_with( + is_expected.to contain_class('cassandra::apache_repo').only_with( 'descr' => 'Repo for Apache Cassandra', 'key_id' => 'A26E528B271F19B9E5D8E19EA278B781FE4B2BDA', 'key_url' => 'https://www.apache.org/dist/cassandra/KEYS', 'release' => '311x' ) - should contain_yumrepo('cassandra_apache').with( + is_expected.to contain_yumrepo('cassandra_apache').with( ensure: 'present', descr: 'Repo for Apache Cassandra', baseurl: 'http://www.apache.org/dist/cassandra/redhat/311x', enabled: 1, gpgcheck: 1, gpgkey: 'https://www.apache.org/dist/cassandra/KEYS' ) end end context 'On a Debian OS with defaults for all parameters' do let :facts do { osfamily: 'Debian', lsbdistid: 'Ubuntu', lsbdistrelease: '14.04' } end it do - should have_resource_count(3) - should contain_class('apt') - should contain_class('apt::update') + is_expected.to have_resource_count(14) + is_expected.to contain_class('apt') + is_expected.to contain_class('apt::update') - should contain_apt__key('apache.cassandra').with( + is_expected.to contain_apt__key('apache.cassandra').with( id: 'A26E528B271F19B9E5D8E19EA278B781FE4B2BDA', source: 'https://www.apache.org/dist/cassandra/KEYS' ) - should contain_apt__source('cassandra.sources').with( + is_expected.to contain_apt__source('cassandra.sources').with( location: 'http://www.apache.org/dist/cassandra/debian', comment: 'Repo for Apache Cassandra', release: 'main', include: { 'src' => false } ).that_notifies('Exec[update-apache-cassandra-repo]') - should contain_exec('update-apache-cassandra-repo').with( + is_expected.to contain_exec('update-apache-cassandra-repo').with( refreshonly: true, command: '/bin/true' ) end end end diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb new file mode 100644 index 0000000..de44654 --- /dev/null +++ b/spec/classes/coverage_spec.rb @@ -0,0 +1,4 @@ +require 'rspec-puppet' + +at_exit { RSpec::Puppet::Coverage.report! } +# vim: syntax=ruby diff --git a/spec/classes/datastax_agent_spec.rb b/spec/classes/datastax_agent_spec.rb index 199adff..40992d4 100644 --- a/spec/classes/datastax_agent_spec.rb +++ b/spec/classes/datastax_agent_spec.rb @@ -1,140 +1,129 @@ require 'spec_helper' describe 'cassandra::datastax_agent' do - let(:pre_condition) do - [ - 'class cassandra() {}', - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Test for cassandra::datastax_agent with defaults (RedHat).' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 6 + operatingsystemmajrelease: '6' } end it do - should have_resource_count(4) + is_expected.to have_resource_count(10) - should contain_class('cassandra::datastax_agent').only_with( + is_expected.to contain_class('cassandra::datastax_agent').only_with( + 'address_config_file' => '/var/lib/datastax-agent/conf/address.yaml', 'defaults_file' => '/etc/default/datastax-agent', 'package_ensure' => 'present', 'package_name' => 'datastax-agent', 'service_ensure' => 'running', 'service_enable' => true, 'service_name' => 'datastax-agent', 'stomp_interface' => nil, 'local_interface' => nil ) - should contain_package('datastax-agent').with( + is_expected.to contain_package('datastax-agent').with( ensure: 'present', notify: 'Exec[datastax_agent_reload_systemctl]' ).that_notifies('Exec[datastax_agent_reload_systemctl]') - should contain_exec('datastax_agent_reload_systemctl').only_with( + is_expected.to contain_exec('datastax_agent_reload_systemctl').only_with( command: '/usr/bin/systemctl daemon-reload', onlyif: 'test -x /usr/bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true, notify: 'Service[datastax-agent]' ).that_notifies('Service[datastax-agent]') - should contain_file('/var/lib/datastax-agent/conf/address.yaml') - .with( + is_expected.to contain_file('/var/lib/datastax-agent/conf/address.yaml'). + with( owner: 'cassandra', group: 'cassandra', mode: '0644' ).that_requires('Package[datastax-agent]') - should contain_service('datastax-agent').only_with( + is_expected.to contain_service('datastax-agent').only_with( ensure: 'running', enable: true, name: 'datastax-agent' ) end end context 'Test for cassandra::datastax_agent with defaults (Debian).' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: 6 + operatingsystemmajrelease: '6' } end it do - should contain_exec('datastax_agent_reload_systemctl').with( + is_expected.to contain_exec('datastax_agent_reload_systemctl').with( command: '/bin/systemctl daemon-reload', onlyif: 'test -x /bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true ).that_notifies('Service[datastax-agent]') end end context 'Test that the JAVA_HOME can be set.' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: 6 + operatingsystemmajrelease: '6' } end let :params do { java_home: '/usr/lib/jvm/java-8-oracle' } end it do - should contain_ini_setting('java_home').with( + is_expected.to contain_ini_setting('java_home').with( ensure: 'present', path: '/etc/default/datastax-agent', section: '', key_val_separator: '=', setting: 'JAVA_HOME', value: '/usr/lib/jvm/java-8-oracle' ).that_notifies('Service[datastax-agent]') end end context 'Test settings.' do let :facts do { osfamily: 'Debian', - operatingsystemmajrelease: 6 + operatingsystemmajrelease: '6' } end let :params do { settings: { 'agent_alias' => { 'setting' => 'agent_alias', 'value' => 'foobar' }, 'stomp_interface' => { 'setting' => 'stomp_interface', 'value' => 'localhost' }, 'async_pool_size' => { 'ensure' => 'absent' } } } end it do - should have_resource_count(4) + is_expected.to have_resource_count(16) end end end diff --git a/spec/classes/datastax_repo_spec.rb b/spec/classes/datastax_repo_spec.rb index d45e7b4..e94642b 100644 --- a/spec/classes/datastax_repo_spec.rb +++ b/spec/classes/datastax_repo_spec.rb @@ -1,71 +1,62 @@ require 'spec_helper' describe 'cassandra::datastax_repo' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $source) {}', - 'define apt::source ($location, $comment, $release, $include) {}' - ] - end - context 'On a RedHat OS with defaults for all parameters' do let :facts do { osfamily: 'RedHat' } end it do - should have_resource_count(1) + is_expected.to have_resource_count(1) - should contain_class('cassandra::datastax_repo').only_with( + is_expected.to contain_class('cassandra::datastax_repo').only_with( 'descr' => 'DataStax Repo for Apache Cassandra', 'key_id' => '7E41C00F85BFC1706C4FFFB3350200F2B999A372', 'key_url' => 'http://debian.datastax.com/debian/repo_key', 'release' => 'stable' ) - should contain_yumrepo('datastax').with( + is_expected.to contain_yumrepo('datastax').with( ensure: 'present', descr: 'DataStax Repo for Apache Cassandra', baseurl: 'http://rpm.datastax.com/community', enabled: 1, gpgcheck: 0 ) end end context 'On a Debian OS with defaults for all parameters' do let :facts do { osfamily: 'Debian', lsbdistid: 'Ubuntu', lsbdistrelease: '14.04' } end it do - should have_resource_count(3) - should contain_class('apt') - should contain_class('apt::update') + is_expected.to have_resource_count(14) + is_expected.to contain_class('apt') + is_expected.to contain_class('apt::update') - should contain_apt__key('datastaxkey').with( + is_expected.to contain_apt__key('datastaxkey').with( id: '7E41C00F85BFC1706C4FFFB3350200F2B999A372', source: 'http://debian.datastax.com/debian/repo_key' ) - should contain_apt__source('datastax').with( + is_expected.to contain_apt__source('datastax').with( location: 'http://debian.datastax.com/community', comment: 'DataStax Repo for Apache Cassandra', release: 'stable', include: { 'src' => false } ).that_notifies('Exec[update-cassandra-repos]') - should contain_exec('update-cassandra-repos').with( + is_expected.to contain_exec('update-cassandra-repos').with( refreshonly: true, command: '/bin/true' ) end end end diff --git a/spec/classes/dse_spec.rb b/spec/classes/dse_spec.rb index ce93cab..aaba78e 100644 --- a/spec/classes/dse_spec.rb +++ b/spec/classes/dse_spec.rb @@ -1,28 +1,21 @@ require 'spec_helper' describe 'cassandra::dse' do - let(:pre_condition) do - [ - 'class stdlib () {}', - 'define file_line($line, $path, $match) {}' - ] - end - context 'with defaults for all parameters' do let :facts do { osfamily: 'RedHat', operatingsystemmajrelease: 7 } end it do - should have_resource_count(6) - should contain_class('cassandra') + is_expected.to have_resource_count(13) + is_expected.to contain_class('cassandra') - should contain_class('cassandra::dse').with( + is_expected.to contain_class('cassandra::dse').with( config_file_mode: '0644', config_file: '/etc/dse/dse.yaml' ) end end end diff --git a/spec/classes/firewall_ports_spec.rb b/spec/classes/firewall_ports_spec.rb index edc7f89..c808c7f 100644 --- a/spec/classes/firewall_ports_spec.rb +++ b/spec/classes/firewall_ports_spec.rb @@ -1,30 +1,23 @@ require 'spec_helper' describe 'cassandra::firewall_ports' do - let(:pre_condition) do - [ - 'class cassandra () {}', - 'define firewall ($action, $dport, $proto, $source) {}' - ] - end - context 'Run with defaults.' do it do - should have_resource_count(2) - should contain_firewall('200 - Cassandra (Public) - 0.0.0.0/0') + is_expected.to have_resource_count(2) + is_expected.to contain_firewall('200 - Cassandra (Public) - 0.0.0.0/0') - should contain_class('cassandra::firewall_ports').with( + is_expected.to contain_class('cassandra::firewall_ports').with( client_ports: [9042, 9160], client_subnets: ['0.0.0.0/0'], inter_node_ports: [7000, 7001, 7199], inter_node_subnets: ['0.0.0.0/0'], public_ports: [8888], public_subnets: ['0.0.0.0/0'], ssh_port: 22, opscenter_ports: [9042, 9160, 61_620, 61_621], opscenter_subnets: ['0.0.0.0/0'] ) - should contain_cassandra__private__firewall_ports__rule('200_Public_0.0.0.0/0').with(ports: [8888, 22]) + is_expected.to contain_cassandra__private__firewall_ports__rule('200_Public_0.0.0.0/0').with(ports: [8888, 22]) end end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index ecd65fd..da810f1 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,403 +1,388 @@ require 'spec_helper' describe 'cassandra' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $source) {}', - 'define apt::source ($location, $comment, $release, $include) {}', - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'On an unknown OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: 10, + operatingsystemmajrelease: '10', osfamily: 'Darwin' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: '7' } end it do - should contain_package('cassandra').with( + is_expected.to contain_package('cassandra').with( ensure: 'present', name: 'cassandra22' ).that_notifies('Exec[cassandra_reload_systemctl]') - should contain_exec('cassandra_reload_systemctl').only_with( + is_expected.to contain_exec('cassandra_reload_systemctl').only_with( command: '/usr/bin/systemctl daemon-reload', onlyif: 'test -x /usr/bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true ) - should contain_file('/etc/cassandra/default.conf').with( + is_expected.to contain_file('/etc/cassandra/default.conf').with( ensure: 'directory', group: 'cassandra', owner: 'cassandra', mode: '0755' ).that_requires('Package[cassandra]') - should contain_file('/etc/cassandra/default.conf/cassandra.yaml') - .with( + is_expected.to contain_file('/etc/cassandra/default.conf/cassandra.yaml'). + with( ensure: 'present', owner: 'cassandra', group: 'cassandra', mode: '0644' - ) - .that_requires('Package[cassandra]') + ). + that_requires('Package[cassandra]') - should contain_class('cassandra').only_with( + is_expected.to contain_class('cassandra').only_with( baseline_settings: {}, cassandra_2356_sleep_seconds: 5, cassandra_9822: false, cassandra_yaml_tmpl: 'cassandra/cassandra.yaml.erb', commitlog_directory_mode: '0750', config_file_mode: '0644', config_path: '/etc/cassandra/default.conf', data_file_directories_mode: '0750', dc: 'DC1', fail_on_non_supported_os: true, hints_directory_mode: '0750', package_ensure: 'present', package_name: 'cassandra22', rack: 'RAC1', rackdc_tmpl: 'cassandra/cassandra-rackdc.properties.erb', saved_caches_directory_mode: '0750', service_enable: true, service_name: 'cassandra', service_provider: nil, service_refresh: true, settings: {}, systemctl: '/usr/bin/systemctl' ) end end context 'On RedHat 7 with data directories specified.' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: '7' } end let :params do { commitlog_directory: '/var/lib/cassandra/commitlog', data_file_directories: ['/var/lib/cassandra/data'], hints_directory: '/var/lib/cassandra/hints', saved_caches_directory: '/var/lib/cassandra/saved_caches', settings: { 'cluster_name' => 'MyCassandraCluster' } } end it do - should have_resource_count(10) - should contain_file('/var/lib/cassandra/commitlog') - should contain_file('/var/lib/cassandra/data') - should contain_file('/var/lib/cassandra/hints') - should contain_file('/var/lib/cassandra/saved_caches') + is_expected.to have_resource_count(10) + is_expected.to contain_file('/var/lib/cassandra/commitlog') + is_expected.to contain_file('/var/lib/cassandra/data') + is_expected.to contain_file('/var/lib/cassandra/hints') + is_expected.to contain_file('/var/lib/cassandra/saved_caches') end end context 'On RedHat 7 with service provider set to init.' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: '7' } end let :params do { service_provider: 'init' } end it do - should have_resource_count(7) - should contain_exec('/sbin/chkconfig --add cassandra').with( + is_expected.to have_resource_count(7) + is_expected.to contain_exec('/sbin/chkconfig --add cassandra').with( unless: '/sbin/chkconfig --list cassandra' - ) - .that_requires('Package[cassandra]') - .that_comes_before('Service[cassandra]') + ). + that_requires('Package[cassandra]'). + that_comes_before('Service[cassandra]') end end context 'On a Debian OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: 8, + operatingsystemmajrelease: '8', osfamily: 'Debian' } end it do - should contain_class('cassandra') - should contain_group('cassandra').with_ensure('present') + is_expected.to contain_class('cassandra') + is_expected.to contain_group('cassandra').with_ensure('present') - should contain_package('cassandra').with( + is_expected.to contain_package('cassandra').with( ensure: 'present', name: 'cassandra' ).that_notifies('Exec[cassandra_reload_systemctl]') - should contain_exec('cassandra_reload_systemctl').only_with( + is_expected.to contain_exec('cassandra_reload_systemctl').only_with( command: '/bin/systemctl daemon-reload', onlyif: 'test -x /bin/systemctl', path: ['/usr/bin', '/bin'], refreshonly: true ) - should contain_service('cassandra').with( + is_expected.to contain_service('cassandra').with( ensure: nil, name: 'cassandra', enable: 'true' ) - should contain_exec('CASSANDRA-2356 sleep') - .with( + is_expected.to contain_exec('CASSANDRA-2356 sleep'). + with( command: '/bin/sleep 5', refreshonly: true, user: 'root' - ) - .that_subscribes_to('Package[cassandra]') - .that_comes_before('Service[cassandra]') + ). + that_subscribes_to('Package[cassandra]'). + that_comes_before('Service[cassandra]') - should contain_user('cassandra') - .with( + is_expected.to contain_user('cassandra'). + with( ensure: 'present', comment: 'Cassandra database,,,', gid: 'cassandra', home: '/var/lib/cassandra', shell: '/bin/false', managehome: true - ) - .that_requires('Group[cassandra]') + ). + that_requires('Group[cassandra]') - should contain_file('/etc/cassandra').with( + is_expected.to contain_file('/etc/cassandra').with( ensure: 'directory', group: 'cassandra', owner: 'cassandra', mode: '0755' ) - should contain_file('/etc/cassandra/cassandra.yaml') - .with( + is_expected.to contain_file('/etc/cassandra/cassandra.yaml'). + with( ensure: 'present', owner: 'cassandra', group: 'cassandra', mode: '0644' - ) - .that_comes_before('Package[cassandra]') - .that_requires(['User[cassandra]', 'File[/etc/cassandra]']) + ). + that_comes_before('Package[cassandra]'). + that_requires(['User[cassandra]', 'File[/etc/cassandra]']) - should contain_file('/etc/cassandra/cassandra-rackdc.properties') - .with( + is_expected.to contain_file('/etc/cassandra/cassandra-rackdc.properties'). + with( ensure: 'file', owner: 'cassandra', group: 'cassandra', mode: '0644' - ) - .that_requires(['File[/etc/cassandra]', 'User[cassandra]']) - .that_comes_before('Package[cassandra]') + ). + that_requires(['File[/etc/cassandra]', 'User[cassandra]']). + that_comes_before('Package[cassandra]') - should contain_service('cassandra') - .that_subscribes_to( + is_expected.to contain_service('cassandra'). + that_subscribes_to( [ 'File[/etc/cassandra/cassandra.yaml]', 'File[/etc/cassandra/cassandra-rackdc.properties]', 'Package[cassandra]' ] ) end end context 'CASSANDRA-9822 activated on Debian' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'Debian', lsbdistid: 'Ubuntu', lsbdistrelease: '14.04' } end let :params do { cassandra_9822: true } end it do - should contain_file('/etc/init.d/cassandra').with( + is_expected.to contain_file('/etc/init.d/cassandra').with( source: 'puppet:///modules/cassandra/CASSANDRA-9822/cassandra', mode: '0555' ).that_comes_before('Package[cassandra]') end end context 'Install DSE on a Red Hat family OS.' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } end let :params do { package_ensure: '4.7.0-1', package_name: 'dse-full', config_path: '/etc/dse/cassandra', service_name: 'dse' } end it do - should contain_file('/etc/dse/cassandra/cassandra.yaml').that_notifies('Service[cassandra]') - should contain_file('/etc/dse/cassandra') + is_expected.to contain_file('/etc/dse/cassandra/cassandra.yaml').that_notifies('Service[cassandra]') + is_expected.to contain_file('/etc/dse/cassandra') - should contain_file('/etc/dse/cassandra/cassandra-rackdc.properties') - .with( + is_expected.to contain_file('/etc/dse/cassandra/cassandra-rackdc.properties'). + with( ensure: 'file', owner: 'cassandra', group: 'cassandra', mode: '0644' - ) - .that_notifies('Service[cassandra]') + ). + that_notifies('Service[cassandra]') - should contain_package('cassandra').with( + is_expected.to contain_package('cassandra').with( ensure: '4.7.0-1', name: 'dse-full' ) is_expected.to contain_service('cassandra').with_name('dse') end end context 'On an unsupported OS pleading tolerance' do let :facts do { - operatingsystemmajrelease: 10, + operatingsystemmajrelease: '10', osfamily: 'Darwin' } end let :params do { config_file_mode: '0755', config_path: '/etc/cassandra', fail_on_non_supported_os: false, package_name: 'cassandra', service_provider: 'base', systemctl: '/bin/true' } end it do - should contain_file('/etc/cassandra/cassandra.yaml').with('mode' => '0755') - should contain_service('cassandra').with(provider: 'base') - should have_resource_count(6) + is_expected.to contain_file('/etc/cassandra/cassandra.yaml').with('mode' => '0755') + is_expected.to contain_service('cassandra').with(provider: 'base') + is_expected.to have_resource_count(6) end end context 'Ensure cassandra service can be stopped and disabled.' do let :facts do { - operatingsystemmajrelease: 8, + operatingsystemmajrelease: '8', osfamily: 'Debian' } end let :params do { service_ensure: 'stopped', service_enable: 'false' } end it do - should contain_service('cassandra') - .with(ensure: 'stopped', - name: 'cassandra', - enable: 'false') + is_expected.to contain_service('cassandra'). + with(ensure: 'stopped', + name: 'cassandra', + enable: 'false') end end context 'Test the dc and rack properties with defaults (Debian).' do let :facts do { - operatingsystemmajrelease: 8, + operatingsystemmajrelease: '8', osfamily: 'Debian' } end it do - should contain_file('/etc/cassandra/cassandra-rackdc.properties') - .with_content(/^dc=DC1/) - .with_content(/^rack=RAC1$/) - .with_content(/^#dc_suffix=$/) - .with_content(/^# prefer_local=true$/) + is_expected.to contain_file('/etc/cassandra/cassandra-rackdc.properties'). + with_content(%r{^dc=DC1}). + with_content(%r{^rack=RAC1$}). + with_content(%r{^#dc_suffix=$}). + with_content(%r{^# prefer_local=true$}) end end context 'Test the dc and rack properties with defaults (RedHat).' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } end it do - should contain_file('/etc/cassandra/default.conf/cassandra-rackdc.properties') - .with_content(/^dc=DC1/) - .with_content(/^rack=RAC1$/) - .with_content(/^#dc_suffix=$/) - .with_content(/^# prefer_local=true$/) + is_expected.to contain_file('/etc/cassandra/default.conf/cassandra-rackdc.properties'). + with_content(%r{^dc=DC1}). + with_content(%r{^rack=RAC1$}). + with_content(%r{^#dc_suffix=$}). + with_content(%r{^# prefer_local=true$}) end end context 'Test the dc and rack properties.' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } end let :params do { snitch_properties_file: 'cassandra-topology.properties', dc: 'NYC', rack: 'R101', dc_suffix: '_1_cassandra', prefer_local: 'true' } end it do - should contain_file('/etc/cassandra/default.conf/cassandra-topology.properties') - .with_content(/^dc=NYC$/) - .with_content(/^rack=R101$/) - .with_content(/^dc_suffix=_1_cassandra$/) - .with_content(/^prefer_local=true$/) + is_expected.to contain_file('/etc/cassandra/default.conf/cassandra-topology.properties'). + with_content(%r{^dc=NYC$}). + with_content(%r{^rack=R101$}). + with_content(%r{^dc_suffix=_1_cassandra$}). + with_content(%r{^prefer_local=true$}) end end end diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index bcb8a42..e517302 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -1,161 +1,155 @@ require 'spec_helper' describe 'cassandra::java' do - let(:pre_condition) do - [ - 'class apt () {}', - 'class apt::update () {}', - 'define apt::key ($id, $server) {}', - 'define apt::source ($location, $comment, $release, $repos) {}' - ] - end - context 'On a RedHat OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } end it do - should contain_class('cassandra::java') - should contain_package('java-1.8.0-openjdk-headless') - should contain_package('jna') + is_expected.to contain_class('cassandra::java') + is_expected.to contain_package('java-1.8.0-openjdk-headless') + is_expected.to contain_package('jna') end end context 'On a Debian OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: 7, - osfamily: 'Debian' + operatingsystemmajrelease: '7', + osfamily: 'Debian', + lsbdistid: 'Debian' } end it do - should contain_class('cassandra::java') - should contain_package('openjdk-7-jre-headless') - should contain_package('libjna-java') - should have_resource_count(2) + is_expected.to contain_class('cassandra::java') + is_expected.to contain_package('openjdk-7-jre-headless') + is_expected.to contain_package('libjna-java') + is_expected.to have_resource_count(2) end end context 'On a Debian OS with package_ensure set' do let :facts do { - operatingsystemmajrelease: 7, - osfamily: 'Debian' + operatingsystemmajrelease: '7', + osfamily: 'Debian', + lsbdistid: 'Debian' } end let :params do { package_ensure: '2.1.13' } end it do - should contain_package('openjdk-7-jre-headless').with_ensure('2.1.13') + is_expected.to contain_package('openjdk-7-jre-headless').with_ensure('2.1.13') end end context 'With package names set to foobar' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } end let :params do { package_name: 'foobar-java', package_ensure: '42', jna_package_name: 'foobar-jna', jna_ensure: 'latest' } end it do - should contain_package('foobar-java').with(ensure: 42) - should contain_package('foobar-jna').with(ensure: 'latest') + is_expected.to contain_package('foobar-java').with(ensure: 42) + is_expected.to contain_package('foobar-jna').with(ensure: 'latest') end end context 'Ensure that a YUM repo can be specified.' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } end let :params do { yumrepo: { 'ACME' => { 'baseurl' => 'http://yum.acme.org/repos', 'descr' => 'YUM Repository for ACME Products' } } } end it do - should contain_yumrepo('ACME').with( + is_expected.to contain_yumrepo('ACME').with( baseurl: 'http://yum.acme.org/repos', descr: 'YUM Repository for ACME Products' ).that_comes_before('Package[java-1.8.0-openjdk-headless]') end end context 'Ensure that Apt key and source can be specified.' do let :facts do { - operatingsystemmajrelease: 7, - osfamily: 'Debian' + operatingsystemmajrelease: '7', + osfamily: 'Debian', + lsbdistid: 'Debian' } end let :params do { aptkey: { 'openjdk-r' => { 'id' => 'DA1A4A13543B466853BAF164EB9B1D8886F44E2A', 'server' => 'keyserver.ubuntu.com' } }, aptsource: { 'openjdk-r' => { 'comment' => 'OpenJDK builds (all archs)', 'location' => 'http://ppa.launchpad.net/openjdk-r/ppa/ubuntu', 'repos' => 'main', 'release' => 'trusty' } } } end it do - should contain_apt__key('openjdk-r') - .with( + is_expected.to contain_apt__key('openjdk-r'). + with( id: 'DA1A4A13543B466853BAF164EB9B1D8886F44E2A', server: 'keyserver.ubuntu.com' - ) - .that_comes_before('Package[openjdk-7-jre-headless]') - should contain_apt__source('openjdk-r') - .with( + ). + that_comes_before('Package[openjdk-7-jre-headless]') + is_expected.to contain_apt__source('openjdk-r'). + with( comment: 'OpenJDK builds (all archs)', location: 'http://ppa.launchpad.net/openjdk-r/ppa/ubuntu', repos: 'main', release: 'trusty' ) - should contain_exec('cassandra::java::apt_update') - .with( + is_expected.to contain_exec('cassandra::java::apt_update'). + with( refreshonly: true, command: '/bin/true' - ) - .that_comes_before('Package[openjdk-7-jre-headless]') + ). + that_comes_before('Package[openjdk-7-jre-headless]') end end end diff --git a/spec/classes/optutils_spec.rb b/spec/classes/optutils_spec.rb index c9efdc5..782b93f 100644 --- a/spec/classes/optutils_spec.rb +++ b/spec/classes/optutils_spec.rb @@ -1,75 +1,75 @@ require 'spec_helper' describe 'cassandra::optutils' do context 'On a RedHat OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'RedHat' } end it do - should have_resource_count(1) - should contain_package('cassandra22-tools').with(ensure: 'present') + is_expected.to have_resource_count(7) + is_expected.to contain_package('cassandra22-tools').with(ensure: 'present') - should contain_class('cassandra::optutils').with( + is_expected.to contain_class('cassandra::optutils').with( package_ensure: 'present', package_name: 'cassandra22-tools' ) end end context 'On a Debian OS with defaults for all parameters' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'Debian' } end it do - should contain_package('cassandra-tools').with(ensure: 'present') + is_expected.to contain_package('cassandra-tools').with(ensure: 'present') - should contain_class('cassandra::optutils').with( + is_expected.to contain_class('cassandra::optutils').with( package_ensure: 'present', package_name: 'cassandra-tools' ) end end context 'With package_name set to foobar' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'Debian' } end let :params do { package_name: 'foobar-java', package_ensure: '42' } end it do - should contain_package('foobar-java').with(ensure: 42) + is_expected.to contain_package('foobar-java').with(ensure: 42) end end context 'On a Debian OS with package_ensure set' do let :facts do { - operatingsystemmajrelease: 7, + operatingsystemmajrelease: '7', osfamily: 'Debian' } end let :params do { package_ensure: '2.1.13' } end - it { should contain_package('cassandra-tools').with_ensure('2.1.13') } + it { is_expected.to contain_package('cassandra-tools').with_ensure('2.1.13') } end end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb index 4a152d0..f641cda 100644 --- a/spec/classes/params_spec.rb +++ b/spec/classes/params_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' describe '::cassandra::params' do let :facts do { osfamily: 'RedHat', - operatingsystemmajrelease: 7 + operatingsystemmajrelease: '7' } end it do - should compile - should contain_class('cassandra::params') - should have_resource_count(0) + is_expected.to compile + is_expected.to contain_class('cassandra::params') + is_expected.to have_resource_count(0) end end diff --git a/spec/classes/schema_spec.rb b/spec/classes/schema_spec.rb index 9d8bbd4..d468623 100644 --- a/spec/classes/schema_spec.rb +++ b/spec/classes/schema_spec.rb @@ -1,142 +1,131 @@ require 'spec_helper' describe 'cassandra::schema' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Ensure that a connection test is made.' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end it do - should contain_class('cassandra::schema') - .with(connection_tries: 6, - connection_try_sleep: 30, - cqlsh_additional_options: '', - cqlsh_command: '/usr/bin/cqlsh', - cqlsh_host: 'localhost', - cqlsh_password: nil, - cqlsh_port: 9042, - cqlsh_user: 'cassandra') + is_expected.to contain_class('cassandra::schema'). + with(connection_tries: 6, + connection_try_sleep: 30, + cqlsh_additional_options: '', + cqlsh_command: '/usr/bin/cqlsh', + cqlsh_host: 'localhost', + cqlsh_password: nil, + cqlsh_port: 9042, + cqlsh_user: 'cassandra') read_command = '/usr/bin/cqlsh -e \'DESC KEYSPACES\' localhost 9042' - should contain_exec('::cassandra::schema connection test') - .only_with(command: read_command, - returns: 0, - tries: 6, - try_sleep: 30, - unless: read_command) + is_expected.to contain_exec('::cassandra::schema connection test'). + only_with(command: read_command, + returns: 0, + tries: 6, + try_sleep: 30, + unless: read_command) end end context 'Test that users can specify a credentials file.' do let :facts do { id: 'root', gid: 'root', operatingsystemmajrelease: 7, osfamily: 'Debian' } end let :params do { cqlsh_client_config: '/root/.puppetcqlshrc' } end it do - should contain_file('/root/.puppetcqlshrc').with( + is_expected.to contain_file('/root/.puppetcqlshrc').with( ensure: 'file', group: 'root', mode: '0600', owner: 'root', - content: /username = cassandra/ + content: %r{username = cassandra} ).that_comes_before('Exec[::cassandra::schema connection test]') read_command = "/usr/bin/cqlsh --cqlshrc=/root/.puppetcqlshrc -e 'DESC KEYSPACES' localhost 9042" - should contain_exec('::cassandra::schema connection test') - .only_with(command: read_command, - returns: 0, - tries: 6, - try_sleep: 30, - unless: read_command) + is_expected.to contain_exec('::cassandra::schema connection test'). + only_with(command: read_command, + returns: 0, + tries: 6, + try_sleep: 30, + unless: read_command) end end context 'Test that users can specify a credentials file and password.' do let :facts do { id: 'root', gid: 'root', operatingsystemmajrelease: 7, osfamily: 'Debian' } end let :params do { cqlsh_client_config: '/root/.puppetcqlshrc', cqlsh_password: 'topsecret' } end it do - should contain_file('/root/.puppetcqlshrc').with( + is_expected.to contain_file('/root/.puppetcqlshrc').with( ensure: 'file', group: 'root', mode: '0600', owner: 'root', - content: /password = topsecret/ + content: %r{password = topsecret} ) read_command = "/usr/bin/cqlsh --cqlshrc=/root/.puppetcqlshrc -e 'DESC KEYSPACES' localhost 9042" - should contain_exec('::cassandra::schema connection test') - .only_with(command: read_command, - returns: 0, - tries: 6, - try_sleep: 30, - unless: read_command) + is_expected.to contain_exec('::cassandra::schema connection test'). + only_with(command: read_command, + returns: 0, + tries: 6, + try_sleep: 30, + unless: read_command) end end context 'Test that users can specify a password.' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'Redhat' } end let :params do { cqlsh_password: 'topsecret' } end it do read_command = "/usr/bin/cqlsh -u cassandra -p topsecret -e 'DESC KEYSPACES' localhost 9042" - should contain_exec('::cassandra::schema connection test') - .only_with(command: read_command, - returns: 0, - tries: 6, - try_sleep: 30, - unless: read_command) + is_expected.to contain_exec('::cassandra::schema connection test'). + only_with(command: read_command, + returns: 0, + tries: 6, + try_sleep: 30, + unless: read_command) end end end diff --git a/spec/classes/system/swapoff_spec.rb b/spec/classes/system/swapoff_spec.rb index 5b95738..13dc298 100644 --- a/spec/classes/system/swapoff_spec.rb +++ b/spec/classes/system/swapoff_spec.rb @@ -1,30 +1,30 @@ require 'spec_helper' describe 'cassandra::system::swapoff' do context 'Test the default parameters' do it do - should have_resource_count(1) - should contain_class('cassandra::system::swapoff') - should contain_exec('Disable Swap') + is_expected.to have_resource_count(1) + is_expected.to contain_class('cassandra::system::swapoff') + is_expected.to contain_exec('Disable Swap') end end context 'Test we can remove a swap device from /etc/fstab' do let :params do { device: '/dev/mapper/centos-swap' } end it do - should have_resource_count(2) - should contain_class('cassandra::system::swapoff') - should contain_exec('Disable Swap') - should contain_mount('swap').with( + is_expected.to have_resource_count(2) + is_expected.to contain_class('cassandra::system::swapoff') + is_expected.to contain_exec('Disable Swap') + is_expected.to contain_mount('swap').with( ensure: 'absent', device: '/dev/mapper/centos-swap', fstype: 'swap' ) end end end diff --git a/spec/classes/system/sysctl_spec.rb b/spec/classes/system/sysctl_spec.rb index b5199a2..14516f9 100644 --- a/spec/classes/system/sysctl_spec.rb +++ b/spec/classes/system/sysctl_spec.rb @@ -1,39 +1,28 @@ require 'spec_helper' describe 'cassandra::system::sysctl' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', operatingsystemmajrelease: 7 } end it do - should have_resource_count(9) - should contain_class('Cassandra::System::Sysctl') - should contain_ini_setting('net.core.optmem_max = 40960') - should contain_ini_setting('net.core.rmem_default = 16777216') - should contain_ini_setting('net.core.rmem_max = 16777216') - should contain_ini_setting('net.core.wmem_default = 16777216') - should contain_ini_setting('net.core.wmem_max = 16777216') - should contain_ini_setting('net.ipv4.tcp_rmem = 4096, 87380, 16777216') - should contain_ini_setting('net.ipv4.tcp_wmem = 4096, 65536, 16777216') - should contain_ini_setting('vm.max_map_count = 1048575') - should contain_exec('Apply sysctl changes').with( + is_expected.to have_resource_count(9) + is_expected.to contain_class('Cassandra::System::Sysctl') + is_expected.to contain_ini_setting('net.core.optmem_max = 40960') + is_expected.to contain_ini_setting('net.core.rmem_default = 16777216') + is_expected.to contain_ini_setting('net.core.rmem_max = 16777216') + is_expected.to contain_ini_setting('net.core.wmem_default = 16777216') + is_expected.to contain_ini_setting('net.core.wmem_max = 16777216') + is_expected.to contain_ini_setting('net.ipv4.tcp_rmem = 4096, 87380, 16777216') + is_expected.to contain_ini_setting('net.ipv4.tcp_wmem = 4096, 65536, 16777216') + is_expected.to contain_ini_setting('vm.max_map_count = 1048575') + is_expected.to contain_exec('Apply sysctl changes').with( command: '/sbin/sysctl -p /etc/sysctl.d/10-cassandra.conf' ) end end end diff --git a/spec/classes/system/transparent_hugepage_spec.rb b/spec/classes/system/transparent_hugepage_spec.rb index b7df548..39ee3c1 100644 --- a/spec/classes/system/transparent_hugepage_spec.rb +++ b/spec/classes/system/transparent_hugepage_spec.rb @@ -1,33 +1,33 @@ require 'spec_helper' describe 'cassandra::system::transparent_hugepage' do context 'Test the default parameters (RedHat)' do let :facts do { osfamily: 'RedHat', operatingsystemmajrelease: 7 } end it do - should have_resource_count(1) - should contain_class('cassandra::system::transparent_hugepage') - should contain_exec('Disable Java Hugepages') + is_expected.to have_resource_count(1) + is_expected.to contain_class('cassandra::system::transparent_hugepage') + is_expected.to contain_exec('Disable Java Hugepages') end end context 'Test the default parameters (Debian)' do let :facts do { osfamily: 'Debian', operatingsystemmajrelease: 7 } end it do - should have_resource_count(1) - should contain_class('cassandra::system::transparent_hugepage') - should contain_exec('Disable Java Hugepages') + is_expected.to have_resource_count(1) + is_expected.to contain_class('cassandra::system::transparent_hugepage') + is_expected.to contain_exec('Disable Java Hugepages') end end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml new file mode 100644 index 0000000..13c4165 --- /dev/null +++ b/spec/default_facts.yml @@ -0,0 +1,14 @@ +# This file is managed via modulesync +# https://github.com/voxpupuli/modulesync +# https://github.com/voxpupuli/modulesync_config +# +# use default_module_facts.yaml for module specific +# facts. +# +# Hint if using with rspec-puppet-facts ("on_supported_os.each"): +# if a same named fact exists in facterdb it will be overridden. +--- +concat_basedir: "/tmp" +ipaddress: "172.16.254.254" +is_pe: false +macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/file_spec.rb b/spec/defines/file_spec.rb index c5d9342..9dab736 100644 --- a/spec/defines/file_spec.rb +++ b/spec/defines/file_spec.rb @@ -1,52 +1,39 @@ require 'spec_helper' describe '::cassandra::file' do - let(:pre_condition) do - [ - 'class stdlib () {}', - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}', - 'define file_line($line, $path, $match) {}' - ] - end - context 'On a Debian OS set the max and new heap size' do let :facts do { osfamily: 'Debian', operatingsystemmajrelease: 8 } end let(:title) { 'cassandra-env.sh' } let :params do { config_path: '/etc/cassandra', 'file_lines' => { 'MAX_HEAP_SIZE 4GB' => { 'line' => 'MAX_HEAP_SIZE="4G"', 'match' => '^#MAX_HEAP_SIZE="4G"$' } } } end it do - should contain_class('cassandra') - should contain_class('cassandra::params') - should contain_class('stdlib') - should contain_cassandra__file('cassandra-env.sh') + is_expected.to contain_class('cassandra') + is_expected.to contain_class('cassandra::params') + is_expected.to contain_class('stdlib') + is_expected.to contain_cassandra__file('cassandra-env.sh') - should contain_file_line('MAX_HEAP_SIZE 4GB').with( + is_expected.to contain_file_line('MAX_HEAP_SIZE 4GB').with( path: '/etc/cassandra/cassandra-env.sh', line: 'MAX_HEAP_SIZE="4G"', match: '^#MAX_HEAP_SIZE="4G"$' ) end end end diff --git a/spec/defines/private/firewall_ports/rule_spec.rb b/spec/defines/private/firewall_ports/rule_spec.rb index 8ebd1b0..a507c56 100644 --- a/spec/defines/private/firewall_ports/rule_spec.rb +++ b/spec/defines/private/firewall_ports/rule_spec.rb @@ -1,25 +1,21 @@ require 'spec_helper' describe 'cassandra::private::firewall_ports::rule' do - let(:pre_condition) do - ['define firewall ($action, $dport, $proto, $source) {}'] - end - context 'Test that rules can be set.' do let(:title) { '200_Public_0.0.0.0/0' } let :params do { ports: [8888, 22] } end it do - should contain_firewall('200 - Cassandra (Public) - 0.0.0.0/0').with( + is_expected.to contain_firewall('200 - Cassandra (Public) - 0.0.0.0/0').with( action: 'accept', dport: [8888, 22], proto: 'tcp', source: '0.0.0.0/0' ) - should have_resource_count(2) + is_expected.to have_resource_count(2) end end end diff --git a/spec/defines/schema/cql_type_spec.rb b/spec/defines/schema/cql_type_spec.rb index 33f679b..9e9b4ee 100644 --- a/spec/defines/schema/cql_type_spec.rb +++ b/spec/defines/schema/cql_type_spec.rb @@ -1,84 +1,73 @@ require 'spec_helper' describe 'cassandra::schema::cql_type' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'CQL TYPE (fullname)' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'fullname' } let(:params) do { 'keyspace' => 'Excelsior', fields: { 'firstname' => 'text', 'lastname' => 'text' } } end it do - should compile - should contain_class('cassandra::schema') - should contain_cassandra__schema__cql_type('fullname') - should contain_exec('/usr/bin/cqlsh -e "CREATE TYPE IF NOT EXISTS Excelsior.fullname (firstname text, lastname text)" localhost 9042') + is_expected.to compile + is_expected.to contain_class('cassandra::schema') + is_expected.to contain_cassandra__schema__cql_type('fullname') + is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE TYPE IF NOT EXISTS Excelsior.fullname (firstname text, lastname text)" localhost 9042') end end context 'Set ensure to absent' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'address' } let(:params) do { 'ensure' => 'absent', 'keyspace' => 'Excalibur' } end it do - should compile - should contain_cassandra__schema__cql_type('address') - should contain_exec('/usr/bin/cqlsh -e "DROP type Excalibur.address" localhost 9042') + is_expected.to compile + is_expected.to contain_cassandra__schema__cql_type('address') + is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP type Excalibur.address" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/index_spec.rb b/spec/defines/schema/index_spec.rb index 6aecb11..f45d716 100644 --- a/spec/defines/schema/index_spec.rb +++ b/spec/defines/schema/index_spec.rb @@ -1,132 +1,121 @@ require 'spec_helper' describe 'cassandra::schema::index' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Create a basic index' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'user_index' } let(:params) do { keys: 'lname', keyspace: 'mykeyspace', table: 'users' } end it do - should compile - should contain_cassandra__schema__index('user_index') - should contain_exec('/usr/bin/cqlsh -e "CREATE INDEX IF NOT EXISTS user_index ON mykeyspace.users (lname)" localhost 9042') + is_expected.to compile + is_expected.to contain_cassandra__schema__index('user_index') + is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE INDEX IF NOT EXISTS user_index ON mykeyspace.users (lname)" localhost 9042') end end context 'Create a custom index.' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'user_index' } let(:params) do { class_name: 'path.to.the.IndexClass', keys: 'email', keyspace: 'Excelsior', table: 'users' } end it do - should compile - should contain_exec('/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\'" localhost 9042') + is_expected.to compile + is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\'" localhost 9042') end end context 'Create a custom index with options.' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'user_index' } let(:params) do { class_name: 'path.to.the.IndexClass', keys: 'email', keyspace: 'Excelsior', options: "{'storage': '/mnt/ssd/indexes/'}", table: 'users' } end it do - should compile - should contain_exec('/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\' WITH OPTIONS = {\'storage\': \'/mnt/ssd/indexes/\'}" localhost 9042') + is_expected.to compile + is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE CUSTOM INDEX IF NOT EXISTS user_index ON Excelsior.users (email) USING \'path.to.the.IndexClass\' WITH OPTIONS = {\'storage\': \'/mnt/ssd/indexes/\'}" localhost 9042') end end context 'Drop Index' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'user_index' } let(:params) do { ensure: 'absent', keys: 'lname', keyspace: 'Excelsior', table: 'users' } end it do - should compile - should contain_exec('/usr/bin/cqlsh -e "DROP INDEX Excelsior.user_index" localhost 9042') + is_expected.to compile + is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP INDEX Excelsior.user_index" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/keyspace_spec.rb b/spec/defines/schema/keyspace_spec.rb index f1f6e09..25b9213 100644 --- a/spec/defines/schema/keyspace_spec.rb +++ b/spec/defines/schema/keyspace_spec.rb @@ -1,110 +1,99 @@ require 'spec_helper' describe 'cassandra::schema::keyspace' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Set ensure to present (SimpleStrategy)' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'SimpleStrategy', 'replication_factor' => 3 } } end it do - should compile - should contain_class('cassandra::schema') - should contain_exec('/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = { \'class\' : \'SimpleStrategy\', \'replication_factor\' : 3 } AND DURABLE_WRITES = true" localhost 9042') + is_expected.to compile + is_expected.to contain_class('cassandra::schema') + is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = { \'class\' : \'SimpleStrategy\', \'replication_factor\' : 3 } AND DURABLE_WRITES = true" localhost 9042') end end context 'Set ensure to present (NetworkTopologyStrategy)' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'present', replication_map: { 'keyspace_class' => 'NetworkTopologyStrategy', 'dc1' => '3', 'dc2' => '2' } } end it do - should contain_cassandra__schema__keyspace('foobar') - should contain_exec('/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = { \'class\' : \'NetworkTopologyStrategy\', \'dc1\': 3, \'dc2\': 2 } AND DURABLE_WRITES = true" localhost 9042') + is_expected.to contain_cassandra__schema__keyspace('foobar') + is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE KEYSPACE IF NOT EXISTS foobar WITH REPLICATION = { \'class\' : \'NetworkTopologyStrategy\', \'dc1\': 3, \'dc2\': 2 } AND DURABLE_WRITES = true" localhost 9042') end end context 'Set ensure to absent' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'absent' } end it do - should compile - should contain_exec('/usr/bin/cqlsh -e "DROP KEYSPACE foobar" localhost 9042') + is_expected.to compile + is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP KEYSPACE foobar" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/permission_spec.rb b/spec/defines/schema/permission_spec.rb index 341d024..7bd53c8 100644 --- a/spec/defines/schema/permission_spec.rb +++ b/spec/defines/schema/permission_spec.rb @@ -1,185 +1,174 @@ require 'spec_helper' describe 'cassandra::schema::permission' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { user_name: 'foobar' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end context 'spillman:SELECT:ALL' do let(:title) { 'spillman:SELECT:ALL' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { user_name: 'spillman', permission_name: 'SELECT' } end it do - should have_resource_count(9) - should contain_cassandra__schema__permission('spillman:SELECT:ALL') - should contain_exec('GRANT SELECT ON ALL KEYSPACES TO spillman') + is_expected.to have_resource_count(9) + is_expected.to contain_cassandra__schema__permission('spillman:SELECT:ALL') + is_expected.to contain_exec('GRANT SELECT ON ALL KEYSPACES TO spillman') end end context 'akers:modify:field' do let(:title) { 'akers:modify:field' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { user_name: 'akers', keyspace_name: 'field', permission_name: 'MODIFY' } end it do - should have_resource_count(9) - should contain_cassandra__schema__permission('akers:modify:field') - should contain_exec('GRANT MODIFY ON KEYSPACE field TO akers') + is_expected.to have_resource_count(9) + is_expected.to contain_cassandra__schema__permission('akers:modify:field') + is_expected.to contain_exec('GRANT MODIFY ON KEYSPACE field TO akers') end end context 'boone:alter:forty9ers' do let(:title) { 'boone:alter:forty9ers' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'ALTER' } end it do - should have_resource_count(9) - should contain_cassandra__schema__permission('boone:alter:forty9ers') - should contain_exec('GRANT ALTER ON KEYSPACE forty9ers TO boone') + is_expected.to have_resource_count(9) + is_expected.to contain_cassandra__schema__permission('boone:alter:forty9ers') + is_expected.to contain_exec('GRANT ALTER ON KEYSPACE forty9ers TO boone') end end context 'boone:ALL:ravens.plays' do let(:title) { 'boone:ALL:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { user_name: 'boone', keyspace_name: 'ravens', table_name: 'plays' } end it do - should have_resource_count(18) - should contain_cassandra__schema__permission('boone:ALL:ravens.plays') - should contain_cassandra__schema__permission('boone:ALL:ravens.plays - ALTER').with( + is_expected.to have_resource_count(18) + is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays') + is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - ALTER').with( ensure: 'present', user_name: 'boone', keyspace_name: 'ravens', permission_name: 'ALTER', table_name: 'plays' ) - should contain_cassandra__schema__permission('boone:ALL:ravens.plays - AUTHORIZE') - should contain_cassandra__schema__permission('boone:ALL:ravens.plays - DROP') - should contain_cassandra__schema__permission('boone:ALL:ravens.plays - MODIFY') - should contain_cassandra__schema__permission('boone:ALL:ravens.plays - SELECT') - should contain_exec('GRANT ALTER ON TABLE ravens.plays TO boone') - should contain_exec('GRANT AUTHORIZE ON TABLE ravens.plays TO boone') - should contain_exec('GRANT DROP ON TABLE ravens.plays TO boone') - should contain_exec('GRANT MODIFY ON TABLE ravens.plays TO boone') - should contain_exec('GRANT SELECT ON TABLE ravens.plays TO boone') + is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - AUTHORIZE') + is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - DROP') + is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - MODIFY') + is_expected.to contain_cassandra__schema__permission('boone:ALL:ravens.plays - SELECT') + is_expected.to contain_exec('GRANT ALTER ON TABLE ravens.plays TO boone') + is_expected.to contain_exec('GRANT AUTHORIZE ON TABLE ravens.plays TO boone') + is_expected.to contain_exec('GRANT DROP ON TABLE ravens.plays TO boone') + is_expected.to contain_exec('GRANT MODIFY ON TABLE ravens.plays TO boone') + is_expected.to contain_exec('GRANT SELECT ON TABLE ravens.plays TO boone') end end context 'REVOKE boone:SELECT:ravens.plays' do let(:title) { 'REVOKE boone:SELECT:ravens.plays' } let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:params) do { ensure: 'absent', user_name: 'boone', keyspace_name: 'forty9ers', permission_name: 'SELECT' } end it do - should have_resource_count(9) - should contain_cassandra__schema__permission('REVOKE boone:SELECT:ravens.plays') - should contain_exec('REVOKE SELECT ON KEYSPACE forty9ers FROM boone') + is_expected.to have_resource_count(9) + is_expected.to contain_cassandra__schema__permission('REVOKE boone:SELECT:ravens.plays') + is_expected.to contain_exec('REVOKE SELECT ON KEYSPACE forty9ers FROM boone') end end end diff --git a/spec/defines/schema/table_spec.rb b/spec/defines/schema/table_spec.rb index c45403b..73d15da 100644 --- a/spec/defines/schema/table_spec.rb +++ b/spec/defines/schema/table_spec.rb @@ -1,93 +1,82 @@ require 'spec_helper' describe 'cassandra::schema::table' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Create Table' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'users' } let(:params) do { keyspace: 'Excelsior', columns: { 'userid' => 'text', 'username' => 'FROZEN', 'emails' => 'set', 'top_scores' => 'list', 'todo' => 'map', 'COLLECTION-TYPE' => 'tuple', 'PRIMARY KEY' => '(userid)' }, options: [ 'COMPACT STORAGE', 'ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'' ] } end it do - should compile - should contain_cassandra__schema__table('users') - should contain_exec('/usr/bin/cqlsh -e "CREATE TABLE IF NOT EXISTS Excelsior.users (userid text, username FROZEN, emails set, top_scores list, todo map, tuple, PRIMARY KEY (userid)) WITH COMPACT STORAGE AND ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'" localhost 9042') + is_expected.to compile + is_expected.to contain_cassandra__schema__table('users') + is_expected.to contain_exec('/usr/bin/cqlsh -e "CREATE TABLE IF NOT EXISTS Excelsior.users (userid text, username FROZEN, emails set, top_scores list, todo map, tuple, PRIMARY KEY (userid)) WITH COMPACT STORAGE AND ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'" localhost 9042') end end context 'Drop Table' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'users' } let(:params) do { keyspace: 'Excelsior', ensure: 'absent' } end it do - should compile - should contain_exec('/usr/bin/cqlsh -e "DROP TABLE IF EXISTS Excelsior.users" localhost 9042') + is_expected.to compile + is_expected.to contain_exec('/usr/bin/cqlsh -e "DROP TABLE IF EXISTS Excelsior.users" localhost 9042') end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/defines/schema/user_spec.rb b/spec/defines/schema/user_spec.rb index e50fbe0..9c7af1b 100644 --- a/spec/defines/schema/user_spec.rb +++ b/spec/defines/schema/user_spec.rb @@ -1,211 +1,200 @@ require 'spec_helper' describe 'cassandra::schema::user' do - let(:pre_condition) do - [ - 'define ini_setting($ensure = nil, - $path, - $section, - $key_val_separator = nil, - $setting, - $value = nil) {}' - ] - end - context 'Create a supper user on cassandrarelease undef' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: nil } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', superuser: true } end it do - should contain_cassandra__schema__user('akers').with_ensure('present') - should contain_exec('Create user (akers)').with( + is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') + is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers WITH PASSWORD \'Niner2\' SUPERUSER" localhost 9042' ) end end context 'Create a supper user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '2.0.1' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', superuser: true } end it do - should contain_cassandra__schema__user('akers').with_ensure('present') - should contain_exec('Create user (akers)').with( + is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') + is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers WITH PASSWORD \'Niner2\' SUPERUSER" localhost 9042' ) end end context 'Create a user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '2.0.1' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2' } end it do - should contain_cassandra__schema__user('akers').with_ensure('present') - should contain_exec('Create user (akers)').with( + is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') + is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE USER IF NOT EXISTS akers WITH PASSWORD \'Niner2\' NOSUPERUSER" localhost 9042' ) end end context 'Create a supper user with login in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '3.0.9' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', superuser: true } end it do - should contain_cassandra__schema__user('akers').with_ensure('present') - should contain_exec('Create user (akers)').with( + is_expected.to contain_cassandra__schema__user('akers').with_ensure('present') + is_expected.to contain_exec('Create user (akers)').with( command: '/usr/bin/cqlsh -e "CREATE ROLE IF NOT EXISTS akers WITH PASSWORD = \'Niner2\' AND SUPERUSER = true AND LOGIN = true" localhost 9042' ) end end context 'Create a user without login in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '3.0.9' } end let(:title) { 'bob' } let(:params) do { password: 'kaZe89a', login: false } end it do - should contain_cassandra__schema__user('bob').with_ensure('present') - should contain_exec('Create user (bob)').with( + is_expected.to contain_cassandra__schema__user('bob').with_ensure('present') + is_expected.to contain_exec('Create user (bob)').with( command: '/usr/bin/cqlsh -e "CREATE ROLE IF NOT EXISTS bob WITH PASSWORD = \'kaZe89a\'" localhost 9042' ) end end context 'Drop a user in cassandrarelease > 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '3.0.9' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', ensure: 'absent' } end it do - should contain_exec('Delete user (akers)').with( + is_expected.to contain_exec('Delete user (akers)').with( command: '/usr/bin/cqlsh -e "DROP ROLE akers" localhost 9042' ) end end context 'Drop a user in cassandrarelease < 2.2' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat', cassandrarelease: '2.0.2' } end let(:title) { 'akers' } let(:params) do { password: 'Niner2', ensure: 'absent' } end it do - should contain_exec('Delete user (akers)').with( + is_expected.to contain_exec('Delete user (akers)').with( command: '/usr/bin/cqlsh -e "DROP USER akers" localhost 9042' ) end end context 'Set ensure to latest' do let :facts do { operatingsystemmajrelease: 7, osfamily: 'RedHat' } end let(:title) { 'foobar' } let(:params) do { ensure: 'latest' } end - it { should raise_error(Puppet::Error) } + it { is_expected.to raise_error(Puppet::Error) } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 674fe08..cdd4935 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,160 +1,31 @@ -require 'rubygems' -require 'rspec-puppet' -require 'rspec-puppet-utils' require 'puppetlabs_spec_helper/module_spec_helper' -require 'simplecov' -require 'coveralls' unless ENV['TRAVIS'] == 'true' - -Coveralls.wear! unless ENV['TRAVIS'] == 'true' -fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) - -RSpec.configure do |config| - config.module_path = File.join(fixture_path, 'modules') - config.manifest_dir = File.join(fixture_path, 'manifests') - config.tty = true - config.mock_with :rspec - config.raise_errors_for_deprecations! - - config.before(:each) do - MockFunction.new('concat') do |f| - f.stubbed.returns([8888, 22]) - f.stubbed.with([], '/etc/cassandra') - .returns(['/etc/cassandra']) - f.stubbed.with([], '/etc/cassandra/default.conf') - .returns(['/etc/cassandra/default.conf']) - f.stubbed.with(['/etc/cassandra'], '/etc/cassandra/default.conf') - .returns(['/etc/cassandra', '/etc/cassandra/default.conf']) - end - - MockFunction.new('count') do |f| - f.stubbed.with( - [ - 'COMPACT STORAGE', - 'ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'' - ] - ).returns(2) - end - - MockFunction.new('create_ini_settings', type: :statement) do |f| - end - - MockFunction.new('delete') do |f| - f.stubbed.with( - { - 'keyspace_class' => 'NetworkTopologyStrategy', - 'dc1' => '3', - 'dc2' => '2' - }, - 'keyspace_class' - ).returns('dc1' => '3', 'dc2' => '2') - f.stubbed.with('userid text, username FROZEN, emails set, top_scores list, todo map, COLLECTION-TYPE tuple, PRIMARY KEY (userid)', 'COLLECTION-TYPE ').returns('userid text, username FROZEN, emails set, top_scores list, todo map, tuple, PRIMARY KEY (userid)') - end - - MockFunction.new('is_array') do |f| - f.stubbed.with('').returns(false) - f.stubbed.with(['/var/lib/cassandra/data']).returns(true) - end - - MockFunction.new('is_hash') do |f| - f.stubbed.with('').returns(false) - end - - MockFunction.new('join') do |f| - f.stubbed.with(['firstname text', 'lastname text'], ', ') - .returns('firstname text, lastname text') - f.stubbed.with( - { - '\'dc1\': ' => '3', - '\'dc2\': ' => '2' - }, - ', ' - ).returns('\'dc1\': 3, \'dc2\': 2') - f.stubbed.with( - [ - 'COMPACT STORAGE', 'ID=\'5a1c395e-b41f-11e5-9f22-ba0be0483c18\'' - ], ' AND ' - ).returns("COMPACT STORAGE AND ID='5a1c395e-b41f-11e5-9f22-ba0be0483c18'") - f.stubbed.with( - [ - 'userid text', 'username FROZEN', 'emails set', - 'top_scores list', 'todo map', - 'COLLECTION-TYPE tuple', 'PRIMARY KEY (userid)' - ], ', ' - ).returns('userid text, username FROZEN, emails set, top_scores list, todo map, COLLECTION-TYPE tuple, PRIMARY KEY (userid)') - end - - MockFunction.new('join_keys_to_values') do |f| - f.stubbed.with({ 'firstname' => 'text', 'lastname' => 'text' }, ' ') - .returns(['firstname text', 'lastname text']) - f.stubbed.with( - { - '\'dc1' => '3', - '\'dc2' => '2' - }, - '\': ' - ).returns('\'dc1\': ' => '3', '\'dc2\': ' => '2') - f.stubbed.with( - { - 'userid' => 'text', 'username' => 'FROZEN', - 'emails' => 'set', 'top_scores' => 'list', - 'todo' => 'map', - 'COLLECTION-TYPE' => 'tuple', - 'PRIMARY KEY' => '(userid)' - }, ' ' - ).returns( - [ - 'userid text', 'username FROZEN', 'emails set', - 'top_scores list', 'todo map', - 'COLLECTION-TYPE tuple', 'PRIMARY KEY (userid)' - ] - ) - end - - MockFunction.new('merge') do |f| - end - - MockFunction.new('prefix') do |f| - f.stubbed.with(['0.0.0.0/0'], - '200_Public_').returns('200_Public_0.0.0.0/0') - f.stubbed.with(['0.0.0.0/0'], - '210_InterNode_').returns('210_InterNode__0.0.0.0/0') - f.stubbed.with(['0.0.0.0/0'], - '220_Client_').returns('220_Client__0.0.0.0/0') - f.stubbed.with( - { - 'dc1' => '3', - 'dc2' => '2' - }, '\'' - ).returns('\'dc1' => '3', '\'dc2' => '2') - end - - MockFunction.new('upcase') do |f| - f.stubbed.with('ALL').returns('ALL') - f.stubbed.with('ALTER').returns('ALTER') - f.stubbed.with('AUTHORIZE').returns('AUTHORIZE') - f.stubbed.with('CREATE').returns('CREATE') - f.stubbed.with('DROP').returns('DROP') - f.stubbed.with('MODIFY').returns('MODIFY') - f.stubbed.with('SELECT').returns('SELECT') - f.stubbed.with('field').returns('FIELD') - f.stubbed.with('forty9ers').returns('FORTY9ERS') - f.stubbed.with('ravens').returns('ravens') - end - - MockFunction.new('size') do |f| - f.stubbed.returns(42) - end - - MockFunction.new('strftime') do |f| - f.stubbed.with('/var/lib/cassandra-%F') - .returns('/var/lib/cassandra-YYYY-MM-DD') - end - - MockFunction.new('validate_hash', type: :statement) do |f| - end +require 'rspec-puppet-facts' +include RspecPuppetFacts + +if Dir.exist?(File.expand_path('../../lib', __FILE__)) + require 'coveralls' + require 'simplecov' + require 'simplecov-console' + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console + ] + SimpleCov.start do + track_files 'lib/**/*.rb' + add_filter '/spec' + add_filter '/vendor' + add_filter '/.vendor' end +end - config.after(:suite) do - exit(1) if RSpec::Puppet::Coverage.report!(100) - 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 diff --git a/spec/unit/facter/cassandracmsheapnewsize_spec.rb b/spec/unit/facter/cassandracmsheapnewsize_spec.rb index a77b58b..36f8b2a 100644 --- a/spec/unit/facter/cassandracmsheapnewsize_spec.rb +++ b/spec/unit/facter/cassandracmsheapnewsize_spec.rb @@ -1,115 +1,48 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end - - describe 'cassandrarelease DSE' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') - expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) - end - end - - describe 'cassandrarelease DDC' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') - expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) - end - end - - describe 'Cassandra not installed or not running' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) - end - end +describe 'cassandracmsheapnewsize' do + before { Facter.clear } + after { Facter.clear } describe 'Heap settings' do - context 'Rasberry Pi 3' do - before :each do + describe 'Rasberry Pi 3' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('1024') Facter.fact(:processorcount).stubs(:value).returns('4') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eq(512) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(512) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(128) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(128) + expect(Facter.fact(:cassandracmsheapnewsize).value).to be(128) end end - context 'm4.large' do - before :each do + describe 'm4.large' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('8191.9') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandracmsheapnewsize).value).to be(200) end end - context 'm4.xlarge' do - before :each do + describe 'm4.xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('16384') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandracmsheapnewsize).value).to be(200) end end - context 'c4.2xlarge' do - before :each do + describe 'c4.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('15360') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandracmsheapnewsize).value).to be(800) end end - context 'i2.2xlarge' do - before :each do + describe 'i2.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('62464') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(8192) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(14_336) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandracmsheapnewsize).value).to be(800) end end end end diff --git a/spec/unit/facter/cassandracmsmaxheapsize_spec.rb b/spec/unit/facter/cassandracmsmaxheapsize_spec.rb index a77b58b..489e9f8 100644 --- a/spec/unit/facter/cassandracmsmaxheapsize_spec.rb +++ b/spec/unit/facter/cassandracmsmaxheapsize_spec.rb @@ -1,115 +1,48 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end - - describe 'cassandrarelease DSE' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') - expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) - end - end - - describe 'cassandrarelease DDC' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') - expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) - end - end - - describe 'Cassandra not installed or not running' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) - end - end +describe 'cassandracmsmaxheapsize' do + before { Facter.clear } + after { Facter.clear } describe 'Heap settings' do - context 'Rasberry Pi 3' do - before :each do + describe 'Rasberry Pi 3' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('1024') Facter.fact(:processorcount).stubs(:value).returns('4') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eq(512) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(512) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(128) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(128) + expect(Facter.fact(:cassandracmsmaxheapsize).value).to be(512) end end - context 'm4.large' do - before :each do + describe 'm4.large' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('8191.9') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandracmsmaxheapsize).value).to be(2048) end end - context 'm4.xlarge' do - before :each do + describe 'm4.xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('16384') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandracmsmaxheapsize).value).to be(4096) end end - context 'c4.2xlarge' do - before :each do + describe 'c4.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('15360') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandracmsmaxheapsize).value).to be(3840) end end - context 'i2.2xlarge' do - before :each do + describe 'i2.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('62464') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(8192) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(14_336) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandracmsmaxheapsize).value).to be(14_336) end end end end diff --git a/spec/unit/facter/cassandraheapnewsize_spec.rb b/spec/unit/facter/cassandraheapnewsize_spec.rb index a77b58b..04af018 100644 --- a/spec/unit/facter/cassandraheapnewsize_spec.rb +++ b/spec/unit/facter/cassandraheapnewsize_spec.rb @@ -1,115 +1,48 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end - - describe 'cassandrarelease DSE' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') - expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) - end - end - - describe 'cassandrarelease DDC' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') - expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) - end - end - - describe 'Cassandra not installed or not running' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) - end - end +describe 'cassandraheapnewsize' do + before { Facter.clear } + after { Facter.clear } describe 'Heap settings' do - context 'Rasberry Pi 3' do - before :each do + describe 'Rasberry Pi 3' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('1024') Facter.fact(:processorcount).stubs(:value).returns('4') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eq(512) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(512) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(128) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(128) + expect(Facter.fact(:cassandraheapnewsize).value).to be(128) end end - context 'm4.large' do - before :each do + describe 'm4.large' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('8191.9') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandraheapnewsize).value).to be(200) end end - context 'm4.xlarge' do - before :each do + describe 'm4.xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('16384') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandraheapnewsize).value).to be(200) end end - context 'c4.2xlarge' do - before :each do + describe 'c4.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('15360') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandraheapnewsize).value).to be(800) end end - context 'i2.2xlarge' do - before :each do + describe 'i2.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('62464') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(8192) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(14_336) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandraheapnewsize).value).to be(800) end end end end diff --git a/spec/unit/facter/cassandramajorversion_spec.rb b/spec/unit/facter/cassandramajorversion_spec.rb index 8e07b9b..151c520 100644 --- a/spec/unit/facter/cassandramajorversion_spec.rb +++ b/spec/unit/facter/cassandramajorversion_spec.rb @@ -1,43 +1,27 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end +describe 'cassandramajorversion' do + before { Facter.clear } + after { Facter.clear } describe 'cassandrarelease DSE' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') - expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('2.1.11.969') + expect(Facter.fact(:cassandramajorversion).value).to be(2) end end describe 'cassandrarelease DDC' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') - expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('3.0.1') + expect(Facter.fact(:cassandramajorversion).value).to be(3) end end describe 'Cassandra not installed or not running' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('') + expect(Facter.fact(:cassandramajorversion).value).to be(nil) end end end diff --git a/spec/unit/facter/cassandramaxheapsize_spec.rb b/spec/unit/facter/cassandramaxheapsize_spec.rb index a77b58b..135afb1 100644 --- a/spec/unit/facter/cassandramaxheapsize_spec.rb +++ b/spec/unit/facter/cassandramaxheapsize_spec.rb @@ -1,115 +1,48 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end - - describe 'cassandrarelease DSE' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') - expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) - end - end - - describe 'cassandrarelease DDC' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') - expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) - end - end - - describe 'Cassandra not installed or not running' do - it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) - end - end +describe ':cassandramaxheapsize' do + before { Facter.clear } + after { Facter.clear } describe 'Heap settings' do - context 'Rasberry Pi 3' do - before :each do + describe 'Rasberry Pi 3' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('1024') Facter.fact(:processorcount).stubs(:value).returns('4') - end - - it do expect(Facter.fact(:cassandramaxheapsize).value).to eq(512) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(512) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(128) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(128) end end - context 'm4.large' do - before :each do + describe 'm4.large' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('8191.9') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(2048) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandramaxheapsize).value).to be(2048) end end - context 'm4.xlarge' do - before :each do + describe 'm4.xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('16384') Facter.fact(:processorcount).stubs(:value).returns('2') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(4096) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(200) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(200) + expect(Facter.fact(:cassandramaxheapsize).value).to be(4096) end end - context 'c4.2xlarge' do - before :each do + describe 'c4.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('15360') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(3840) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandramaxheapsize).value).to be(3840) end end - context 'i2.2xlarge' do - before :each do + describe 'i2.2xlarge' do + it do Facter.fact(:memorysize_mb).stubs(:value).returns('62464') Facter.fact(:processorcount).stubs(:value).returns('8') - end - - it do - expect(Facter.fact(:cassandramaxheapsize).value).to eql(8192) - expect(Facter.fact(:cassandracmsmaxheapsize).value).to eql(14_336) - expect(Facter.fact(:cassandraheapnewsize).value).to eql(800) - expect(Facter.fact(:cassandracmsheapnewsize).value).to eql(800) + expect(Facter.fact(:cassandramaxheapsize).value).to be(8192) end end end end diff --git a/spec/unit/facter/cassandraminorversion_spec.rb b/spec/unit/facter/cassandraminorversion_spec.rb index 8e07b9b..575c184 100644 --- a/spec/unit/facter/cassandraminorversion_spec.rb +++ b/spec/unit/facter/cassandraminorversion_spec.rb @@ -1,43 +1,27 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end +describe 'cassandraminorversion' do + before { Facter.clear } + after { Facter.clear } describe 'cassandrarelease DSE' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') - expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('2.1.11.969') + expect(Facter.fact(:cassandraminorversion).value).to be(1) end end describe 'cassandrarelease DDC' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') - expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('3.0.1') + expect(Facter.fact(:cassandraminorversion).value).to be(0) end end describe 'Cassandra not installed or not running' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('') + expect(Facter.fact(:cassandraminorversion).value).to be(nil) end end end diff --git a/spec/unit/facter/cassandrapatchversion_spec.rb b/spec/unit/facter/cassandrapatchversion_spec.rb index 8e07b9b..c85aaf8 100644 --- a/spec/unit/facter/cassandrapatchversion_spec.rb +++ b/spec/unit/facter/cassandrapatchversion_spec.rb @@ -1,43 +1,27 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end +describe 'cassandrapatchversion' do + before { Facter.clear } + after { Facter.clear } describe 'cassandrarelease DSE' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') - expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('2.1.11.969') + expect(Facter.fact(:cassandrapatchversion).value).to be(11) end end describe 'cassandrarelease DDC' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') - expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('3.0.1') + expect(Facter.fact(:cassandrapatchversion).value).to be(1) end end describe 'Cassandra not installed or not running' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('') + expect(Facter.fact(:cassandrapatchversion).value).to be(nil) end end end diff --git a/spec/unit/facter/cassandrarelease_spec.rb b/spec/unit/facter/cassandrarelease_spec.rb index 8e07b9b..98b1830 100644 --- a/spec/unit/facter/cassandrarelease_spec.rb +++ b/spec/unit/facter/cassandrarelease_spec.rb @@ -1,43 +1,27 @@ require 'spec_helper' -describe 'Facter::Util::Fact' do - before do - Facter.clear - end +describe 'cassandrarelease' do + before { Facter.clear } + after { Facter.clear } describe 'cassandrarelease DSE' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('2.1.11.969') + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('2.1.11.969') expect(Facter.fact(:cassandrarelease).value).to eql('2.1.11') - expect(Facter.fact(:cassandramajorversion).value).to eql(2) - expect(Facter.fact(:cassandraminorversion).value).to eql(1) - expect(Facter.fact(:cassandrapatchversion).value).to eql(11) end end describe 'cassandrarelease DDC' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('3.0.1') + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('3.0.1') expect(Facter.fact(:cassandrarelease).value).to eql('3.0.1') - expect(Facter.fact(:cassandramajorversion).value).to eql(3) - expect(Facter.fact(:cassandraminorversion).value).to eql(0) - expect(Facter.fact(:cassandrapatchversion).value).to eql(1) end end describe 'Cassandra not installed or not running' do it do - allow(Facter::Util::Resolution) - .to receive(:exec).with('nodetool version') - .and_return('') - expect(Facter.fact(:cassandrarelease).value).to eql(nil) - expect(Facter.fact(:cassandramajorversion).value).to eql(nil) - expect(Facter.fact(:cassandraminorversion).value).to eql(nil) - expect(Facter.fact(:cassandrapatchversion).value).to eql(nil) + Facter::Util::Resolution.stubs(:exec).with('nodetool version').returns('') + expect(Facter.fact(:cassandrarelease).value).to be(nil) end end end