diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2240a97..f1f88cc 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,281 +1,282 @@ # Contribution guidelines ## Table of contents * [Contributing](#contributing) * [Writing proper commits - short version](#writing-proper-commits-short-version) * [Writing proper commits - long version](#writing-proper-commits-long-version) * [Dependencies](#dependencies) * [Note for OS X users](#note-for-os-x-users) * [The test matrix](#the-test-matrix) * [Syntax and style](#syntax-and-style) * [Running the unit tests](#running-the-unit-tests) * [Unit tests in docker](#unit-tests-in-docker) * [Integration tests](#integration-tests) This module has grown over time based on a range of contributions from people using it. If you follow these contributing guidelines your patch will likely make it into a release a little more quickly. ## Contributing Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. [Contributor Code of Conduct](https://voxpupuli.org/coc/). * Fork the repo. * Create a separate branch for your change. * We only take pull requests with passing tests, and documentation. [travis-ci](http://travis-ci.org) runs the tests for us. You can also execute them locally. This is explained [in a later section](#the-test-matrix). * Checkout [our docs](https://voxpupuli.org/docs/reviewing_pr/) we use to review a module and the [official styleguide](https://puppet.com/docs/puppet/6.0/style_guide.html). They provide some guidance for new code that might help you before you submit a pull request. * Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, please add a test. * Squash your commits down into logical components. Make sure to rebase against our current master. * Push the branch to your fork and submit a pull request. Please be prepared to repeat some of these steps as our contributors review your code. +Also consider sending in your profile code that calls this component module as an acceptance test or provide it via an issue. This helps reviewers a lot to test your use case and prevents future regressions! + ## Writing proper commits - short version * Make commits of logical units. * Check for unnecessary whitespace with "git diff --check" before committing. * Commit using Unix line endings (check the settings around "crlf" in git-config(1)). * Do not check in commented out code or unneeded files. * The first line of the commit message should be a short description (50 characters is the soft limit, excluding ticket number(s)), and should skip the full stop. * Associate the issue in the message. The first line should include the issue number in the form "(#XXXX) Rest of message". * The body should provide a meaningful commit message, which: *uses the imperative, present tense: `change`, not `changed` or `changes`. * includes motivation for the change, and contrasts its implementation with the previous behavior. * Make sure that you have tests for the bug you are fixing, or feature you are adding. * Make sure the test suites passes after your commit: * When introducing a new feature, make sure it is properly documented in the README.md ## Writing proper commits - long version 1. Make separate commits for logically separate changes. Please break your commits down into logically consistent units which include new or changed tests relevant to the rest of the change. The goal of doing this is to make the diff easier to read for whoever is reviewing your code. In general, the easier your diff is to read, the more likely someone will be happy to review it and get it into the code base. If you are going to refactor a piece of code, please do so as a separate commit from your feature or bug fix changes. We also really appreciate changes that include tests to make sure the bug is not re-introduced, and that the feature is not accidentally broken. Describe the technical detail of the change(s). If your description starts to get too long, that is a good sign that you probably need to split up your commit into more finely grained pieces. Commits which plainly describe the things which help reviewers check the patch and future developers understand the code are much more likely to be merged in with a minimum of bike-shedding or requested changes. Ideally, the commit message would include information, and be in a form suitable for inclusion in the release notes for the version of Puppet that includes them. Please also check that you are not introducing any trailing whitespace or other "whitespace errors". You can do this by running "git diff --check" on your changes before you commit. 2. Sending your patches To submit your changes via a GitHub pull request, we _highly_ recommend that you have them on a topic branch, instead of directly on `master`. It makes things much easier to keep track of, especially if you decide to work on another thing before your first change is merged in. GitHub has some pretty good [general documentation](http://help.github.com/) on using their site. They also have documentation on [creating pull requests](http://help.github.com/send-pull-requests/). In general, after pushing your topic branch up to your repository on GitHub, you can switch to the branch in the GitHub UI and click "Pull Request" towards the top of the page in order to open a pull request. 3. Update the related GitHub issue. If there is a GitHub issue associated with the change you submitted, then you should update the ticket to include the location of your branch, along with any other commentary you may wish to make. ## Dependencies The testing and development tools have a bunch of dependencies, all managed by [bundler](http://bundler.io/) according to the [Puppet support matrix](http://docs.puppetlabs.com/guides/platforms.html#ruby-versions). By default the tests use a baseline version of Puppet. If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: ```sh export PUPPET_VERSION="~> 5.5.6" ``` You can install all needed gems for spec tests into the modules directory by running: ```sh bundle install --path .vendor/ --without development system_tests release --jobs "$(nproc)" ``` If you also want to run acceptance tests: ```sh bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)" ``` Our all in one solution if you don't know if you need to install or update gems: ```sh bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)"; bundle update; bundle clean ``` As an alternative to the `--jobs "$(nproc)` parameter, you can set an environment variable: ```sh BUNDLE_JOBS="$(nproc)" ``` ### Note for OS X users `nproc` isn't a valid command under OS x. As an alternative, you can do: ```sh --jobs "$(sysctl -n hw.ncpu)" ``` ## The test matrix ### Syntax and style The test suite will run [Puppet Lint](http://puppet-lint.com/) and [Puppet Syntax](https://github.com/gds-operations/puppet-syntax) to check various syntax and style things. You can run these locally with: ```sh bundle exec rake lint bundle exec rake validate ``` It will also run some [Rubocop](http://batsov.com/rubocop/) tests against it. You can run those locally ahead of time with: ```sh bundle exec rake rubocop ``` ### Running the unit tests The unit test suite covers most of the code, as mentioned above please add tests if you're adding new functionality. If you've not used [rspec-puppet](http://rspec-puppet.com/) before then feel free to ask about how best to test your new feature. To run the linter, the syntax checker and the unit tests: ```sh bundle exec rake test ``` To run your all the unit tests ```sh bundle exec rake spec ``` To run a specific spec test set the `SPEC` variable: ```sh bundle exec rake spec SPEC=spec/foo_spec.rb ``` #### Unit tests in docker Some people don't want to run the dependencies locally or don't want to install ruby. We ship a Dockerfile that enables you to run all unit tests and linting. You only need to run: ```sh docker build . ``` Please ensure that a docker daemon is running and that your user has the permission to talk to it. You can specify a remote docker host by setting the `DOCKER_HOST` environment variable. it will copy the content of the module into the docker image. So it will not work if a Gemfile.lock exists. ### Integration tests The unit tests just check the code runs, not that it does exactly what we want on a real machine. For that we're using [beaker](https://github.com/puppetlabs/beaker). This fires up a new virtual machine (using vagrant) and runs a series of simple tests against it after applying the module. You can run this with: ```sh -bundle exec rake acceptance +bundle exec rake beaker ``` This will run the tests on the module's default nodeset. You can override the nodeset used, e.g., ```sh -BEAKER_set=centos-7-x64 bundle exec rake acceptance +BEAKER_set=centos-7-x64 bundle exec rake beaker ``` There are default rake tasks for the various acceptance test modules, e.g., ```sh bundle exec rake beaker:centos-7-x64 bundle exec rake beaker:ssh:centos-7-x64 ``` If you don't want to have to recreate the virtual machine every time you can use `BEAKER_destroy=no` and `BEAKER_provision=no`. On the first run you will at least need `BEAKER_provision` set to yes (the default). The Vagrantfile for the created virtual machines will be in `.vagrant/beaker_vagrant_files`. Beaker also supports docker containers. We also use that in our automated CI pipeline at [travis-ci](http://travis-ci.org). To use that instead of Vagrant: ```sh PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian10-64{hypervisor=docker} BEAKER_destroy=yes bundle exec rake beaker ``` You can replace the string `debian10` with any common operating system. The following strings are known to work: * ubuntu1604 * ubuntu1804 -* debian8 +* ubuntu2004 * debian9 * debian10 -* centos6 * centos7 * centos8 The easiest way to debug in a docker container is to open a shell: ```sh docker exec -it -u root ${container_id_or_name} bash ``` The source of this file is in our [modulesync_config](https://github.com/voxpupuli/modulesync_config/blob/master/moduleroot/.github/CONTRIBUTING.md.erb) repository. diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..cacadf2 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Vox Pupuli Security Policy + +Our vulnerabilities reporting process is at https://voxpupuli.org/security/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b4f47e8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +name: CI + +on: pull_request + +jobs: + setup_matrix: + name: 'Setup Test Matrix' + runs-on: ubuntu-latest + outputs: + beaker_setfiles: ${{ steps.get-outputs.outputs.beaker_setfiles }} + puppet_major_versions: ${{ steps.get-outputs.outputs.puppet_major_versions }} + puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} + env: + BUNDLE_WITHOUT: development:test:release + steps: + - uses: actions/checkout@v2 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + - name: Run rake validate + run: bundle exec rake validate + - name: Setup Test Matrix + id: get-outputs + run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false + + unit: + needs: setup_matrix + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: ${{fromJson(needs.setup_matrix.outputs.puppet_unit_test_matrix)}} + env: + BUNDLE_WITHOUT: development:system_tests:release + PUPPET_VERSION: "~> ${{ matrix.puppet }}.0" + name: Puppet ${{ matrix.puppet }} (Ruby ${{ matrix.ruby }}) + steps: + - uses: actions/checkout@v2 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run tests + run: bundle exec rake + + acceptance: + needs: setup_matrix + runs-on: ubuntu-latest + env: + BUNDLE_WITHOUT: development:test:release + strategy: + fail-fast: false + matrix: + setfile: ${{fromJson(needs.setup_matrix.outputs.beaker_setfiles)}} + puppet: ${{fromJson(needs.setup_matrix.outputs.puppet_major_versions)}} + name: ${{ matrix.puppet.name }} - ${{ matrix.setfile.name }} + steps: + - name: Enable IPv6 on docker + run: | + echo '{"ipv6":true,"fixed-cidr-v6":"2001:db8:1::/64"}' | sudo tee /etc/docker/daemon.json + sudo service docker restart + - uses: actions/checkout@v2 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + - name: Run tests + run: bundle exec rake beaker + env: + BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet.collection }} + BEAKER_setfile: ${{ matrix.setfile.value }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..68b8528 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release + +on: + push: + tags: + - '*' + +env: + BUNDLE_WITHOUT: development:test:system_tests + +jobs: + deploy: + name: 'deploy to forge' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + bundler-cache: true + - name: Build and Deploy + env: + # Configure secrets here: + # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets + BLACKSMITH_FORGE_USERNAME: '${{ secrets.PUPPET_FORGE_USERNAME }}' + BLACKSMITH_FORGE_API_KEY: '${{ secrets.PUPPET_FORGE_API_KEY }}' + run: bundle exec rake module:push diff --git a/.msync.yml b/.msync.yml index 8864fc0..a0770a8 100644 --- a/.msync.yml +++ b/.msync.yml @@ -1 +1,2 @@ -modulesync_config_version: '2.12.0' +--- +modulesync_config_version: '4.0.0' diff --git a/.overcommit.yml b/.overcommit.yml index 1b03fad..0af0fdc 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -1,64 +1,64 @@ # 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: - 'validate' - 'test' - 'rubocop' - command: [ 'bundle', 'exec', 'rake' ] + command: ['bundle', 'exec', 'rake'] diff --git a/.pmtignore b/.pmtignore index 4e6d54b..33a8c65 100644 --- a/.pmtignore +++ b/.pmtignore @@ -1,21 +1,34 @@ docs/ pkg/ +Gemfile Gemfile.lock Gemfile.local vendor/ .vendor/ -spec/fixtures/manifests/ -spec/fixtures/modules/ +spec/ +Rakefile .vagrant/ .bundle/ .ruby-version coverage/ log/ .idea/ .dependencies/ +.github/ .librarian/ Puppetfile.lock *.iml +.editorconfig +.fixtures.yml +.gitignore +.msync.yml +.overcommit.yml +.pmtignore +.rspec +.rspec_parallel +.rubocop.yml +.sync.yml .*.sw? .yardoc/ +.yardopts Dockerfile diff --git a/.rubocop.yml b/.rubocop.yml index c2ebc88..198a359 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,546 +1,3 @@ -require: rubocop-rspec -AllCops: -# Puppet Server 5 defaults to jruby 1.7 so TargetRubyVersion must stay at 1.9 until we drop support for puppet 5 - TargetRubyVersion: 1.9 - Include: - - ./**/*.rb - Exclude: - - files/**/* - - vendor/**/* - - .vendor/**/* - - pkg/**/* - - spec/fixtures/**/* - - Gemfile - - Rakefile - - Guardfile - - Vagrantfile -Lint/ConditionPosition: - Enabled: True - -Lint/ElseLayout: - Enabled: True - -Lint/UnreachableCode: - Enabled: True - -Lint/UselessComparison: - Enabled: True - -Lint/EnsureReturn: - Enabled: True - -Lint/HandleExceptions: - Enabled: True - -Lint/LiteralInCondition: - Enabled: True - -Lint/ShadowingOuterLocalVariable: - Enabled: True - -Lint/LiteralInInterpolation: - Enabled: True - -Style/HashSyntax: - Enabled: True - -Style/RedundantReturn: - Enabled: True - -Layout/EndOfLine: - Enabled: False - -Lint/AmbiguousOperator: - Enabled: True - -Lint/AssignmentInCondition: - Enabled: True - -Layout/SpaceBeforeComment: - Enabled: True - -Style/AndOr: - Enabled: True - -Style/RedundantSelf: - Enabled: True - -Metrics/BlockLength: - Enabled: False - -# Method length is not necessarily an indicator of code quality -Metrics/MethodLength: - Enabled: False - -# Module length is not necessarily an indicator of code quality -Metrics/ModuleLength: - Enabled: False - -Style/WhileUntilModifier: - Enabled: True - -Lint/AmbiguousRegexpLiteral: - Enabled: True - -Security/Eval: - Enabled: True - -Lint/BlockAlignment: - Enabled: True - -Lint/DefEndAlignment: - Enabled: True - -Lint/EndAlignment: - Enabled: True - -Lint/DeprecatedClassMethods: - Enabled: True - -Lint/Loop: - Enabled: True - -Lint/ParenthesesAsGroupedExpression: - Enabled: True - -Lint/RescueException: - Enabled: True - -Lint/StringConversionInInterpolation: - Enabled: True - -Lint/UnusedBlockArgument: - Enabled: True - -Lint/UnusedMethodArgument: - Enabled: True - -Lint/UselessAccessModifier: - Enabled: True - -Lint/UselessAssignment: - Enabled: True - -Lint/Void: - Enabled: True - -Layout/AccessModifierIndentation: - Enabled: True - -Style/AccessorMethodName: - Enabled: True - -Style/Alias: - Enabled: True - -Layout/AlignArray: - Enabled: True - -Layout/AlignHash: - Enabled: True - -Layout/AlignParameters: - Enabled: True - -Metrics/BlockNesting: - Enabled: True - -Style/AsciiComments: - Enabled: True - -Style/Attr: - Enabled: True - -Style/BracesAroundHashParameters: - Enabled: True - -Style/CaseEquality: - Enabled: True - -Layout/CaseIndentation: - Enabled: True - -Style/CharacterLiteral: - Enabled: True - -Style/ClassAndModuleCamelCase: - Enabled: True - -Style/ClassAndModuleChildren: - Enabled: False - -Style/ClassCheck: - Enabled: True - -# Class length is not necessarily an indicator of code quality -Metrics/ClassLength: - Enabled: False - -Style/ClassMethods: - Enabled: True - -Style/ClassVars: - Enabled: True - -Style/WhenThen: - Enabled: True - -Style/WordArray: - Enabled: True - -Style/UnneededPercentQ: - Enabled: True - -Layout/Tab: - Enabled: True - -Layout/SpaceBeforeSemicolon: - Enabled: True - -Layout/TrailingBlankLines: - Enabled: True - -Layout/SpaceInsideBlockBraces: - Enabled: True - -Layout/SpaceInsideBrackets: - Enabled: True - -Layout/SpaceInsideHashLiteralBraces: - Enabled: True - -Layout/SpaceInsideParens: - Enabled: True - -Layout/LeadingCommentSpace: - Enabled: True - -Layout/SpaceBeforeFirstArg: - Enabled: True - -Layout/SpaceAfterColon: - Enabled: True - -Layout/SpaceAfterComma: - Enabled: True - -Layout/SpaceAfterMethodName: - Enabled: True - -Layout/SpaceAfterNot: - Enabled: True - -Layout/SpaceAfterSemicolon: - Enabled: True - -Layout/SpaceAroundEqualsInParameterDefault: - Enabled: True - -Layout/SpaceAroundOperators: - Enabled: True - -Layout/SpaceBeforeBlockBraces: - Enabled: True - -Layout/SpaceBeforeComma: - Enabled: True - -Style/CollectionMethods: - Enabled: True - -Layout/CommentIndentation: - Enabled: True - -Style/ColonMethodCall: - Enabled: True - -Style/CommentAnnotation: - Enabled: True - -# 'Complexity' is very relative -Metrics/CyclomaticComplexity: - Enabled: False - -Style/ConstantName: - Enabled: True - -Style/Documentation: - Enabled: False - -Style/DefWithParentheses: - Enabled: True - -Style/PreferredHashMethods: - Enabled: True - -Layout/DotPosition: - EnforcedStyle: trailing - -Style/DoubleNegation: - Enabled: True - -Style/EachWithObject: - Enabled: True - -Layout/EmptyLineBetweenDefs: - Enabled: True - -Layout/IndentArray: - Enabled: True - -Layout/IndentHash: - Enabled: True - -Layout/IndentationConsistency: - Enabled: True - -Layout/IndentationWidth: - Enabled: True - -Layout/EmptyLines: - Enabled: True - -Layout/EmptyLinesAroundAccessModifier: - Enabled: True - -Style/EmptyLiteral: - Enabled: True - -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Enabled: False - -Style/MethodCallWithoutArgsParentheses: - Enabled: True - -Style/MethodDefParentheses: - Enabled: True - -Style/LineEndConcatenation: - Enabled: True - -Layout/TrailingWhitespace: - Enabled: True - -Style/StringLiterals: - Enabled: True - -Style/TrailingCommaInArguments: - Enabled: True - -Style/TrailingCommaInLiteral: - Enabled: True - -Style/GlobalVars: - Enabled: True - -Style/GuardClause: - Enabled: True - -Style/IfUnlessModifier: - Enabled: True - -Style/MultilineIfThen: - Enabled: True - -Style/NegatedIf: - Enabled: True - -Style/NegatedWhile: - Enabled: True - -Style/Next: - Enabled: True - -Style/SingleLineBlockParams: - Enabled: True - -Style/SingleLineMethods: - Enabled: True - -Style/SpecialGlobalVars: - Enabled: True - -Style/TrivialAccessors: - Enabled: True - -Style/UnlessElse: - Enabled: True - -Style/VariableInterpolation: - Enabled: True - -Style/VariableName: - Enabled: True - -Style/WhileUntilDo: - Enabled: True - -Style/EvenOdd: - Enabled: True - -Style/FileName: - Enabled: True - -Style/For: - Enabled: True - -Style/Lambda: - Enabled: True - -Style/MethodName: - Enabled: True - -Style/MultilineTernaryOperator: - Enabled: True - -Style/NestedTernaryOperator: - Enabled: True - -Style/NilComparison: - Enabled: True - -Style/FormatString: - Enabled: True - -Style/MultilineBlockChain: - Enabled: True - -Style/Semicolon: - Enabled: True - -Style/SignalException: - Enabled: True - -Style/NonNilCheck: - Enabled: True - -Style/Not: - Enabled: True - -Style/NumericLiterals: - Enabled: True - -Style/OneLineConditional: - Enabled: True - -Style/OpMethod: - Enabled: True - -Style/ParenthesesAroundCondition: - Enabled: True - -Style/PercentLiteralDelimiters: - Enabled: True - -Style/PerlBackrefs: - Enabled: True - -Style/PredicateName: - Enabled: True - -Style/RedundantException: - Enabled: True - -Style/SelfAssignment: - Enabled: True - -Style/Proc: - Enabled: True - -Style/RaiseArgs: - Enabled: True - -Style/RedundantBegin: - Enabled: True - -Style/RescueModifier: - Enabled: True - -# based on https://github.com/voxpupuli/modulesync_config/issues/168 -Style/RegexpLiteral: - EnforcedStyle: percent_r - Enabled: True - -Lint/UnderscorePrefixedVariableName: - Enabled: True - -Metrics/ParameterLists: - Enabled: False - -Lint/RequireParentheses: - Enabled: True - -Style/ModuleFunction: - Enabled: True - -Lint/Debugger: - Enabled: True - -Style/IfWithSemicolon: - Enabled: True - -Style/Encoding: - Enabled: True - -Style/BlockDelimiters: - Enabled: True - -Layout/MultilineBlockLayout: - Enabled: True - -# 'Complexity' is very relative -Metrics/AbcSize: - Enabled: False - -# 'Complexity' is very relative -Metrics/PerceivedComplexity: - Enabled: False - -Lint/UselessAssignment: - Enabled: True - -Layout/ClosingParenthesisIndentation: - Enabled: True - -# RSpec - -RSpec/BeforeAfterAll: - Exclude: - - spec/acceptance/**/* - -# We don't use rspec in this way -RSpec/DescribeClass: - Enabled: False - -# Example length is not necessarily an indicator of code quality -RSpec/ExampleLength: - Enabled: False - -RSpec/NamedSubject: - Enabled: False - -# disabled for now since they cause a lot of issues -# these issues aren't easy to fix -RSpec/RepeatedDescription: - Enabled: False - -RSpec/NestedGroups: - Enabled: False - -# this is broken on ruby1.9 -Layout/IndentHeredoc: - Enabled: False - -# disable Yaml safe_load. This is needed to support ruby2.0.0 development envs -Security/YAMLLoad: - Enabled: false - -# This affects hiera interpolation, as well as some configs that we push. -Style/FormatStringToken: - Enabled: false - -# This is useful, but sometimes a little too picky about where unit tests files -# are located. -RSpec/FilePath: - Enabled: false +--- +inherit_gem: + voxpupuli-test: rubocop.yml diff --git a/.sync.yml b/.sync.yml deleted file mode 100644 index 930d06c..0000000 --- a/.sync.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -.travis.yml: - docker_sets: - - set: debian8-64 - - set: debian9-64 - - set: debian10-64 - - set: ubuntu1604-64 - - set: ubuntu1804-64 - - set: centos6-64 - - set: centos7-64 - secure: "j/Db/NnuJUwyFWGVwZEciC/0Xrhaes647UK49ZnlZTjUppUeTsqY/rKE8Pc4jpiW8DsfeGijCYP1O02tquH+KSKSwiwxIBjbToFjhNNJ6Qgh0DGIR29VZkiyirh5ZkK1yLMx9Ciyn8opwOXHqTRMk6JwAY05Gux1sD2T7Eu2c4w=" -spec/acceptance/nodesets/ec2/amazonlinux-2016091.yml: - delete: true -spec/acceptance/nodesets/ec2/image_templates.yaml: - delete: true -spec/acceptance/nodesets/ec2/rhel-73-x64.yml: - delete: true -spec/acceptance/nodesets/ec2/sles-12sp2-x64.yml: - delete: true -spec/acceptance/nodesets/ec2/ubuntu-1604-x64.yml: - delete: true -spec/acceptance/nodesets/ec2/windows-2016-base-x64.yml: - delete: true -spec/acceptance/nodesets/archlinux-2-x64.yml: - delete: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8c52ae2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,104 +0,0 @@ ---- -os: linux -dist: bionic -language: ruby -cache: bundler -before_install: - - yes | gem update --system - - bundle --version -script: - - 'bundle exec rake $CHECK' -jobs: - fast_finish: true - include: - - rvm: 2.4.4 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 5.0" CHECK=test - - rvm: 2.5.3 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 6.0" CHECK=test_with_coveralls - - rvm: 2.5.3 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 6.0" CHECK=rubocop - - rvm: 2.4.4 - bundler_args: --without system_tests development release - env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=debian8-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=debian8-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=debian9-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=debian9-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=debian10-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=debian10-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=ubuntu1604-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu1604-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=ubuntu1804-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=ubuntu1804-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=centos6-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=centos6-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_setfile=centos7-64 CHECK=beaker - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_setfile=centos7-64 CHECK=beaker - services: docker -branches: - only: - - master - - /^v\d/ -notifications: - email: false - webhooks: https://voxpupu.li/incoming/travis - irc: - on_success: always - on_failure: always - channels: - - "chat.freenode.org#voxpupuli-notifications" -deploy: - provider: puppetforge - username: puppet - password: - secure: "j/Db/NnuJUwyFWGVwZEciC/0Xrhaes647UK49ZnlZTjUppUeTsqY/rKE8Pc4jpiW8DsfeGijCYP1O02tquH+KSKSwiwxIBjbToFjhNNJ6Qgh0DGIR29VZkiyirh5ZkK1yLMx9Ciyn8opwOXHqTRMk6JwAY05Gux1sD2T7Eu2c4w=" - on: - tags: true - # all_branches is required to use tags - all_branches: true - # Only publish the build marked with "DEPLOY_TO_FORGE" - condition: "$DEPLOY_TO_FORGE = yes" diff --git a/Gemfile b/Gemfile index abd6226..0d0a9fb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,49 +1,33 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" -def location_for(place, fake_version = nil) - if place =~ /^(git[:@][^#]*)#(.*)/ - [fake_version, { :git => $1, :branch => $2, :require => false }].compact - elsif place =~ /^file:\/\/(.*)/ - ['>= 0', { :path => File.expand_path($1), :require => false }] - else - [place, { :require => false }] - end -end - group :test do - gem 'voxpupuli-test', '>= 1.4.0', :require => false - gem 'coveralls', :require => false - gem 'simplecov-console', :require => false + gem 'voxpupuli-test', '~> 2.1', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false end group :development do - gem 'travis', :require => false - gem 'travis-lint', :require => false gem 'guard-rake', :require => false gem 'overcommit', '>= 0.39.1', :require => false end group :system_tests do - gem 'beaker', '4.22.1', :require => true - gem 'voxpupuli-acceptance', :require => false + gem 'puppet_metadata', '~> 0.3.0', :require => false + gem 'voxpupuli-acceptance', :require => false end group :release do gem 'github_changelog_generator', :require => false, :git => 'https://github.com/voxpupuli/github-changelog-generator', :branch => 'voxpupuli_essential_fixes' gem 'puppet-blacksmith', :require => false gem 'voxpupuli-release', :require => false gem 'puppet-strings', '>= 2.2', :require => false end +gem 'puppetlabs_spec_helper', '~> 2.0', :require => false +gem 'rake', :require => false +gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] - -if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', facterversion.to_s, :require => false, :groups => [:test] -else - gem 'facter', :require => false, :groups => [:test] -end - -ENV['PUPPET_VERSION'].nil? ? puppetversion = '~> 6.0' : puppetversion = ENV['PUPPET_VERSION'].to_s +puppetversion = ENV['PUPPET_VERSION'] || '~> 6.0' gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/README.md b/README.md index c52b74d..853c03a 100644 --- a/README.md +++ b/README.md @@ -1,133 +1,132 @@ # Kafka module for Puppet [![Build Status](https://travis-ci.org/voxpupuli/puppet-kafka.png?branch=master)](https://travis-ci.org/voxpupuli/puppet-kafka) [![Puppet Forge](https://img.shields.io/puppetforge/v/puppet/kafka.svg)](https://forge.puppetlabs.com/puppet/kafka) [![Puppet Forge - downloads](https://img.shields.io/puppetforge/dt/puppet/kafka.svg)](https://forge.puppetlabs.com/puppet/kafka) [![Puppet Forge - endorsement](https://img.shields.io/puppetforge/e/puppet/kafka.svg)](https://forge.puppetlabs.com/puppet/kafka) [![Puppet Forge - scores](https://img.shields.io/puppetforge/f/puppet/kafka.svg)](https://forge.puppetlabs.com/puppet/kafka) ## Table of Contents 1. [Overview](#overview) 1. [Module Description - What the module does and why it is useful](#module-description) 1. [Setup - The basics of getting started with Kafka](#setup) * [What Kafka affects](#what-kafka-affects) * [Setup requirements](#setup-requirements) * [Beginning with Kafka](#beginning-with-kafka) 1. [Usage - Configuration options and additional functionality](#usage) 1. [Reference - An under-the-hood peek at what the module is doing and how](#reference) 1. [Limitations - OS compatibility, etc.](#limitations) 1. [Development - Guide for contributing to the module](#development) ## Overview The Kafka module for managing the installation and configuration of [Apache Kafka](http://kafka.apache.org). ## Module Description The Kafka module for managing the installation and configuration of Apache Kafka: it's brokers, producers and consumers. ## Setup ### What Kafka affects Installs the Kafka package and creates a new service. ### Setup requirements This module has the following dependencies: * [deric/zookeeper](https://github.com/deric/puppet-zookeeper) * [camptocamp/systemd](https://github.com/camptocamp/puppet-systemd) * [puppet/archive](https://github.com/voxpupuli/puppet-archive) * [puppetlabs/java](https://github.com/puppetlabs/puppetlabs-java) * [puppetlabs/stdlib](https://github.com/puppetlabs/puppetlabs-stdlib) ### Beginning with Kafka To successfully install Kafka using this module you need to have Apache ZooKeeper already running at localhost:2181. You can specify another ZooKeeper host:port configuration using the config hash of the kafka::broker class. The default configuration installs Kafka 0.11.0.3 binaries with Scala 2.11: ```puppet class { 'kafka': } ``` If you want a Kafka broker server that connects to ZooKeeper listening on port 2181: ```puppet class { 'kafka::broker': config => { 'broker.id' => '0', 'zookeeper.connect' => 'localhost:2181' } } ``` ## Usage You can specify different Kafka binaries packages versions to install. Please take a look at the different Scala and Kafka versions combinations at the [Apache Kafka Website](http://kafka.apache.org/downloads.html) ### Installing Kafka version 1.1.0 with scala 2.12 We first install the binary package with: ```puppet class { 'kafka': version => '1.1.0', scala_version => '2.12' } ``` Then we set a minimal Kafka broker configuration with: ```puppet class { 'kafka::broker': config => { 'broker.id' => '0', 'zookeeper.connect' => 'localhost:2181' } } ``` ## Reference The [reference][1] documentation of this module is generated using [puppetlabs/puppetlabs-strings][2]. ## Limitations This module only supports Kafka >= 0.9.0.0. This module is tested on the following platforms: * Debian 8 * Debian 9 * Debian 10 * Ubuntu 16.04 * Ubuntu 18.04 -* CentOS 6 * CentOS 7 It is tested with the OSS version of Puppet (>= 5.5) only. ## Development This module has grown over time based on a range of contributions from people using it. If you follow these [contributing][3] guidelines your patch will likely make it into a release a little more quickly. ## Author This module is maintained by [Vox Pupuli][4]. It was originally written and maintained by [Liam Bennett][5]. [1]: https://github.com/voxpupuli/puppet-kafka/blob/master/REFERENCE.md [2]: https://github.com/puppetlabs/puppetlabs-strings [3]: https://github.com/voxpupuli/puppet-kafka/blob/master/.github/CONTRIBUTING.md [4]: https://voxpupuli.org -[5]: https://www.opentable.com \ No newline at end of file +[5]: https://www.opentable.com diff --git a/Rakefile b/Rakefile index b450fe7..d1bf749 100644 --- a/Rakefile +++ b/Rakefile @@ -1,54 +1,61 @@ -require 'voxpupuli/test/rake' +# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# otherwise attempt to load it directly. +begin + require 'voxpupuli/test/rake' +rescue LoadError + require 'puppetlabs_spec_helper/rake_tasks' +end # load optional tasks for releases # only available if gem group releases is installed begin require 'voxpupuli/release/rake_tasks' rescue LoadError end desc "Run main 'test' task and report merged results to coveralls" task test_with_coveralls: [:test] do if Dir.exist?(File.expand_path('../lib', __FILE__)) require 'coveralls/rake/task' Coveralls::RakeTask.new Rake::Task['coveralls:push'].invoke else puts 'Skipping reporting to coveralls. Module has no lib dir' end end desc 'Generate REFERENCE.md' task :reference, [:debug, :backtrace] do |t, args| patterns = '' Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) end begin require 'github_changelog_generator/task' + require 'puppet_blacksmith' 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' metadata_json = File.join(File.dirname(__FILE__), 'metadata.json') metadata = JSON.load(File.read(metadata_json)) config.project = metadata['name'] end # Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715 require 'rbconfig' if RbConfig::CONFIG['host_os'] =~ /linux/ task :changelog do puts 'Fixing line endings...' changelog_file = File.join(__dir__, 'CHANGELOG.md') changelog_txt = File.read(changelog_file) new_contents = changelog_txt.gsub(%r{\r\n}, "\n") File.open(changelog_file, "w") {|file| file.puts new_contents } end end rescue LoadError end # vim: syntax=ruby diff --git a/manifests/broker.pp b/manifests/broker.pp index f708814..e36f9a3 100644 --- a/manifests/broker.pp +++ b/manifests/broker.pp @@ -1,159 +1,158 @@ # @summary # This class handles the Kafka (broker). # # @example Basic usage # class { 'kafka::broker': # config => { # 'broker.id' => '0', # 'zookeeper.connect' => 'localhost:2181' # } # } # # @param kafka_version # The version of Kafka that should be installed. # # @param scala_version # The scala version what Kafka was built with. # # @param install_dir # The directory to install Kafka to. # # @param mirror_url # The url where the Kafka is downloaded from. # # @param manage_java # Install java if it's not already installed. # # @param package_dir # The directory to install Kafka. # # @param package_name # Package name, when installing Kafka from a package. # # @param package_ensure # Package version or ensure state, when installing Kafka from a package. # # @param user_name # User to run Kafka as. # # @param user_shell # Login shell of the Kafka user. # # @param group_name # Group to run Kafka as. # # @param user_id # Create the Kafka user with this ID. # # @param group_id # Create the Kafka group with this ID. # # @param manage_user # Create the Kafka user if it's not already present. # # @param manage_group # Create the Kafka group if it's not already present. # # @param config_mode # The permissions for the config files. # # @param config_dir # The directory to create the Kafka config files to. # # @param log_dir # The directory for Kafka log files. # # @param bin_dir # The directory where the Kafka scripts are. # # @param service_name # Set the name of the service. # # @param manage_service # Install the init.d or systemd service. # # @param service_ensure # Set the ensure state of the service. # # @param service_restart # Whether the configuration files should trigger a service restart. # # @param service_requires # Set the list of services required to be running before Kafka. # # @param limit_nofile # Set the 'LimitNOFILE' option of the systemd service. # # @param limit_core # Set the 'LimitCORE' option of the systemd service. # # @param timeout_stop # Set the 'TimeoutStopSec' option of the systemd service. # # @param exec_stop # Set the 'ExecStop' option of the systemd service to 'kafka-server-stop.sh'. # # @param daemon_start # Use the '-daemon' option when starting Kafka with 'kafka-server-start.sh'. # # @param env # A hash of the environment variables to set. # # @param config # A hash of the broker configuration options. # # @param heap_opts # Set the Java heap size. # # @param jmx_opts # Set the JMX options. # # @param log4j_opts # Set the Log4j options. # # @param opts # Set the Kafka options. # class kafka::broker ( String[1] $kafka_version = $kafka::params::kafka_version, String[1] $scala_version = $kafka::params::scala_version, Stdlib::Absolutepath $install_dir = $kafka::params::install_dir, Stdlib::HTTPUrl $mirror_url = $kafka::params::mirror_url, Boolean $manage_java = $kafka::params::manage_java, Stdlib::Absolutepath $package_dir = $kafka::params::package_dir, Optional[String[1]] $package_name = $kafka::params::package_name, String[1] $package_ensure = $kafka::params::package_ensure, String[1] $user_name = $kafka::params::user_name, Stdlib::Absolutepath $user_shell = $kafka::params::user_shell, String[1] $group_name = $kafka::params::group_name, Optional[Integer] $user_id = $kafka::params::user_id, Optional[Integer] $group_id = $kafka::params::group_id, Boolean $manage_user = $kafka::params::manage_user, Boolean $manage_group = $kafka::params::manage_group, Stdlib::Filemode $config_mode = $kafka::params::config_mode, Stdlib::Absolutepath $config_dir = $kafka::params::config_dir, Stdlib::Absolutepath $log_dir = $kafka::params::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::params::bin_dir, String[1] $service_name = 'kafka', Boolean $manage_service = $kafka::params::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::params::service_ensure, Boolean $service_restart = $kafka::params::service_restart, Array[String[1]] $service_requires = $kafka::params::service_requires, Optional[String[1]] $limit_nofile = $kafka::params::limit_nofile, Optional[String[1]] $limit_core = $kafka::params::limit_core, Optional[String[1]] $timeout_stop = $kafka::params::timeout_stop, Boolean $exec_stop = $kafka::params::exec_stop, Boolean $daemon_start = $kafka::params::daemon_start, Hash $env = {}, Hash[String[1], Any] $config = {}, String[1] $heap_opts = $kafka::params::broker_heap_opts, String[1] $jmx_opts = $kafka::params::broker_jmx_opts, String[1] $log4j_opts = $kafka::params::broker_log4j_opts, String[0] $opts = $kafka::params::broker_opts, ) inherits kafka::params { - class { 'kafka::broker::install': } -> class { 'kafka::broker::config': } -> class { 'kafka::broker::service': } -> Class['kafka::broker'] } diff --git a/manifests/broker/config.pp b/manifests/broker/config.pp index 1602351..0407ecc 100644 --- a/manifests/broker/config.pp +++ b/manifests/broker/config.pp @@ -1,35 +1,34 @@ # @summary # This class handles the Kafka (broker) config. # # @api private # -class kafka::broker::config( +class kafka::broker::config ( Boolean $manage_service = $kafka::broker::manage_service, String[1] $service_name = $kafka::broker::service_name, Boolean $service_restart = $kafka::broker::service_restart, Hash[String[1], Any] $config = $kafka::broker::config, Stdlib::Absolutepath $config_dir = $kafka::broker::config_dir, String[1] $user_name = $kafka::broker::user_name, String[1] $group_name = $kafka::broker::group_name, Stdlib::Filemode $config_mode = $kafka::broker::config_mode, ) { - assert_private() if ($manage_service and $service_restart) { $config_notify = Service[$service_name] } else { $config_notify = undef } $doctag = 'brokerconfigs' file { "${config_dir}/server.properties": - ensure => present, + ensure => file, owner => $user_name, group => $group_name, mode => $config_mode, content => template('kafka/properties.erb'), notify => $config_notify, require => File[$config_dir], } } diff --git a/manifests/broker/install.pp b/manifests/broker/install.pp index 8870e36..5c66a06 100644 --- a/manifests/broker/install.pp +++ b/manifests/broker/install.pp @@ -1,31 +1,30 @@ # @summary # This class handles the Kafka (broker) package. # # @api private # class kafka::broker::install { - assert_private() if !defined(Class['kafka']) { class { 'kafka': manage_java => $kafka::broker::manage_java, manage_group => $kafka::broker::manage_group, group_id => $kafka::broker::group_id, group_name => $kafka::broker::group_name, manage_user => $kafka::broker::manage_user, user_id => $kafka::broker::user_id, user_name => $kafka::broker::user_name, user_shell => $kafka::broker::user_shell, config_dir => $kafka::broker::config_dir, log_dir => $kafka::broker::log_dir, mirror_url => $kafka::broker::mirror_url, kafka_version => $kafka::broker::kafka_version, scala_version => $kafka::broker::scala_version, install_dir => $kafka::broker::install_dir, package_dir => $kafka::broker::package_dir, package_ensure => $kafka::broker::package_ensure, package_name => $kafka::broker::package_name, } } } diff --git a/manifests/broker/service.pp b/manifests/broker/service.pp index a2f66fa..fa59c84 100644 --- a/manifests/broker/service.pp +++ b/manifests/broker/service.pp @@ -1,72 +1,71 @@ # @summary # This class handles the Kafka (broker) service. # # @api private # -class kafka::broker::service( +class kafka::broker::service ( Boolean $manage_service = $kafka::broker::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::broker::service_ensure, String[1] $service_name = $kafka::broker::service_name, String[1] $user_name = $kafka::broker::user_name, String[1] $group_name = $kafka::broker::group_name, Stdlib::Absolutepath $config_dir = $kafka::broker::config_dir, Stdlib::Absolutepath $log_dir = $kafka::broker::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::broker::bin_dir, Array[String[1]] $service_requires = $kafka::broker::service_requires, Optional[String[1]] $limit_nofile = $kafka::broker::limit_nofile, Optional[String[1]] $limit_core = $kafka::broker::limit_core, Optional[String[1]] $timeout_stop = $kafka::broker::timeout_stop, Boolean $exec_stop = $kafka::broker::exec_stop, Boolean $daemon_start = $kafka::broker::daemon_start, Hash $env = $kafka::broker::env, String[1] $heap_opts = $kafka::broker::heap_opts, String[1] $jmx_opts = $kafka::broker::jmx_opts, String[1] $log4j_opts = $kafka::broker::log4j_opts, String[0] $opts = $kafka::broker::opts, ) { - assert_private() if $manage_service { $env_defaults = { 'KAFKA_HEAP_OPTS' => $heap_opts, 'KAFKA_JMX_OPTS' => $jmx_opts, 'KAFKA_LOG4J_OPTS' => $log4j_opts, 'KAFKA_OPTS' => $opts, 'LOG_DIR' => $log_dir, } $environment = deep_merge($env_defaults, $env) if $facts['service_provider'] == 'systemd' { include systemd file { "/etc/systemd/system/${service_name}.service": ensure => file, mode => '0644', content => template('kafka/unit.erb'), } file { "/etc/init.d/${service_name}": ensure => absent, } File["/etc/systemd/system/${service_name}.service"] ~> Exec['systemctl-daemon-reload'] -> Service[$service_name] } else { file { "/etc/init.d/${service_name}": ensure => file, mode => '0755', content => template('kafka/init.erb'), before => Service[$service_name], } } service { $service_name: ensure => $service_ensure, enable => true, hasstatus => true, hasrestart => true, } } } diff --git a/manifests/consumer.pp b/manifests/consumer.pp index d10394c..06439f9 100644 --- a/manifests/consumer.pp +++ b/manifests/consumer.pp @@ -1,143 +1,142 @@ # @summary # This class handles the Kafka (consumer). # # @example Basic usage # class { 'kafka::consumer': # config => { # 'client.id' => '0', # 'zookeeper.connect' => 'localhost:2181' # } # } # # @param kafka_version # The version of Kafka that should be installed. # # @param scala_version # The scala version what Kafka was built with. # # @param install_dir # The directory to install Kafka to. # # @param mirror_url # The url where the Kafka is downloaded from. # # @param manage_java # Install java if it's not already installed. # # @param package_dir # The directory to install Kafka. # # @param package_name # Package name, when installing Kafka from a package. # # @param package_ensure # Package version or ensure state, when installing Kafka from a package. # # @param user_name # User to run Kafka as. # # @param user_shell # Login shell of the Kafka user. # # @param group_name # Group to run Kafka as. # # @param user_id # Create the Kafka user with this ID. # # @param group_id # Create the Kafka group with this ID. # # @param manage_user # Create the Kafka user if it's not already present. # # @param manage_group # Create the Kafka group if it's not already present. # # @param config_mode # The permissions for the config files. # # @param config_dir # The directory to create the Kafka config files to. # # @param log_dir # The directory for Kafka log files. # # @param bin_dir # The directory where the Kafka scripts are. # # @param service_name # Set the name of the service. # # @param manage_service # Install the init.d or systemd service. # # @param service_ensure # Set the ensure state of the service. # # @param service_restart # Whether the configuration files should trigger a service restart. # # @param service_requires # Set the list of services required to be running before Kafka. # # @param limit_nofile # Set the 'LimitNOFILE' option of the systemd service. # # @param limit_core # Set the 'LimitCORE' option of the systemd service. # # @param env # A hash of the environment variables to set. # # @param config # A hash of the consumer configuration options. # # @param service_config # A hash of the `kafka-console-consumer.sh` script options. # # @param jmx_opts # Set the JMX options. # # @param log4j_opts # Set the Log4j options. # class kafka::consumer ( String[1] $kafka_version = $kafka::params::kafka_version, String[1] $scala_version = $kafka::params::scala_version, Stdlib::Absolutepath $install_dir = $kafka::params::install_dir, Stdlib::HTTPUrl $mirror_url = $kafka::params::mirror_url, Boolean $manage_java = $kafka::params::manage_java, Stdlib::Absolutepath $package_dir = $kafka::params::package_dir, Optional[String[1]] $package_name = $kafka::params::package_name, String[1] $package_ensure = $kafka::params::package_ensure, String[1] $user_name = $kafka::params::user_name, Stdlib::Absolutepath $user_shell = $kafka::params::user_shell, String[1] $group_name = $kafka::params::group_name, Optional[Integer] $user_id = $kafka::params::user_id, Optional[Integer] $group_id = $kafka::params::group_id, Boolean $manage_user = $kafka::params::manage_user, Boolean $manage_group = $kafka::params::manage_group, Stdlib::Filemode $config_mode = $kafka::params::config_mode, Stdlib::Absolutepath $config_dir = $kafka::params::config_dir, Stdlib::Absolutepath $log_dir = $kafka::params::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::params::bin_dir, String[1] $service_name = 'kafka-consumer', Boolean $manage_service = $kafka::params::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::params::service_ensure, Boolean $service_restart = $kafka::params::service_restart, Array[String[1]] $service_requires = $kafka::params::service_requires, Optional[String[1]] $limit_nofile = $kafka::params::limit_nofile, Optional[String[1]] $limit_core = $kafka::params::limit_core, Hash $env = {}, Hash[String[1], Any] $config = {}, Hash[String[1],String[1]] $service_config = {}, String[1] $jmx_opts = $kafka::params::consumer_jmx_opts, String[1] $log4j_opts = $kafka::params::consumer_log4j_opts, ) inherits kafka::params { - class { 'kafka::consumer::install': } -> class { 'kafka::consumer::config': } -> class { 'kafka::consumer::service': } -> Class['kafka::consumer'] } diff --git a/manifests/consumer/config.pp b/manifests/consumer/config.pp index 6e92d9d..b44f096 100644 --- a/manifests/consumer/config.pp +++ b/manifests/consumer/config.pp @@ -1,31 +1,30 @@ # @summary # This class handles the Kafka (consumer) config. # -class kafka::consumer::config( +class kafka::consumer::config ( Boolean $manage_service = $kafka::consumer::manage_service, String[1] $service_name = $kafka::consumer::service_name, Boolean $service_restart = $kafka::consumer::service_restart, Hash[String[1], Any] $config = $kafka::consumer::config, Stdlib::Absolutepath $config_dir = $kafka::consumer::config_dir, String[1] $user_name = $kafka::consumer::user_name, String[1] $group_name = $kafka::consumer::group_name, Stdlib::Filemode $config_mode = $kafka::consumer::config_mode, ) { - if ($manage_service and $service_restart) { $config_notify = Service[$service_name] } else { $config_notify = undef } $doctag = 'consumerconfigs' file { "${config_dir}/consumer.properties": - ensure => present, + ensure => file, owner => $user_name, group => $group_name, mode => $config_mode, content => template('kafka/properties.erb'), notify => $config_notify, require => File[$config_dir], } } diff --git a/manifests/consumer/install.pp b/manifests/consumer/install.pp index 5b98f9f..9a1d63c 100644 --- a/manifests/consumer/install.pp +++ b/manifests/consumer/install.pp @@ -1,31 +1,30 @@ # @summary # This class handles the Kafka (consumer) package. # # @api private # class kafka::consumer::install { - assert_private() if !defined(Class['kafka']) { class { 'kafka': manage_java => $kafka::consumer::manage_java, manage_group => $kafka::consumer::manage_group, group_id => $kafka::consumer::group_id, group_name => $kafka::consumer::group_name, manage_user => $kafka::consumer::manage_user, user_id => $kafka::consumer::user_id, user_name => $kafka::consumer::user_name, user_shell => $kafka::consumer::user_shell, config_dir => $kafka::consumer::config_dir, log_dir => $kafka::consumer::log_dir, mirror_url => $kafka::consumer::mirror_url, kafka_version => $kafka::consumer::kafka_version, scala_version => $kafka::consumer::scala_version, install_dir => $kafka::consumer::install_dir, package_dir => $kafka::consumer::package_dir, package_ensure => $kafka::consumer::package_ensure, package_name => $kafka::consumer::package_name, } } } diff --git a/manifests/consumer/service.pp b/manifests/consumer/service.pp index 287ae32..e96facd 100644 --- a/manifests/consumer/service.pp +++ b/manifests/consumer/service.pp @@ -1,73 +1,71 @@ # @summary # This class handles the Kafka (consumer) service. # # @api private # -class kafka::consumer::service( +class kafka::consumer::service ( Boolean $manage_service = $kafka::consumer::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::consumer::service_ensure, String[1] $service_name = $kafka::consumer::service_name, String[1] $user_name = $kafka::consumer::user_name, String[1] $group_name = $kafka::consumer::group_name, Stdlib::Absolutepath $config_dir = $kafka::consumer::config_dir, Stdlib::Absolutepath $log_dir = $kafka::consumer::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::consumer::bin_dir, Array[String[1]] $service_requires = $kafka::consumer::service_requires, Optional[String[1]] $limit_nofile = $kafka::consumer::limit_nofile, Optional[String[1]] $limit_core = $kafka::consumer::limit_core, Hash $env = $kafka::consumer::env, String[1] $jmx_opts = $kafka::consumer::jmx_opts, String[1] $log4j_opts = $kafka::consumer::log4j_opts, Hash[String[1],String[1]] $service_config = $kafka::consumer::service_config, ) { - assert_private() if $manage_service { - if $service_config['topic'] == '' { fail('[Consumer] You need to specify a value for topic') } if $service_config['zookeeper'] == '' { fail('[Consumer] You need to specify a value for zookeeper') } $env_defaults = { 'KAFKA_JMX_OPTS' => $jmx_opts, 'KAFKA_LOG4J_OPTS' => $log4j_opts, } $environment = deep_merge($env_defaults, $env) if $facts['service_provider'] == 'systemd' { include systemd file { "/etc/systemd/system/${service_name}.service": ensure => file, mode => '0644', content => template('kafka/unit.erb'), } file { "/etc/init.d/${service_name}": ensure => absent, } File["/etc/systemd/system/${service_name}.service"] ~> Exec['systemctl-daemon-reload'] -> Service[$service_name] } else { file { "/etc/init.d/${service_name}": ensure => file, mode => '0755', content => template('kafka/init.erb'), before => Service[$service_name], } } service { $service_name: ensure => $service_ensure, enable => true, hasstatus => true, hasrestart => true, } } } diff --git a/manifests/init.pp b/manifests/init.pp index cd43efa..c8dd525 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,236 +1,235 @@ # @summary # This class handles the Kafka requirements. # # @example Basic usage # class { 'kafka': } # # @param kafka_version # The version of Kafka that should be installed. # # @param scala_version # The scala version what Kafka was built with. # # @param install_dir # The directory to install Kafka to. # # @param mirror_url # The url where the Kafka is downloaded from. # # @param manage_java # Install java if it's not already installed. # # @param package_dir # The directory to install Kafka. # # @param package_name # Package name, when installing Kafka from a package. # # @param mirror_subpath # The sub directory where the source is downloaded from. # # @param proxy_server # Set proxy server, when installing Kafka from source. # # @param proxy_port # Set proxy port, when installing Kafka from source. # # @param proxy_host # Set proxy host, when installing Kafka from source. # # @param proxy_type # Set proxy type, when installing Kafka from source. # # @param package_ensure # Package version or ensure state, when installing Kafka from a package. # # @param user_name # User to run Kafka as. # # @param user_shell # Login shell of the Kafka user. # # @param group_name # Group to run Kafka as. # # @param system_user # Whether the Kafka user is a system user or not. # # @param system_group # Whether the Kafka group is a system group or not. # # @param user_id # Create the Kafka user with this ID. # # @param group_id # Create the Kafka group with this ID. # # @param manage_user # Create the Kafka user if it's not already present. # # @param manage_group # Create the Kafka group if it's not already present. # # @param config_dir # The directory to create the Kafka config files to. # # @param log_dir # The directory for Kafka log files. # # @param install_mode # The permissions for the install directory. # class kafka ( String[1] $kafka_version = $kafka::params::kafka_version, String[1] $scala_version = $kafka::params::scala_version, Stdlib::Absolutepath $install_dir = $kafka::params::install_dir, Stdlib::HTTPUrl $mirror_url = $kafka::params::mirror_url, Boolean $manage_java = $kafka::params::manage_java, Stdlib::Absolutepath $package_dir = $kafka::params::package_dir, Optional[String[1]] $package_name = $kafka::params::package_name, Optional[String[1]] $mirror_subpath = $kafka::params::mirror_subpath, Optional[String[1]] $proxy_server = $kafka::params::proxy_server, Optional[String[1]] $proxy_port = $kafka::params::proxy_port, Optional[String[1]] $proxy_host = $kafka::params::proxy_host, Optional[String[1]] $proxy_type = $kafka::params::proxy_type, String[1] $package_ensure = $kafka::params::package_ensure, String[1] $user_name = $kafka::params::user_name, Stdlib::Absolutepath $user_shell = $kafka::params::user_shell, String[1] $group_name = $kafka::params::group_name, Boolean $system_user = $kafka::params::system_user, Boolean $system_group = $kafka::params::system_group, Optional[Integer] $user_id = $kafka::params::user_id, Optional[Integer] $group_id = $kafka::params::group_id, Boolean $manage_user = $kafka::params::manage_user, Boolean $manage_group = $kafka::params::manage_group, Stdlib::Absolutepath $config_dir = $kafka::params::config_dir, Stdlib::Absolutepath $log_dir = $kafka::params::log_dir, Stdlib::Filemode $install_mode = $kafka::params::install_mode, ) inherits kafka::params { - if $manage_java { class { 'java': distribution => 'jdk', } } if $manage_group { group { $group_name: ensure => present, gid => $group_id, system => $system_group, } } if $manage_user { user { $user_name: ensure => present, shell => $user_shell, require => Group[$group_name], uid => $user_id, system => $system_user, } } file { $config_dir: ensure => directory, owner => $user_name, group => $group_name, } file { $log_dir: ensure => directory, owner => $user_name, group => $group_name, require => [ Group[$group_name], User[$user_name], ], } if $package_name == undef { include archive $mirror_path = $mirror_subpath ? { # if mirror_subpath was not changed, # we adapt it for the version $kafka::params::mirror_subpath => "kafka/${kafka_version}", # else, we just take whatever was supplied: default => $mirror_subpath, } $basefilename = "kafka_${scala_version}-${kafka_version}.tgz" $package_url = "${mirror_url}${mirror_path}/${basefilename}" - $source = $mirror_url ?{ + $source = $mirror_url ? { /tgz$/ => $mirror_url, default => $package_url, } $install_directory = $install_dir ? { # if install_dir was not changed, # we adapt it for the scala_version and the version $kafka::params::install_dir => "/opt/kafka-${scala_version}-${kafka_version}", # else, we just take whatever was supplied: default => $install_dir, } file { $package_dir: ensure => directory, owner => $user_name, group => $group_name, require => [ Group[$group_name], User[$user_name], ], } file { $install_directory: ensure => directory, owner => $user_name, group => $group_name, mode => $install_mode, require => [ Group[$group_name], User[$user_name], ], } file { '/opt/kafka': ensure => link, target => $install_directory, require => File[$install_directory], } if $proxy_server == undef and $proxy_host != undef and $proxy_port != undef { $final_proxy_server = "${proxy_host}:${proxy_port}" } else { $final_proxy_server = $proxy_server } archive { "${package_dir}/${basefilename}": ensure => present, extract => true, extract_command => 'tar xfz %s --strip-components=1', extract_path => $install_directory, source => $source, creates => "${install_directory}/config", cleanup => true, proxy_server => $final_proxy_server, proxy_type => $proxy_type, user => $user_name, group => $group_name, require => [ File[$package_dir], File[$install_directory], Group[$group_name], User[$user_name], ], before => File[$config_dir], } } else { package { $package_name: ensure => $package_ensure, before => File[$config_dir], } } } diff --git a/manifests/mirror.pp b/manifests/mirror.pp index 80d156e..0ceddd1 100644 --- a/manifests/mirror.pp +++ b/manifests/mirror.pp @@ -1,157 +1,156 @@ # @summary # This class handles the Kafka (mirror). # # @example Basic usage # class { 'kafka::mirror': # consumer_config => { # 'group.id' => 'kafka-mirror', # 'zookeeper.connect' => 'localhost:2181' # }, # producer_config => { # 'zookeeper.connect' => 'localhost:2181', # }, # service_config => { # 'whitelist' => '.*', # } # } # # @param kafka_version # The version of Kafka that should be installed. # # @param scala_version # The scala version what Kafka was built with. # # @param install_dir # The directory to install Kafka to. # # @param mirror_url # The url where the Kafka is downloaded from. # # @param manage_java # Install java if it's not already installed. # # @param package_dir # The directory to install Kafka. # # @param package_name # Package name, when installing Kafka from a package. # # @param package_ensure # Package version or ensure state, when installing Kafka from a package. # # @param user_name # User to run Kafka as. # # @param user_shell # Login shell of the Kafka user. # # @param group_name # Group to run Kafka as. # # @param user_id # Create the Kafka user with this ID. # # @param group_id # Create the Kafka group with this ID. # # @param manage_user # Create the Kafka user if it's not already present. # # @param manage_group # Create the Kafka group if it's not already present. # # @param config_mode # The permissions for the config files. # # @param config_dir # The directory to create the Kafka config files to. # # @param log_dir # The directory for Kafka log files. # # @param bin_dir # The directory where the Kafka scripts are. # # @param service_name # Set the name of the service. # # @param manage_service # Install the init.d or systemd service. # # @param service_ensure # Set the ensure state of the service. # # @param service_restart # Whether the configuration files should trigger a service restart. # # @param service_requires # Set the list of services required to be running before Kafka. # # @param limit_nofile # Set the 'LimitNOFILE' option of the systemd service. # # @param limit_core # Set the 'LimitCORE' option of the systemd service. # # @param env # A hash of the environment variables to set. # # @param consumer_config # A hash of the consumer configuration options. # # @param producer_config # A hash of the producer configuration options. # # @param service_config # A hash of the mirror script options. # # @param heap_opts # Set the Java heap size. # # @param jmx_opts # Set the JMX options. # # @param log4j_opts # Set the Log4j options. # class kafka::mirror ( String[1] $kafka_version = $kafka::params::kafka_version, String[1] $scala_version = $kafka::params::scala_version, Stdlib::Absolutepath $install_dir = $kafka::params::install_dir, Stdlib::HTTPUrl $mirror_url = $kafka::params::mirror_url, Boolean $manage_java = $kafka::params::manage_java, Stdlib::Absolutepath $package_dir = $kafka::params::package_dir, Optional[String[1]] $package_name = $kafka::params::package_name, String[1] $package_ensure = $kafka::params::package_ensure, String[1] $user_name = $kafka::params::user_name, Stdlib::Absolutepath $user_shell = $kafka::params::user_shell, String[1] $group_name = $kafka::params::group_name, Optional[Integer] $user_id = $kafka::params::user_id, Optional[Integer] $group_id = $kafka::params::group_id, Boolean $manage_user = $kafka::params::manage_user, Boolean $manage_group = $kafka::params::manage_group, Stdlib::Filemode $config_mode = $kafka::params::config_mode, Stdlib::Absolutepath $config_dir = $kafka::params::config_dir, Stdlib::Absolutepath $log_dir = $kafka::params::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::params::bin_dir, String[1] $service_name = 'kafka-mirror', Boolean $manage_service = $kafka::params::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::params::service_ensure, Boolean $service_restart = $kafka::params::service_restart, Array[String[1]] $service_requires = $kafka::params::service_requires, Optional[String[1]] $limit_nofile = $kafka::params::limit_nofile, Optional[String[1]] $limit_core = $kafka::params::limit_core, Hash $env = {}, Hash[String[1],String[1]] $consumer_config = {}, Hash[String[1],String[1]] $producer_config = {}, Hash[String[1],String[1]] $service_config = {}, String[1] $heap_opts = $kafka::params::mirror_heap_opts, String[1] $jmx_opts = $kafka::params::mirror_jmx_opts, String[1] $log4j_opts = $kafka::params::mirror_log4j_opts, ) inherits kafka::params { - class { 'kafka::mirror::install': } -> class { 'kafka::mirror::config': } -> class { 'kafka::mirror::service': } -> Class['kafka::mirror'] } diff --git a/manifests/mirror/config.pp b/manifests/mirror/config.pp index 38a667a..9bd1bd2 100644 --- a/manifests/mirror/config.pp +++ b/manifests/mirror/config.pp @@ -1,51 +1,50 @@ # @summary # This class handles the Kafka (mirror) config. # # @api private # -class kafka::mirror::config( +class kafka::mirror::config ( Boolean $manage_service = $kafka::mirror::manage_service, String[1] $service_name = $kafka::mirror::service_name, Boolean $service_restart = $kafka::mirror::service_restart, Hash[String[1],String[1]] $consumer_config = $kafka::mirror::consumer_config, Hash[String[1],String[1]] $producer_config = $kafka::mirror::producer_config, Stdlib::Absolutepath $config_dir = $kafka::mirror::config_dir, String[1] $user_name = $kafka::mirror::user_name, String[1] $group_name = $kafka::mirror::group_name, Stdlib::Filemode $config_mode = $kafka::mirror::config_mode, ) { - assert_private() if $consumer_config['group.id'] == '' { fail('[Consumer] You need to specify a value for group.id') } if $consumer_config['zookeeper.connect'] == '' { fail('[Consumer] You need to specify a value for zookeeper.connect') } if $producer_config['bootstrap.servers'] == '' { fail('[Producer] You need to specify a value for bootstrap.servers') } class { 'kafka::consumer::config': manage_service => $manage_service, service_name => $service_name, service_restart => $service_restart, config => $consumer_config, config_dir => $config_dir, user_name => $user_name, group_name => $group_name, config_mode => $config_mode, } class { 'kafka::producer::config': manage_service => $manage_service, service_name => $service_name, service_restart => $service_restart, config => $producer_config, config_dir => $config_dir, user_name => $user_name, group_name => $group_name, config_mode => $config_mode, } } diff --git a/manifests/mirror/install.pp b/manifests/mirror/install.pp index d243aa4..f310bda 100644 --- a/manifests/mirror/install.pp +++ b/manifests/mirror/install.pp @@ -1,31 +1,30 @@ # @summary # This class handles the Kafka (mirror) package. # # @api private # class kafka::mirror::install { - assert_private() if !defined(Class['kafka']) { class { 'kafka': manage_java => $kafka::mirror::manage_java, manage_group => $kafka::mirror::manage_group, group_id => $kafka::mirror::group_id, group_name => $kafka::mirror::group_name, manage_user => $kafka::mirror::manage_user, user_id => $kafka::mirror::user_id, user_name => $kafka::mirror::user_name, user_shell => $kafka::mirror::user_shell, config_dir => $kafka::mirror::config_dir, log_dir => $kafka::mirror::log_dir, mirror_url => $kafka::mirror::mirror_url, kafka_version => $kafka::mirror::kafka_version, scala_version => $kafka::mirror::scala_version, install_dir => $kafka::mirror::install_dir, package_dir => $kafka::mirror::package_dir, package_ensure => $kafka::mirror::package_ensure, package_name => $kafka::mirror::package_name, } } } diff --git a/manifests/mirror/service.pp b/manifests/mirror/service.pp index 015c912..91e9cd8 100644 --- a/manifests/mirror/service.pp +++ b/manifests/mirror/service.pp @@ -1,69 +1,68 @@ # @summary # This class handles the Kafka (mirror) service. # # @api private # -class kafka::mirror::service( +class kafka::mirror::service ( Boolean $manage_service = $kafka::mirror::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::mirror::service_ensure, String[1] $service_name = $kafka::mirror::service_name, String[1] $user_name = $kafka::mirror::user_name, String[1] $group_name = $kafka::mirror::group_name, Stdlib::Absolutepath $config_dir = $kafka::mirror::config_dir, Stdlib::Absolutepath $log_dir = $kafka::mirror::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::mirror::bin_dir, Array[String[1]] $service_requires = $kafka::mirror::service_requires, Optional[String[1]] $limit_nofile = $kafka::mirror::limit_nofile, Optional[String[1]] $limit_core = $kafka::mirror::limit_core, Hash $env = $kafka::mirror::env, Hash[String[1],String[1]] $consumer_config = $kafka::mirror::consumer_config, Hash[String[1],String[1]] $producer_config = $kafka::mirror::producer_config, Hash[String[1],String[1]] $service_config = $kafka::mirror::service_config, String[1] $heap_opts = $kafka::mirror::heap_opts, String[1] $jmx_opts = $kafka::mirror::jmx_opts, String[1] $log4j_opts = $kafka::mirror::log4j_opts, ) { - assert_private() if $manage_service { $env_defaults = { 'KAFKA_HEAP_OPTS' => $heap_opts, 'KAFKA_JMX_OPTS' => $jmx_opts, 'KAFKA_LOG4J_OPTS' => $log4j_opts, } $environment = deep_merge($env_defaults, $env) if $facts['service_provider'] == 'systemd' { include systemd file { "/etc/systemd/system/${service_name}.service": ensure => file, mode => '0644', content => template('kafka/unit.erb'), } file { "/etc/init.d/${service_name}": ensure => absent, } File["/etc/systemd/system/${service_name}.service"] ~> Exec['systemctl-daemon-reload'] -> Service[$service_name] } else { file { "/etc/init.d/${service_name}": ensure => file, mode => '0755', content => template('kafka/init.erb'), before => Service[$service_name], } } service { $service_name: ensure => $service_ensure, enable => true, hasstatus => true, hasrestart => true, } } } diff --git a/manifests/params.pp b/manifests/params.pp index 5297349..d322a8c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,61 +1,61 @@ # @summary # This class provides default parameters. # class kafka::params { unless $facts['os']['family'] =~ /(RedHat|Debian|Suse)/ { warning("${facts['os']['family']} is not supported") } $kafka_version = '2.4.1' $scala_version = '2.12' $install_dir = "/opt/kafka-${scala_version}-${kafka_version}" $config_dir = '/opt/kafka/config' $bin_dir = '/opt/kafka/bin' $log_dir = '/var/log/kafka' - $mirror_url = 'https://www.apache.org/dyn/closer.lua?action=download&filename=' + $mirror_url = 'https://archive.apache.org/dist/' $mirror_subpath = "kafka/${kafka_version}" $manage_java = false $package_dir = '/var/tmp/kafka' $package_name = undef $proxy_server = undef $proxy_host = undef $proxy_port = undef $proxy_type = undef $package_ensure = 'present' $user_name = 'kafka' $user_shell = '/sbin/nologin' $group_name = 'kafka' $user_id = undef $group_id = undef $system_user = false $system_group = false $manage_user = true $manage_group = true $config_mode = '0644' $install_mode = '0755' $manage_service = true $service_ensure = 'running' $service_restart = true $service_requires = ['network.target', 'syslog.target'] $limit_nofile = undef $limit_core = undef $timeout_stop = undef $exec_stop = false $daemon_start = false $broker_heap_opts = '-Xmx1G -Xms1G' $broker_jmx_opts = '-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9990' $broker_log4j_opts = "-Dlog4j.configuration=file:${config_dir}/log4j.properties" $broker_opts = '' $mirror_heap_opts = '-Xmx256M' $mirror_jmx_opts = '-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9991' $mirror_log4j_opts = $broker_log4j_opts $producer_jmx_opts = '-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9992' $producer_log4j_opts = $broker_log4j_opts $consumer_jmx_opts = '-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9993' $consumer_log4j_opts = $broker_log4j_opts } diff --git a/manifests/producer.pp b/manifests/producer.pp index 6981717..45f7561 100644 --- a/manifests/producer.pp +++ b/manifests/producer.pp @@ -1,147 +1,146 @@ # @summary # This class handles the Kafka (producer). # # @example Basic usage # class { 'kafka::producer': # config => { # 'client.id' => '0', # 'zookeeper.connect' => 'localhost:2181' # } # } # # @param input # Set named pipe as input. # # @param kafka_version # The version of Kafka that should be installed. # # @param scala_version # The scala version what Kafka was built with. # # @param install_dir # The directory to install Kafka to. # # @param mirror_url # The url where the Kafka is downloaded from. # # @param manage_java # Install java if it's not already installed. # # @param package_dir # The directory to install Kafka. # # @param package_name # Package name, when installing Kafka from a package. # # @param package_ensure # Package version or ensure state, when installing Kafka from a package. # # @param user_name # User to run Kafka as. # # @param user_shell # Login shell of the Kafka user. # # @param group_name # Group to run Kafka as. # # @param user_id # Create the Kafka user with this ID. # # @param group_id # Create the Kafka group with this ID. # # @param manage_user # Create the Kafka user if it's not already present. # # @param manage_group # Create the Kafka group if it's not already present. # # @param config_mode # The permissions for the config files. # # @param config_dir # The directory to create the Kafka config files to. # # @param log_dir # The directory for Kafka log files. # # @param bin_dir # The directory where the Kafka scripts are. # # @param service_name # Set the name of the service. # # @param manage_service # Install the init.d or systemd service. # # @param service_ensure # Set the ensure state of the service. # # @param service_restart # Whether the configuration files should trigger a service restart. # # @param service_requires # Set the list of services required to be running before Kafka. # # @param limit_nofile # Set the 'LimitNOFILE' option of the systemd service. # # @param limit_core # Set the 'LimitCORE' option of the systemd service. # # @param env # A hash of the environment variables to set. # # @param config # A hash of the producer configuration options. # # @param service_config # A hash of the `kafka-console-producer.sh` script options. # # @param jmx_opts # Set the JMX options. # # @param log4j_opts # Set the Log4j options. # class kafka::producer ( Optional[String[1]] $input, String[1] $kafka_version = $kafka::params::kafka_version, String[1] $scala_version = $kafka::params::scala_version, Stdlib::Absolutepath $install_dir = $kafka::params::install_dir, Stdlib::HTTPUrl $mirror_url = $kafka::params::mirror_url, Boolean $manage_java = $kafka::params::manage_java, Stdlib::Absolutepath $package_dir = $kafka::params::package_dir, Optional[String[1]] $package_name = $kafka::params::package_name, String[1] $package_ensure = $kafka::params::package_ensure, String[1] $user_name = $kafka::params::user_name, Stdlib::Absolutepath $user_shell = $kafka::params::user_shell, String[1] $group_name = $kafka::params::group_name, Optional[Integer] $user_id = $kafka::params::user_id, Optional[Integer] $group_id = $kafka::params::group_id, Boolean $manage_user = $kafka::params::manage_user, Boolean $manage_group = $kafka::params::manage_group, Stdlib::Filemode $config_mode = $kafka::params::config_mode, Stdlib::Absolutepath $config_dir = $kafka::params::config_dir, Stdlib::Absolutepath $log_dir = $kafka::params::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::params::bin_dir, String[1] $service_name = 'kafka-producer', Boolean $manage_service = $kafka::params::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::params::service_ensure, Boolean $service_restart = $kafka::params::service_restart, Array[String[1]] $service_requires = $kafka::params::service_requires, Optional[String[1]] $limit_nofile = $kafka::params::limit_nofile, Optional[String[1]] $limit_core = $kafka::params::limit_core, Hash $env = {}, Hash[String[1], Any] $config = {}, Hash[String[1],String[1]] $service_config = {}, String[1] $jmx_opts = $kafka::params::producer_jmx_opts, String[1] $log4j_opts = $kafka::params::producer_log4j_opts, ) inherits kafka::params { - class { 'kafka::producer::install': } -> class { 'kafka::producer::config': } -> class { 'kafka::producer::service': } -> Class['kafka::producer'] } diff --git a/manifests/producer/config.pp b/manifests/producer/config.pp index 36a8c13..7869830 100644 --- a/manifests/producer/config.pp +++ b/manifests/producer/config.pp @@ -1,31 +1,30 @@ # @summary # This class handles the Kafka (producer) config. # -class kafka::producer::config( +class kafka::producer::config ( Boolean $manage_service = $kafka::producer::manage_service, String[1] $service_name = $kafka::producer::service_name, Boolean $service_restart = $kafka::producer::service_restart, Hash[String[1], Any] $config = $kafka::producer::config, Stdlib::Absolutepath $config_dir = $kafka::producer::config_dir, String[1] $user_name = $kafka::producer::user_name, String[1] $group_name = $kafka::producer::group_name, Stdlib::Filemode $config_mode = $kafka::producer::config_mode, ) { - if ($manage_service and $service_restart) { $config_notify = Service[$service_name] } else { $config_notify = undef } $doctag = 'producerconfigs' file { "${config_dir}/producer.properties": - ensure => present, + ensure => file, owner => $user_name, group => $group_name, mode => $config_mode, content => template('kafka/properties.erb'), notify => $config_notify, require => File[$config_dir], } } diff --git a/manifests/producer/install.pp b/manifests/producer/install.pp index fbb7a2c..6200791 100644 --- a/manifests/producer/install.pp +++ b/manifests/producer/install.pp @@ -1,31 +1,30 @@ # @summary # This class handles the Kafka (producer) package. # # @api private # class kafka::producer::install { - assert_private() if !defined(Class['kafka']) { class { 'kafka': manage_java => $kafka::producer::manage_java, manage_group => $kafka::producer::manage_group, group_id => $kafka::producer::group_id, group_name => $kafka::producer::group_name, manage_user => $kafka::producer::manage_user, user_id => $kafka::producer::user_id, user_name => $kafka::producer::user_name, user_shell => $kafka::producer::user_shell, config_dir => $kafka::producer::config_dir, log_dir => $kafka::producer::log_dir, mirror_url => $kafka::producer::mirror_url, kafka_version => $kafka::producer::kafka_version, scala_version => $kafka::producer::scala_version, install_dir => $kafka::producer::install_dir, package_dir => $kafka::producer::package_dir, package_ensure => $kafka::producer::package_ensure, package_name => $kafka::producer::package_name, } } } diff --git a/manifests/producer/service.pp b/manifests/producer/service.pp index 7d8b4a9..89f44c9 100644 --- a/manifests/producer/service.pp +++ b/manifests/producer/service.pp @@ -1,60 +1,58 @@ # @summary # This class handles the Kafka (producer) service. # # @api private # -class kafka::producer::service( +class kafka::producer::service ( Boolean $manage_service = $kafka::producer::manage_service, Enum['running', 'stopped'] $service_ensure = $kafka::producer::service_ensure, String[1] $service_name = $kafka::producer::service_name, String[1] $user_name = $kafka::producer::user_name, String[1] $group_name = $kafka::producer::group_name, Stdlib::Absolutepath $config_dir = $kafka::producer::config_dir, Stdlib::Absolutepath $log_dir = $kafka::producer::log_dir, Stdlib::Absolutepath $bin_dir = $kafka::producer::bin_dir, Array[String[1]] $service_requires = $kafka::producer::service_requires, Optional[String[1]] $limit_nofile = $kafka::producer::limit_nofile, Optional[String[1]] $limit_core = $kafka::producer::limit_core, Hash $env = $kafka::producer::env, Optional[String[1]] $input = $kafka::producer::input, String[1] $jmx_opts = $kafka::producer::jmx_opts, String[1] $log4j_opts = $kafka::producer::log4j_opts, Hash[String[1],String[1]] $service_config = $kafka::producer::service_config, ) { - assert_private() if $manage_service { - if $service_config['broker-list'] == '' { fail('[Producer] You need to specify a value for broker-list') } if $service_config['topic'] == '' { fail('[Producer] You need to specify a value for topic') } $env_defaults = { 'KAFKA_JMX_OPTS' => $jmx_opts, 'KAFKA_LOG4J_OPTS' => $log4j_opts, } $environment = deep_merge($env_defaults, $env) if $facts['service_provider'] == 'systemd' { fail('Console Producer is not supported on systemd, because the stdin of the process cannot be redirected') } else { file { "/etc/init.d/${service_name}": ensure => file, mode => '0755', content => template('kafka/init.erb'), before => Service[$service_name], } } service { $service_name: ensure => $service_ensure, enable => true, hasstatus => true, hasrestart => true, } } } diff --git a/manifests/topic.pp b/manifests/topic.pp index fc0f8d5..95c5bed 100644 --- a/manifests/topic.pp +++ b/manifests/topic.pp @@ -1,68 +1,67 @@ # @summary # This defined type handles the creation of Kafka topics. # # @example Basic usage # kafka::topic { 'test': # ensure => present, # zookeeper => 'localhost:2181', # replication_factor => 1, # partitions => 1, # } # # @param ensure # Should the topic be created. # # @param zookeeper # The connection string for the ZooKeeper connection in the form host:port. # Multiple hosts can be given to allow fail-over. # # @param replication_factor # The replication factor for each partition in the topic being created. If # not supplied, defaults to the cluster default. # # @param partitions # The number of partitions for the topic being created or altered. If not # supplied for create, defaults to the cluster default. # # @param bin_dir # The directory where the file kafka-topics.sh is located. # # @param config # A topic configuration override for the topic being created or altered. # See the Kafka documentation for full details on the topic configs. # -define kafka::topic( +define kafka::topic ( String[1] $ensure = '', String[1] $zookeeper = '', Variant[Integer,String[1]] $replication_factor = 1, Variant[Integer,String[1]] $partitions = 1, String[1] $bin_dir = '/opt/kafka/bin', Optional[Hash[String[1],String[1]]] $config = undef, ) { - if is_string($replication_factor) { deprecation('kafka::topic', 'Please use Integer type, not String, for paramter replication_factor') } if is_string($partitions) { deprecation('kafka::topic', 'Please use Integer type, not String, for paramter partitions') } $_zookeeper = "--zookeeper ${zookeeper}" $_replication_factor = "--replication-factor ${replication_factor}" $_partitions = "--partitions ${partitions}" if $config { $_config_array = $config.map |$key, $value| { "--config ${key}=${value}" } $_config = join($_config_array, ' ') } else { $_config = '' } if $ensure == 'present' { exec { "create topic ${name}": path => "/usr/bin:/usr/sbin/:/bin:/sbin:${bin_dir}", command => "kafka-topics.sh --create ${_zookeeper} ${_replication_factor} ${_partitions} --topic ${name} ${_config}", unless => "kafka-topics.sh --list ${_zookeeper} | grep -x ${name}", } } } diff --git a/metadata.json b/metadata.json index 187fd40..f7c0780 100644 --- a/metadata.json +++ b/metadata.json @@ -1,81 +1,79 @@ { "name": "puppet-kafka", "version": "7.0.1-rc0", "author": "Vox Pupuli", "summary": "Puppet module for Kafka", "license": "MIT", "source": "https://github.com/voxpupuli/puppet-kafka", "project_page": "https://github.com/voxpupuli/puppet-kafka", "issues_url": "https://github.com/voxpupuli/puppet-kafka/issues", "dependencies": [ { "name": "puppet/archive", "version_requirement": ">= 1.0.0 < 5.0.0" }, { "name": "puppetlabs/java", "version_requirement": ">= 1.4.2 < 6.0.0" }, { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.22.0 < 7.0.0" }, { "name": "deric/zookeeper", "version_requirement": ">= 0.5.1 < 2.0.0" }, { "name": "camptocamp/systemd", "version_requirement": ">= 0.4.0 < 3.0.0" } ], "operatingsystem_support": [ { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "6", "7" ] }, { "operatingsystem": "RedHat", "operatingsystemrelease": [ - "6", "7" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "16.04", "18.04" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ "8", "9", "10" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "11", "12", "15" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 5.5.8 < 7.0.0" } ], "tags": [ "kafka", "pubsub" ] } diff --git a/spec/acceptance/01_zookeeper_spec.rb b/spec/acceptance/01_zookeeper_spec.rb index acfcfeb..e2b8f31 100644 --- a/spec/acceptance/01_zookeeper_spec.rb +++ b/spec/acceptance/01_zookeeper_spec.rb @@ -1,41 +1,36 @@ require 'spec_helper_acceptance' describe 'zookeeper prereq' do zookeeper = <<-EOS if $::osfamily == 'RedHat' { class { 'java' : package => 'java-1.8.0-openjdk-devel', } exec { 'create pid dir': command => '/bin/mkdir -p /var/run/', creates => '/var/run/', } file { '/var/run/zookeeper/': ensure => directory, owner => 'zookeeper', group => 'zookeeper', } - $zookeeper_service_provider = $facts['os']['release']['major'] ? { - '6' => 'redhat', - '7' => 'systemd', - } - class { 'zookeeper': install_method => 'archive', archive_version => '3.6.1', - service_provider => $zookeeper_service_provider, manage_service_file => true, + archive_dl_site => 'https://archive.apache.org/dist/zookeeper', } } else { include zookeeper } EOS it 'installs zookeeper with no errors' do apply_manifest(zookeeper, catch_failures: true) apply_manifest(zookeeper, catch_changes: true) end end diff --git a/spec/acceptance/broker_spec.rb b/spec/acceptance/broker_spec.rb index 6f90278..4b9136f 100644 --- a/spec/acceptance/broker_spec.rb +++ b/spec/acceptance/broker_spec.rb @@ -1,245 +1,226 @@ require 'spec_helper_acceptance' -if fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat' - user_shell = '/bin/bash' -else - case fact('osfamily') - when 'RedHat', 'Suse' - user_shell = '/sbin/nologin' - when 'Debian' - user_shell = '/usr/sbin/nologin' - end +case fact('osfamily') +when 'RedHat', 'Suse' + user_shell = '/sbin/nologin' +when 'Debian' + user_shell = '/usr/sbin/nologin' end describe 'kafka::broker' do it 'works with no errors' do pp = <<-EOS class { 'kafka::broker': config => { 'zookeeper.connect' => 'localhost:2181', }, } -> kafka::topic { 'demo': ensure => present, zookeeper => 'localhost:2181', } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe 'kafka::broker::install' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::broker': config => { 'zookeeper.connect' => 'localhost:2181', }, } EOS apply_manifest(pp, catch_failures: true) end describe group('kafka') do it { is_expected.to exist } end describe user('kafka') do it { is_expected.to exist } it { is_expected.to belong_to_group 'kafka' } it { is_expected.to have_login_shell user_shell } end describe file('/var/tmp/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka-2.12-2.4.1') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka') do it { is_expected.to be_linked_to('/opt/kafka-2.12-2.4.1') } end describe file('/opt/kafka/config') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/var/log/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end describe 'kafka::broker::config' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::broker': config => { 'zookeeper.connect' => 'localhost:2181', }, } EOS apply_manifest(pp, catch_failures: true) end describe file('/opt/kafka/config/server.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } it { is_expected.to contain 'zookeeper.connect=localhost:2181' } end end context 'with custom config dir' do it 'works with no errors' do pp = <<-EOS class { 'kafka::broker': config => { 'zookeeper.connect' => 'localhost:2181', }, config_dir => '/opt/kafka/custom_config' } EOS apply_manifest(pp, catch_failures: true) end describe file('/opt/kafka/custom_config/server.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } it { is_expected.to contain 'zookeeper.connect=localhost:2181' } end end context 'with specific version' do it 'works with no errors' do pp = <<-EOS class { 'kafka::broker': kafka_version => '2.4.0', config => { 'zookeeper.connect' => 'localhost:2181', }, } EOS apply_manifest(pp, catch_failures: true) end describe file('/opt/kafka/config/server.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end describe 'kafka::broker::service' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::broker': config => { 'zookeeper.connect' => 'localhost:2181', }, } EOS apply_manifest(pp, catch_failures: true) end - describe file('/etc/init.d/kafka'), if: (fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - end - describe file('/etc/systemd/system/kafka.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } end describe service('kafka') do it { is_expected.to be_running } it { is_expected.to be_enabled } end end end describe 'kafka::broker::service' do context 'with log4j/jmx parameters' do it 'works with no errors' do pp = <<-EOS exec { 'create log dir': command => '/bin/mkdir -p /some/path/to/logs', creates => '/some/path/to/logs', } -> class { 'kafka::broker': config => { 'zookeeper.connect' => 'localhost:2181', }, heap_opts => '-Xmx512M -Xmx512M', log4j_opts => '-Dlog4j.configuration=file:/tmp/log4j.properties', jmx_opts => '-Dcom.sun.management.jmxremote', opts => '-Djava.security.policy=/some/path/my.policy', log_dir => '/some/path/to/logs' } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end - describe file('/etc/init.d/kafka'), if: (fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote"' } - it { is_expected.to contain 'export KAFKA_HEAP_OPTS="-Xmx512M -Xmx512M"' } - it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/tmp/log4j.properties"' } - end - describe file('/etc/init.d/kafka'), if: (fact('service_provider') == 'upstart' && fact('osfamily') == 'Debian') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } it { is_expected.to contain %r{^# Provides:\s+kafka$} } it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote"' } it { is_expected.to contain 'export KAFKA_HEAP_OPTS="-Xmx512M -Xmx512M"' } it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/tmp/log4j.properties"' } end describe file('/etc/systemd/system/kafka.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } it { is_expected.to contain "Environment='KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote'" } it { is_expected.to contain "Environment='KAFKA_HEAP_OPTS=-Xmx512M -Xmx512M'" } it { is_expected.to contain "Environment='KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:/tmp/log4j.properties'" } it { is_expected.to contain "Environment='KAFKA_OPTS=-Djava.security.policy=/some/path/my.policy'" } it { is_expected.to contain "Environment='LOG_DIR=/some/path/to/logs'" } end describe service('kafka') do it { is_expected.to be_running } it { is_expected.to be_enabled } end end end end diff --git a/spec/acceptance/consumer_spec.rb b/spec/acceptance/consumer_spec.rb index 5813475..812abff 100644 --- a/spec/acceptance/consumer_spec.rb +++ b/spec/acceptance/consumer_spec.rb @@ -1,177 +1,165 @@ require 'spec_helper_acceptance' -if fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat' - user_shell = '/bin/bash' -else - case fact('osfamily') - when 'RedHat', 'Suse' - user_shell = '/sbin/nologin' - when 'Debian' - user_shell = '/usr/sbin/nologin' - end +case fact('osfamily') +when 'RedHat', 'Suse' + user_shell = '/sbin/nologin' +when 'Debian' + user_shell = '/usr/sbin/nologin' end describe 'kafka::consumer' do it 'works with no errors' do pp = <<-EOS class { 'kafka::consumer': service_config => { topic => 'demo', bootstrap-server => 'localhost:9092', }, } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe 'kafka::consumer::install' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::consumer': service_config => { topic => 'demo', bootstrap-server => 'localhost:9092', }, } EOS apply_manifest(pp, catch_failures: true) end describe group('kafka') do it { is_expected.to exist } end describe user('kafka') do it { is_expected.to exist } it { is_expected.to belong_to_group 'kafka' } it { is_expected.to have_login_shell user_shell } end describe file('/var/tmp/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka-2.12-2.4.1') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka') do it { is_expected.to be_linked_to('/opt/kafka-2.12-2.4.1') } end describe file('/opt/kafka/config') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/var/log/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end describe 'kafka::consumer::config' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::consumer': service_config => { topic => 'demo', bootstrap-server => 'localhost:9092', }, } EOS apply_manifest(pp, catch_failures: true) end describe file('/opt/kafka/config/consumer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end describe 'kafka::consumer::config' do context 'with custom config_dir' do it 'works with no errors' do pp = <<-EOS class { 'kafka::consumer': service_config => { topic => 'demo', bootstrap-server => 'localhost:9092', }, config_dir => '/opt/kafka/custom_config', } EOS apply_manifest(pp, catch_failures: true) end describe file('/opt/kafka/custom_config/consumer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end describe 'kafka::consumer::service' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::consumer': service_config => { topic => 'demo', bootstrap-server => 'localhost:9092', }, } EOS apply_manifest(pp, catch_failures: true) end - describe file('/etc/init.d/kafka-consumer'), if: (fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9993"' } - it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"' } - end - describe file('/etc/init.d/kafka-consumer'), if: (fact('service_provider') == 'upstart' && fact('osfamily') == 'Debian') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } it { is_expected.to contain %r{^# Provides:\s+kafka-consumer$} } it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9993"' } it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"' } end describe file('/etc/systemd/system/kafka-consumer.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } it { is_expected.to contain 'Environment=\'KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9993\'' } it { is_expected.to contain 'Environment=\'KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties\'' } end describe service('kafka-consumer') do it { is_expected.to be_running } it { is_expected.to be_enabled } end end end end diff --git a/spec/acceptance/init_spec.rb b/spec/acceptance/init_spec.rb index 53c4db3..df552dc 100644 --- a/spec/acceptance/init_spec.rb +++ b/spec/acceptance/init_spec.rb @@ -1,223 +1,219 @@ require 'spec_helper_acceptance' -if fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat' - user_shell = '/bin/bash' -else - case fact('osfamily') - when 'RedHat', 'Suse' - user_shell = '/sbin/nologin' - when 'Debian' - user_shell = '/usr/sbin/nologin' - end +case fact('osfamily') +when 'RedHat', 'Suse' + user_shell = '/sbin/nologin' +when 'Debian' + user_shell = '/usr/sbin/nologin' end describe 'kafka' do it 'works with no errors' do pp = <<-EOS class { 'kafka': } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe 'kafka::init' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka': } EOS apply_manifest(pp, catch_failures: true) end describe group('kafka') do it { is_expected.to exist } end describe user('kafka') do it { is_expected.to exist } it { is_expected.to belong_to_group 'kafka' } it { is_expected.to have_login_shell user_shell } end describe file('/var/tmp/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka-2.12-2.4.1') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka') do it { is_expected.to be_linked_to('/opt/kafka-2.12-2.4.1') } end describe file('/opt/kafka/config') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/var/log/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end context 'with specific kafka version' do it 'works with no errors' do pp = <<-EOS class { 'kafka': kafka_version => '2.4.0', } EOS apply_manifest(pp, catch_failures: true) end describe group('kafka') do it { is_expected.to exist } end describe user('kafka') do it { is_expected.to exist } it { is_expected.to belong_to_group 'kafka' } it { is_expected.to have_login_shell user_shell } end describe file('/var/tmp/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka-2.12-2.4.0') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka') do it { is_expected.to be_linked_to('/opt/kafka-2.12-2.4.0') } end describe file('/opt/kafka/config') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/var/log/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end context 'with specific scala version' do it 'works with no errors' do pp = <<-EOS class { 'kafka': scala_version => '2.13', } EOS apply_manifest(pp, catch_failures: true) end describe group('kafka') do it { is_expected.to exist } end describe user('kafka') do it { is_expected.to exist } it { is_expected.to belong_to_group 'kafka' } it { is_expected.to have_login_shell user_shell } end describe file('/var/tmp/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka-2.13-2.4.1') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka') do it { is_expected.to be_linked_to('/opt/kafka-2.13-2.4.1') } end describe file('/opt/kafka/config') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/var/log/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end context 'with specific config dir' do it 'works with no errors' do pp = <<-EOS class { 'kafka': config_dir => '/opt/kafka/custom_config', } EOS apply_manifest(pp, catch_failures: true) end describe group('kafka') do it { is_expected.to exist } end describe user('kafka') do it { is_expected.to exist } it { is_expected.to belong_to_group 'kafka' } it { is_expected.to have_login_shell user_shell } end describe file('/var/tmp/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka-2.12-2.4.1') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka') do it { is_expected.to be_linked_to('/opt/kafka-2.12-2.4.1') } end describe file('/opt/kafka/custom_config') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/var/log/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end end diff --git a/spec/acceptance/mirror_spec.rb b/spec/acceptance/mirror_spec.rb index d5144e7..443d144 100644 --- a/spec/acceptance/mirror_spec.rb +++ b/spec/acceptance/mirror_spec.rb @@ -1,255 +1,243 @@ require 'spec_helper_acceptance' -if fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat' - user_shell = '/bin/bash' -else - case fact('osfamily') - when 'RedHat', 'Suse' - user_shell = '/sbin/nologin' - when 'Debian' - user_shell = '/usr/sbin/nologin' - end +case fact('osfamily') +when 'RedHat', 'Suse' + user_shell = '/sbin/nologin' +when 'Debian' + user_shell = '/usr/sbin/nologin' end describe 'kafka::mirror' do it 'works with no errors' do pp = <<-EOS class { 'kafka::mirror': consumer_config => { 'group.id' => 'kafka-mirror', 'bootstrap.servers' => 'localhost:9092', }, producer_config => { 'bootstrap.servers' => 'localhost:9092', }, service_config => { 'whitelist' => '.*', }, } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe 'kafka::mirror::install' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::mirror': consumer_config => { 'group.id' => 'kafka-mirror', 'bootstrap.servers' => 'localhost:9092', }, producer_config => { 'bootstrap.servers' => 'localhost:9092', }, service_config => { 'whitelist' => '.*', }, } EOS apply_manifest(pp, catch_failures: true) end describe group('kafka') do it { is_expected.to exist } end describe user('kafka') do it { is_expected.to exist } it { is_expected.to belong_to_group 'kafka' } it { is_expected.to have_login_shell user_shell } end describe file('/var/tmp/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka-2.12-2.4.1') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka') do it { is_expected.to be_linked_to('/opt/kafka-2.12-2.4.1') } end describe file('/opt/kafka/config') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/var/log/kafka') do it { is_expected.to be_directory } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end describe 'kafka::mirror::config' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::mirror': consumer_config => { 'group.id' => 'kafka-mirror', 'bootstrap.servers' => 'localhost:9092', }, producer_config => { 'bootstrap.servers' => 'localhost:9092', }, service_config => { 'whitelist' => '.*', }, } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe file('/opt/kafka/config/consumer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka/config/producer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end context 'with custom config_dir' do it 'works with no errors' do pp = <<-EOS class { 'kafka::mirror': consumer_config => { 'group.id' => 'kafka-mirror', 'bootstrap.servers' => 'localhost:9092', }, producer_config => { 'bootstrap.servers' => 'localhost:9092', }, service_config => { 'whitelist' => '.*', }, config_dir => '/opt/kafka/custom_config', } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe file('/opt/kafka/custom_config/consumer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka/custom_config/producer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end context 'with specific version' do it 'works with no errors' do pp = <<-EOS class { 'kafka::mirror': kafka_version => '2.4.0', consumer_config => { 'group.id' => 'kafka-mirror', 'bootstrap.servers' => 'localhost:9092', }, producer_config => { 'bootstrap.servers' => 'localhost:9092', }, service_config => { 'whitelist' => '.*', }, } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end describe file('/opt/kafka/config/consumer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end describe file('/opt/kafka/config/producer.properties') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'kafka' } it { is_expected.to be_grouped_into 'kafka' } end end end describe 'kafka::mirror::service' do context 'with default parameters' do it 'works with no errors' do pp = <<-EOS class { 'kafka::mirror': consumer_config => { 'group.id' => 'kafka-mirror', 'bootstrap.servers' => 'localhost:9092', }, producer_config => { 'bootstrap.servers' => 'localhost:9092', }, service_config => { 'whitelist' => '.*', }, } EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end - describe file('/etc/init.d/kafka-mirror'), if: (fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9991"' } - it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"' } - end - describe file('/etc/init.d/kafka-mirror'), if: (fact('service_provider') == 'upstart' && fact('osfamily') == 'Debian') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } it { is_expected.to contain %r{^# Provides:\s+kafka-mirror$} } it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9991"' } it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"' } end describe file('/etc/systemd/system/kafka-mirror.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } it { is_expected.to contain 'Environment=\'KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9991\'' } it { is_expected.to contain 'Environment=\'KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties\'' } end describe service('kafka-mirror') do it { is_expected.to be_running } it { is_expected.to be_enabled } end end end end diff --git a/spec/acceptance/producer_spec.rb b/spec/acceptance/producer_spec.rb deleted file mode 100644 index 2df0dce..0000000 --- a/spec/acceptance/producer_spec.rb +++ /dev/null @@ -1,162 +0,0 @@ -require 'spec_helper_acceptance' - -if fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat' - user_shell = '/bin/bash' -else - case fact('osfamily') - when 'RedHat', 'Suse' - user_shell = '/sbin/nologin' - when 'Debian' - user_shell = '/usr/sbin/nologin' - end -end - -describe 'kafka::producer', if: (fact('operatingsystemmajrelease') == '6' && fact('osfamily') == 'RedHat') do # systemd systems not supported by kafka::producer::service - it 'works with no errors' do - pp = <<-EOS - exec { 'create fifo': - command => '/usr/bin/mkfifo /tmp/kafka-producer', - user => 'kafka', - creates => '/tmp/kafka-producer', - } -> - class { 'kafka::producer': - service_config => { - 'broker-list' => 'localhost:9092', - topic => 'demo', - }, - input => '3<>/tmp/kafka-producer 0>&3', - } - EOS - - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe 'kafka::producer::install' do - context 'with default parameters' do - it 'works with no errors' do - pp = <<-EOS - exec { 'create fifo': - command => '/usr/bin/mkfifo /tmp/kafka-producer', - user => 'kafka', - creates => '/tmp/kafka-producer', - } -> - class { 'kafka::producer': - service_config => { - 'broker-list' => 'localhost:9092', - topic => 'demo', - }, - input => '3<>/tmp/kafka-producer 0>&3', - } - EOS - - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe group('kafka') do - it { is_expected.to exist } - end - - describe user('kafka') do - it { is_expected.to exist } - it { is_expected.to belong_to_group 'kafka' } - it { is_expected.to have_login_shell user_shell } - end - - describe file('/var/tmp/kafka') do - it { is_expected.to be_directory } - it { is_expected.to be_owned_by 'kafka' } - it { is_expected.to be_grouped_into 'kafka' } - end - - describe file('/opt/kafka-2.12-2.4.1') do - it { is_expected.to be_directory } - it { is_expected.to be_owned_by 'kafka' } - it { is_expected.to be_grouped_into 'kafka' } - end - - describe file('/opt/kafka') do - it { is_expected.to be_linked_to('/opt/kafka-2.12-2.4.1') } - end - - describe file('/opt/kafka/config') do - it { is_expected.to be_directory } - it { is_expected.to be_owned_by 'kafka' } - it { is_expected.to be_grouped_into 'kafka' } - end - - describe file('/var/log/kafka') do - it { is_expected.to be_directory } - it { is_expected.to be_owned_by 'kafka' } - it { is_expected.to be_grouped_into 'kafka' } - end - end - end - - describe 'kafka::producer::config' do - context 'with default parameters' do - it 'works with no errors' do - pp = <<-EOS - exec { 'create fifo': - command => '/usr/bin/mkfifo /tmp/kafka-producer', - user => 'kafka', - creates => '/tmp/kafka-producer', - } -> - class { 'kafka::producer': - service_config => { - 'broker-list' => 'localhost:9092', - topic => 'demo', - }, - input => '3<>/tmp/kafka-producer 0>&3', - } - EOS - - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe file('/opt/kafka/config/producer.properties') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'kafka' } - it { is_expected.to be_grouped_into 'kafka' } - end - end - end - - describe 'kafka::producer::service' do - context 'with default parameters' do - it 'works with no errors' do - pp = <<-EOS - class { 'kafka::producer': - service_config => { - 'broker-list' => 'localhost:9092', - topic => 'demo', - }, - input => '3<>/tmp/kafka-producer 0>&3', - } - EOS - - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe file('/etc/init.d/kafka-producer') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9992"' } - it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"' } - end - - describe file('/etc/init.d/kafka-producer'), if: (fact('service_provider') == 'upstart' && fact('osfamily') == 'Debian') do - it { is_expected.to contain %r{^# Provides:\s+kafka-producer$} } - end - - describe service('kafka-producer') do - it { is_expected.to be_running } - it { is_expected.to be_enabled } - end - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b2b2704..d266f6b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,18 @@ # This file is managed via modulesync # https://github.com/voxpupuli/modulesync # https://github.com/voxpupuli/modulesync_config # puppetlabs_spec_helper will set up coverage if the env variable is set. # We want to do this if lib exists and it hasn't been explicitly set. ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__)) require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) - facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml'))) + facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) if facts facts.each do |name, value| add_custom_fact name.to_sym, value end end end