diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ecb10a8 --- /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 57d338a..3b8dd93 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,3 +1,4 @@ +--- fixtures: repositories: stdlib: @@ -18,5 +19,3 @@ fixtures: selinux_core: repo: "https://github.com/puppetlabs/puppetlabs-selinux_core.git" ref: "1.0.1" - symlinks: - varnish: "#{source_dir}" diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 8dda79b..048d2b5 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,31 +1,116 @@ +# 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 quicker. +will likely make it into a release a little more quickly. ## Contributing -Please note that this project has adopted the [Voxpupuli Contributor Code of Conduct](https://voxpupuli.org/coc/). +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. -. - -1. Fork the repo. - -1. Create a separate branch for your change. - -1. Run the tests. Only pull requests with passing tests, and documentation will - be merged. - -1. Add a test for your change. Only refactoring and documentation - changes require no new tests. If you are adding functionality - or fixing a bug, please add a test. - -1. Squash your commits down into logical components. Make sure to rebase - against the current master. - -1. Push the branch to your fork and submit a pull request. - -Please be prepared to repeat some of these steps as our contributors review -your code. +[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 @@ -38,41 +123,130 @@ By default the tests use a baseline version of Puppet. If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: - export PUPPET_VERSION="~> 4.2.0" +```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: -Install the dependencies like so... +```sh +BUNDLE_JOBS="$(nproc)" +``` - bundle install +### Note for OS X users -## Syntax and style +`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: - bundle exec rake lint - bundle exec rake validate +```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: - bundle exec rake rubocop +```sh +bundle exec rake rubocop +``` -## Running the unit tests +### 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 - bundle exec rake spec SPEC_OPTS='--format documentation' +```sh +bundle exec rake spec +``` To run a specific spec test set the `SPEC` variable: - bundle exec rake spec SPEC=spec/foo_spec.rb +```sh +bundle exec rake spec SPEC=spec/foo_spec.rb +``` -To run the linter, the syntax checker and the unit tests: +#### 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=debian10-x64 bundle exec rake beaker +``` + +You can replace the string `debian10` with any common operating system. +The following strings are known to work: + +* ubuntu1604 +* ubuntu1804 +* ubuntu2004 +* debian9 +* debian10 +* centos7 +* centos8 + +For more information and tips & tricks, see [voxpupuli-acceptance's documentation](https://github.com/voxpupuli/voxpupuli-acceptance#running-tests). - bundle exec rake test +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/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 66f8044..342807b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,3 +6,15 @@ Thank you for contributing to this project! - Our vulnerabilities reporting process is at https://voxpupuli.org/security/ --> +#### Pull Request (PR) description + + +#### This Pull Request (PR) fixes the following issues + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..086a667 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: CI + +on: + - pull_request + - push + +jobs: + setup_matrix: + name: 'Setup Test Matrix' + runs-on: ubuntu-latest + timeout-minutes: 40 + outputs: + puppet_unit_test_matrix: ${{ steps.get-outputs.outputs.puppet_unit_test_matrix }} + github_action_test_matrix: ${{ steps.get-outputs.outputs.github_action_test_matrix }} + env: + BUNDLE_WITHOUT: development:system_tests:release + steps: + - uses: actions/checkout@v2 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + bundler-cache: true + - name: Run static validations + run: bundle exec rake validate lint check + - name: Run rake rubocop + run: bundle exec rake rubocop + - name: Setup Test Matrix + id: get-outputs + run: bundle exec metadata2gha --use-fqdn --pidfile-workaround false + + unit: + needs: setup_matrix + runs-on: ubuntu-latest + timeout-minutes: 40 + 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 parallel_spec diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a78d2d6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +--- +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +name: Release + +on: + push: + tags: + - '*' + +env: + BUNDLE_WITHOUT: development:test:system_tests + +jobs: + deploy: + name: 'deploy to forge' + runs-on: ubuntu-latest + if: github.repository_owner == 'fe80' + 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/.gitignore b/.gitignore index 6344515..59a6173 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,25 @@ -.git/ -.*.sw[op] -.metadata -.yardoc -.yardwarns +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ + +pkg/ +Gemfile.lock +Gemfile.local +vendor/ +.vendor/ +spec/fixtures/manifests/ +spec/fixtures/modules/ +.vagrant/ +.bundle/ +.ruby-version +coverage/ +log/ +.idea/ +.dependencies/ +.librarian/ +Puppetfile.lock *.iml -/.bundle/ -/.idea/ -/.vagrant/ -/coverage/ -/bin/ -/doc/ -/Gemfile.local -/Gemfile.lock -/junit/ -/log/ -/pkg/ -/spec/fixtures/manifests/ -/spec/fixtures/modules/ -/tmp/ -/vendor/ -/convert_report.txt -/update_report.txt -.DS_Store +.*.sw? +.yardoc/ +Guardfile *.log convert_report.txt diff --git a/.msync.yml b/.msync.yml new file mode 100644 index 0000000..a83abd9 --- /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.1.0' diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..d367ada --- /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/.pdkignore b/.pdkignore deleted file mode 100644 index b713b3b..0000000 --- a/.pdkignore +++ /dev/null @@ -1,37 +0,0 @@ -.git/ -.*.sw[op] -.metadata -.yardoc -.yardwarns -*.iml -/.bundle/ -/.idea/ -/.vagrant/ -/coverage/ -/bin/ -/doc/ -/Gemfile.local -/Gemfile.lock -/junit/ -/log/ -/pkg/ -/spec/fixtures/manifests/ -/spec/fixtures/modules/ -/tmp/ -/vendor/ -/convert_report.txt -/update_report.txt -.DS_Store -/appveyor.yml -/.fixtures.yml -/Gemfile -/.gitattributes -/.gitignore -/.gitlab-ci.yml -/.pdkignore -/Rakefile -/.rspec -/.rubocop.yml -/.travis.yml -/.yardopts -/spec/ diff --git a/.pmtignore b/.pmtignore new file mode 100644 index 0000000..65f5051 --- /dev/null +++ b/.pmtignore @@ -0,0 +1,37 @@ +# 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 index cc96ece..dd8272c 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -1 +1,3 @@ ---relative +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/.rspec b/.rspec index 16f9cdb..f634583 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,5 @@ ---color +# 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 index e4d136b..a9a84f8 100644 --- a/.rspec_parallel +++ b/.rspec_parallel @@ -1 +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 f5a6c2a..53ac189 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,122 +1,6 @@ --- -require: rubocop-rspec -AllCops: - DisplayCopNames: true - TargetRubyVersion: '2.1' - Include: - - "./**/*.rb" - Exclude: - - bin/* - - ".vendor/**/*" - - "**/Gemfile" - - "**/Rakefile" - - pkg/**/* - - spec/fixtures/**/* - - vendor/**/* - - "**/Puppetfile" - - "**/Vagrantfile" - - "**/Guardfile" -Metrics/LineLength: - Description: People have wide screens, use them. - Max: 200 -GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/* -RSpec/BeforeAfterAll: - Description: Beware of using after(:all) as it may cause state to leak between tests. - A necessary evil in acceptance testing. - Exclude: - - spec/acceptance/**/*.rb -RSpec/HookArgument: - Description: Prefer explicit :each argument, matching existing module's style - EnforcedStyle: each -Style/BlockDelimiters: - Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to - be consistent then. - EnforcedStyle: braces_for_chaining -Style/ClassAndModuleChildren: - Description: Compact style reduces the required amount of indentation. - EnforcedStyle: compact -Style/EmptyElse: - Description: Enforce against empty else clauses, but allow `nil` for clarity. - EnforcedStyle: empty -Style/FormatString: - Description: Following the main puppet project's style, prefer the % format format. - EnforcedStyle: percent -Style/FormatStringToken: - Description: Following the main puppet project's style, prefer the simpler template - tokens over annotated ones. - EnforcedStyle: template -Style/Lambda: - Description: Prefer the keyword for easier discoverability. - EnforcedStyle: literal -Style/RegexpLiteral: - Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 - EnforcedStyle: percent_r -Style/TernaryParentheses: - Description: Checks for use of parentheses around ternary conditions. Enforce parentheses - on complex expressions for better readability, but seriously consider breaking - it up. - EnforcedStyle: require_parentheses_when_complex -Style/TrailingCommaInArguments: - Description: Prefer always trailing comma on multiline argument lists. This makes - diffs, and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/TrailingCommaInLiteral: - Description: Prefer always trailing comma on multiline literals. This makes diffs, - and re-ordering nicer. - EnforcedStyleForMultiline: comma -Style/SymbolArray: - Description: Using percent style obscures symbolic intent of array's contents. - EnforcedStyle: brackets -RSpec/MessageSpies: - EnforcedStyle: receive -Style/Documentation: - Exclude: - - lib/puppet/parser/functions/**/* - - spec/**/* -Style/WordArray: - EnforcedStyle: brackets -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Layout/EndOfLine: - Enabled: false -Layout/IndentHeredoc: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/MessageExpectation: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/NestedGroups: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/SymbolProc: - Enabled: false +# 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 index 5040ef4..d2b20c5 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,14 +1,11 @@ --- .gitignore: paths: - - '*.log' - - 'convert_report.txt' + - '*.log' + - 'convert_report.txt' .gitlab-ci.yml: delete: true appveyor.yml: delete: true - -.yardopts: - delete: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 521510d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -dist: trusty -language: ruby -cache: bundler -before_install: - - bundle -v - - rm -f Gemfile.lock - - gem update --system $RUBYGEMS_VERSION - - gem --version - - bundle -v -script: - - 'bundle exec rake $CHECK' -bundler_args: --without system_tests -rvm: - - 2.5.1 -env: - global: - - BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0" -matrix: - fast_finish: true - include: - - - env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" - - - env: CHECK=parallel_spec - - - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.4 -branches: - only: - - master - - /^v\d/ -notifications: - email: false -deploy: - provider: puppetforge - user: puppet - password: - secure: "" - on: - tags: true - all_branches: true - condition: "$DEPLOY_TO_FORGE = yes" diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..2f1e4f7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "puppet.puppet-vscode", + "rebornix.Ruby" + ] +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e3cf307 --- /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_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 cf2c387..b6dcf45 100644 --- a/Gemfile +++ b/Gemfile @@ -1,71 +1,34 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -def location_for(place_or_version, fake_version = nil) - git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} - file_url_regex = %r{\Afile:\/\/(?.*)} +source ENV['GEM_SOURCE'] || "https://rubygems.org" - if place_or_version && (git_url = place_or_version.match(git_url_regex)) - [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact - elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) - ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] - else - [place_or_version, { require: false }] - end +group :test do + gem 'voxpupuli-test', '~> 5.0', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false + gem 'puppet_metadata', '~> 1.0', :require => false end -ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments -minor_version = ruby_version_segments[0..1].join('.') - group :development do - gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') - gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') - gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') - gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9') - gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem 'guard-rake', :require => false + gem 'overcommit', '>= 0.39.1', :require => false end -puppet_version = ENV['PUPPET_GEM_VERSION'] -facter_version = ENV['FACTER_GEM_VERSION'] -hiera_version = ENV['HIERA_GEM_VERSION'] - -gems = {} - -gems['puppet'] = location_for(puppet_version) - -# If facter or hiera versions have been specified via the environment -# variables - -gems['facter'] = location_for(facter_version) if facter_version -gems['hiera'] = location_for(hiera_version) if hiera_version - -if Gem.win_platform? && puppet_version =~ %r{^(file:///|git://)} - # If we're using a Puppet gem on Windows which handles its own win32-xxx gem - # dependencies (>= 3.5.0), set the maximum versions (see PUP-6445). - gems['win32-dir'] = ['<= 0.4.9', require: false] - gems['win32-eventlog'] = ['<= 0.6.5', require: false] - gems['win32-process'] = ['<= 0.7.5', require: false] - gems['win32-security'] = ['<= 0.2.5', require: false] - gems['win32-service'] = ['0.8.8', require: false] +group :system_tests do + gem 'voxpupuli-acceptance', '~> 1.0', :require => false end -gems.each do |gem_name, gem_params| - gem gem_name, *gem_params +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 -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] +gem 'rake', :require => false +gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] + +puppetversion = ENV['PUPPET_VERSION'] || '>= 6.0' +gem 'puppet', puppetversion, :require => false, :groups => [:test] -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end -end # vim: syntax=ruby diff --git a/README.md b/README.md index ae0a5d8..7ca3a81 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ please use the latest version [4.x version from the Puppet Forge](https://forge. ## Module Description This module Supports Varnish versions 3.0, 4.0, 4.1, 5.0, 5.1, 5.2, -6.0, 6.1 across Ubuntu 14.04/16.04/18.04, Debian 7/8/9 and RedHat derivates -6/7. +6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6 across Ubuntu 14.04/16.04/18.04, +Debian 7/8/9/10 and RedHat derivates 6/7. This module will install Varnish, **by default version 4.1** from the official Packagecloud repositories, adding EPEL for RedHat-like systems and working diff --git a/Rakefile b/Rakefile index a6b14c5..f92f051 100644 --- a/Rakefile +++ b/Rakefile @@ -1,76 +1,72 @@ -require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? -require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? -require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -def changelog_user - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['author'] - raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator user:#{returnVal}" - returnVal +# 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 -def changelog_project - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = nil || JSON.load(File.read('metadata.json'))['name'] - raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator project:#{returnVal}" - returnVal +# load optional tasks for releases +# only available if gem group releases is installed +begin + require 'voxpupuli/release/rake_tasks' +rescue LoadError end -def changelog_future_release - return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = JSON.load(File.read('metadata.json'))['version'] - raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? - puts "GitHubChangelogGenerator future_release:#{returnVal}" - returnVal +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 -PuppetLint.configuration.send('disable_relative') +desc 'Generate REFERENCE.md' +task :reference, [:debug, :backtrace] do |t, args| + patterns = '' + Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) +end -if Bundler.rubygems.find_name('github_changelog_generator').any? +begin + require 'github_changelog_generator/task' + require 'puppet_blacksmith' GitHubChangelogGenerator::RakeTask.new :changelog do |config| - raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? - config.user = "#{changelog_user}" - config.project = "#{changelog_project}" - config.future_release = "#{changelog_future_release}" - config.exclude_labels = ['maintenance'] - config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." - config.add_pr_wo_labels = true - config.issues = false - config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" - config.configure_sections = { - "Changed" => { - "prefix" => "### Changed", - "labels" => ["backwards-incompatible"], - }, - "Added" => { - "prefix" => "### Added", - "labels" => ["feature", "enhancement"], - }, - "Fixed" => { - "prefix" => "### Fixed", - "labels" => ["bugfix"], - }, - } + 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 = metadata.metadata['name'] end -else - desc 'Generate a Changelog from GitHub' - task :changelog do - raise <= Gem::Version.new('2.2.2')" -EOM + + # 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 -end +rescue LoadError +end +# vim: syntax=ruby diff --git a/Vagrantfile b/Vagrantfile index 5524489..4e23c56 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -11,7 +11,8 @@ PUPPET_VERSION = "5.5.10" BOXES = [ { name: "debian7", box: "debian/wheezy64", version: "7.11.2" }, { name: "debian8", box: "debian/jessie64", version: "8.11.0" }, - { name: "debian8", box: "debian/stretch64", version: "9.8.0" }, + { name: "debian9", box: "debian/stretch64", version: "9.8.0" }, + { name: "debian10", box: "debian/buster64", version: "10.11.0" }, { name: "ubuntu14", box: "ubuntu/trusty64", version: "20190301.0.1" }, { name: "ubuntu16", box: "ubuntu/xenial64", version: "20190221.0.0" }, diff --git a/examples/init.pp b/examples/init.pp index 43b28e0..84b362c 100644 --- a/examples/init.pp +++ b/examples/init.pp @@ -1,14 +1,13 @@ node default { - $version = '6.0lts' # == Package Versions - case $::osfamily { + case $facts['os']['family'] { 'Debian': { - if $::operatingsystem == 'Debian' and versioncmp($::lsbdistrelease,'8.0') >= 0 and $version == '3.0' { + if $facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['full'] , '8.0') >= 0 and $version == '3.0' { $package_ensure = '3.0.7-1~jessie' - } elsif $::operatingsystem == 'Ubuntu' and versioncmp($::lsbdistrelease,'16.04') >= 0 and $version == '4.0' { + } elsif $facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '16.04') >= 0 and $version == '4.0' { $package_ensure = '4.0.5-1~xenial' } else { $package_ensure = 'present' @@ -16,7 +15,7 @@ } 'RedHat': { - if $::operatingsystemmajrelease == '7' and $version == '4.0' { + if $facts['os']['release']['major'] == '7' and $version == '4.0' { $package_ensure = '4.0.4-1.el7' } else { $package_ensure = 'present' @@ -30,10 +29,10 @@ # == Varnish - class { '::varnish': + class { 'varnish': varnish_version => $version, package_ensure => $package_ensure, - listen => ['127.0.0.1:8888',"${::ipaddress}:6081"], + listen => ['127.0.0.1:8888',"${facts['networking']['ip']}:6081"], storage_additional => ['file,/var/lib/varnish/varnish_additional.bin,1G'], storage_type => 'malloc', storage_size => '64M', @@ -42,12 +41,12 @@ # == Nginx + test file - class { '::nginx': + class { 'nginx': server_purge => true, confd_purge => true, } - if $::osfamily == 'Debian' { + if $facts['os']['family'] == 'Debian' { $nginx_port = 8080 } else { $nginx_port = 80 @@ -64,8 +63,7 @@ owner => 'root', group => 'root', mode => '0644', - content => "VarnishHello, I am Varnish ${version} running on ${::hostname}\n", + content => "VarnishHello, I am Varnish ${version} running on ${facts['networking']['hostname']}\n", require => Package['nginx'], } - } diff --git a/manifests/config.pp b/manifests/config.pp index b34515a..c11507b 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,35 +3,34 @@ # This class is called from varnish # class varnish::config { - - if versioncmp("${::varnish::version_major}.${::varnish::version_minor}",'4.1') >= 0 { + if versioncmp("${varnish::version_major}.${varnish::version_minor}",'4.1') >= 0 { $jail_opt = '-j unix,user=varnish,ccgroup=varnish' } else { $jail_opt = '-u varnish -g varnish' } # Deploy Varnish 4+ SELinux hack on RHEL6 - if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '6' and $::varnish::version_major != '3' { - if $::selinux_current_mode == 'enforcing' { - ::selinux::module { 'varnishpol': + if $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '6' and $varnish::version_major != '3' { + # lint:ignore:legacy_facts + if $facts['selinux_current_mode'] == 'enforcing' { + selinux::module { 'varnishpol': ensure => present, source_te => 'puppet:///modules/varnish/varnishpol.te', - before => Service[$::varnish::service_name], - notify => Service[$::varnish::service_name], + before => Service[$varnish::service_name], + notify => Service[$varnish::service_name], } } + # lint:endignore } - file { $::varnish::params::sysconfig: + file { $varnish::params::sysconfig: owner => 'root', group => 'root', mode => '0644', content => template('varnish/sysconfig.erb'), } - - if $::varnish::params::service_provider == 'systemd' { - + if $varnish::params::service_provider == 'systemd' { file { '/etc/systemd/system/varnish.service': ensure => file, owner => 'root', @@ -45,8 +44,7 @@ command => '/bin/systemctl daemon-reload', refreshonly => true, require => File['/etc/systemd/system/varnish.service'], - notify => Service[$::varnish::service_name], + notify => Service[$varnish::service_name], } } - } diff --git a/manifests/init.pp b/manifests/init.pp index b8c7c1a..4c83431 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -65,10 +65,9 @@ String $package_name = 'varnish', String $service_name = 'varnish', Optional[String] $vcl_reload_cmd = undef, - String $vcl_reload_path = $::path, + String $vcl_reload_path = $facts['path'], Boolean $proxy_protocol = false, ) { - if $package_ensure == 'present' { $version_major = regsubst($varnish_version, '^(\d+)\.(\d+).*$', '\1') $version_minor = regsubst($varnish_version, '^(\d+)\.(\d+).*$', '\2') @@ -86,35 +85,33 @@ default => '', } - include ::varnish::params + include varnish::params if $vcl_reload_cmd == undef { - $vcl_reload = $::varnish::params::vcl_reload + $vcl_reload = $varnish::params::vcl_reload } else { $vcl_reload = $vcl_reload_cmd } if $addrepo { - class { '::varnish::repo': - before => Class['::varnish::install'], + class { 'varnish::repo': + before => Class['varnish::install'], } } - include ::varnish::install - + include varnish::install - class { '::varnish::secret': + class { 'varnish::secret': secret => $secret, - require => Class['::varnish::install'], + require => Class['varnish::install'], } - class { '::varnish::config': - require => Class['::varnish::secret'], - notify => Class['::varnish::service'], + class { 'varnish::config': + require => Class['varnish::secret'], + notify => Class['varnish::service'], } - class { '::varnish::service': - require => Class['::varnish::config'], + class { 'varnish::service': + require => Class['varnish::config'], } - } diff --git a/manifests/install.pp b/manifests/install.pp index 2b94048..feccd22 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,14 +1,13 @@ # == Class varnish::install # class varnish::install { - - if $::varnish::addrepo == true { - Package[$::varnish::package_name] { - require => $::varnish::repo::package_require, + if $varnish::addrepo == true { + Package[$varnish::package_name] { + require => $varnish::repo::package_require, } } - package { $::varnish::package_name: - ensure => $::varnish::package_ensure, + package { $varnish::package_name: + ensure => $varnish::package_ensure, } } diff --git a/manifests/params.pp b/manifests/params.pp index c7f8947..436233c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,17 +4,14 @@ # It sets variables according to platform # class varnish::params { - - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { - $sysconfig = '/etc/sysconfig/varnish' - case $::operatingsystemmajrelease { - + case $facts['os']['release']['major'] { '6': { $os_service_provider = 'sysvinit' - $vcl_reload = $::varnish::version_major ? { + $vcl_reload = $varnish::version_major ? { '6' => '/usr/sbin/varnishreload', '5' => '/usr/sbin/varnish_reload_vcl', '4' => '/usr/sbin/varnish_reload_vcl', @@ -24,7 +21,7 @@ '7': { $os_service_provider = 'systemd' - $vcl_reload = $::varnish::version_major ? { + $vcl_reload = $varnish::version_major ? { '6' => '/usr/sbin/varnishreload', '5' => '/sbin/varnish_reload_vcl', '4' => '/usr/sbin/varnish_reload_vcl', @@ -40,15 +37,20 @@ } 'Debian': { - $vcl_reload = $::varnish::version_major ? { - '6' => '/usr/sbin/varnishreload', - '5' => '/usr/share/varnish/reload-vcl -q', - '4' => '/usr/share/varnish/reload-vcl -q', - '3' => '/usr/share/varnish/reload-vcl -q', + if versioncmp($varnish::version_full,'6.1') >= 0 and versioncmp($facts['os']['release']['full'],'10.0') >= 0 { + $vcl_reload = '/usr/share/varnish/varnishreload' + } + else { + $vcl_reload = $varnish::version_major ? { + '6' => '/usr/sbin/varnishreload', + '5' => '/usr/share/varnish/reload-vcl -q', + '4' => '/usr/share/varnish/reload-vcl -q', + '3' => '/usr/share/varnish/reload-vcl -q', + } } $sysconfig = '/etc/default/varnish' - case $::operatingsystem { + case $facts['os']['name'] { 'Ubuntu': { $systemd_version = '16.04' } @@ -56,11 +58,11 @@ $systemd_version = '8' } default: { - fail("Unsupported Debian OS: ${::operatingsystem}") + fail("Unsupported Debian OS: ${facts['os']['name']}") } } - if versioncmp($::lsbdistrelease,$systemd_version) >= 0 { + if versioncmp($facts['os']['release']['full'], $systemd_version) >= 0 { $os_service_provider = 'systemd' } else { $os_service_provider = 'sysvinit' @@ -68,15 +70,15 @@ } default: { - fail("${::osfamily} not supported") + fail("${facts['os']['family']} not supported") } } # == Service provider depends on Varnish version and OS - if $::varnish::version_major == '3' { - if $::operatingsystem == 'Debian' { - if versioncmp($::lsbdistrelease,'8.0') >= 0 { + if $varnish::version_major == '3' { + if $facts['os']['name'] == 'Debian' { + if versioncmp($facts['os']['release']['full'], '8.0') >= 0 { $service_provider = 'systemd' } else { $service_provider = 'sysvinit' @@ -87,5 +89,4 @@ } else { $service_provider = $os_service_provider } - } diff --git a/manifests/repo.pp b/manifests/repo.pp index 68759d3..bd4c6dc 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -1,29 +1,27 @@ # Add the Varnish repo class varnish::repo { + $ver = "${varnish::version_major}${varnish::version_minor}${varnish::version_lts}" - $ver = "${::varnish::version_major}${::varnish::version_minor}${::varnish::version_lts}" - - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { - if $ver == '50' { - if $::operatingsystemmajrelease == '6' { + if $facts['os']['release']['major'] == '6' { fail('Varnish 5.0 from Packagecloud is not supported on RHEL/CentOS 6') - } elsif $::operatingsystemmajrelease == '7' { + } elsif $facts['os']['release']['major'] == '7' { # https://github.com/varnishcache/pkg-varnish-cache/issues/42 fail('Varnish 5.0 on RHEL/CentOS 7 has a known packaging bug in the varnish_reload_vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.') } } - if $::varnish::version_major == '6' and $::operatingsystemmajrelease == '6' { + if $varnish::version_major == '6' and $facts['os']['release']['major'] == '6' { fail('Varnish 6.0 and above from Packagecloud is not supported on RHEL/CentOS 6') } $package_require = undef # Varnish 4 and above need EPEL for jemalloc - if $::varnish::version_major != '3' { - include ::epel + if $varnish::version_major != '3' { + include epel Yumrepo['varnish-cache','varnish-cache-source'] { require => Yumrepo['epel'], } @@ -31,7 +29,7 @@ yumrepo { 'varnish-cache': descr => "varnishcache_varnish${ver}", - baseurl => "https://packagecloud.io/varnishcache/varnish${ver}/el/${::operatingsystemmajrelease}/\$basearch", + baseurl => "https://packagecloud.io/varnishcache/varnish${ver}/el/${facts['os']['release']['major']}/\$basearch", gpgkey => "https://packagecloud.io/varnishcache/varnish${ver}/gpgkey", metadata_expire => '300', repo_gpgcheck => '1', @@ -42,7 +40,7 @@ yumrepo { 'varnish-cache-source': descr => "varnishcache_varnish${ver}-source", - baseurl => "https://packagecloud.io/varnishcache/varnish${ver}/el/${::operatingsystemmajrelease}/SRPMS", + baseurl => "https://packagecloud.io/varnishcache/varnish${ver}/el/${facts['os']['release']['major']}/SRPMS", gpgkey => "https://packagecloud.io/varnishcache/varnish${ver}/gpgkey", metadata_expire => '300', repo_gpgcheck => '1', @@ -52,43 +50,47 @@ } } - 'Debian': { - case $::operatingsystem { + case $facts['os']['name'] { 'Debian': { - if $ver == '50' and $::lsbdistcodename == 'wheezy' { + if $ver == '50' and $facts['os']['distro']['codename'] == 'wheezy' { fail('Varnish 5.0 from Packagecloud is not supported on Debian 7 (Wheezy)') } - if $::varnish::version_major == '6' and $::lsbdistcodename != 'stretch' { - fail('Varnish 6.0 and above is only supported on Debian 9 (Stretch)') + if $varnish::version_major == '6' and versioncmp($facts['os']['release']['full'],'9.0') == -1 { + fail('Varnish 6.0 and above is only supported on Debian 9 (Stretch) and above') } } 'Ubuntu': { - if $ver == '30' and versioncmp($::operatingsystemmajrelease,'16.04') >= 0 { + if $ver == '30' and versioncmp($facts['os']['release']['full'], '16.04') >= 0 { fail('Varnish 3 from Packagecloud is not supported after Ubuntu 14.04 (Trusty)') } - if $ver == '50' and $::lsbdistcodename == 'trusty' { + if $ver == '50' and $facts['os']['distro']['codename'] == 'trusty' { fail('Varnish 5.0 has a known packaging bug in the reload-vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.') } - if $::varnish::version_major == '6' and versioncmp($::operatingsystemmajrelease,'16.04') == -1 { + if $varnish::version_major == '6' and versioncmp($facts['os']['release']['full'], '16.04') == -1 { fail('Varnish 6.0 and above is only supported on Ubuntu 16.04 (Xenial) and newer') } } default: { - fail("Unsupported Debian OS: ${::operatingsystem}") + fail("Unsupported Debian OS: ${facts['os']['name']}") } } ensure_packages('apt-transport-https') - $os_lower = downcase($::operatingsystem) + $os_lower = downcase($facts['os']['name']) $package_require = Exec['apt_update'] - $gpg_key_id = "${::varnish::version_major}.${::varnish::version_minor}${::varnish::version_lts}" ? { + $gpg_key_id = "${varnish::version_major}.${varnish::version_minor}${varnish::version_lts}" ? { + '6.6' => 'A0378A38E4EACA3660789E570BAC19E3F6C90CD5', + '6.5' => 'A487F9BE81D9DF5121488CFE1C7B4E9FF149D65B', + '6.4' => 'A9897320C397E3A60C03E8BF821AD320F71BFF3D', + '6.3' => '920A8A7AA7120A8604BCCD294A42CD6EB810E55D', + '6.2' => 'B54813B54CA95257D3590B3F1B0096460868C7A9', '6.1' => '4A066C99B76A0F55A40E3E1E387EF1F5742D76CC', '6.0lts' => '48D81A24CB0456F5D59431D94CFCFD6BA750EDCD', '6.0' => '7C5B46721AF00FD57E68E6E8D2605BF74E8B9DBA', @@ -101,7 +103,7 @@ } ::apt::source { 'varnish-cache': - comment => "Apt source for Varnish ${::varnish::version_major}.${::varnish::version_minor}${::varnish::version_lts}", + comment => "Apt source for Varnish ${varnish::version_major}.${varnish::version_minor}${varnish::version_lts}", location => "https://packagecloud.io/varnishcache/varnish${ver}/${os_lower}/", repos => 'main', require => Package['apt-transport-https'], @@ -117,7 +119,7 @@ } default: { - fail("Unsupported repo osfamily: ${::osfamily}") + fail("Unsupported repo osfamily: ${facts['os']['family']}") } } } diff --git a/manifests/secret.pp b/manifests/secret.pp index 07cd783..ee3e2fe 100644 --- a/manifests/secret.pp +++ b/manifests/secret.pp @@ -1,30 +1,25 @@ # Specify the secret file for varnishadm # This file can be changed without notifying varnish class varnish::secret ( - $secret = undef, + Optional[String] $secret = undef, ) { - if $secret { - - file { $::varnish::secret_file: + file { $varnish::secret_file: owner => 'root', group => 'varnish', mode => '0640', content => "${secret}\n", } - } else { - - file { $::varnish::secret_file: + file { $varnish::secret_file: owner => 'root', group => 'varnish', mode => '0640', } exec { 'Generate Varnish secret file': - unless => "/bin/egrep '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' '${::varnish::secret_file}' >/dev/null", - command => "/bin/cp /proc/sys/kernel/random/uuid '${::varnish::secret_file}'", + unless => "/bin/egrep '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' '${varnish::secret_file}' >/dev/null", + command => "/bin/cp /proc/sys/kernel/random/uuid '${varnish::secret_file}'", } - } } diff --git a/manifests/service.pp b/manifests/service.pp index 910e60f..0f641aa 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -4,18 +4,16 @@ # It ensure the service is running # class varnish::service { - # This exec resource receives notifications from varnish::vcl resources exec { 'vcl_reload': - command => $::varnish::vcl_reload, - path => $::varnish::vcl_reload_path, + command => $varnish::vcl_reload, + path => $varnish::vcl_reload_path, refreshonly => true, - require => Service[$::varnish::service_name], + require => Service[$varnish::service_name], } - service { $::varnish::service_name: + service { $varnish::service_name: ensure => 'running', enable => true, } - } diff --git a/manifests/vcl.pp b/manifests/vcl.pp index 5954437..9f8211e 100644 --- a/manifests/vcl.pp +++ b/manifests/vcl.pp @@ -4,12 +4,11 @@ # If the VCL fails to parse, the exec will fail # and Varnish will continue to run with the old config define varnish::vcl ( - $content, - $file = $name + String $content, + String $file = $name ) { - - include ::varnish - include ::varnish::params + include varnish + include varnish::params file { $file: content => $content, diff --git a/metadata.json b/metadata.json index 7ac4b9d..0b9069d 100644 --- a/metadata.json +++ b/metadata.json @@ -18,11 +18,11 @@ }, { "name": "puppetlabs/apt", - "version_requirement": ">= 2.0.0 < 5.0.0" + "version_requirement": ">= 2.0.0 < 9.0.0" }, { "name": "puppetlabs/stdlib", - "version_requirement": ">=4.6.0 < 6.0.0" + "version_requirement": ">=4.6.0 < 9.0.0" } ], "operatingsystem_support": [ @@ -67,14 +67,15 @@ "operatingsystemrelease": [ "7", "8", - "9" + "9", + "10" ] } ], "requirements": [ { "name": "puppet", - "version_requirement": ">= 4.7.1 < 6.0.0" + "version_requirement": ">= 6.1.0 < 8.0.0" } ], "description": "Install and configure Varnish Cache", @@ -83,7 +84,7 @@ "cache", "http" ], - "pdk-version": "1.9.0", - "template-url": "file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git", - "template-ref": "1.9.0-0-g7281db5" + "pdk-version": "2.3.0", + "template-url": "pdk-default#2.3.0", + "template-ref": "tags/2.3.0-0-g8aaceff" } diff --git a/spec/classes/coverage_spec.rb b/spec/classes/coverage_spec.rb deleted file mode 100644 index c083569..0000000 --- a/spec/classes/coverage_spec.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'rspec-puppet' - -at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/classes/varnish_spec.rb b/spec/classes/varnish_spec.rb index b4a86a1..d52db8d 100644 --- a/spec/classes/varnish_spec.rb +++ b/spec/classes/varnish_spec.rb @@ -1,137 +1,336 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'varnish', type: :class do - ['3.0', '4.0', '4.1', '5.0', '5.1', '5.2', '6.0', '6.0lts', '6.1'].each do |version| - on_supported_os.each do |os, facts| - context "Varnish #{version} on #{os}" do - let(:facts) do - facts.merge(path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin') + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) { facts } + + it { is_expected.to compile.with_all_deps } + + # Temporary variable before remove init support + systemd = ( + facts[:os]['family'] == 'RedHat' && + facts[:os]['release']['major'].to_i >= 7 + ) || ( + facts[:os]['release']['name'] == 'Ubuntu' && + facts[:os]['release']['major'].to_f >= 16.04 + ) || ( + facts[:os]['release']['name'] == 'Debian' && + facts[:os]['release']['major'].to_i >= 8 + ) + + context 'with default params' do + it { is_expected.to contain_class('varnish::params') } + it { is_expected.to contain_class('varnish::repo') } + it { is_expected.to contain_class('varnish::install') } + it { is_expected.to contain_class('varnish::secret') } + it { is_expected.to contain_class('varnish::config') } + it { is_expected.to contain_class('varnish::service') } + + if facts[:os]['family'] == 'RedHat' + it { is_expected.to contain_class('epel') } + + it do + is_expected.to contain_yumrepo('varnish-cache').with( + descr: 'varnishcache_varnish41', + baseurl: format( + 'https://packagecloud.io/varnishcache/varnish41/el/%s/$basearch', + facts[:os]['release']['major'] + ), + gpgkey: 'https://packagecloud.io/varnishcache/varnish41/gpgkey', + metadata_expire: '300', + repo_gpgcheck: '1', + gpgcheck: '0', + sslverify: '1', + sslcacert: '/etc/pki/tls/certs/ca-bundle.crt' + ) + end + + it do + is_expected.to contain_yumrepo('varnish-cache-source').with( + descr: 'varnishcache_varnish41-source', + baseurl: format( + 'https://packagecloud.io/varnishcache/varnish41/el/%s/SRPMS', + facts[:os]['release']['major'] + ), + gpgkey: 'https://packagecloud.io/varnishcache/varnish41/gpgkey', + metadata_expire: '300', + repo_gpgcheck: '1', + gpgcheck: '0', + sslverify: '1', + sslcacert: '/etc/pki/tls/certs/ca-bundle.crt' + ) + end + else + it { is_expected.to contain_package('apt-transport-https') } + + it do + is_expected.to contain_apt__source('varnish-cache').with( + comment: 'Apt source for Varnish 4.1', + location: format( + 'https://packagecloud.io/varnishcache/varnish41/%s/', + facts[:os]['name'].downcase + ), + repos: 'main', + require: 'Package[apt-transport-https]', + key: { + 'source' => 'https://packagecloud.io/varnishcache/varnish41/gpgkey', + 'id' => '9C96F9CA0DC3F4EA78FF332834BF6E8ECBF5C49E', + }, + include: { + 'deb' => true, + 'src' => true, + } + ) + end end - let(:params) do - { - varnish_version: version, - } + it { is_expected.to contain_package('varnish') } + + it do + is_expected.to contain_file('/etc/varnish/secret').with( + owner: 'root', + group: 'varnish', + mode: '0640' + ) + end + + it do + is_expected.to contain_exec('Generate Varnish secret file').with( + unless: "/bin/egrep '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' '/etc/varnish/secret' >/dev/null", + command: "/bin/cp /proc/sys/kernel/random/uuid '/etc/varnish/secret'" + ) + end + + it do + sysconfig = if facts[:os]['family'] == 'RedHat' + '/etc/sysconfig/varnish' + else + '/etc/default/varnish' + end + is_expected.to contain_file(sysconfig).with( + owner: 'root', + group: 'root', + mode: '0644' + ) end - should_fail = 0 - case version - when '3.0' - if facts[:operatingsystem] == 'Ubuntu' && Gem::Version.new(facts[:operatingsystemmajrelease]) >= Gem::Version.new('16.04') - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 3 from Packagecloud is not supported after Ubuntu 14.04 \(Trusty\)}) } - should_fail = 1 + varnish_reload = if facts[:os]['family'] == 'RedHat' + '/usr/sbin/varnish_reload_vcl' + else + '/usr/share/varnish/reload-vcl -q' + end + + if systemd + it do + is_expected.to contain_file('/etc/systemd/system/varnish.service'). + with( + ensure: 'file', + owner: 'root', + group: 'root', + mode: '0644', + notify: 'Exec[varnish_systemctl_daemon_reload]', + content: <<~EOF + [Unit] + Description=Varnish HTTP accelerator + After=network.target + + [Install] + WantedBy=multi-user.target + + [Service] + Type=forking + LimitNOFILE=131072 + LimitMEMLOCK=82000 + LimitCORE=infinity + PrivateTmp=true + + ExecReload=#{varnish_reload} + ExecStart=/usr/sbin/varnishd -j unix,user=varnish,ccgroup=varnish \\ + -P /var/run/varnish.pid \\ + -t 120 \\ + -f /etc/varnish/default.vcl \\ + -a 0.0.0.0:6081 \\ + -T 127.0.0.1:6082 \\ + -p thread_pool_min=50 \\ + -p thread_pool_max=1000 \\ + -p thread_pool_timeout=120 \\ + -S /etc/varnish/secret \\ + -s file,/var/lib/varnish/varnish_storage.bin,1G + EOF + ) end - when '5.0' - if facts[:osfamily] == 'RedHat' - case facts[:operatingsystemmajrelease] - when '6' - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 from Packagecloud is not supported on RHEL\/CentOS 6}) } - should_fail = 1 - when '7' - # rubocop:disable LineLength - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 on RHEL\/CentOS 7 has a known packaging bug in the varnish_reload_vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.}) } - # rubocop:enable LineLength - should_fail = 1 - end - elsif facts[:osfamily] == 'Debian' - case facts[:lsbdistcodename] - when 'wheezy' - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 from Packagecloud is not supported on Debian 7 \(Wheezy\)}) } - should_fail = 1 - when 'trusty' - # rubocop:disable LineLength - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 has a known packaging bug in the reload-vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.}) } - # rubocop:enable LineLength - should_fail = 1 - end + + it do + is_expected.to contain_exec('varnish_systemctl_daemon_reload').with( + command: '/bin/systemctl daemon-reload', + refreshonly: true, + require: 'File[/etc/systemd/system/varnish.service]', + notify: 'Service[varnish]' + ) end - when %r{6} - if facts[:osfamily] == 'RedHat' - if facts[:operatingsystemmajrelease] == '6' - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 6.0 and above from Packagecloud is not supported on RHEL\/CentOS 6}) } - should_fail = 1 - end - elsif facts[:osfamily] == 'Debian' - if facts[:operatingsystem] == 'Debian' && facts[:lsbdistcodename] != 'stretch' - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 6.0 and above is only supported on Debian 9 \(Stretch\)}) } - should_fail = 1 - end + end + + it do + is_expected.to contain_exec('vcl_reload').with( + command: varnish_reload, + refreshonly: true, + require: 'Service[varnish]' + ) + end + + it do + is_expected.to contain_service('varnish').with( + ensure: 'running', + enable: true + ) + end + + describe 'with selinux_current_mode to enforcing' do + let(:facts) { super().merge(selinux_current_mode: 'enforcing') } - if facts[:operatingsystem] == 'Ubuntu' && Gem::Version.new(facts[:operatingsystemmajrelease]) < Gem::Version.new('16.04') - it { is_expected.to raise_error(Puppet::Error, %r{Varnish 6.0 and above is only supported on Ubuntu 16.04 \(Xenial\) and newer}) } - should_fail = 1 + if facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'] == '6' + it do + is_expected.to contain_selinux__module('varnishpol').with( + ensure: 'present', + source_te: 'puppet:///modules/varnish/varnishpol.te', + notify: 'Service[varnish]' + ) end end end + end - if should_fail == 0 - it { is_expected.to compile.with_all_deps } + context 'with runtime_params' do + let(:params) do + { runtime_params: { accept_filter: true, acceptor_sleep_max: 10 } } + end - if (facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease] == '7' && version != '3.0') || - (facts[:osfamily] == 'Debian' && (facts[:lsbdistcodename] == 'jessie' || facts[:lsbdistcodename] == 'xenial')) - it { is_expected.to contain_file('/etc/systemd/system/varnish.service') } - it { is_expected.to contain_exec('varnish_systemctl_daemon_reload') } + if systemd + it do + is_expected.to contain_file('/etc/systemd/system/varnish.service'). + with( + content: %r{-p accept_filter=true \\\n -p acceptor_sleep_max=10} + ) end + end + end - case facts[:osfamily] - when 'RedHat' + context 'with addrepo at false' do + let(:params) { { addrepo: false } } - if facts[:operatingsystemmajrelease] == '6' && version != '3.0' - it { is_expected.to contain_selinux__module('varnishpol') } - end + it { is_expected.not_to contain_class('varnish::repo') } + end - it { is_expected.to contain_file('/etc/sysconfig/varnish') } - it { is_expected.to contain_yumrepo('varnish-cache') } - it { is_expected.to contain_yumrepo('varnish-cache-source') } - when 'Debian' - it { is_expected.to contain_file('/etc/default/varnish') } - it { is_expected.to contain_package('apt-transport-https') } - it { is_expected.to contain_apt__source('varnish-cache') } + context 'with secret at supersecret' do + let(:params) { { secret: 'supersecret' } } + + it { is_expected.not_to contain_exec('Generate Varnish secret file') } + + it do + is_expected.to contain_file('/etc/varnish/secret').with( + owner: 'root', + group: 'varnish', + mode: '0640', + content: "supersecret\n" + ) + end + end + + context 'with storage_type at malloc' do + let(:params) { { storage_type: 'malloc' } } + + if systemd + it do + is_expected.to contain_file('/etc/systemd/system/varnish.service'). + with( + content: %r{-s malloc,1G} + ) end + end + end + context 'with storage_additional define' do + let(:params) do + { storage_additional: ['malloc,2G', 'file,/tmp/fast,1G'] } + end + + if systemd + it do + is_expected.to contain_file('/etc/systemd/system/varnish.service'). + with( + content: %r{-s malloc,2G \\\n -s file,/tmp/fast,1G} + ) + end end end - end - end - context 'supported operating systems' do - let(:facts) do - { - osfamily: 'RedHat', - operatingsystem: 'CentOS', - operatingsystemmajrelease: '7', - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', - lsbdistrelease: nil, - } - end + context 'with vcl_reload_cmd define' do + let(:params) { { vcl_reload_cmd: '/bin/varnish reload' } } - it { is_expected.to contain_class('varnish::params') } - it { is_expected.to contain_class('varnish::repo').that_comes_before('Class[varnish::install]') } - it { is_expected.to contain_class('varnish::install').that_comes_before('Class[varnish::secret]') } - it { is_expected.to contain_class('varnish::secret').that_comes_before('Class[varnish::config]') } - it { is_expected.to contain_class('varnish::config').that_notifies('Class[varnish::service]') } - it { is_expected.to contain_class('varnish::config').that_comes_before('Class[varnish::service]') } - it { is_expected.to contain_class('varnish::service') } - - it { is_expected.to contain_file('/etc/varnish/secret') } - it { is_expected.to contain_exec('Generate Varnish secret file') } - it { is_expected.to contain_package('varnish') } - it { is_expected.to contain_service('varnish') } - it { is_expected.to contain_exec('vcl_reload') } - end + it do + is_expected.to contain_exec('vcl_reload').with( + command: '/bin/varnish reload' + ) + end - context 'unsupported operating systems' do - describe 'varnish class fail on unsupported OS' do - let(:facts) do - { - osfamily: 'Darwin', - operatingsystem: 'Darwin', - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', - lsbdistrelease: nil, - } + if systemd + it do + is_expected.to contain_file('/etc/systemd/system/varnish.service'). + with( + content: %r{ExecReload=/bin/varnish reload} + ) + end + end end - it { is_expected.to raise_error(Puppet::Error, %r{Darwin not supported}) } + context 'with lts version' do + let(:params) { { varnish_version: '6.0lts' } } + + if facts[:os]['family'] == 'RedHat' + unless facts[:os]['release']['major'] == '6' + it do + is_expected.to contain_yumrepo('varnish-cache').with( + descr: 'varnishcache_varnish60lts', + baseurl: format( + 'https://packagecloud.io/varnishcache/varnish60lts/el/%s/$basearch', + facts[:os]['release']['major'] + ), + gpgkey: 'https://packagecloud.io/varnishcache/varnish60lts/gpgkey' + ) + end + + it do + is_expected.to contain_yumrepo('varnish-cache-source').with( + descr: 'varnishcache_varnish60lts-source', + baseurl: format( + 'https://packagecloud.io/varnishcache/varnish60lts/el/%s/SRPMS', + facts[:os]['release']['major'] + ), + gpgkey: 'https://packagecloud.io/varnishcache/varnish60lts/gpgkey' + ) + end + end + else + unless facts[:os]['release']['major'] =~ %r{(7|8|14\.04)} + it do + is_expected.to contain_apt__source('varnish-cache').with( + comment: 'Apt source for Varnish 6.0lts', + location: format( + 'https://packagecloud.io/varnishcache/varnish60lts/%s/', + facts[:os]['name'].downcase + ), + key: { + 'source' => 'https://packagecloud.io/varnishcache/varnish60lts/gpgkey', + 'id' => '48D81A24CB0456F5D59431D94CFCFD6BA750EDCD' + } + ) + end + end + end + end end end end diff --git a/spec/default_facts.yml b/spec/default_facts.yml deleted file mode 100644 index ea1e480..0000000 --- a/spec/default_facts.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Use default_module_facts.yml for module specific facts. -# -# Facts specified here will override the values provided by rspec-puppet-facts. ---- -ipaddress: "172.16.254.254" -is_pe: false -macaddress: "AA:AA:AA:AA:AA:AA" diff --git a/spec/defines/vcl_spec.rb b/spec/defines/vcl_spec.rb index 5aa351b..e1f5621 100644 --- a/spec/defines/vcl_spec.rb +++ b/spec/defines/vcl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'varnish::vcl' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0d5efc0..4d617f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,47 +1,17 @@ -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' +# frozen_string_literal: true -require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) +# Managed by modulesync - DO NOT EDIT +# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -include RspecPuppetFacts +# 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__)) -default_facts = { - puppetversion: Puppet.version, - facterversion: Facter.version, -} +require 'voxpupuli/test/spec_helper' -default_fact_files = [ - File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), - File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), -] - -default_fact_files.each do |f| - next unless File.exist?(f) && File.readable?(f) && File.size?(f) - - begin - default_facts.merge!(YAML.safe_load(File.read(f))) - rescue => e - RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" - end -end - -RSpec.configure do |c| - c.default_facts = default_facts - c.before :each do - # set to strictest setting for testing - # by default Puppet runs at warning level - Puppet.settings[:strict] = :warning - end - c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] - c.after(:suite) do +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 - -def ensure_module_defined(module_name) - module_name.split('::').reduce(Object) do |last_module, next_module| - last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) - last_module.const_get(next_module, false) - end -end - -# 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb deleted file mode 100644 index 3e9d37e..0000000 --- a/spec/spec_helper_system.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'rspec-system/spec_helper' -require 'rspec-system-puppet/helpers' - -include RSpecSystemPuppet::Helpers - -RSpec.configure do |c| - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - c.tty = true - c.include RSpecSystemPuppet::Helpers - - c.before :suite do - puppet_install - puppet_module_install(source: proj_root, module_name: 'varnish') - shell('puppet module install puppetlabs-stdlib') - end -end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb deleted file mode 100644 index 1d58716..0000000 --- a/spec/system/basic_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper_system' - -describe 'basic tests' do - it 'class should work without errors' do - pp = <<-EOS - class { 'varnish': } - EOS - - puppet_apply(pp) do |r| - r.exit_code.should == 2 - end - end -end diff --git a/templates/varnish.service.erb b/templates/varnish.service.erb index 2981d04..68f65c0 100644 --- a/templates/varnish.service.erb +++ b/templates/varnish.service.erb @@ -1,5 +1,9 @@ [Unit] Description=Varnish HTTP accelerator +After=network.target + +[Install] +WantedBy=multi-user.target [Service] Type=forking @@ -41,10 +45,7 @@ ExecStart=/usr/sbin/varnishd <%= scope['::varnish::config::jail_opt'] %> \ -p <%= k %>=<%= v %> \ <% end -%> -S <%= scope['::varnish::secret_file'] %> \ - -s <%= scope['::varnish::storage_type'] %>,<% if scope['::varnish::storage_type'] == 'file' -%><%= scope['::varnish::storage_file'] %>,<% end -%><%= scope['::varnish::storage_size'] %> \ -<% scope['::varnish::storage_additional'].each do |k| -%> - -s <%= k %> \ -<% end -%> - -[Install] -WantedBy=multi-user.target +<% _default_storage_parts = [ scope['varnish::storage_type'], scope['varnish::storage_size'] ] + _default_storage_parts.insert(1, scope['varnish::storage_file']) if scope['varnish::storage_type'] == 'file' + _default_storage = _default_storage_parts.join(',') -%> + -s <%= [ [ _default_storage ] + scope['varnish::storage_additional'] ].join(" \\\n -s ") %>