diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..ecb10a80 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# editorconfig.org + +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +tab_width = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.fixtures.yml b/.fixtures.yml index 7fc2ed14..80aacd50 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -4,3 +4,4 @@ fixtures: stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git zypprepo: https://github.com/voxpupuli/puppet-zypprepo.git elastic_stack: https://github.com/voxpupuli/puppet-elastic_stack.git + yumrepo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 00000000..8b466cfb --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,251 @@ +# Contribution guidelines + +## Table of contents + +* [Contributing](#contributing) +* [Writing proper commits - short version](#writing-proper-commits-short-version) +* [Writing proper commits - long version](#writing-proper-commits-long-version) +* [Dependencies](#dependencies) + * [Note for OS X users](#note-for-os-x-users) +* [The test matrix](#the-test-matrix) +* [Syntax and style](#syntax-and-style) +* [Running the unit tests](#running-the-unit-tests) +* [Unit tests in docker](#unit-tests-in-docker) +* [Integration tests](#integration-tests) + +This module has grown over time based on a range of contributions from +people using it. If you follow these contributing guidelines your patch +will likely make it into a release a little more quickly. + +## Contributing + +Please note that this project is released with a Contributor Code of Conduct. +By participating in this project you agree to abide by its terms. +[Contributor Code of Conduct](https://voxpupuli.org/coc/). + +* Fork the repo. +* Create a separate branch for your change. +* We only take pull requests with passing tests, and documentation. [GitHub Actions](https://docs.github.com/en/actions) run the tests for us. You can also execute them locally. This is explained [in a later section](#the-test-matrix). +* Checkout [our docs](https://voxpupuli.org/docs/reviewing_pr/) we use to review a module and the [official styleguide](https://puppet.com/docs/puppet/6.0/style_guide.html). They provide some guidance for new code that might help you before you submit a pull request. +* Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, please add a test. +* Squash your commits down into logical components. Make sure to rebase against our current master. +* Push the branch to your fork and submit a pull request. + +Please be prepared to repeat some of these steps as our contributors review your code. + +Also consider sending in your profile code that calls this component module as an acceptance test or provide it via an issue. This helps reviewers a lot to test your use case and prevents future regressions! + +## Writing proper commits - short version + +* Make commits of logical units. +* Check for unnecessary whitespace with "git diff --check" before committing. +* Commit using Unix line endings (check the settings around "crlf" in git-config(1)). +* Do not check in commented out code or unneeded files. +* The first line of the commit message should be a short description (50 characters is the soft limit, excluding ticket number(s)), and should skip the full stop. +* Associate the issue in the message. The first line should include the issue number in the form "(#XXXX) Rest of message". +* The body should provide a meaningful commit message, which: + *uses the imperative, present tense: `change`, not `changed` or `changes`. + * includes motivation for the change, and contrasts its implementation with the previous behavior. + * Make sure that you have tests for the bug you are fixing, or feature you are adding. + * Make sure the test suites passes after your commit: + * When introducing a new feature, make sure it is properly documented in the README.md + +## Writing proper commits - long version + + 1. Make separate commits for logically separate changes. + + Please break your commits down into logically consistent units + which include new or changed tests relevant to the rest of the + change. The goal of doing this is to make the diff easier to + read for whoever is reviewing your code. In general, the easier + your diff is to read, the more likely someone will be happy to + review it and get it into the code base. + + If you are going to refactor a piece of code, please do so as a + separate commit from your feature or bug fix changes. + + We also really appreciate changes that include tests to make + sure the bug is not re-introduced, and that the feature is not + accidentally broken. + + Describe the technical detail of the change(s). If your + description starts to get too long, that is a good sign that you + probably need to split up your commit into more finely grained + pieces. + + Commits which plainly describe the things which help + reviewers check the patch and future developers understand the + code are much more likely to be merged in with a minimum of + bike-shedding or requested changes. Ideally, the commit message + would include information, and be in a form suitable for + inclusion in the release notes for the version of Puppet that + includes them. + + Please also check that you are not introducing any trailing + whitespace or other "whitespace errors". You can do this by + running "git diff --check" on your changes before you commit. + + 2. Sending your patches + + To submit your changes via a GitHub pull request, we _highly_ + recommend that you have them on a topic branch, instead of + directly on `master`. + It makes things much easier to keep track of, especially if + you decide to work on another thing before your first change + is merged in. + + GitHub has some pretty good + [general documentation](http://help.github.com/) on using + their site. They also have documentation on + [creating pull requests](http://help.github.com/send-pull-requests/). + + In general, after pushing your topic branch up to your + repository on GitHub, you can switch to the branch in the + GitHub UI and click "Pull Request" towards the top of the page + in order to open a pull request. + + + 3. Update the related GitHub issue. + + If there is a GitHub issue associated with the change you + submitted, then you should update the ticket to include the + location of your branch, along with any other commentary you + may wish to make. + +## Dependencies + +The testing and development tools have a bunch of dependencies, +all managed by [bundler](http://bundler.io/) according to the +[Puppet support matrix](http://docs.puppetlabs.com/guides/platforms.html#ruby-versions). + +By default the tests use a baseline version of Puppet. + +If you have Ruby 2.x or want a specific version of Puppet, +you must set an environment variable such as: + +```sh +export PUPPET_GEM_VERSION="~> 6.1.0" +``` + +You can install all needed gems for spec tests into the modules directory by +running: + +```sh +bundle install --path .vendor/ --without development system_tests release --jobs "$(nproc)" +``` + +If you also want to run acceptance tests: + +```sh +bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)" +``` + +Our all in one solution if you don't know if you need to install or update gems: + +```sh +bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)"; bundle update; bundle clean +``` + +As an alternative to the `--jobs "$(nproc)` parameter, you can set an +environment variable: + +```sh +BUNDLE_JOBS="$(nproc)" +``` + +### Note for OS X users + +`nproc` isn't a valid command under OS x. As an alternative, you can do: + +```sh +--jobs "$(sysctl -n hw.ncpu)" +``` + +## The test matrix + +### Syntax and style + +The test suite will run [Puppet Lint](http://puppet-lint.com/) and +[Puppet Syntax](https://github.com/gds-operations/puppet-syntax) to +check various syntax and style things. You can run these locally with: + +```sh +bundle exec rake lint +bundle exec rake validate +``` + +It will also run some [Rubocop](http://batsov.com/rubocop/) tests +against it. You can run those locally ahead of time with: + +```sh +bundle exec rake rubocop +``` + +### Running the unit tests + +The unit test suite covers most of the code, as mentioned above please +add tests if you're adding new functionality. If you've not used +[rspec-puppet](http://rspec-puppet.com/) before then feel free to ask +about how best to test your new feature. + +To run the linter, the syntax checker and the unit tests: + +```sh +bundle exec rake test +``` + +To run your all the unit tests + +```sh +bundle exec rake spec +``` + +To run a specific spec test set the `SPEC` variable: + +```sh +bundle exec rake spec SPEC=spec/foo_spec.rb +``` + +#### Unit tests in docker + +Some people don't want to run the dependencies locally or don't want to install +ruby. We ship a Dockerfile that enables you to run all unit tests and linting. +You only need to run: + +```sh +docker build . +``` + +Please ensure that a docker daemon is running and that your user has the +permission to talk to it. You can specify a remote docker host by setting the +`DOCKER_HOST` environment variable. it will copy the content of the module into +the docker image. So it will not work if a Gemfile.lock exists. + +### Integration tests + +The unit tests just check the code runs, not that it does exactly what +we want on a real machine. For that we're using +[beaker](https://github.com/puppetlabs/beaker). + +This fires up a new virtual machine (using vagrant) and runs a series of +simple tests against it after applying the module. You can run this +with: + +```sh +BEAKER_setfile=debian11-64 bundle exec rake beaker +``` + +You can replace the string `debian10` with any common operating system. +The following strings are known to work: + +* ubuntu1804 +* ubuntu2004 +* debian10 +* debian11 +* centos7 +* centos8 + +For more information and tips & tricks, see [voxpupuli-acceptance's documentation](https://github.com/voxpupuli/voxpupuli-acceptance#running-tests). + +The source of this file is in our [modulesync_config](https://github.com/voxpupuli/modulesync_config/blob/master/moduleroot/.github/CONTRIBUTING.md.erb) +repository. diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..593e7aa8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## Affected Puppet, Ruby, OS and module versions/distributions + +- Puppet: +- Ruby: +- Distribution: +- Module version: + +## How to reproduce (e.g Puppet code you use) + +## What are you seeing + +## What behaviour did you expect instead + +## Output log + +## Any additional information you'd like to impart diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..342807bc --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,20 @@ + +#### Pull Request (PR) description + + +#### This Pull Request (PR) fixes the following issues + diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 00000000..cacadf22 --- /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 00000000..8a077911 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: CI + +on: pull_request + +concurrency: + group: ${{ github.ref_name }} + cancel-in-progress: true + +jobs: + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v1 + with: + pidfile_workaround: 'false' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..15f17213 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,22 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: Release + +on: + push: + tags: + - '*' + +jobs: + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.gitignore b/.gitignore index cca98112..9b95224c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,23 @@ -.swp -.#* -spec/fixtures/artifacts/* -!spec/fixtures/artifacts/.gitignore -spec/fixtures/modules/* -!spec/fixtures/modules/logstash -files/*.gem -files/*.rpm -files/*.deb -templates/configfile-template.erb -.bundle -.vendor -.vagrant -.ruby-version -.yardoc +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + pkg/ -spec/reports/ -spec/logs -log -doc -*.lock -**.swp -files/logstash-output-cowsay-5.0.0.zip +Gemfile.lock +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.librarian/ +Puppetfile.lock +*.iml +.*.sw? +.yardoc/ +Guardfile diff --git a/.msync.yml b/.msync.yml new file mode 100644 index 00000000..f3156d15 --- /dev/null +++ b/.msync.yml @@ -0,0 +1,5 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +modulesync_config_version: '5.4.0' diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 00000000..d367adae --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,65 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ +# +# Hooks are only enabled if you take action. +# +# To enable the hooks run: +# +# ``` +# bundle exec overcommit --install +# # ensure .overcommit.yml does not harm to you and then +# bundle exec overcommit --sign +# ``` +# +# (it will manage the .git/hooks directory): +# +# Examples howto skip a test for a commit or push: +# +# ``` +# SKIP=RuboCop git commit +# SKIP=PuppetLint git commit +# SKIP=RakeTask git push +# ``` +# +# Don't invoke overcommit at all: +# +# ``` +# OVERCOMMIT_DISABLE=1 git commit +# ``` +# +# Read more about overcommit: https://github.com/brigade/overcommit +# +# To manage this config yourself in your module add +# +# ``` +# .overcommit.yml: +# unmanaged: true +# ``` +# +# to your modules .sync.yml config +--- +PreCommit: + RuboCop: + enabled: true + description: 'Runs rubocop on modified files only' + command: ['bundle', 'exec', 'rubocop'] + PuppetLint: + enabled: true + description: 'Runs puppet-lint on modified files only' + command: ['bundle', 'exec', 'puppet-lint'] + YamlSyntax: + enabled: true + JsonSyntax: + enabled: true + TrailingWhitespace: + enabled: true + +PrePush: + RakeTarget: + enabled: true + description: 'Run rake targets' + targets: + - 'validate' + - 'test' + - 'rubocop' + command: ['bundle', 'exec', 'rake'] diff --git a/.pmtignore b/.pmtignore index b5e79edf..65f50514 100644 --- a/.pmtignore +++ b/.pmtignore @@ -1,6 +1,37 @@ -spec/ -Rakefile -junit/ -logs/ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +docs/ +pkg/ Gemfile Gemfile.lock +Gemfile.local +vendor/ +.vendor/ +spec/ +Rakefile +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.github/ +.librarian/ +Puppetfile.lock +*.iml +.editorconfig +.fixtures.yml +.gitignore +.msync.yml +.overcommit.yml +.pmtignore +.rspec +.rspec_parallel +.rubocop.yml +.sync.yml +.*.sw? +.yardoc/ +.yardopts +Dockerfile diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 00000000..b2d2a644 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,2 @@ +--fail-on-warnings +--no-parameter_types-check diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..f634583d --- /dev/null +++ b/.rspec @@ -0,0 +1,5 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +--format documentation +--color diff --git a/.rspec_parallel b/.rspec_parallel new file mode 100644 index 00000000..a9a84f85 --- /dev/null +++ b/.rspec_parallel @@ -0,0 +1,4 @@ +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +--format progress diff --git a/.rubocop.yml b/.rubocop.yml index 2f5d9257..53ac1898 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,6 @@ -AllCops: - Include: - - Rakefile - - Vagrantfile - - spec/**/*.rb - Exclude: - - spec/fixtures/**/* - - pkg/**/* +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +inherit_gem: + voxpupuli-test: rubocop.yml diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 00000000..5279662c --- /dev/null +++ b/.sync.yml @@ -0,0 +1,7 @@ +--- +spec/spec_helper_acceptance.rb: + unmanaged: false + +.puppet-lint.rc: + enabled_lint_checks: + - parameter_documentation diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8dd82d63 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# MANAGED BY MODULESYNC +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +FROM ruby:2.7 + +WORKDIR /opt/puppet + +# https://github.com/puppetlabs/puppet/blob/06ad255754a38f22fb3a22c7c4f1e2ce453d01cb/lib/puppet/provider/service/runit.rb#L39 +RUN mkdir -p /etc/sv + +ARG PUPPET_GEM_VERSION="~> 6.0" +ARG PARALLEL_TEST_PROCESSORS=4 + +# Cache gems +COPY Gemfile . +RUN bundle install --without system_tests development release --path=${BUNDLE_PATH:-vendor/bundle} + +COPY . . + +RUN bundle install +RUN bundle exec rake release_checks + +# Container should not saved +RUN exit 1 diff --git a/Gemfile b/Gemfile index 22af19d7..b3827ba7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,48 +1,34 @@ -source 'https://rubygems.org' -ruby '2.3.4' - -puppetversion = ENV['PUPPET_VERSION'] || '4.10.7' -gem 'puppet', puppetversion, :require => false - -gem 'beaker', '3.15.0' -gem 'beaker-pe', '1.13.0' -gem 'beaker-rspec', '6.1.0' - -# REF: https://github.com/voxpupuli/metadata-json-lint/issues/10 -# gem 'metadata-json-lint' - -gem 'rspec-puppet' - -gem 'pry' -gem 'pry-rescue' -gem 'docker-api', '~> 1.0' -gem 'rubysl-securerandom' -gem 'ci_reporter_rspec' -gem 'google-api-client', '0.9.4' # 0.9.5 needs Ruby 2. -gem 'rgen' -gem 'rspec', '~> 3.0' -gem 'rake' -gem 'metadata-json-lint' -gem 'puppet-doc-lint' -gem 'puppet-lint' -gem 'puppet-strings' -gem 'puppetlabs_spec_helper' -gem 'puppet-syntax' -gem 'rspec-puppet-facts' -gem 'rubocop' -gem 'semantic_puppet' -gem 'serverspec', '2.38.0' -gem 'specinfra', '2.67.3' -gem 'syck' -gem 'webmock' -gem 'redcarpet' - -# Extra Puppet-lint gems -# gem 'puppet-lint-appends-check', :require => false -gem 'puppet-lint-version_comparison-check', :require => false -gem 'puppet-lint-unquoted_string-check', :require => false -gem 'puppet-lint-undef_in_function-check', :require => false -gem 'puppet-lint-trailing_comma-check', :require => false -gem 'puppet-lint-leading_zero-check', :require => false -gem 'puppet-lint-file_ensure-check', :require => false -gem 'puppet-lint-empty_string-check', :require => false +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +group :test do + gem 'voxpupuli-test', '~> 5.4', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'puppet_metadata', '~> 2.0', :require => false +end + +group :development do + gem 'guard-rake', :require => false + gem 'overcommit', '>= 0.39.1', :require => false +end + +group :system_tests do + gem 'voxpupuli-acceptance', '~> 1.0', :require => false +end + +group :release do + gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' + gem 'voxpupuli-release', '>= 1.2.0', :require => false + gem 'puppet-strings', '>= 2.2', :require => false +end + +gem 'rake', :require => false +gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] + +puppetversion = ENV['PUPPET_GEM_VERSION'] || '>= 6.0' +gem 'puppet', puppetversion, :require => false, :groups => [:test] + +# vim: syntax=ruby diff --git a/Rakefile b/Rakefile index cbfe615b..6fd83994 100644 --- a/Rakefile +++ b/Rakefile @@ -1,40 +1,72 @@ -require 'rubygems' -require 'puppetlabs_spec_helper/rake_tasks' -require 'rspec/core/rake_task' - -exclude_paths = [ - 'pkg/**/*', - 'vendor/**/*', - 'spec/**/*' -] - -PuppetLint::RakeTask.new :lint do |config| - config.disable_checks = ['80chars'] - config.fail_on_warnings = true - config.with_context = true - config.ignore_paths = exclude_paths - config.log_format = '%{filename}:%{line} - %{message}' +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), +# otherwise attempt to load it directly. +begin + require 'voxpupuli/test/rake' +rescue LoadError + begin + require 'puppetlabs_spec_helper/rake_tasks' + rescue LoadError + end +end + +# load optional tasks for acceptance +# only available if gem group releases is installed +begin + require 'voxpupuli/acceptance/rake' +rescue LoadError +end + +# load optional tasks for releases +# only available if gem group releases is installed +begin + require 'voxpupuli/release/rake_tasks' +rescue LoadError end -RSpec::Core::RakeTask.new(:spec_verbose) do |t| - t.pattern = 'spec/{classes,defines,lib,reports}/**/*_spec.rb' - t.rspec_opts = [ - '--format documentation', - '--require "ci/reporter/rspec"', - '--format CI::Reporter::RSpecFormatter', - '--color' - ] +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 -# RSpec::Core::RakeTask.new(:henry) do |t| -# t.pattern = 'spec/acceptance/**/*_spec.rb' -# t.rspec_opts = '--format progress --color' -# end - -# RSpec::Core::RakeTask.new(:beaker_verbose) do |t| -# t.pattern = 'spec/acceptance/**/*_spec.rb' -# t.rspec_opts = [ -# '--format documentation', -# '--color' -# ] -# 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| + metadata = Blacksmith::Modulefile.new + config.future_release = "v#{metadata.version}" if metadata.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' + config.project = 'puppet-logstash' + 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/plugin.pp b/manifests/plugin.pp index 52e60c28..d798a70d 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -43,7 +43,7 @@ $source = undef, $ensure = present, $environment = [], - String $user = $logstash::logstash_user, + String $user = 'root', ) { require logstash::package $exe = "${logstash::home_dir}/bin/logstash-plugin" diff --git a/manifests/service.pp b/manifests/service.pp index 83fd30de..9b1c1758 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -16,7 +16,6 @@ } $default_startup_options = { - 'JAVACMD' => '/usr/bin/java', 'LS_HOME' => $logstash::home_dir, 'LS_SETTINGS_DIR' => $logstash::config_dir, 'LS_OPTS' => "--path.settings=${logstash::config_dir}", diff --git a/metadata.json b/metadata.json index e6d20c62..9d3c8e03 100644 --- a/metadata.json +++ b/metadata.json @@ -5,7 +5,6 @@ "author": "elastic", "license": "Apache-2.0", "summary": "Module for managing and configuring Logstash", - "description": "Module for managing and configuring Logstash", "project_page": "https://github.com/voxpupuli/puppet-logstash", "dependencies": [ { @@ -19,58 +18,51 @@ ], "operatingsystem_support": [ { - "operatingsystem": "RedHat", - "operatingsystemrelease": [ - "6", - "7" - ] - }, - { - "operatingsystem": "CentOS", + "operatingsystem": "Debian", "operatingsystemrelease": [ - "6", - "7" + "10", + "11" ] }, { - "operatingsystem": "OracleLinux", + "operatingsystem": "OpenSuSE", "operatingsystemrelease": [ - "6", - "7" + "15" ] }, { - "operatingsystem": "Scientific", + "operatingsystem": "RedHat", "operatingsystemrelease": [ - "6", - "7" + "7", + "8" ] }, { - "operatingsystem": "Debian", + "operatingsystem": "CentOS", "operatingsystemrelease": [ "7", "8" ] }, - { - "operatingsystem": "Ubuntu", + { + "operatingsystem": "SLES", "operatingsystemrelease": [ - "14.04", - "16.04" + "12", + "15" ] }, { - "operatingsystem": "OpenSuSE", + "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "13.x" + "18.04", + "20.04" ] } ], "requirements": [ { "name": "puppet", - "version_requirement": ">=4.6.1 <6.0.0" + "version_requirement": ">= 6.1.0 < 8.0.0" } ] } diff --git a/spec/acceptance/00_meta_spec.rb b/spec/acceptance/00_meta_spec.rb deleted file mode 100644 index f1575c81..00000000 --- a/spec/acceptance/00_meta_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper_acceptance' - -# Here we put the more basic fundamental tests, ultra obvious stuff. -describe 'puppet' do - it "should have an lsbdistdescription fact" do - expect(fact('lsbdistdescription')).to match(/(centos|ubuntu|debian|suse)/i) - end - - desired_version = PUPPET_VERSION[/(\d+\.\d+)/] unless puppet_enterprise? - desired_version = "Puppet Enterprise #{PE_VERSION[/(\d+\.\d+)/]}" if puppet_enterprise? - - it "should be version: #{desired_version}.x" do - actual_version = shell('puppet --version').stdout.chomp - expect(actual_version).to contain(desired_version) - end -end - -describe 'logstash module' do - it 'should be available' do - shell( - "ls #{default['distmoduledir']}/logstash/metadata.json", - acceptable_exit_codes: 0 - ) - end - - it 'should be parsable' do - shell( - "puppet parser validate #{default['distmoduledir']}/logstash/manifests/*.pp", - acceptable_exit_codes: 0 - ) - end -end diff --git a/spec/acceptance/class_logstash_spec.rb b/spec/acceptance/class_logstash_spec.rb index 42947214..69e0b964 100644 --- a/spec/acceptance/class_logstash_spec.rb +++ b/spec/acceptance/class_logstash_spec.rb @@ -1,40 +1,41 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' shared_examples 'a logstash installer' do - it "should install logstash version #{LS_VERSION}" do - expect(shell('/usr/share/logstash/bin/logstash --version').stdout).to eq("logstash #{LS_VERSION}\n") + it "installs logstash version #{LS_VERSION}" do + expect(shell('/usr/share/logstash/bin/logstash --version').stdout).to contain("logstash #{LS_VERSION}") end case fact('osfamily') when 'RedHat', 'Suse' describe package('logstash') do - it { should be_installed } + it { is_expected.to be_installed } end when 'Debian' # Serverspec has been falsely reporting the package as not installed on # Debian 7, so we'll implement our own version of "should be_installed". - it "should install logstash package version #{logstash_package_version}" do + it "installs logstash package version #{logstash_package_version}" do apt_output = shell('apt-cache policy logstash').stdout expect(apt_output).to include("Installed: #{logstash_package_version}") end end describe service('logstash') do - it { should be_running } - it 'should be_enabled' do - if fact('lsbdistdescription') =~ /centos release 6/i - skip('Serverspec seems confused about this on Centos 6.') - end - should be_enabled + it { is_expected.to be_running } + + it 'be_enableds' do + skip('Serverspec seems confused about this on Centos 6.') if fact('lsbdistdescription') =~ %r{centos release 6}i + is_expected.to be_enabled end end - it 'should spawn a single logstash process' do + it 'spawns a single logstash process' do expect(logstash_process_list.length).to eq(1) end - it 'should run logstash as the "logstash" user' do - expect(logstash_process_list.pop).to match(/^logstash /) + it 'runs logstash as the "logstash" user' do + expect(logstash_process_list.pop).to match(%r{^logstash }) end end @@ -48,7 +49,7 @@ it_behaves_like 'a logstash installer' - it 'should be idempotent' do + it 'is idempotent' do expect_no_change_from_manifest(install_logstash_manifest) end end @@ -73,10 +74,12 @@ context 'when installing from a "puppet://" url' do before(:all) do + skip('There is no rpm package in the module ...') remove_logstash install_logstash_from_url(puppet_fileserver_package_url) end + skip('There is no rpm package in the module ...') it_behaves_like 'a logstash installer' end end @@ -87,18 +90,19 @@ remove_logstash end - it 'should be idempotent' do + it 'is idempotent' do expect_no_change_from_manifest(remove_logstash_manifest) end describe package('logstash') do - it { should_not be_installed } + it { is_expected.not_to be_installed } end describe service('logstash') do - it { should_not be_running } - it 'should not be enabled' do - should_not be_enabled + it { is_expected.not_to be_running } + + it 'is not enabled' do + is_expected.not_to be_enabled end end end @@ -119,19 +123,19 @@ install_logstash_from_local_file("settings => #{settings}") end - it 'it sets "http.port" to "9999"' do + it 'sets "http.port" to "9999"' do expect_setting('http.port', '9999') end - it 'it retains the default "path.data" setting' do + it 'retains the default "path.data" setting' do expect_setting('path.data', '/var/lib/logstash') end - it 'it retains the default "path.config" setting' do + it 'retains the default "path.config" setting' do expect_setting('path.config', '/etc/logstash/conf.d') end - it 'it retains the default "path.logs" setting' do + it 'retains the default "path.logs" setting' do expect_setting('path.logs', '/var/log/logstash') end end @@ -178,8 +182,8 @@ install_logstash_from_local_file("startup_options => #{startup_options}") end - it 'should run logstash as root' do - expect(logstash_process_list.pop).to match(/^root /) + it 'runs logstash as root' do + expect(logstash_process_list.pop).to match(%r{^root }) end end end @@ -191,24 +195,21 @@ install_logstash_from_local_file("jvm_options => #{jvm_options}") end - it 'should run java with -Xms1g' do + it 'runs java with -Xms1g' do expect(logstash_process_list.pop).to include('-Xms1g') end - it 'should not run java with the default of -Xms256m' do + it 'does not run java with the default of -Xms256m' do expect(logstash_process_list.pop).not_to include('-Xms256m') end - it 'should run java with the default "expert" flags' do + it 'runs java with the default "expert" flags' do expert_flags = [ '-Dfile.encoding=UTF-8', '-Djava.awt.headless=true', '-XX:CMSInitiatingOccupancyFraction=75', - '-XX:+DisableExplicitGC', '-XX:+HeapDumpOnOutOfMemoryError', '-XX:+UseCMSInitiatingOccupancyOnly', - '-XX:+UseConcMarkSweepGC', - '-XX:+UseParNewGC', ] expert_flags.each do |flag| expect(logstash_process_list.pop).to include(flag) @@ -216,17 +217,19 @@ end context 'when the option is changed' do - it 'should restart logstash' do + it 'restarts logstash' do puppet_log = install_logstash_from_local_file( - "jvm_options => [ '-Xms512m' ]").stdout + "jvm_options => [ '-Xms512m' ]" + ).stdout expect(puppet_log).to include(service_restart_message) end context 'when restart_on_change is false' do - it 'should not restart logstash' do + it 'does not restart logstash' do puppet_log = install_logstash_from_local_file( "jvm_options => [ '-Xms256m' ], - restart_on_change => false").stdout + restart_on_change => false" + ).stdout expect(puppet_log).not_to include(service_restart_message) end end @@ -235,7 +238,7 @@ end describe 'pipelines_parameter' do - context "with pipelines declared" do + context 'with pipelines declared' do before(:context) do pipelines_puppet = <<-END [ @@ -252,12 +255,12 @@ install_logstash_from_local_file("pipelines => #{pipelines_puppet}") end - it 'should render them to pipelines.yml' do + it 'renders them to pipelines.yml' do expect(pipelines_from_yaml[0]['pipeline.id']).to eq('pipeline_one') expect(pipelines_from_yaml[1]['pipeline.id']).to eq('pipeline_two') end - it 'should remove "path.config" from "logstash.yml"' do + it 'removes "path.config" from "logstash.yml"' do expect(logstash_settings['path.config']).to be_nil end end @@ -270,7 +273,7 @@ install_logstash_from_local_file("settings => #{settings_puppet_code}") end - it 'should remove "path.config" from "logstash.yml"' do + it 'removes "path.config" from "logstash.yml"' do expect(logstash_settings['path.config']).to be_nil end end @@ -289,7 +292,7 @@ install_logstash_from_local_file("settings => #{settings_puppet_code}") end - it 'should remove "path.config" from "logstash.yml"' do + it 'removes "path.config" from "logstash.yml"' do expect(logstash_settings['path.config']).to be_nil end end diff --git a/spec/acceptance/class_plugin_spec.rb b/spec/acceptance/class_plugin_spec.rb index b9fdd2f3..fd93f304 100644 --- a/spec/acceptance/class_plugin_spec.rb +++ b/spec/acceptance/class_plugin_spec.rb @@ -1,7 +1,13 @@ -# coding: utf-8 +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'class plugin' do + before(:all) do + remove_logstash + install_logstash('status => "disabled", restart_on_change => false') + end + def ensure_plugin(present_absent, plugin, extra_args = nil) manifest = <<-END class { 'logstash': @@ -11,9 +17,9 @@ class { 'logstash': -> logstash::plugin { '#{plugin}': ensure => #{present_absent}, - #{extra_args if extra_args} + #{extra_args} } - END + END apply_manifest(manifest, catch_failures: true) end @@ -26,13 +32,13 @@ def remove(plugin) end context 'when a plugin is not installed' do - before(:each) do + before do remove('logstash-input-sqs') end it 'will not remove it again' do log = ensure_plugin('absent', 'logstash-input-sqs').stdout - expect(log).to_not contain('remove-logstash-input-sqs') + expect(log).not_to contain('remove-logstash-input-sqs') end it 'can install it from rubygems' do @@ -42,13 +48,13 @@ def remove(plugin) end context 'when a plugin is installed' do - before(:each) do + it 'will contain the required plugin' do expect(installed_plugins).to contain('logstash-input-file') end it 'will not install it again' do log = ensure_plugin('present', 'logstash-input-file').stdout - expect(log).to_not contain('install-logstash-input-file') + expect(log).not_to contain('install-logstash-input-file') end it 'can remove it' do @@ -59,6 +65,7 @@ def remove(plugin) if Gem::Version.new(LS_VERSION) >= Gem::Version.new('5.2.0') it 'can install x-pack from an https url' do + skip('The latest x-pack release is 6.2.4 released April 17, 2018 ...') plugin = 'x-pack' source = "https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-#{LS_VERSION}.zip" ensure_plugin('present', plugin, "source => '#{source}'") @@ -67,6 +74,7 @@ def remove(plugin) end it 'can install a plugin from a "puppet://" url' do + skip('There is no plugins embedded in the module ...') plugin = 'logstash-output-cowthink' source = "puppet:///modules/logstash/#{plugin}-5.0.0.gem" ensure_plugin('present', plugin, "source => '#{source}'") @@ -74,6 +82,7 @@ def remove(plugin) end it 'can install a plugin from a local gem' do + skip('No download means no local plugin available ...') plugin = 'logstash-output-cowsay' source = "/tmp/#{plugin}-5.0.0.gem" ensure_plugin('present', plugin, "source => '#{source}'") @@ -81,6 +90,7 @@ def remove(plugin) end it 'can install a plugin from an offline zip' do + skip('There is no plugins embedded in the module ...') plugin = 'logstash-output-cowsay' source = "puppet:///modules/logstash/#{plugin}-5.0.0.zip" ensure_plugin('present', plugin, "source => '#{source}'") diff --git a/spec/acceptance/define_configfile_spec.rb b/spec/acceptance/define_configfile_spec.rb index 809f8e6c..cd8416c6 100644 --- a/spec/acceptance/define_configfile_spec.rb +++ b/spec/acceptance/define_configfile_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'define logstash::configfile' do @@ -28,10 +30,12 @@ END before(:context) do + skip('There is no configfile-template.erb in the module ..') apply_manifest(manifest, catch_failures: true, debug: true) end it 'creates a config file from the template' do + skip('There is no configfile-template.erb in the module ..') result = shell('cat /etc/logstash/conf.d/from-template').stdout expect(result).to include('2 + 2 equals 4') end diff --git a/spec/acceptance/define_patternfile_spec.rb b/spec/acceptance/define_patternfile_spec.rb index ad2287d1..78395a19 100644 --- a/spec/acceptance/define_patternfile_spec.rb +++ b/spec/acceptance/define_patternfile_spec.rb @@ -1,16 +1,17 @@ -# coding: utf-8 +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'class patternfile' do def apply_pattern(pattern_number, extra_logstash_class_args = nil) manifest = <<-END - #{install_logstash_from_local_file_manifest(extra_logstash_class_args)} + #{install_logstash_manifest(extra_logstash_class_args)} logstash::patternfile { 'pattern': source => 'puppet:///modules/logstash/grok-pattern-#{pattern_number}', filename => 'the_only_pattern_file', } - END + END apply_manifest(manifest) end @@ -18,13 +19,14 @@ def apply_pattern(pattern_number, extra_logstash_class_args = nil) before(:context) { apply_pattern(0) } describe file '/etc/logstash/patterns/the_only_pattern_file' do - it { should be_a_file } - its(:content) { should match(/GROK_PATTERN_0/) } + it { is_expected.to be_a_file } + its(:content) { is_expected.to match(%r{GROK_PATTERN_0}) } end end context 'with a pattern file in place' do - before(:each) { apply_pattern(0) } + before { apply_pattern(0) } + restart_message = 'Scheduling refresh of Service[logstash]' it 'restarts logstash when a pattern file changes' do @@ -33,12 +35,8 @@ def apply_pattern(pattern_number, extra_logstash_class_args = nil) end it 'does not restart logstash if logstash::restart_on_change is false' do - os = fact('lsbdistdescription') - if (os =~ /(centos release 6\.|ubuntu 12\.04)/i) && PUPPET_VERSION[0] == '3' - skip('Something funky happening with Upstart and Puppet 3?') - end log = apply_pattern(1, 'restart_on_change => false').stdout expect(log).not_to include(restart_message) end end - end +end diff --git a/spec/acceptance/nodesets/centos-6-docker.yml b/spec/acceptance/nodesets/centos-6-docker.yml deleted file mode 100644 index 27c8a17b..00000000 --- a/spec/acceptance/nodesets/centos-6-docker.yml +++ /dev/null @@ -1,17 +0,0 @@ -HOSTS: - centos-6-x64: - roles: [agent, database, dashboard, master] - platform: el-6-x86_64 - image: library/centos:6 - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - rm /etc/init/tty.conf - - yum install -y wget ntpdate redhat-lsb-core redhat-lsb rubygems ruby-augeas ruby-devel augeas-devel logrotate - - touch /etc/sysconfig/network - - 'cd / && wget -q --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jre-8u131-linux-x64.rpm"' - - 'cd / && yum localinstall -y jre-8u131-linux-x64.rpm' - docker_preserve_image: true -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/centos-6-vagrant.yml b/spec/acceptance/nodesets/centos-6-vagrant.yml deleted file mode 100644 index 45646cdb..00000000 --- a/spec/acceptance/nodesets/centos-6-vagrant.yml +++ /dev/null @@ -1,8 +0,0 @@ -HOSTS: - centos-6-x64: - platform: el-6-x86_64 - box: puppetlabs/centos-6.6-64-nocm - hypervisor: vagrant -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/centos-6.yml b/spec/acceptance/nodesets/centos-6.yml deleted file mode 120000 index 2aced8ba..00000000 --- a/spec/acceptance/nodesets/centos-6.yml +++ /dev/null @@ -1 +0,0 @@ -centos-6-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/centos-7-docker.yml b/spec/acceptance/nodesets/centos-7-docker.yml deleted file mode 100644 index c81b48e4..00000000 --- a/spec/acceptance/nodesets/centos-7-docker.yml +++ /dev/null @@ -1,17 +0,0 @@ -HOSTS: - centos-7-x64: - roles: [agent, database, dashboard, master] - platform: el-7-x86_64 - image: centos:7 - hypervisor: docker - docker_cmd: '["/usr/sbin/init"]' - docker_image_commands: - - rm /lib/systemd/system/systemd*udev* - - rm /lib/systemd/system/getty.target - - yum install -y wget ntpdate redhat-lsb-core redhat-lsb rubygems ruby-devel augeas-devel ruby-augeas tar logrotate - - 'cd / && wget -q --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jre-8u131-linux-x64.rpm"' - - 'cd / && yum localinstall -y jre-8u131-linux-x64.rpm' - docker_preserve_image: true -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/centos-7-vagrant.yml b/spec/acceptance/nodesets/centos-7-vagrant.yml deleted file mode 100644 index 03e088a6..00000000 --- a/spec/acceptance/nodesets/centos-7-vagrant.yml +++ /dev/null @@ -1,8 +0,0 @@ -HOSTS: - centos-7-x64: - platform: el-7-x86_64 - box: puppetlabs/centos-7.2-64-nocm - hypervisor: vagrant -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/centos-7.yml b/spec/acceptance/nodesets/centos-7.yml deleted file mode 120000 index 4756a91c..00000000 --- a/spec/acceptance/nodesets/centos-7.yml +++ /dev/null @@ -1 +0,0 @@ -centos-7-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/debian-7-docker.yml b/spec/acceptance/nodesets/debian-7-docker.yml deleted file mode 100644 index 727c1284..00000000 --- a/spec/acceptance/nodesets/debian-7-docker.yml +++ /dev/null @@ -1,33 +0,0 @@ -HOSTS: - debian-7: - roles: [agent, database, dashboard, master] - platform: debian-7-amd64 - image: debian:7 - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - # The base image contains a stub shell script in place of '/sbin/initctl' which - # confuses the heck out of Pleaserun when installing Logstash. - # REF: https://github.com/jordansissel/pleaserun/blob/master/lib/pleaserun/detector.rb - - rm /sbin/initctl - - - apt-get update - - apt-get -y upgrade - - apt-get install -yq apt-transport-https lsb-release wget net-tools ruby rubygems ruby1.8-dev libaugeas-dev libaugeas-ruby ntpdate locales-all logrotate procps - - # Install Oracle Java 8 - - echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list - - echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list - - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 - - apt-get -y update - - echo 'debconf shared/accepted-oracle-license-v1-1 select true' | debconf-set-selections - - echo 'debconf shared/accepted-oracle-license-v1-1 seen true' | debconf-set-selections - - apt-get install -yq oracle-java8-installer - - apt-get install -yq oracle-java8-set-default - - - REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-ri --no-rdoc - docker_preserve_image: true - -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/debian-7-vagrant.yml b/spec/acceptance/nodesets/debian-7-vagrant.yml deleted file mode 100644 index 3af37c1b..00000000 --- a/spec/acceptance/nodesets/debian-7-vagrant.yml +++ /dev/null @@ -1,9 +0,0 @@ -HOSTS: - debian-7: - roles: [agent, database, dashboard, master] - platform: debian-7-amd64 - box: puppetlabs/debian-7.8-64-nocm - hypervisor: vagrant -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/debian-7.yml b/spec/acceptance/nodesets/debian-7.yml deleted file mode 120000 index 098c1b6a..00000000 --- a/spec/acceptance/nodesets/debian-7.yml +++ /dev/null @@ -1 +0,0 @@ -debian-7-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/debian-8-docker.yml b/spec/acceptance/nodesets/debian-8-docker.yml deleted file mode 100644 index a73fc6e5..00000000 --- a/spec/acceptance/nodesets/debian-8-docker.yml +++ /dev/null @@ -1,18 +0,0 @@ -HOSTS: - debian-8: - roles: [agent, database, dashboard, master] - platform: debian-8-amd64 - image: debian:jessie-backports - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - rm /lib/systemd/system/systemd*udev* - - rm /lib/systemd/system/getty.target - - apt-get update - - apt-get install -yq apt-transport-https ruby ruby-dev lsb-release wget net-tools libaugeas-dev libaugeas-ruby ntpdate locales-all logrotate - - apt-get install -yq -t jessie-backports openjdk-8-jre-headless ca-certificates-java - - REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-ri --no-rdoc - docker_preserve_image: true -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/debian-8-vagrant.yml b/spec/acceptance/nodesets/debian-8-vagrant.yml deleted file mode 100644 index f6829a12..00000000 --- a/spec/acceptance/nodesets/debian-8-vagrant.yml +++ /dev/null @@ -1,8 +0,0 @@ -HOSTS: - debian-8-x64: - platform: debian-8-amd64 - box: puppetlabs/debian-8.2-64-nocm - hypervisor: vagrant -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/debian-8.yml b/spec/acceptance/nodesets/debian-8.yml deleted file mode 120000 index abb98ce2..00000000 --- a/spec/acceptance/nodesets/debian-8.yml +++ /dev/null @@ -1 +0,0 @@ -debian-8-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 120000 index d3846865..00000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1 +0,0 @@ -ubuntu-1404.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/opensuse-13-docker.yml b/spec/acceptance/nodesets/opensuse-13-docker.yml deleted file mode 100644 index c0081c1a..00000000 --- a/spec/acceptance/nodesets/opensuse-13-docker.yml +++ /dev/null @@ -1,20 +0,0 @@ -HOSTS: - opensuse-13: - platform: sles-13-x86_64 # Not really, but Beaker doesn't know about OpenSuSE! - image: library/opensuse:13.2 - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - zypper install -y lsb dbus-1 rubygems which augeas augeas-lenses wget - - zypper install -y -t pattern devel_basis || true - - mkdir -p /etc/selinux/targeted/contexts/ - - echo '' > /etc/selinux/targeted/contexts/dbus_contexts - - mkdir /etc/systemd/system/sshd.service.d/ - - echo -e "[Service]\nExecStart=\nExecStart=/usr/bin/sshd -D" - - ln -s /usr/lib/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/sshd.service - - 'cd / && wget -q --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jre-8u111-linux-x64.rpm"' - - 'cd / && zypper install -y jre-8u111-linux-x64.rpm' - docker_preserve_image: true -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/opensuse-13-vagrant.yml b/spec/acceptance/nodesets/opensuse-13-vagrant.yml deleted file mode 100644 index 61af7397..00000000 --- a/spec/acceptance/nodesets/opensuse-13-vagrant.yml +++ /dev/null @@ -1,8 +0,0 @@ -HOSTS: - opensuse-131-x64: - platform: sles-13-x64 - box: elastic/opensuse-13-x86_64 - hypervisor: vagrant -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/opensuse-13.yml b/spec/acceptance/nodesets/opensuse-13.yml deleted file mode 120000 index cb70ff73..00000000 --- a/spec/acceptance/nodesets/opensuse-13.yml +++ /dev/null @@ -1 +0,0 @@ -opensuse-13-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/sles-11-docker.yml b/spec/acceptance/nodesets/sles-11-docker.yml deleted file mode 100644 index 92aa07f9..00000000 --- a/spec/acceptance/nodesets/sles-11-docker.yml +++ /dev/null @@ -1,18 +0,0 @@ -HOSTS: - sles-11: - platform: sles-11-x86_64 - image: netways/sles-11-sp3-x86_64 - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - zypper install -y dbus-1 rubygems which augeas augeas-lenses wget - - zypper install -y -t pattern devel_basis || true - - mkdir -p /etc/selinux/targeted/contexts/ - - echo '' > /etc/selinux/targeted/contexts/dbus_contexts - - mkdir /etc/systemd/system/sshd.service.d/ - - echo -e "[Service]\nExecStart=\nExecStart=/usr/bin/sshd -D" - - ln -s /usr/lib/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/sshd.service - docker_preserve_image: true -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/sles-11-vagrant.yml b/spec/acceptance/nodesets/sles-11-vagrant.yml deleted file mode 100644 index a45f110e..00000000 --- a/spec/acceptance/nodesets/sles-11-vagrant.yml +++ /dev/null @@ -1,13 +0,0 @@ -HOSTS: - sles-11-x64: - roles: - - master - - database - - dashboard - platform: sles-11-x86_64 - box: sles-11sp3-x64 - box_url: https://s3-eu-west-1.amazonaws.com/users.eu.elasticsearch.org/electrical/sles-11sp3-x64.box - hypervisor: vagrant -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/sles-11.yml b/spec/acceptance/nodesets/sles-11.yml deleted file mode 120000 index bcca9500..00000000 --- a/spec/acceptance/nodesets/sles-11.yml +++ /dev/null @@ -1 +0,0 @@ -sles-11-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/ubuntu-1204-docker.yml b/spec/acceptance/nodesets/ubuntu-1204-docker.yml deleted file mode 100644 index 1cda899b..00000000 --- a/spec/acceptance/nodesets/ubuntu-1204-docker.yml +++ /dev/null @@ -1,31 +0,0 @@ -HOSTS: - ubuntu-12-04: - roles: - - master - - database - - dashboard - platform: ubuntu-12.04-amd64 - image: library/ubuntu:12.04 - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - # The base image disables Upstart, which is the "right thing" to do for - # containers. However, we actually want Upstart, because we are trying - # to simulate a full system. Thus, we undo the magic from upstream's - # Dockerfile. - # REF: https://github.com/tianon/docker-brew-ubuntu-core/blob/aec74cf404240664b289d28948d9284a4afd1181/precise/Dockerfile#L14 - - rm /sbin/initctl - - dpkg-divert --rename --remove /sbin/initctl - - - apt-get install -yq apt-transport-https ruby1.8-dev libaugeas-dev libaugeas-ruby ruby rubygems lsb-release wget net-tools curl python-software-properties - - # Install Oracle Java 8 - - echo 'debconf shared/accepted-oracle-license-v1-1 select true' | debconf-set-selections - - echo 'debconf shared/accepted-oracle-license-v1-1 seen true' | debconf-set-selections - - apt-add-repository ppa:webupd8team/java - - apt-get update - - apt-get install -yq oracle-java8-installer - docker_preserve_image: true -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/ubuntu-1204.yml b/spec/acceptance/nodesets/ubuntu-1204.yml deleted file mode 120000 index 6489cd84..00000000 --- a/spec/acceptance/nodesets/ubuntu-1204.yml +++ /dev/null @@ -1 +0,0 @@ -ubuntu-1204-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/ubuntu-1404-docker.yml b/spec/acceptance/nodesets/ubuntu-1404-docker.yml deleted file mode 100644 index 63e6c7b1..00000000 --- a/spec/acceptance/nodesets/ubuntu-1404-docker.yml +++ /dev/null @@ -1,26 +0,0 @@ -HOSTS: - ubuntu-14-04: - roles: - - master - - database - - dashboard - platform: ubuntu-14.04-amd64 - image: electrical/ubuntu:14.04 - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - apt-get update - - apt-get install -yq apt-transport-https ruby ruby1.9.1-dev libaugeas-dev libaugeas-ruby lsb-release wget net-tools curl software-properties-common - - # Install Oracle Java 8 - - echo 'debconf shared/accepted-oracle-license-v1-1 select true' | debconf-set-selections - - echo 'debconf shared/accepted-oracle-license-v1-1 seen true' | debconf-set-selections - - apt-add-repository ppa:webupd8team/java - - apt-get update - - apt-get install -yq oracle-java8-installer - - apt-get install -yq oracle-java8-set-default - docker_preserve_image: true - -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/acceptance/nodesets/ubuntu-1404.yml b/spec/acceptance/nodesets/ubuntu-1404.yml deleted file mode 120000 index bd89387b..00000000 --- a/spec/acceptance/nodesets/ubuntu-1404.yml +++ /dev/null @@ -1 +0,0 @@ -ubuntu-1404-docker.yml \ No newline at end of file diff --git a/spec/acceptance/nodesets/ubuntu-1604.yml b/spec/acceptance/nodesets/ubuntu-1604.yml deleted file mode 100644 index 54896dbb..00000000 --- a/spec/acceptance/nodesets/ubuntu-1604.yml +++ /dev/null @@ -1,25 +0,0 @@ -HOSTS: - ubuntu-16-04: - roles: - - master - - database - - dashboard - platform: ubuntu-16.04-amd64 - image: library/ubuntu:16.04 - hypervisor: docker - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - apt-get update - - apt-get install -yq apt-transport-https ruby-dev libaugeas-dev ruby rubygems lsb-release wget net-tools curl software-properties-common - - # Install Oracle Java 8 - - echo 'debconf shared/accepted-oracle-license-v1-1 select true' | debconf-set-selections - - echo 'debconf shared/accepted-oracle-license-v1-1 seen true' | debconf-set-selections - - apt-add-repository ppa:webupd8team/java - - apt-get update - - apt-get install -yq oracle-java8-installer - - apt-get install -yq oracle-java8-set-default - docker_preserve_image: true -CONFIG: - type: foss - :trace_limit: 100 # Get more than 10 lines of trace when something fails. diff --git a/spec/defines/define_plugin_spec.rb b/spec/defines/define_plugin_spec.rb index 785472f5..09039fd7 100644 --- a/spec/defines/define_plugin_spec.rb +++ b/spec/defines/define_plugin_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'logstash::plugin' do @@ -7,17 +9,19 @@ facts end - let(:pre_condition) { %q( - include elastic_stack::repo - include logstash - )} + let(:pre_condition) do + <<~PUPPET + include elastic_stack::repo + include logstash + PUPPET + end let(:title) { 'logstash-input-mysql' } it { is_expected.to compile } it { - is_expected.to contain_exec("install-#{title}").with(user: 'logstash') + is_expected.to contain_exec("install-#{title}").with(user: 'root') } end end diff --git a/spec/fixtures/manifests/.gitignore b/spec/fixtures/manifests/.gitignore deleted file mode 100644 index e69de29b..00000000 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5028b477..6515b7bf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,19 @@ -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' -include RspecPuppetFacts +# frozen_string_literal: true -default_facts = { - puppetversion: Puppet.version, - facterversion: Facter.version, -} +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -RSpec.configure do |c| - c.default_facts = default_facts +# puppetlabs_spec_helper will set up coverage if the env variable is set. +# We want to do this if lib exists and it hasn't been explicitly set. +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) + +require 'voxpupuli/test/spec_helper' + +add_mocked_facts! + +if File.exist?(File.join(__dir__, 'default_module_facts.yml')) + facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) + facts&.each do |name, value| + add_custom_fact name.to_sym, value + end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 78d74b32..d3a6e23c 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,315 +1,10 @@ -require 'beaker-rspec' -require 'net/http' -require 'pry' -require 'securerandom' -require 'yaml' +# frozen_string_literal: true -# Collect global options from the environment. -if ENV['LOGSTASH_VERSION'].nil? - raise 'Please set the LOGSTASH_VERSION environment variable.' -end -LS_VERSION = ENV['LOGSTASH_VERSION'] -PUPPET_VERSION = ENV['PUPPET_VERSION'] || '4.10.7' +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -PE_VERSION = ENV['BEAKER_PE_VER'] || ENV['PE_VERSION'] || '3.8.3' -PE_DIR = ENV['BEAKER_PE_DIR'] +require 'voxpupuli/acceptance/spec_helper_acceptance' -if LS_VERSION =~ /(alpha|beta|rc)/ - IS_PRERELEASE = true -else - IS_PRERELEASE = false -end +configure_beaker -def agent_version_for_puppet_version(puppet_version) - # REF: https://docs.puppet.com/puppet/latest/reference/about_agent.html - version_map = { - # Puppet => Agent - '4.9.4' => '1.9.3', - '4.8.2' => '1.8.3', - '4.8.1' => '1.8.2', - '4.8.0' => '1.8.0', - '4.7.1' => '1.7.2', - '4.7.0' => '1.7.1', - '4.6.2' => '1.6.2', - '4.6.1' => '1.6.1', - '4.6.0' => '1.6.0', - '4.5.3' => '1.5.3', - '4.4.2' => '1.4.2', - '4.4.1' => '1.4.1', - '4.4.0' => '1.4.0', - '4.3.2' => '1.3.6', - '4.3.1' => '1.3.2', - '4.3.0' => '1.3.0', - '4.2.3' => '1.2.7', - '4.2.2' => '1.2.6', - '4.2.1' => '1.2.2', - '4.2.0' => '1.2.1', - '4.1.0' => '1.1.1', - '4.0.0' => '1.0.1' - } - version_map[puppet_version] -end - -def apply_manifest_fixture(manifest_name) - manifest = File.read("./spec/fixtures/manifests/#{manifest_name}.pp") - apply_manifest(manifest, catch_failures: true) -end - -def expect_no_change_from_manifest(manifest) - expect(apply_manifest(manifest).exit_code).to eq(0) -end - -def http_package_url - url_root = "https://artifacts.elastic.co/downloads/logstash/logstash-#{LS_VERSION}" - - case fact('osfamily') - when 'Debian' - "#{url_root}.deb" - when 'RedHat', 'Suse' - "#{url_root}.rpm" - end -end - -def local_file_package_url - "file:///tmp/#{logstash_package_filename}" -end - -def puppet_fileserver_package_url - "puppet:///modules/logstash/#{logstash_package_filename}" -end - -def logstash_package_filename - File.basename(http_package_url) -end - -def logstash_package_version - if LS_VERSION =~ /(alpha|beta|rc)/ - package_version = LS_VERSION.gsub('-', '~') - else - package_version = LS_VERSION - end - - case fact('osfamily') # FIXME: Put this logic in the module, not the tests. - when 'RedHat' - "#{package_version}-1" - when 'Debian', 'Suse' - "1:#{package_version}-1" - end -end - -def logstash_config_manifest - <<-END - logstash::configfile { 'basic_config': - content => 'input { tcp { port => 2000 } } output { null {} }' - } - END -end - -def install_logstash_manifest(extra_args = nil) - <<-END - class { 'elastic_stack::repo': - version => #{LS_VERSION[0]}, - prerelease => #{IS_PRERELEASE.to_s}, - } - class { 'logstash': - manage_repo => true, - version => '#{logstash_package_version}', - #{extra_args if extra_args} - } - - #{logstash_config_manifest} - END -end - -def include_logstash_manifest() - <<-END - class { 'elastic_stack::repo': - version => #{LS_VERSION[0]}, - prerelease => #{IS_PRERELEASE.to_s}, - } - - include logstash - - #{logstash_config_manifest} - END -end - -def install_logstash_from_url_manifest(url, extra_args = nil) - <<-END - class { 'logstash': - package_url => '#{url}', - #{extra_args if extra_args} - } - - #{logstash_config_manifest} - END -end - -def install_logstash_from_local_file_manifest(extra_args = nil) - install_logstash_from_url_manifest(local_file_package_url, extra_args) -end - -def remove_logstash_manifest - "class { 'logstash': ensure => 'absent' }" -end - -def stop_logstash_manifest - "class { 'logstash': status => 'disabled' }" -end - -# Provide a basic Logstash install. Useful as a testing pre-requisite. -def install_logstash(extra_args = nil) - result = apply_manifest(install_logstash_manifest(extra_args), catch_failures: true) - sleep 5 # FIXME: This is horrible. - return result -end - -def include_logstash - result = apply_manifest(include_logstash_manifest, catch_failures: true, debug: true) - sleep 5 # FIXME: This is horrible. - return result -end - -def install_logstash_from_url(url, extra_args = nil) - manifest = install_logstash_from_url_manifest(url, extra_args) - result = apply_manifest(manifest, catch_failures: true) - sleep 5 # FIXME: This is horrible. - return result -end - -def install_logstash_from_local_file(extra_args = nil) - install_logstash_from_url(local_file_package_url, extra_args) -end - -def remove_logstash - result = apply_manifest(remove_logstash_manifest) - sleep 5 # FIXME: This is horrible. - return result -end - -def stop_logstash - result = apply_manifest(stop_logstash_manifest, catch_failures: true) - shell('ps -eo comm | grep java | xargs kill -9', accept_all_exit_codes: true) - sleep 5 # FIXME: This is horrible. - return result -end - -def logstash_process_list - ps_cmd = 'ps -ww --no-headers -C java -o user,command | grep logstash' - shell(ps_cmd, accept_all_exit_codes: true).stdout.split("\n") -end - -def logstash_settings - YAML.load(shell('cat /etc/logstash/logstash.yml').stdout) -end - -def expect_setting(setting, value) - expect(logstash_settings[setting]).to eq(value) -end - -def pipelines_from_yaml - YAML.load(shell('cat /etc/logstash/pipelines.yml').stdout) -end - -def service_restart_message - "Service[logstash]: Triggered 'refresh'" -end - -def pe_package_url - distro, distro_version = ENV['BEAKER_set'].split('-') - case distro - when 'debian' - os = 'debian' - arch = 'amd64' - when 'centos' - os = 'el' - arch = 'x86_64' - when 'ubuntu' - os = 'ubuntu' - arch = 'amd64' - end - url_root = "https://s3.amazonaws.com/pe-builds/released/#{PE_VERSION}" - url = "#{url_root}/puppet-enterprise-#{PE_VERSION}-#{os}-#{distro_version}-#{arch}.tar.gz" -end - -def pe_package_filename - File.basename(pe_package_url) -end - -def puppet_enterprise? - ENV['BEAKER_IS_PE'] == 'true' || ENV['IS_PE'] == 'true' -end - -hosts.each do |host| - # Install Puppet - if puppet_enterprise? - pe_download = File.join(PE_DIR, pe_package_filename) - `curl -s -o #{pe_download} #{pe_package_url}` unless File.exist?(pe_download) - on host, "hostname #{host.name}" - install_pe_on(host, pe_ver: PE_VERSION) - else - if PUPPET_VERSION.start_with?('4.') - agent_version = agent_version_for_puppet_version(PUPPET_VERSION) - install_puppet_agent_on(host, puppet_agent_version: agent_version) - else - begin - install_puppet_on(host, version: PUPPET_VERSION) - rescue - install_puppet_from_gem_on(host, version: PUPPET_VERSION) - end - end - end - - if fact('osfamily') == 'Suse' - if fact('operatingsystem') == 'OpenSuSE' - install_package host, 'ruby-devel augeas-devel libxml2-devel' - on host, 'gem install ruby-augeas --no-ri --no-rdoc' - end - end - - # Update package cache for those who need it. - on host, 'apt-get update' if fact('osfamily') == 'Debian' - - # Aquire a binary package of Logstash. - logstash_download = "spec/fixtures/artifacts/#{logstash_package_filename}" - `curl -s -o #{logstash_download} #{http_package_url}` unless File.exist?(logstash_download) - # ...send it to the test host - scp_to(host, logstash_download, '/tmp/') - # ...and also make it available as a "puppet://" url, by putting it in the - # 'files' directory of the Logstash module. - FileUtils.cp(logstash_download, './files/') - - # ...and put some grok pattern examples in their too. - Dir.glob('./spec/fixtures/grok-patterns/*').each do |f| - FileUtils.cp(f, './files/') - end - - # Provide a Logstash plugin as a local Gem. - scp_to(host, './spec/fixtures/plugins/logstash-output-cowsay-5.0.0.gem', '/tmp/') - - # ...and another plugin that can be fetched from Puppet with "puppet://" - FileUtils.cp('./spec/fixtures/plugins/logstash-output-cowthink-5.0.0.gem', './files/') - - # ...and yet another plugin, this time packaged as an offline installer - FileUtils.cp('./spec/fixtures/plugins/logstash-output-cowsay-5.0.0.zip', './files/') - - # Provide a config file template. - FileUtils.cp('./spec/fixtures/templates/configfile-template.erb', './templates/') - - # Provide this module to the test system. - project_root = File.dirname(File.dirname(__FILE__)) - install_dev_puppet_module_on(host, source: project_root, module_name: 'logstash') - - # Also install any other modules we need on the test system. - install_puppet_module_via_pmt_on(host, module_name: 'elastic-elastic_stack') - install_puppet_module_via_pmt_on(host, module_name: 'darin-zypprepo') -end - -RSpec.configure do |c| - # Readable test descriptions - c.formatter = :documentation - c.color = true - - # declare an exclusion filter - c.filter_run_excluding broken: true -end +Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } diff --git a/spec/support/acceptance/helpers.rb b/spec/support/acceptance/helpers.rb new file mode 100644 index 00000000..83e5b29c --- /dev/null +++ b/spec/support/acceptance/helpers.rb @@ -0,0 +1,171 @@ +# frozen_string_literal: true + +require 'yaml' + +# Collect global options from the environment. +LS_VERSION = ENV['LOGSTASH_VERSION'] || '7.17.7' +IS_PRERELEASE = if LS_VERSION =~ %r{(alpha|beta|rc)} + true + else + false + end + +def expect_no_change_from_manifest(manifest) + expect(apply_manifest(manifest).exit_code).to eq(0) +end + +def http_package_url + url_root = "https://artifacts.elastic.co/downloads/logstash/logstash-#{LS_VERSION}" + + case fact('osfamily') + when 'Debian' + "#{url_root}-amd64.deb" + when 'RedHat', 'Suse' + "#{url_root}-x86_64.rpm" + end +end + +def local_file_package_url + "file:///tmp/#{logstash_package_filename}" +end + +def puppet_fileserver_package_url + "puppet:///modules/logstash/#{logstash_package_filename}" +end + +def logstash_package_filename + File.basename(http_package_url) +end + +def logstash_package_version + package_version = if LS_VERSION =~ %r{(alpha|beta|rc)} + LS_VERSION.gsub('-', '~') + else + LS_VERSION + end + + case fact('osfamily') # FIXME: Put this logic in the module, not the tests. + when 'RedHat' + "#{package_version}-1" + when 'Debian', 'Suse' + "1:#{package_version}-1" + end +end + +def logstash_config_manifest + <<-END + logstash::configfile { 'basic_config': + content => 'input { tcp { port => 2000 } } output { null {} }' + } + END +end + +def install_logstash_manifest(extra_args = nil) + <<-END + class { 'elastic_stack::repo': + version => #{LS_VERSION[0]}, + prerelease => #{IS_PRERELEASE}, + } + class { 'logstash': + manage_repo => true, + version => '#{logstash_package_version}', + #{extra_args} + } + + #{logstash_config_manifest} + END +end + +def include_logstash_manifest + <<-END + class { 'elastic_stack::repo': + version => #{LS_VERSION[0]}, + prerelease => #{IS_PRERELEASE}, + } + + include logstash + + #{logstash_config_manifest} + END +end + +def install_logstash_from_url_manifest(url, extra_args = nil) + <<-END + class { 'logstash': + package_url => '#{url}', + #{extra_args} + } + + #{logstash_config_manifest} + END +end + +def install_logstash_from_local_file_manifest(extra_args = nil) + install_logstash_from_url_manifest(local_file_package_url, extra_args) +end + +def remove_logstash_manifest + "class { 'logstash': ensure => 'absent' }" +end + +def stop_logstash_manifest + "class { 'logstash': status => 'disabled' }" +end + +# Provide a basic Logstash install. Useful as a testing pre-requisite. +def install_logstash(extra_args = nil) + result = apply_manifest(install_logstash_manifest(extra_args), catch_failures: true) + sleep 5 # FIXME: This is horrible. + result +end + +def include_logstash + result = apply_manifest(include_logstash_manifest, catch_failures: true) + sleep 5 # FIXME: This is horrible. + result +end + +def install_logstash_from_url(url, extra_args = nil) + manifest = install_logstash_from_url_manifest(url, extra_args) + result = apply_manifest(manifest, catch_failures: true) + sleep 5 # FIXME: This is horrible. + result +end + +def install_logstash_from_local_file(extra_args = nil) + install_logstash_from_url(local_file_package_url, extra_args) +end + +def remove_logstash + result = apply_manifest(remove_logstash_manifest) + sleep 5 # FIXME: This is horrible. + result +end + +def stop_logstash + result = apply_manifest(stop_logstash_manifest, catch_failures: true) + shell('ps -eo comm | grep java | xargs kill -9', accept_all_exit_codes: true) + sleep 5 # FIXME: This is horrible. + result +end + +def logstash_process_list + ps_cmd = 'ps -ww --no-headers -C java -o user,command | grep logstash' + shell(ps_cmd, accept_all_exit_codes: true).stdout.split("\n") +end + +def logstash_settings + YAML.safe_load(shell('cat /etc/logstash/logstash.yml').stdout) +end + +def expect_setting(setting, value) + expect(logstash_settings[setting]).to eq(value) +end + +def pipelines_from_yaml + YAML.safe_load(shell('cat /etc/logstash/pipelines.yml').stdout) +end + +def service_restart_message + "Service[logstash]: Triggered 'refresh'" +end