From 9b967f8bc7c677d029aad4bfaa4082421d58483b Mon Sep 17 00:00:00 2001 From: Matthieu FAURE Date: Sat, 5 Oct 2019 14:59:33 +0200 Subject: [PATCH] REFACTOR separate tests: applies without error / applies idempotently --- .github/CONTRIBUTING.md | 163 +++++++++++++++++++----- .msync.yml | 2 +- .rubocop.yml | 1 + .sync.yml | 3 - .travis.yml | 90 +++---------- .travis/setup.sh | 12 -- Dockerfile | 4 +- Gemfile | 27 +--- README.md | 18 +++ REFERENCE.md | 3 + Rakefile | 89 +++---------- data/default.yaml | 7 +- manifests/composer.pp | 5 + manifests/composer/auto_update.pp | 10 +- manifests/fpm.pp | 28 ++-- manifests/global.pp | 2 +- manifests/globals.pp | 8 ++ manifests/init.pp | 63 ++++----- manifests/packages.pp | 4 +- manifests/params.pp | 3 +- manifests/pear.pp | 10 +- manifests/repo.pp | 6 +- manifests/repo/ubuntu.pp | 2 +- metadata.json | 2 +- spec/acceptance/php_spec.rb | 119 ++++++++--------- spec/classes/php_fpm_service_spec.rb | 4 - spec/classes/php_fpm_spec.rb | 8 -- spec/spec_helper.rb | 32 +---- spec/spec_helper_acceptance.rb | 12 +- spec/unit/provider/package/pear_spec.rb | 42 +++--- spec/unit/provider/package/pecl_spec.rb | 22 ++-- types/composerchannel.pp | 7 + 32 files changed, 381 insertions(+), 427 deletions(-) delete mode 100644 .travis/setup.sh create mode 100644 types/composerchannel.pp diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 5d047472..2240a970 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,3 +1,18 @@ +# 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. @@ -8,29 +23,92 @@ Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. [Contributor Code of Conduct](https://voxpupuli.org/coc/). -1. Fork the repo. - -1. Create a separate branch for your change. - -1. We only take pull requests with passing tests, and documentation. [travis-ci](http://travis-ci.org) - runs the tests for us. You can also execute them locally. This is explained - in a later section. - -1. Checkout [our docs](https://voxpupuli.org/docs/#reviewing-a-module-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. - -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 our 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. +* Fork the repo. +* Create a separate branch for your change. +* We only take pull requests with passing tests, and documentation. [travis-ci](http://travis-ci.org) runs the tests for us. You can also execute them locally. This is explained [in a later section](#the-test-matrix). +* Checkout [our docs](https://voxpupuli.org/docs/reviewing_pr/) we use to review a module and the [official styleguide](https://puppet.com/docs/puppet/6.0/style_guide.html). They provide some guidance for new code that might help you before you submit a pull request. +* Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, please add a test. +* Squash your commits down into logical components. Make sure to rebase against our current master. +* Push the branch to your fork and submit a pull request. + +Please be prepared to repeat some of these steps as our contributors review your code. + +## 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 @@ -51,22 +129,39 @@ 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 +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 +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; bundle update; bundle clean +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)" ``` -## Syntax and style +### 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 @@ -84,7 +179,7 @@ against it. You can run those locally ahead of time with: 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 @@ -109,7 +204,7 @@ To run a specific spec test set the `SPEC` variable: bundle exec rake spec SPEC=spec/foo_spec.rb ``` -### Unit tests in docker +#### 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. @@ -124,7 +219,7 @@ 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 +### 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 @@ -160,19 +255,21 @@ created virtual machines will be in `.vagrant/beaker_vagrant_files`. Beaker also supports docker containers. We also use that in our automated CI pipeline at [travis-ci](http://travis-ci.org). To use that instead of Vagrant: -``` -PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian9-64{hypervisor=docker} BEAKER_destroy=yes bundle exec rake beaker +```sh +PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian10-64{hypervisor=docker} BEAKER_destroy=yes bundle exec rake beaker ``` -You can replace the string `debian9` with any common operating system. +You can replace the string `debian10` with any common operating system. The following strings are known to work: * ubuntu1604 * ubuntu1804 * debian8 * debian9 +* debian10 * centos6 * centos7 +* centos8 The easiest way to debug in a docker container is to open a shell: diff --git a/.msync.yml b/.msync.yml index 4c6463a5..8864fc09 100644 --- a/.msync.yml +++ b/.msync.yml @@ -1 +1 @@ -modulesync_config_version: '2.5.1' +modulesync_config_version: '2.12.0' diff --git a/.rubocop.yml b/.rubocop.yml index 099a11c5..c2ebc88d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ require: rubocop-rspec AllCops: +# Puppet Server 5 defaults to jruby 1.7 so TargetRubyVersion must stay at 1.9 until we drop support for puppet 5 TargetRubyVersion: 1.9 Include: - ./**/*.rb diff --git a/.sync.yml b/.sync.yml index fd8e067b..0d3c790d 100644 --- a/.sync.yml +++ b/.sync.yml @@ -19,7 +19,4 @@ - set: debian9-64 options: script: 'bundle exec rspec spec/acceptance/php_spec.rb' - - set: debian8-64 - options: - script: 'bundle exec rspec spec/acceptance/php_spec.rb' secure: "GOhttACuJt+3s38m4WnW5RuTgwqaAoeEQnNT+X1Ukn7KdcIk4KV8NzYU/CC0VIm8lUOnBWYJKEC4ixX/J/4Wbxox2RAoKMQrO++L0DB1zTCJnq9SfoUBMaQhXvLu+PbxAR0p3P47ozra0C+pOWDpOaxT9ecufrPQt9W9Z4aY/bs=" diff --git a/.travis.yml b/.travis.yml index d819e106..9319058b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ --- -dist: xenial +dist: bionic language: ruby cache: bundler before_install: - - sh ./.travis/setup.sh + - yes | gem update --system + - bundle --version script: - 'bundle exec rake $CHECK' matrix: @@ -23,122 +24,62 @@ matrix: env: PUPPET_VERSION="~> 5.0" CHECK=build DEPLOY_TO_FORGE=yes - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php56_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php56_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php56_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php56_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php56_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php56_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker - script: bundle exec rspec spec/acceptance/php_spec.rb - services: docker - - rvm: 2.5.3 - bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1804-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=ubuntu1604-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian8-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=centos7-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian8-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker - rvm: 2.5.3 bundler_args: --without development release - env: PUPPET_INSTALL_TYPE=agent BEAKER_IS_PE=no BEAKER_PUPPET_COLLECTION=puppet6-nightly BEAKER_debug=true BEAKER_setfile=debian8-64 BEAKER_HYPERVISOR=docker CHECK=beaker + env: PUPPET_INSTALL_TYPE=agent BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_debug=true BEAKER_setfile=debian9-64 BEAKER_HYPERVISOR=docker CHECK=beaker script: bundle exec rspec spec/acceptance/php_spec.rb services: docker branches: @@ -147,6 +88,7 @@ branches: - /^v\d/ notifications: email: false + webhooks: https://voxpupu.li/incoming/travis irc: on_success: always on_failure: always diff --git a/.travis/setup.sh b/.travis/setup.sh deleted file mode 100644 index ae1a0438..00000000 --- a/.travis/setup.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# THIS FILE IS MANAGED BY MODULESYNC - -rm -f Gemfile.lock -if [ "${PUPPET_VERSION}" = '~> 4.0' ]; then - gem install bundler -v '< 2' --no-rdoc --no-ri; -else - gem update --system; - gem update bundler; - bundle --version; -fi diff --git a/Dockerfile b/Dockerfile index 27a33cf6..6fd63422 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.5.1 +FROM ruby:2.5.3 WORKDIR /opt/puppet @@ -15,7 +15,7 @@ RUN bundle install --without system_tests development release --path=${BUNDLE_PA COPY . . RUN bundle install -RUN bundle exec release_checks +RUN bundle exec rake release_checks # Container should not saved RUN exit 1 diff --git a/Gemfile b/Gemfile index 9524f1ab..11c85584 100644 --- a/Gemfile +++ b/Gemfile @@ -11,23 +11,9 @@ def location_for(place, fake_version = nil) end group :test do - gem 'puppetlabs_spec_helper', '>= 2.11.0', :require => false - gem 'rspec-puppet-facts', '>= 1.8.0', :require => false - gem 'rspec-puppet-utils', :require => false - gem 'puppet-lint-leading_zero-check', :require => false - gem 'puppet-lint-trailing_comma-check', :require => false - gem 'puppet-lint-version_comparison-check', :require => false - gem 'puppet-lint-classes_and_types_beginning_with_digits-check', :require => false - gem 'puppet-lint-unquoted_string-check', :require => false - gem 'puppet-lint-variable_contains_upcase', :require => false - gem 'metadata-json-lint', :require => false - gem 'redcarpet', :require => false - gem 'rubocop', '~> 0.49.1', :require => false - gem 'rubocop-rspec', '~> 1.15.0', :require => false - gem 'mocha', '~> 1.4.0', :require => false - gem 'coveralls', :require => false - gem 'simplecov-console', :require => false - gem 'parallel_tests', :require => false + gem 'voxpupuli-test', '>= 1.0.0', :require => false + gem 'coveralls', :require => false + gem 'simplecov-console', :require => false end group :development do @@ -58,13 +44,14 @@ group :system_tests do gem 'rbnacl', '>= 4', :require => false gem 'rbnacl-libsodium', :require => false gem 'bcrypt_pbkdf', :require => false + gem 'ed25519', :require => false end group :release do - gem 'github_changelog_generator', :require => false, :git => 'https://github.com/github-changelog-generator/github-changelog-generator' + gem 'github_changelog_generator', :require => false, :git => 'https://github.com/voxpupuli/github-changelog-generator', :branch => 'voxpupuli_essential_fixes' gem 'puppet-blacksmith', :require => false - gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem' - gem 'puppet-strings', '>= 1.0', :require => false + gem 'voxpupuli-release', :require => false + gem 'puppet-strings', '>= 2.2', :require => false end diff --git a/README.md b/README.md index 86866723..1de158e6 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,24 @@ php::fpm::pools: ## Notes +### Inheriting configuration across mutliple Hiera sources + +Configuration from Hiera such as `php::fpm::pools` is automatically +lookup up using the "first" merge method. This means that the first +value found is used. If you instead want to merge the hash keys +across multiple Hiera sources, you can use [`lookup_options`] to +set [`hash` or `deep` behaviors] such as in the example +[data/default.yaml](data/default.yaml): + +```yaml +lookup_options: + php::fpm::pools: + merge: hash +``` + +[`lookup_options`]: https://puppet.com/docs/puppet/6.4/hiera_merging.html#concept-2997 +[`hash` or `deep` behaviors]: https://puppet.com/docs/puppet/6.4/hiera_merging.html#merge-behaviors + ### Debian squeeze & Ubuntu precise come with PHP 5.3 On Debian-based systems, we use `php5enmod` to enable extension-specific diff --git a/REFERENCE.md b/REFERENCE.md index a82cca46..0d64530d 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -497,6 +497,9 @@ Install composer package manager [*path*] Holds path to the Composer executable +[*channel*] + Holds the Update channel (stable|preview|snapshot|1|2) + [*proxy_type*] proxy server type (none|http|https|ftp) diff --git a/Rakefile b/Rakefile index 13ef17c0..b450fe7b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,63 +1,12 @@ -require 'puppetlabs_spec_helper/rake_tasks' +require 'voxpupuli/test/rake' # load optional tasks for releases # only available if gem group releases is installed begin - require 'puppet_blacksmith/rake_tasks' require 'voxpupuli/release/rake_tasks' - require 'puppet-strings/tasks' rescue LoadError end -PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' -PuppetLint.configuration.fail_on_warnings = true -PuppetLint.configuration.send('relative') -PuppetLint.configuration.send('disable_140chars') -PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send('disable_documentation') -PuppetLint.configuration.send('disable_single_quote_string_with_variables') - -exclude_paths = %w( - pkg/**/* - vendor/**/* - .vendor/**/* - spec/**/* -) -PuppetLint.configuration.ignore_paths = exclude_paths -PuppetSyntax.exclude_paths = exclude_paths - -desc 'Auto-correct puppet-lint offenses' -task 'lint:auto_correct' do - PuppetLint.configuration.fix = true - Rake::Task[:lint].invoke -end - -desc 'Run acceptance tests' -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' -end - -desc 'Run tests release_checks' -task test: [ - :release_checks, -] - -namespace :check do - desc 'Check for trailing whitespace' - task :trailing_whitespace do - Dir.glob('**/*.md', File::FNM_DOTMATCH).sort.each do |filename| - next if filename =~ %r{^((modules|acceptance|\.?vendor|spec/fixtures|pkg)/|REFERENCE.md)} - File.foreach(filename).each_with_index do |line, index| - if line =~ %r{\s\n$} - puts "#{filename} has trailing whitespace on line #{index + 1}" - exit 1 - end - end - end - end -end -Rake::Task[:release_checks].enhance ['check:trailing_whitespace'] - 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__)) @@ -69,25 +18,10 @@ task test_with_coveralls: [:test] do end end -desc "Print supported beaker sets" -task 'beaker_sets', [:directory] do |t, args| - directory = args[:directory] - - metadata = JSON.load(File.read('metadata.json')) - - (metadata['operatingsystem_support'] || []).each do |os| - (os['operatingsystemrelease'] || []).each do |release| - if directory - beaker_set = "#{directory}/#{os['operatingsystem'].downcase}-#{release}" - else - beaker_set = "#{os['operatingsystem'].downcase}-#{release}-x64" - end - - filename = "spec/acceptance/nodesets/#{beaker_set}.yml" - - puts beaker_set if File.exists? filename - end - end +desc 'Generate REFERENCE.md' +task :reference, [:debug, :backtrace] do |t, args| + patterns = '' + Rake::Task['strings:generate:reference'].invoke(patterns, args[:debug], args[:backtrace]) end begin @@ -102,6 +36,19 @@ begin metadata = JSON.load(File.read(metadata_json)) config.project = metadata['name'] end + + # Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715 + require 'rbconfig' + if RbConfig::CONFIG['host_os'] =~ /linux/ + task :changelog do + puts 'Fixing line endings...' + changelog_file = File.join(__dir__, 'CHANGELOG.md') + changelog_txt = File.read(changelog_file) + new_contents = changelog_txt.gsub(%r{\r\n}, "\n") + File.open(changelog_file, "w") {|file| file.puts new_contents } + end + end + rescue LoadError end # vim: syntax=ruby diff --git a/data/default.yaml b/data/default.yaml index a48a7b48..3451666f 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -1,5 +1,10 @@ --- -php::fpm_pools: + +lookup_options: + php::fpm::pools: + merge: first + +php::fpm::pools: www: catch_workers_output: 'no' listen: '127.0.0.1:9000' diff --git a/manifests/composer.pp b/manifests/composer.pp index a3c6fdb5..701e5963 100644 --- a/manifests/composer.pp +++ b/manifests/composer.pp @@ -8,6 +8,9 @@ # [*path*] # Holds path to the Composer executable # +# [*channel*] +# Holds the Update channel (stable|preview|snapshot|1|2) +# # [*proxy_type*] # proxy server type (none|http|https|ftp) # @@ -28,6 +31,7 @@ Stdlib::Absolutepath $path = $php::params::composer_path, $proxy_type = undef, $proxy_server = undef, + Php::ComposerChannel $channel = 'stable', Boolean $auto_update = true, Integer $max_age = $php::params::composer_max_age, Variant[Integer, String] $root_group = $php::params::root_group, @@ -52,6 +56,7 @@ max_age => $max_age, source => $source, path => $path, + channel => $channel, proxy_type => $proxy_type, proxy_server => $proxy_server, } diff --git a/manifests/composer/auto_update.pp b/manifests/composer/auto_update.pp index 66f73db2..a182c38c 100644 --- a/manifests/composer/auto_update.pp +++ b/manifests/composer/auto_update.pp @@ -11,6 +11,9 @@ # [*path*] # Holds path to the Composer executable # +# [*channel*] +# Holds the Update channel (stable|preview|snapshot|1|2) +# # [*proxy_type*] # proxy server type (none|http|https|ftp) # @@ -29,8 +32,9 @@ $max_age, $source, $path, - $proxy_type = undef, - $proxy_server = undef, + Php::ComposerChannel $channel = 'stable', + $proxy_type = undef, + $proxy_server = undef, ) { assert_private() @@ -44,7 +48,7 @@ exec { 'update composer': # touch binary when an update is attempted to update its mtime for idempotency when no update is available - command => "${path} --no-interaction --quiet self-update; touch ${path}", + command => "${path} --no-interaction --quiet self-update --${channel}; touch ${path}", environment => $env, onlyif => "test `find '${path}' -mtime +${max_age}`", path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/', '/usr/local/bin', '/usr/local/sbin' ], diff --git a/manifests/fpm.pp b/manifests/fpm.pp index a74dcc53..c8dd31e5 100644 --- a/manifests/fpm.pp +++ b/manifests/fpm.pp @@ -49,6 +49,10 @@ # Hash of defaults params php::fpm::pool resources that will be created. # Defaults is empty hash. # +# [*pool_purge*] +# Whether to purge pool config files not created +# by this module +# class php::fpm ( String $ensure = $php::ensure, $user = $php::fpm_user, @@ -64,13 +68,14 @@ Hash $pools = $php::real_fpm_pools, $log_owner = $php::log_owner, $log_group = $php::log_group, + Boolean $pool_purge = $php::pool_purge, ) { if ! defined(Class['php']) { warning('php::fpm is private') } - $real_settings = lookup('php::fpm::settings', Hash, {'strategy' => 'deep', 'merge_hash_arrays' => true}, $settings) + $real_settings = $settings # On FreeBSD fpm is not a separate package, but included in the 'php' package. # Implies that the option SET+=FPM was set when building the port. @@ -85,13 +90,14 @@ } class { 'php::fpm::config': - user => $user, - group => $group, - inifile => $inifile, - settings => $real_settings, - log_owner => $log_owner, - log_group => $log_group, - require => Package[$real_package], + user => $user, + group => $group, + inifile => $inifile, + settings => $real_settings, + log_owner => $log_owner, + log_group => $log_group, + pool_purge => $pool_purge, + require => Package[$real_package], } contain 'php::fpm::config' @@ -99,8 +105,8 @@ Class['php::fpm::config'] ~> Class['php::fpm::service'] - $real_global_pool_settings = lookup('php::fpm::global_pool_settings', Hash, {'strategy' => 'unique'}, $global_pool_settings) - $real_pools = lookup('php::fpm::pools', Hash, {'strategy' => 'unique'}, $pools) + $real_global_pool_settings = $global_pool_settings + $real_pools = $pools create_resources(::php::fpm::pool, $real_pools, $real_global_pool_settings) # Create an override to use a reload signal as trusty and utopic's @@ -114,7 +120,7 @@ else { $fpm_override = "reload signal USR2\nmanual" } - file { "/etc/init/${::php::fpm::service::service_name}.override": + file { "/etc/init/${php::fpm::service::service_name}.override": content => $fpm_override, before => Package[$real_package], } diff --git a/manifests/global.pp b/manifests/global.pp index d5237e38..bc28e26d 100644 --- a/manifests/global.pp +++ b/manifests/global.pp @@ -21,7 +21,7 @@ # No deep merging required since the settings we have are the global settings. $real_settings = $settings - ::php::config { 'global': + php::config { 'global': file => $inifile, config => $real_settings, } diff --git a/manifests/globals.pp b/manifests/globals.pp index 22b9fb38..8a800548 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -144,6 +144,14 @@ } } 'FreeBSD': { + case $globals_php_version { + /^(\d)\.(\d)$/: { + $package_prefix = "php${1}${2}-" + } + default: { + $package_prefix = 'php56-' + } + } $default_config_root = '/usr/local/etc' $default_fpm_pid_file = '/var/run/php-fpm.pid' $fpm_service_name = undef diff --git a/manifests/init.pp b/manifests/init.pp index 481f453e..c235baa1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -123,6 +123,10 @@ # For example, 'PHP/memory_limit' => '1000M' sets memory_limit to 1000M # for the PHP cli ini file, regardless of the values from $settings. # +# [*pool_purge*] +# Whether to purge pool config files not created +# by this module +# class php ( String $ensure = $php::params::ensure, Boolean $manage_repos = $php::params::manage_repos, @@ -157,9 +161,10 @@ Boolean $ext_tool_enabled = $php::params::ext_tool_enabled, String $log_owner = $php::params::fpm_user, String $log_group = $php::params::fpm_group, + Boolean $pool_purge = $php::params::pool_purge, ) inherits php::params { - $real_fpm_package = pick($fpm_package, "${package_prefix}${::php::params::fpm_package_suffix}") + $real_fpm_package = pick($fpm_package, "${package_prefix}${php::params::fpm_package_suffix}") $real_settings = $settings $real_extensions = $extensions @@ -170,16 +175,15 @@ $final_cli_settings = $real_settings + $cli_settings if $manage_repos { - class { 'php::repo': } - -> Anchor['php::begin'] + contain php::repo } - anchor { 'php::begin': } - -> class { 'php::packages': } + class { 'php::packages': } -> class { 'php::cli': settings => $final_cli_settings, } - -> anchor { 'php::end': } + contain php::packages + contain php::cli # Configure global PHP settings in php.ini if $facts['os']['family'] != 'Debian' { @@ -187,7 +191,7 @@ -> class {'php::global': settings => $real_settings, } - -> Anchor['php::end'] + contain php::global } if $fpm { contain 'php::fpm' } @@ -197,48 +201,37 @@ fail('Enabling both cli and embedded sapis is not currently supported') } - Anchor['php::begin'] - -> class { 'php::embedded': - settings => $real_settings, - } - -> Anchor['php::end'] + class { 'php::embedded': + settings => $real_settings, + } + contain php::embedded } if $dev { - Anchor['php::begin'] - -> class { 'php::dev': } - -> Anchor['php::end'] + contain php::dev } if $composer { - Anchor['php::begin'] - -> class { 'php::composer': - proxy_type => $proxy_type, - proxy_server => $proxy_server, - } - -> Anchor['php::end'] + class { 'php::composer': + proxy_type => $proxy_type, + proxy_server => $proxy_server, + } } if $pear { - Anchor['php::begin'] - -> class { 'php::pear': - ensure => $pear_ensure, - } - -> Anchor['php::end'] + class { 'php::pear': + ensure => $pear_ensure, + } } if $phpunit { - Anchor['php::begin'] - -> class { 'php::phpunit': } - -> Anchor['php::end'] + contain php::phpunit } if $apache_config { - Anchor['php::begin'] - -> class { 'php::apache_config': - settings => $real_settings, - } - -> Anchor['php::end'] + class { 'php::apache_config': + settings => $real_settings, + } + contain php::apache_config } create_resources('php::extension', $real_extensions, { require => Class['php::cli'], - before => Anchor['php::end'] }) # On FreeBSD purge the system-wide extensions.ini. It is going diff --git a/manifests/packages.pp b/manifests/packages.pp index aa274b36..fd556e02 100644 --- a/manifests/packages.pp +++ b/manifests/packages.pp @@ -22,9 +22,9 @@ assert_private() $real_names = union($names, $names_to_prefix) - if $facts['os']['family'] == 'debian' { + if $facts['os']['family'] == 'Debian' { if $manage_repos { - include ::apt + include apt Class['::apt::update'] -> Package[$real_names] } package { $real_names: diff --git a/manifests/params.pp b/manifests/params.pp index 46dd37ff..6d0da0d9 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -13,6 +13,7 @@ $phpunit_source = 'https://phar.phpunit.de/phpunit.phar' $phpunit_path = '/usr/local/bin/phpunit' $phpunit_max_age = 30 + $pool_purge = false case $facts['os']['family'] { 'Debian': { @@ -178,7 +179,7 @@ $fpm_group = 'www' $embedded_package_suffix = 'embed' $embedded_inifile = "${config_root}/php-embed.ini" - $package_prefix = 'php56-' + $package_prefix = $php::globals::package_prefix $compiler_packages = ['gcc'] $manage_repos = false $root_group = 'wheel' diff --git a/manifests/pear.pp b/manifests/pear.pp index dec0acc5..6c3cd52c 100644 --- a/manifests/pear.pp +++ b/manifests/pear.pp @@ -24,22 +24,18 @@ # On Amazon Linux the package name is also just 'php-pear'. # This would normally not be problematic but if you specify a # package_prefix other than 'php' then it will fail. - $package_name = "php-${::php::params::pear_package_suffix}" + $package_name = "php-${php::params::pear_package_suffix}" } else { case $facts['os']['family'] { 'Debian': { # Debian is a litte stupid: The pear package is called 'php-pear' # even though others are called 'php5-fpm' or 'php5-dev' - $package_name = "php-${::php::params::pear_package_suffix}" - } - 'FreeBSD': { - # On FreeBSD the package name is just 'pear'. - $package_name = $php::params::pear_package_suffix + $package_name = "php-${php::params::pear_package_suffix}" } default: { # This is the default for all other architectures - $package_name = "${::php::package_prefix}${::php::params::pear_package_suffix}" + $package_name = "${php::package_prefix}${php::params::pear_package_suffix}" } } } diff --git a/manifests/repo.pp b/manifests/repo.pp index 85b808d4..dd773a66 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -9,10 +9,10 @@ # no contain here because apt does that already case $facts['os']['name'] { 'Debian': { - include ::php::repo::debian + include php::repo::debian } 'Ubuntu': { - include ::php::repo::ubuntu + include php::repo::ubuntu } default: { fail($msg_no_repo) @@ -21,7 +21,7 @@ } 'FreeBSD': {} 'Suse': { - contain ::php::repo::suse + contain php::repo::suse } 'RedHat': { contain 'php::repo::redhat' diff --git a/manifests/repo/ubuntu.pp b/manifests/repo/ubuntu.pp index 09883092..c375b25a 100644 --- a/manifests/repo/ubuntu.pp +++ b/manifests/repo/ubuntu.pp @@ -8,7 +8,7 @@ class php::repo::ubuntu ( $version = undef, ) { - include '::apt' + include 'apt' if($version == undef) { $version_real = '5.6' diff --git a/metadata.json b/metadata.json index 6987bcf2..2f78ac51 100644 --- a/metadata.json +++ b/metadata.json @@ -19,7 +19,7 @@ }, { "name": "puppetlabs/inifile", - "version_requirement": ">= 1.4.1 < 4.0.0" + "version_requirement": ">= 1.4.1 < 5.0.0" }, { "name": "puppet/zypprepo", diff --git a/spec/acceptance/php_spec.rb b/spec/acceptance/php_spec.rb index 01ab0a5c..b07db4ba 100644 --- a/spec/acceptance/php_spec.rb +++ b/spec/acceptance/php_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper_acceptance' -describe 'php with default settings' do - context 'default parameters' do - it 'works with defaults' do - pp = 'include php' - # Run it twice and test for idempotency +describe 'php class' do + context 'with default parameters' do + pp = 'include php' + it 'applies without error' do apply_manifest(pp, catch_failures: true) + end + it 'applies idempotently' do apply_manifest(pp, catch_changes: true) end @@ -14,8 +15,6 @@ packagename = 'php7.2-fpm' when %r{ubuntu-16.04} packagename = 'php7.0-fpm' - when %r{ubuntu-14.04} - packagename = 'php5-fpm' when %r{el} packagename = 'php-fpm' when %r{debian-8} @@ -34,71 +33,56 @@ it { is_expected.to be_enabled } end end - context 'default parameters with extensions' do - case default[:platform] - when %r{ubuntu-18.04}, %r{ubuntu-16.04} - it 'works with defaults' do - case default[:platform] - when %r{ubuntu-18.04} - simplexmlpackagename = 'php7.2-xml' - when %r{ubuntu-16.04} - simplexmlpackagename = 'php7.0-xml' - end - pp = <<-EOS - class{'php': - extensions => { - 'mysql' => {}, - 'gd' => {}, - 'net-url' => { - package_prefix => 'php-', - settings => { - extension => undef - }, - }, - 'simplexml' => { - package_name => '#{simplexmlpackagename}', - } - } - } - EOS - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - when %r{ubuntu-14.04} - it 'works with defaults' do - pp = <<-EOS + context 'with extensions' do + added_extensions = case default[:platform] + when %r{ubuntu-18.04} + <<-EOS + 'bz2' => {}, + 'curl' => {}, + 'intl' => {}, + 'json' => {}, + 'mbstring' => {}, + 'zip' => {}, + 'net-url' => { + package_prefix => 'php-', + settings => { + extension => undef + }, + }, + 'simplexml' => { + package_name => 'php7.2-xml', + }, + EOS + when %r{ubuntu-16.04} + <<-EOS + 'net-url' => { + package_prefix => 'php-', + settings => { + extension => undef + }, + }, + 'simplexml' => { + package_name => 'php7.0-xml', + }, + EOS + else + '' + end + + pp = <<-EOS class{'php': extensions => { 'mysql' => {}, 'gd' => {}, - 'net-url' => { - package_prefix => 'php-', - settings => { - extension => undef - }, - } + #{added_extensions} } } - EOS - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - else - it 'works with defaults' do - pp = <<-EOS - class{'php': - extensions => { - 'mysql' => {}, - 'gd' => {} - } - } - EOS - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end + EOS + it 'applies without error' do + apply_manifest(pp, catch_failures: true) + end + it 'applies idempotently' do + apply_manifest(pp, catch_changes: true) end case default[:platform] @@ -106,8 +90,6 @@ packagename = 'php7.2-fpm' when %r{ubuntu-16.04} packagename = 'php7.0-fpm' - when %r{ubuntu-14.04} - packagename = 'php5-fpm' when %r{el} packagename = 'php-fpm' when %r{debian-8} @@ -117,6 +99,7 @@ when %r{debian-10} packagename = 'php7.3-fpm' end + describe package(packagename) do it { is_expected.to be_installed } end diff --git a/spec/classes/php_fpm_service_spec.rb b/spec/classes/php_fpm_service_spec.rb index 6056f409..5e15a836 100644 --- a/spec/classes/php_fpm_service_spec.rb +++ b/spec/classes/php_fpm_service_spec.rb @@ -14,10 +14,6 @@ case facts[:osfamily] when 'Debian' case facts[:operatingsystemrelease] - when '12.04' - it { is_expected.to contain_service('php5-fpm').with_ensure('running').without_restart } - when '14.04' - it { is_expected.to contain_service('php5-fpm').with_restart('service php5-fpm reload').with_ensure('running') } when '16.04' it { is_expected.to contain_service('php7.0-fpm').with_ensure('running') } end diff --git a/spec/classes/php_fpm_spec.rb b/spec/classes/php_fpm_spec.rb index da3f0242..afe1c595 100644 --- a/spec/classes/php_fpm_spec.rb +++ b/spec/classes/php_fpm_spec.rb @@ -13,14 +13,6 @@ case facts[:osfamily] when 'Debian' case facts[:operatingsystemrelease] - when '14.04' - it { is_expected.to contain_file('/etc/init/php5-fpm.override').with_content('reload signal USR2') } - it { is_expected.to contain_package('php5-fpm').with_ensure('present') } - it { is_expected.to contain_service('php5-fpm').with_ensure('running') } - when '12.02' - it { is_expected.to contain_file('/etc/init/php5-fpm.override').with_content("reload signal USR2\nmanual") } - it { is_expected.to contain_package('php5-fpm').with_ensure('present') } - it { is_expected.to contain_service('php5-fpm').with_ensure('running') } when '16.04' it { is_expected.to contain_package('php7.0-fpm').with_ensure('present') } it { is_expected.to contain_service('php7.0-fpm').with_ensure('running') } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f2279d2..b2b27045 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,12 @@ # This file is managed via modulesync # https://github.com/voxpupuli/modulesync # https://github.com/voxpupuli/modulesync_config -require 'puppetlabs_spec_helper/module_spec_helper' -require 'rspec-puppet-facts' -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', __FILE__)) + +require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.load(File.read(File.join(__dir__, 'default_module_facts.yml'))) @@ -13,26 +16,3 @@ end end end - -if Dir.exist?(File.expand_path('../../lib', __FILE__)) - require 'coveralls' - require 'simplecov' - require 'simplecov-console' - SimpleCov.formatters = [ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::Console - ] - SimpleCov.start do - track_files 'lib/**/*.rb' - add_filter '/spec' - add_filter '/vendor' - add_filter '/.vendor' - end -end - -RSpec.configure do |c| - # Coverage generation - c.after(:suite) do - RSpec::Puppet::Coverage.report! - end -end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index c978c402..76106237 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -4,16 +4,14 @@ require 'beaker/module_install_helper' run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' -install_ca_certs unless ENV['PUPPET_INSTALL_TYPE'] =~ %r{pe}i -install_module_on(hosts) -install_module_dependencies_on(hosts) RSpec.configure do |c| # Readable test descriptions c.formatter = :documentation - hosts.each do |host| - if host[:platform] =~ %r{el-7-x86_64} && host[:hypervisor] =~ %r{docker} - on(host, "sed -i '/nodocs/d' /etc/yum.conf") - end + + # Configure all nodes in nodeset + c.before :suite do + install_module + install_module_dependencies end end diff --git a/spec/unit/provider/package/pear_spec.rb b/spec/unit/provider/package/pear_spec.rb index fc36a095..cdc17ccb 100644 --- a/spec/unit/provider/package/pear_spec.rb +++ b/spec/unit/provider/package/pear_spec.rb @@ -12,15 +12,15 @@ end before do - described_class.stubs(:command).with(:pear).returns '/fake/pear' + allow(described_class).to receive(:command).with(:pear).and_return '/fake/pear' resource.provider = provider end describe '.instances' do it 'returns an array of installed packages' do - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('list', '-a'). - returns File.read(my_fixture('list_a')) + and_return File.read(my_fixture('list_a')) expect(described_class.instances.map(&:properties)).to eq [ { name: 'Archive_Tar', vendor: 'pear.php.net', ensure: '1.4.0', provider: :pear }, @@ -33,31 +33,31 @@ end it 'ignores malformed lines' do - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('list', '-a'). - returns 'aaa2.1' - Puppet.expects(:warning).with('Could not match aaa2.1') + and_return 'aaa2.1' + allow(Puppet).to receive(:warning).with('Could not match aaa2.1') expect(described_class.instances).to eq [] end end describe '#install' do it 'installs a package' do - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy') provider.install end it 'installs a specific version' do resource[:ensure] = '0.2' - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('-D', 'auto_discover=1', 'upgrade', '--alldeps', '-f', 'dummy-0.2') provider.install end it 'installs from a specific source' do resource[:source] = 'pear.php.net/dummy' - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'pear.php.net/dummy') provider.install end @@ -65,14 +65,14 @@ it 'installs a specific version from a specific source' do resource[:ensure] = '0.2' resource[:source] = 'pear.php.net/dummy' - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('-D', 'auto_discover=1', 'upgrade', '--alldeps', '-f', 'pear.php.net/dummy-0.2') provider.install end it 'uses the specified responsefile' do resource[:responsefile] = '/fake/pearresponse' - Puppet::Util::Execution.expects(:execute). + allow(Puppet::Util::Execution).to receive(:execute). with( ['/fake/pear', '-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy'], stdinfile: resource[:responsefile] @@ -82,7 +82,7 @@ it 'accepts install_options' do resource[:install_options] = ['--onlyreqdeps'] - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('-D', 'auto_discover=1', 'upgrade', '--onlyreqdeps', 'dummy') provider.install end @@ -90,9 +90,9 @@ describe '#query' do it 'queries information about one package' do - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('list', '-a'). - returns File.read(my_fixture('list_a')) + and_return File.read(my_fixture('list_a')) resource[:name] = 'pear' expect(provider.query).to eq( @@ -103,9 +103,9 @@ describe '#latest' do it 'fetches the latest version available' do - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('remote-info', 'Benchmark'). - returns File.read(my_fixture('remote-info_benchmark')) + and_return File.read(my_fixture('remote-info_benchmark')) resource[:name] = 'Benchmark' expect(provider.latest).to eq '1.2.9' @@ -114,16 +114,16 @@ describe '#uninstall' do it 'uninstalls a package' do - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('uninstall', resource[:name]). - returns('uninstall ok') + and_return('uninstall ok') provider.uninstall end it 'raises an error otherwise' do - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('uninstall', resource[:name]). - returns('unexpected output') + and_return('unexpected output') expect { provider.uninstall }.to raise_error(Puppet::Error) end end @@ -132,7 +132,7 @@ it 'ignores the resource version' do resource[:ensure] = '2.0' - described_class.expects(:pear). + allow(described_class).to receive(:pear). with('-D', 'auto_discover=1', 'upgrade', '--alldeps', 'dummy') provider.update end diff --git a/spec/unit/provider/package/pecl_spec.rb b/spec/unit/provider/package/pecl_spec.rb index ae2f15d1..1233a65a 100644 --- a/spec/unit/provider/package/pecl_spec.rb +++ b/spec/unit/provider/package/pecl_spec.rb @@ -14,14 +14,14 @@ end before do - parent_class.stubs(:command).with(:pear).returns '/fake/pear' + allow(parent_class).to receive(:command).with(:pear).and_return '/fake/pear' end describe '.instances' do it 'returns pecl installed packages via pear' do - parent_class.expects(:pear). + allow(parent_class).to receive(:pear). with('list', '-a'). - returns File.read(fixtures('unit/provider/package/pear/list_a')) + and_return File.read(fixtures('unit/provider/package/pear/list_a')) expect(described_class.instances.map(&:properties)).to eq [ { ensure: '1.13.5', name: 'zip', vendor: 'pecl.php.net', provider: :pecl } @@ -31,16 +31,16 @@ describe '#install' do it 'installs with pear' do - parent_class.expects(:pear) + allow(parent_class).to receive(:pear) provider.install end end describe '#query' do it 'queries pecl package info via pear' do - parent_class.expects(:pear). + allow(parent_class).to receive(:pear). with('list', '-a'). - returns File.read(fixtures('unit/provider/package/pear/list_a')) + and_return File.read(fixtures('unit/provider/package/pear/list_a')) resource[:name] = 'zip' expect(provider.query).to eq(ensure: '1.13.5', name: 'zip', vendor: 'pecl.php.net', provider: :pecl) @@ -49,9 +49,9 @@ describe '#latest' do it 'fetches the latest version available via pear' do - parent_class.expects(:pear). + allow(parent_class).to receive(:pear). with('remote-info', 'pecl.php.net/zip'). - returns File.read(fixtures('unit/provider/package/pear/remote-info_zip')) + and_return File.read(fixtures('unit/provider/package/pear/remote-info_zip')) resource[:name] = 'zip' expect(provider.latest).to eq '1.13.5' @@ -60,8 +60,8 @@ describe '#uninstall' do it 'uninstalls a package via pear' do - parent_class.expects(:pear). - returns('uninstall ok') + allow(parent_class).to receive(:pear). + and_return('uninstall ok') provider.uninstall end end @@ -70,7 +70,7 @@ it 'updates to latest version via pear' do resource[:ensure] = '2.0' - parent_class.expects(:pear) + allow(parent_class).to receive(:pear) provider.update end end diff --git a/types/composerchannel.pp b/types/composerchannel.pp new file mode 100644 index 00000000..00d77ddd --- /dev/null +++ b/types/composerchannel.pp @@ -0,0 +1,7 @@ +type Php::ComposerChannel = Enum[ + 'stable', + 'preview', + 'snapshot', + '1', + '2' # lint:ignore:trailing_comma +]