diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 048d2b55..8b466cfb 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -124,7 +124,7 @@ If you have Ruby 2.x or want a specific version of Puppet, you must set an environment variable such as: ```sh -export PUPPET_VERSION="~> 5.5.6" +export PUPPET_GEM_VERSION="~> 6.1.0" ``` You can install all needed gems for spec tests into the modules directory by @@ -232,17 +232,16 @@ simple tests against it after applying the module. You can run this with: ```sh -BEAKER_setfile=debian10-x64 bundle exec rake beaker +BEAKER_setfile=debian11-64 bundle exec rake beaker ``` You can replace the string `debian10` with any common operating system. The following strings are known to work: -* ubuntu1604 * ubuntu1804 * ubuntu2004 -* debian9 * debian10 +* debian11 * centos7 * centos8 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d08d05e8..8a077911 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,84 +7,12 @@ name: CI on: pull_request concurrency: - group: ${{ github.head_ref }} + group: ${{ github.ref_name }} cancel-in-progress: true 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 - - acceptance: - needs: setup_matrix - runs-on: ubuntu-latest - env: - BUNDLE_WITHOUT: development:test:release - strategy: - fail-fast: false - matrix: - include: ${{fromJson(needs.setup_matrix.outputs.github_action_test_matrix)}} - name: ${{ matrix.puppet.name }} - ${{ matrix.setfile.name }} - steps: - - uses: actions/checkout@v2 - - name: Setup ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Run tests - run: bundle exec rake beaker - env: - BEAKER_PUPPET_COLLECTION: ${{ matrix.puppet.collection }} - BEAKER_setfile: ${{ matrix.setfile.value }} - - tests: - needs: - - unit - - acceptance - runs-on: ubuntu-latest - name: Test suite - steps: - - run: echo Test suite completed + puppet: + name: Puppet + uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v1 + with: + pidfile_workaround: 'false' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 664ba694..15f17213 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,26 +9,14 @@ on: tags: - '*' -env: - BUNDLE_WITHOUT: development:test:system_tests - jobs: - deploy: - name: 'deploy to forge' - runs-on: ubuntu-latest - if: github.repository_owner == 'voxpupuli' - 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 + release: + name: Release + uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1 + with: + allowed_owner: 'voxpupuli' + secrets: + # Configure secrets here: + # https://docs.github.com/en/actions/security-guides/encrypted-secrets + username: ${{ secrets.PUPPET_FORGE_USERNAME }} + api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} diff --git a/.msync.yml b/.msync.yml index 43966c2f..02353859 100644 --- a/.msync.yml +++ b/.msync.yml @@ -2,4 +2,4 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -modulesync_config_version: '4.2.0' +modulesync_config_version: '5.3.0' diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 00000000..dd8272c7 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,3 @@ +--fail-on-warnings +--no-parameter_documentation-check +--no-parameter_types-check diff --git a/Dockerfile b/Dockerfile index e3cf307f..8dd82d63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,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 PUPPET_GEM_VERSION="~> 6.0" ARG PARALLEL_TEST_PROCESSORS=4 # Cache gems diff --git a/Gemfile b/Gemfile index a39114ce..07209b79 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,10 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -source ENV['GEM_SOURCE'] || "https://rubygems.org" +source ENV['GEM_SOURCE'] || 'https://rubygems.org' group :test do - gem 'voxpupuli-test', '~> 2.5', :require => false + gem 'voxpupuli-test', '~> 5.4', :require => false gem 'coveralls', :require => false gem 'simplecov-console', :require => false gem 'puppet_metadata', '~> 1.0', :require => false @@ -21,14 +21,14 @@ end group :release do gem 'github_changelog_generator', '>= 1.16.1', :require => false if RUBY_VERSION >= '2.5' - gem 'voxpupuli-release', '>= 1.0.2', :require => false + gem 'voxpupuli-release', '>= 1.2.0', :require => false gem 'puppet-strings', '>= 2.2', :require => false end gem 'rake', :require => false gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false, :groups => [:test] -puppetversion = ENV['PUPPET_VERSION'] || '>= 6.0' +puppetversion = ENV['PUPPET_GEM_VERSION'] || '>= 6.0' gem 'puppet', puppetversion, :require => false, :groups => [:test] # vim: syntax=ruby diff --git a/Rakefile b/Rakefile index 80b799d6..f92f0516 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ -# Attempt to load voxupuli-test (which pulls in puppetlabs_spec_helper), +# Attempt to load voxpupuli-test (which pulls in puppetlabs_spec_helper), # otherwise attempt to load it directly. begin require 'voxpupuli/test/rake' diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index f1d909d6..2a628b39 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'logrotate class' do diff --git a/spec/classes/defaults_spec.rb b/spec/classes/defaults_spec.rb index 3216d583..e5521c53 100644 --- a/spec/classes/defaults_spec.rb +++ b/spec/classes/defaults_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'logrotate' do @@ -10,6 +12,7 @@ is_expected.to contain_logrotate__conf('/etc/logrotate.conf') } end + on_supported_os.each do |os, facts| context os, if: facts[:osfamily] == 'Debian' do let(:facts) { facts } @@ -39,6 +42,7 @@ 'missingok' => true ) } + it { is_expected.to contain_logrotate__rule('btmp').with( 'rotate_every' => 'monthly', @@ -51,12 +55,14 @@ ) } end + context os, if: facts[:osfamily] == 'RedHat' do let(:facts) { facts } it { is_expected.to contain_logrotate__conf('/etc/logrotate.conf') } + it { is_expected.to contain_logrotate__rule('wtmp').with( 'path' => '/var/log/wtmp', @@ -70,6 +76,7 @@ 'rotate_every' => 'monthly' ) } + it { is_expected.to contain_logrotate__rule('btmp').with( 'path' => '/var/log/btmp', @@ -83,10 +90,12 @@ ) } end + context os, if: facts[:osfamily] == 'Suse' do it { is_expected.to contain_logrotate__conf('/etc/logrotate.conf') } + it { is_expected.to contain_logrotate__rule('wtmp').with( 'path' => '/var/log/wtmp', @@ -103,25 +112,14 @@ ) } end - context os, if: facts[:osfamily] == 'FreeBSD' do - let(:facts) { facts } - it { - is_expected.to contain_logrotate__conf('/usr/local/etc/logrotate.conf') - } - it { - is_expected.to contain_logrotate__conf('/usr/local/etc/logrotate.conf').with( - 'su_user' => 'root', - 'su_group' => 'wheel' - ) - } - end context os, if: facts[:osfamily] == 'FreeBSD' do let(:facts) { facts } it { is_expected.to contain_logrotate__conf('/usr/local/etc/logrotate.conf') } + it { is_expected.to contain_logrotate__conf('/usr/local/etc/logrotate.conf').with( 'su_user' => 'root', diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index c41c1139..5c3fde9d 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'logrotate' do @@ -11,6 +13,7 @@ context 'logrotate class without any parameters' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('logrotate') } + %w[install config params rules].each do |classs| it { is_expected.to contain_class("logrotate::#{classs}") } end @@ -30,9 +33,9 @@ is_expected.to contain_package('logrotate').with_ensure('present') is_expected.to contain_file('/usr/local/etc/logrotate.d').with('ensure' => 'directory', - 'owner' => 'root', - 'group' => 'wheel', - 'mode' => '0755') + 'owner' => 'root', + 'group' => 'wheel', + 'mode' => '0755') is_expected.to contain_class('logrotate::defaults') end @@ -59,14 +62,14 @@ is_expected.to contain_package('logrotate').with_ensure('present') is_expected.to contain_file('/etc/logrotate.d').with('ensure' => 'directory', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0755') + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755') is_expected.to contain_file('/etc/cron.daily/logrotate').with('ensure' => 'present', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0700') + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0700') is_expected.to contain_class('logrotate::defaults') end diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb index 0ffdf135..1100868b 100644 --- a/spec/defines/conf_spec.rb +++ b/spec/defines/conf_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'logrotate::conf' do _, facts = on_supported_os.first let(:facts) { facts } - shared_examples 'error raised' do |param, _| + shared_examples 'error raised' do |param, _os| context "=> 'foo'" do let(:params) { { param.to_sym => 'foo' } } @@ -16,7 +18,7 @@ end end - shared_examples 'error match' do |param, _| + shared_examples 'error match' do |param, _os| context "=> 'foo'" do let(:params) { { param.to_sym => 'foo' } } @@ -38,6 +40,7 @@ with_content(%r{^no(t|)#{param}$}) } end + context "#{param} => true" do let(:params) { { param.to_sym => true } } @@ -106,13 +109,14 @@ it { is_expected.to contain_class('logrotate') } + it { is_expected.to contain_file('/etc/logrotate.conf').with( 'owner' => 'root', 'group' => 'root', 'ensure' => 'present', 'mode' => '0644' - ).with_content(%r{\ninclude \/etc\/logrotate.d\n}) + ).with_content(%r{\ninclude /etc/logrotate.d\n}) } context 'compresscmd => bzip2' do @@ -319,6 +323,7 @@ is_expected.to contain_file('/etc/logrotate.conf'). with_content(%r{^mail test@example.com$}) } + %w[mailfirst maillast].each do |value| context "mail_when => #{value}" do let(:params) do @@ -350,7 +355,7 @@ it { is_expected.to contain_file('/etc/logrotate.conf'). - with_content(%r{^olddir \/var\/log\/old$}) + with_content(%r{^olddir /var/log/old$}) } end @@ -370,7 +375,7 @@ it { is_expected.to contain_file('/etc/logrotate.conf'). - with_content(%r{#{param}\n\s{2}\/bin\/true\nendscript}) + with_content(%r{#{param}\n\s{2}/bin/true\nendscript}) } end end @@ -431,6 +436,7 @@ it_behaves_like 'integer', param end end + context '=> /etc/logrotate_custom.config' do let(:title) { '/etc/logrotate_custom.config' } @@ -440,9 +446,10 @@ 'group' => 'root', 'ensure' => 'present', 'mode' => '0644' - ).with_content(%r{\ninclude \/etc\/logrotate.d\n}) + ).with_content(%r{\ninclude /etc/logrotate.d\n}) } end + context 'with a non-path title' do let(:title) { 'foo bar' } diff --git a/spec/defines/cron_spec.rb b/spec/defines/cron_spec.rb index 81d4cf30..596ddee7 100644 --- a/spec/defines/cron_spec.rb +++ b/spec/defines/cron_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'logrotate::cron' do @@ -14,17 +16,17 @@ let(:title) { 'test' } let(:params) { { ensure: 'present' } } - if facts[:osfamily] != 'FreeBSD' + if facts[:osfamily] == 'FreeBSD' it { - is_expected.to contain_file('/etc/cron.test/logrotate'). + is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). with_ensure('present'). - with_content(%r{(\/usr\/sbin\/logrotate \/etc\/logrotate.conf 2>&1)}) + with_content(%r{(/usr/local/sbin/logrotate /usr/local/etc/logrotate.conf 2>&1)}) } else it { - is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). + is_expected.to contain_file('/etc/cron.test/logrotate'). with_ensure('present'). - with_content(%r{(\/usr\/local\/sbin\/logrotate \/usr\/local\/etc\/logrotate.conf 2>&1)}) + with_content(%r{(/usr/sbin/logrotate /etc/logrotate.conf 2>&1)}) } end end @@ -34,17 +36,17 @@ let(:title) { 'test' } let(:params) { { ensure: 'present' } } - if facts[:osfamily] != 'FreeBSD' + if facts[:osfamily] == 'FreeBSD' it { - is_expected.to contain_file('/etc/cron.test/logrotate'). + is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). with_ensure('present'). - with_content(%r{(\/usr\/sbin\/logrotate -s \/var\/lib\/logrotate\/logrotate.status -m \/usr\/sbin\/mailer \/etc\/logrotate.conf 2>&1)}) + with_content(%r{(/usr/local/sbin/logrotate -s /var/lib/logrotate/logrotate.status -m /usr/sbin/mailer /usr/local/etc/logrotate.conf 2>&1)}) } else it { - is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). + is_expected.to contain_file('/etc/cron.test/logrotate'). with_ensure('present'). - with_content(%r{(\/usr\/local\/sbin\/logrotate -s \/var\/lib\/logrotate\/logrotate.status -m \/usr\/sbin\/mailer \/usr\/local\/etc\/logrotate.conf 2>&1)}) + with_content(%r{(/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status -m /usr/sbin/mailer /etc/logrotate.conf 2>&1)}) } end end @@ -63,11 +65,11 @@ it { is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). with_ensure('present'). - with_content(%r{(\/usr\/local\/sbin\/logrotate \/usr\/local\/etc\/logrotate.conf 2>&1)}) + with_content(%r{(/usr/local/sbin/logrotate /usr/local/etc/logrotate.conf 2>&1)}) } end - context 'With additional arguments' do + context 'With additional arguments and status' do let(:pre_condition) { 'class {"::logrotate": logrotate_args => ["-s /var/lib/logrotate/logrotate.status", "-m /usr/sbin/mailer"]}' } let(:title) { 'test' } let(:params) { { ensure: 'present' } } @@ -75,7 +77,7 @@ it { is_expected.to contain_file('/usr/local/bin/logrotate.test.sh'). with_ensure('present'). - with_content(%r{(\/usr\/local\/sbin\/logrotate -s \/var\/lib\/logrotate\/logrotate.status -m \/usr\/sbin\/mailer \/usr\/local\/etc\/logrotate.conf 2>&1)}) + with_content(%r{(/usr/local/sbin/logrotate -s /var/lib/logrotate/logrotate.status -m /usr/sbin/mailer /usr/local/etc/logrotate.conf 2>&1)}) } end diff --git a/spec/defines/rule_spec.rb b/spec/defines/rule_spec.rb index 9baf5f28..59524d55 100644 --- a/spec/defines/rule_spec.rb +++ b/spec/defines/rule_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'shared_examples' @@ -87,6 +89,7 @@ with_content(%r{^ create$}) } end + describe 'and create_mode => 0777' do let(:params) do { @@ -101,7 +104,7 @@ } end - context 'and create_owner => www-data' do + context 'and create_owner => www-data with mode' do let(:params) do { path: '/var/log/foo.log', @@ -283,7 +286,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{^ olddir \/var\/log\/old$}) + with_content(%r{^ olddir /var/log/old$}) } end @@ -308,7 +311,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{postrotate\n \/bin\/true\n endscript}) + with_content(%r{postrotate\n /bin/true\n endscript}) } end @@ -322,7 +325,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{postrotate\n \/bin\/true\n \/bin\/false\n endscript}) + with_content(%r{postrotate\n /bin/true\n /bin/false\n endscript}) } end @@ -333,7 +336,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{prerotate\n \/bin\/true\n endscript}) + with_content(%r{prerotate\n /bin/true\n endscript}) } end @@ -342,7 +345,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{prerotate\n \/bin\/true\n \/bin\/false\n endscript}) + with_content(%r{prerotate\n /bin/true\n /bin/false\n endscript}) } end @@ -353,7 +356,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{firstaction\n \/bin\/true\n endscript}) + with_content(%r{firstaction\n /bin/true\n endscript}) } end @@ -362,7 +365,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{firstaction\n \/bin\/true\n \/bin\/false\n endscript}) + with_content(%r{firstaction\n /bin/true\n /bin/false\n endscript}) } end @@ -373,7 +376,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test'). - with_content(%r{lastaction\n \/bin\/true\n endscript}) + with_content(%r{lastaction\n /bin/true\n endscript}) } end @@ -382,7 +385,7 @@ it { is_expected.to contain_file('/etc/logrotate.d/test').\ - with_content(%r{lastaction\n \/bin\/true\n \/bin\/false\n endscript}) + with_content(%r{lastaction\n /bin/true\n /bin/false\n endscript}) } end diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index 52cc2626..e4b53dea 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_context 'config file' do |base_params = {}| let(:space_prefix) { '' } @@ -35,6 +37,7 @@ with_content(%r{^#{space_prefix}no(t|)#{param}$}) } end + context "#{param} => true" do let(:params) { base_params.merge(param.to_sym => true) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb5f0cbe..4d617f39 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,17 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ # 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__)) +ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) require 'voxpupuli/test/spec_helper' if File.exist?(File.join(__dir__, 'default_module_facts.yml')) facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) - if facts - facts.each do |name, value| - add_custom_fact name.to_sym, value - end + facts&.each do |name, value| + add_custom_fact name.to_sym, value end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index d3b906bf..d3a6e23c 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/