From 54db10d91bb5da04f8f4fb9d66138aba9e5e38a4 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Tue, 17 Aug 2021 09:46:58 -0700 Subject: (maint) Fix rubocop errors Took the safest route and disabled cops either globally in .rubocop.yml for just for specific cases in lib/ --- lib/puppet/provider/cron/crontab.rb | 2 +- lib/puppet/provider/cron/filetype.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/provider') diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb index 9144725..12ad7f1 100644 --- a/lib/puppet/provider/cron/crontab.rb +++ b/lib/puppet/provider/cron/crontab.rb @@ -207,7 +207,7 @@ Puppet::Type.type(:cron).provide(:crontab, parent: Puppet::Provider::ParsedFile, envs << record[:line] record[:skip] = true end - when :blank # rubocop: disable Lint/EmptyWhen + when :blank # nothing else if name diff --git a/lib/puppet/provider/cron/filetype.rb b/lib/puppet/provider/cron/filetype.rb index c381afa..153285d 100644 --- a/lib/puppet/provider/cron/filetype.rb +++ b/lib/puppet/provider/cron/filetype.rb @@ -26,7 +26,7 @@ class Puppet::Provider::Cron # implementation in the future. This way, we can refactor all three of # our cron file types into a common crontab file type. newfiletype(:crontab) do - def initialize(user) + def initialize(user) # rubocop:disable Lint/MissingSuper self.path = user end -- cgit v1.2.3 From dd42efd5323314047d2c44e02f2f7e3472954697 Mon Sep 17 00:00:00 2001 From: Gabriel Nagy Date: Fri, 1 Oct 2021 14:57:09 +0300 Subject: (MODULES-11197) Update to pdk-templates 2.2.0 Includes REFERENCE.md ToC fixes for MODULES-8183. --- .github/workflows/auto_release.yml | 84 ++++++++++ .github/workflows/release.yml | 47 ++++++ .rubocop.yml | 16 +- .sync.yml | 51 +++--- .travis.yml | 45 ------ Gemfile | 33 ++-- REFERENCE.md | 176 ++++++++++++--------- Rakefile | 2 +- lib/puppet/provider/cron/crontab.rb | 1 - lib/puppet/provider/cron/filetype.rb | 14 +- lib/puppet/type/cron.rb | 28 ++-- rakelib/commits.rake | 3 +- ...il_to_write_a_nonexistent_users_crontab_spec.rb | 2 +- ...erwrite_crontab_file_on_file_read_error_spec.rb | 2 +- ...associated_resources_on_file_read_error_spec.rb | 2 +- ...users_crontab_if_puppet_authorizes_them_spec.rb | 2 +- ...users_crontab_after_puppet_creates_them_spec.rb | 2 +- spec/unit/provider/cron/crontab_spec.rb | 4 +- spec/unit/provider/cron/parsed_spec.rb | 8 +- spec/unit/type/cron_spec.rb | 12 +- 20 files changed, 309 insertions(+), 225 deletions(-) create mode 100644 .github/workflows/auto_release.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml (limited to 'lib/puppet/provider') diff --git a/.github/workflows/auto_release.yml b/.github/workflows/auto_release.yml new file mode 100644 index 0000000..e028483 --- /dev/null +++ b/.github/workflows/auto_release.yml @@ -0,0 +1,84 @@ +name: "Auto release" + +on: + workflow_dispatch: + +env: + HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6 + HONEYCOMB_DATASET: litmus tests + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + auto_release: + name: "Automatic release prep" + runs-on: ubuntu-20.04 + + steps: + - name: "Honeycomb: Start recording" + uses: puppetlabs/kvrhdn-gha-buildevents@pdk-templates-v1 + with: + apikey: ${{ env.HONEYCOMB_WRITEKEY }} + dataset: ${{ env.HONEYCOMB_DATASET }} + job-status: ${{ job.status }} + + - name: "Honeycomb: start first step" + run: | + echo STEP_ID="auto-release" >> $GITHUB_ENV + echo STEP_START=$(date +%s) >> $GITHUB_ENV + + - name: "Checkout Source" + if: ${{ github.repository_owner == 'puppetlabs' }} + uses: actions/checkout@v2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: "PDK Release prep" + uses: docker://puppet/iac_release:ci + with: + args: 'release prep --force' + env: + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: "Get Version" + if: ${{ github.repository_owner == 'puppetlabs' }} + id: gv + run: | + echo "::set-output name=ver::$(jq --raw-output .version metadata.json)" + + - name: "Commit changes" + if: ${{ github.repository_owner == 'puppetlabs' }} + run: | + git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com" + git config --local user.name "GitHub Action" + git add . + git commit -m "Release prep v${{ steps.gv.outputs.ver }}" + + - name: Create Pull Request + id: cpr + uses: puppetlabs/peter-evans-create-pull-request@v3 + if: ${{ github.repository_owner == 'puppetlabs' }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Release prep v${{ steps.gv.outputs.ver }}" + branch: "release-prep" + delete-branch: true + title: "Release prep v${{ steps.gv.outputs.ver }}" + body: | + Automated release-prep through [pdk-templates](https://github.com/puppetlabs/pdk-templates/blob/main/moduleroot/.github/workflows/auto_release.yml.erb) from commit ${{ github.sha }}. + Please verify before merging: + - [ ] last [nightly](https://github.com/${{ github.repository }}/actions/workflows/nightly.yml) run is green + - [ ] [Changelog](https://github.com/${{ github.repository }}/blob/release-prep/CHANGELOG.md) is readable and has no unlabeled pull requests + - [ ] Ensure the [changelog](https://github.com/${{ github.repository }}/blob/release-prep/CHANGELOG.md) version and [metadata](https://github.com/${{ github.repository }}/blob/release-prep/metadata.json) version match + labels: "maintenance" + + - name: PR outputs + if: ${{ github.repository_owner == 'puppetlabs' }} + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" + + - name: "Honeycomb: Record finish step" + if: ${{ always() }} + run: | + buildevents step $TRACE_ID $STEP_ID $STEP_START 'Finished auto release workflow' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1509f6e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,47 @@ +name: "Publish module" + +on: + workflow_dispatch: + +jobs: + create-github-release: + name: Deploy GitHub Release + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.ref }} + clean: true + fetch-depth: 0 + - name: Get Version + id: gv + run: | + echo "::set-output name=ver::$(jq --raw-output .version metadata.json)" + - name: Create Release + uses: actions/create-release@v1 + id: create_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: "v${{ steps.gv.outputs.ver }}" + draft: false + prerelease: false + + deploy-forge: + name: Deploy to Forge + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.ref }} + clean: true + - name: "PDK Build" + uses: docker://puppet/pdk:nightly + with: + args: 'build' + - name: "Push to Forge" + uses: docker://puppet/pdk:nightly + with: + args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force' diff --git a/.rubocop.yml b/.rubocop.yml index 03b1242..82e41e8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,7 +20,7 @@ AllCops: - "**/Guardfile" Layout/LineLength: Description: People have wide screens, use them. - Enabled: false + Max: 260 RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. @@ -73,6 +73,8 @@ Style/SymbolArray: EnforcedStyle: brackets RSpec/NamedSubject: Enabled: false +RSpec/SubjectStub: + Enabled: false RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: @@ -135,8 +137,6 @@ Layout/EmptyLineAfterGuardClause: Enabled: false Layout/EmptyLinesAroundArguments: Enabled: false -Layout/EmptyLinesAroundBlockBody: - Enabled: false Layout/EmptyLinesAroundAttributeAccessor: Enabled: false Layout/EndOfLine: @@ -285,8 +285,6 @@ Performance/DeleteSuffix: Enabled: false Performance/InefficientHashSearch: Enabled: false -Performance/RegexpMatch: - Enabled: false Performance/UnfreezeString: Enabled: false Performance/UriDefaultParser: @@ -317,8 +315,6 @@ RSpec/ExampleLength: Enabled: false RSpec/ExampleWithoutDescription: Enabled: false -RSpec/ExampleWording: - Enabled: false RSpec/ExpectChange: Enabled: false RSpec/ExpectInHook: @@ -367,8 +363,6 @@ RSpec/SharedExamples: Enabled: false RSpec/StubbedMock: Enabled: false -RSpec/SubjectStub: - Enabled: false RSpec/UnspecifiedException: Enabled: false RSpec/VariableDefinition: @@ -463,16 +457,12 @@ Style/RedundantRegexpCharacterClass: Enabled: false Style/RedundantRegexpEscape: Enabled: false -Style/RedundantReturn: - Enabled: false Style/RedundantSelfAssignment: Enabled: false Style/RedundantSort: Enabled: false Style/RescueStandardError: Enabled: false -Style/SafeNavigation: - Enabled: false Style/SingleArgumentDig: Enabled: false Style/SlicingWithRange: diff --git a/.sync.yml b/.sync.yml index 834bfd3..664fad1 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,29 +1,21 @@ --- .rubocop.yml: default_configs: - Metrics/LineLength: + Layout/LineLength: Max: 260 RSpec/NamedSubject: Enabled: false - + RSpec/SubjectStub: + Enabled: false Gemfile: - required: - ':system_tests': - - gem: 'puppet-module-posix-system-r#{minor_version}' - platforms: ruby - version: '~> 1.0' - - gem: 'puppet-module-win-system-r#{minor_version}' - platforms: - - mswin - - mingw - - x64_mingw - version: '~> 1.0' + optional: + ":development": - gem: beaker - version: '~> 3.34' + version: '~> 4.30' from_env: BEAKER_VERSION - gem: beaker-abs from_env: BEAKER_ABS_VERSION - version: '~> 0.5' + version: '~> 0.9' - gem: beaker-pe - gem: beaker-hostgenerator from_env: BEAKER_HOSTGENERATOR_VERSION @@ -31,24 +23,19 @@ Gemfile: from_env: BEAKER_RSPEC_VERSION - gem: beaker-puppet from_env: BEAKER_PUPPET_VERSION - version: '~> 0.14' - optional: - ':development': - - gem: 'github_changelog_generator' - git: 'https://github.com/skywinder/github-changelog-generator' - ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')" - -.gitlab-ci.yml: - delete: true + version: '~> 1.22' + - gem: github_changelog_generator + - gem: beaker-module_install_helper + - gem: beaker-puppet_install_helper + - gem: nokogiri appveyor.yml: delete: true - .travis.yml: - remove_includes: - - env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec - rvm: 2.1.9 - -Rakefile: - changelog_version_tag_pattern: '%s' + delete: true +.github/workflows/auto_release.yml: + unmanaged: false +.github/workflows/release.yml: + unmanaged: false +.gitlab-ci.yml: + delete: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 444e17a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -os: linux -dist: xenial -language: ruby -cache: bundler -before_install: - - bundle -v - - rm -f Gemfile.lock - - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner" - - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used" - - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set" - - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION' - - gem --version - - bundle -v -script: - - 'bundle exec rake $CHECK' -bundler_args: --without system_tests -rvm: - - 2.5.7 -stages: - - static - - spec - - acceptance - - - if: tag =~ ^v\d - name: deploy -jobs: - fast_finish: true - include: - - - env: CHECK="validate lint check rubocop" - stage: static - - - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec - rvm: 2.5.7 - stage: spec - - - env: DEPLOY_TO_FORGE=yes - stage: deploy -branches: - only: - - main - - /^v\d/ -notifications: - email: false diff --git a/Gemfile b/Gemfile index fffecc4..26f0def 100644 --- a/Gemfile +++ b/Gemfile @@ -17,24 +17,27 @@ ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments minor_version = ruby_version_segments[0..1].join('.') group :development do - 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 "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] - gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] - gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') -end -group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 3.34') - gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.5') + 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 "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 2.8.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "puppet-module-posix-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-posix-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-default-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 4.30') + gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.9') gem "beaker-pe", require: false gem "beaker-hostgenerator" gem "beaker-rspec" - gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || '~> 0.14') + gem "beaker-puppet", *location_for(ENV['BEAKER_PUPPET_VERSION'] || '~> 1.22') + gem "github_changelog_generator", require: false + gem "beaker-module_install_helper", require: false + gem "beaker-puppet_install_helper", require: false + gem "nokogiri", require: false +end +group :system_tests do + gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby] + gem "puppet-module-win-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:mswin, :mingw, :x64_mingw] end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/REFERENCE.md b/REFERENCE.md index afe98bb..6b7b91f 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,55 +1,28 @@ # Reference + ## Table of Contents -**Resource types** +### Resource types -* [`cron`](#cron): Installs and manages cron jobs. Every cron resource created by Puppet requires a command and at least one periodic attribute (hour, minute, m +* [`cron`](#cron): Installs and manages cron jobs. ## Resource types -### cron +### `cron` -Installs and manages cron jobs. Every cron resource created by Puppet -requires a command and at least one periodic attribute (hour, minute, -month, monthday, weekday, or special). While the name of the cron job is -not part of the actual job, the name is stored in a comment beginning with -`# Puppet Name: `. These comments are used to match crontab entries created -by Puppet with cron resources. +Every cron resource created by Puppet requires a command and at least one +periodic attribute (hour, minute, month, monthday, weekday, or special). While +the name of the cron job is not part of the actual job, the name is stored in a +comment beginning with `# Puppet Name: `. These comments are used to match +crontab entries created by Puppet with cron resources. If an existing crontab entry happens to match the scheduling and command of a cron resource that has never been synced, Puppet defers to the existing crontab entry and does not create a new entry tagged with the `# Puppet Name: ` comment. -Example: - - cron { 'logrotate': - command => '/usr/sbin/logrotate', - user => 'root', - hour => 2, - minute => 0, - } - -Note that all periodic attributes can be specified as an array of values: - - cron { 'logrotate': - command => '/usr/sbin/logrotate', - user => 'root', - hour => [2, 4], - } - -...or using ranges or the step syntax `*/2` (although there's no guarantee -that your `cron` daemon supports these): - - cron { 'logrotate': - command => '/usr/sbin/logrotate', - user => 'root', - hour => ['2-4'], - minute => '*/10', - } - **Important:** _The Cron type will not reset parameters that are removed from a manifest_. For example, removing a `minute => 10` parameter will not reset the minute component of the associated cronjob to `*`. @@ -61,17 +34,46 @@ sync with manifest entries. `user` property of a cron resource, then the cron resource will autorequire that user. -#### Properties +#### Examples -The following properties are available in the `cron` type. +##### -##### `ensure` +```puppet -Valid values: present, absent +cron { 'logrotate': + command => '/usr/sbin/logrotate', + user => 'root', + hour => 2, + minute => 0, +} +``` -The basic property that the resource should be in. +##### Note that all periodic attributes can be specified as an array of values: + +```puppet + +cron { 'logrotate': + command => '/usr/sbin/logrotate', + user => 'root', + hour => [2, 4], +} +``` -Default value: present +##### ...or using ranges or the step syntax `*/2` (although there's no guarantee that your `cron` daemon supports these): + +```puppet + +cron { 'logrotate': + command => '/usr/sbin/logrotate', + user => 'root', + hour => ['2-4'], + minute => '*/10', +} +``` + +#### Properties + +The following properties are available in the `cron` type. ##### `command` @@ -84,32 +86,40 @@ user's environment is desired it should be sourced manually. All cron parameters support `absent` as a value; this will remove any existing values for that field. -##### `special` +##### `ensure` -A special value such as 'reboot' or 'annually'. -Only available on supported systems such as Vixie Cron. -Overrides more specific time of day/week settings. -Set to 'absent' to make puppet revert to a plain numeric schedule. +Valid values: `present`, `absent` -##### `minute` +The basic property that the resource should be in. -The minute at which to run the cron job. -Optional; if specified, must be between 0 and 59, inclusive. +Default value: `present` + +##### `environment` + +Any environment settings associated with this cron job. They +will be stored between the header and the job in the crontab. There +can be no guarantees that other, earlier settings will not also +affect a given cron job. + + +Also, Puppet cannot automatically determine whether an existing, +unmanaged environment setting is associated with a given cron +job. If you already have cron jobs with environment settings, +then Puppet will keep those settings in the same place in the file, +but will not associate them with a specific job. + +Settings should be specified exactly as they should appear in +the crontab, like `PATH=/bin:/usr/bin:/usr/sbin`. ##### `hour` The hour at which to run the cron job. Optional; if specified, must be between 0 and 23, inclusive. -##### `weekday` - -The weekday on which to run the command. Optional; if specified, -must be either: - -- A number between 0 and 7, inclusive, with 0 or 7 being Sunday -- The name of the day, such as 'Tuesday'. +##### `minute` -Day ranges can only be numeric; e.g. '1-5' for weekdays, but not 'Mon-Fri'. +The minute at which to run the cron job. +Optional; if specified, must be between 0 and 59, inclusive. ##### `month` @@ -124,22 +134,24 @@ must be either: The day of the month on which to run the command. Optional; if specified, must be between 1 and 31. -##### `environment` +##### `special` -Any environment settings associated with this cron job. They -will be stored between the header and the job in the crontab. There -can be no guarantees that other, earlier settings will not also -affect a given cron job. +A special value such as 'reboot' or 'annually'. +Only available on supported systems such as Vixie Cron. +Overrides more specific time of day/week settings. +Set to 'absent' to make puppet revert to a plain numeric schedule. +##### `target` -Also, Puppet cannot automatically determine whether an existing, -unmanaged environment setting is associated with a given cron -job. If you already have cron jobs with environment settings, -then Puppet will keep those settings in the same place in the file, -but will not associate them with a specific job. +The name of the crontab file in which the cron job should be stored. -Settings should be specified exactly as they should appear in -the crontab, like `PATH=/bin:/usr/bin:/usr/sbin`. +This property defaults to the value of the `user` property if set, the +user running Puppet or `root`. + +For the default crontab provider, this property is functionally +equivalent to the `user` property and should be avoided. In particular, +setting both `user` and `target` to different values will result in +undefined behavior. ##### `user` @@ -152,23 +164,24 @@ This property defaults to the user running Puppet or `root`. The default crontab provider executes the system `crontab` using the user account specified by this property. -##### `target` +##### `weekday` -The name of the crontab file in which the cron job should be stored. +The weekday on which to run the command. Optional; if specified, +must be either: -This property defaults to the value of the `user` property if set, the -user running Puppet or `root`. +- A number between 0 and 7, inclusive, with 0 or 7 being Sunday +- The name of the day, such as 'Tuesday'. -For the default crontab provider, this property is functionally -equivalent to the `user` property and should be avoided. In particular, -setting both `user` and `target` to different values will result in -undefined behavior. +Day ranges can only be numeric; e.g. '1-5' for weekdays, but not 'Mon-Fri'. #### Parameters The following parameters are available in the `cron` type. -##### `name` +* [`name`](#name) +* [`provider`](#provider) + +##### `name` namevar @@ -180,3 +193,8 @@ against specified jobs (and Puppet adds a comment to cron jobs it adds), but it is at least possible that converting from unmanaged jobs to managed jobs might require manual intervention. +##### `provider` + +The specific backend to use for this `cron` resource. You will seldom need to specify this --- Puppet will usually +discover the appropriate provider for your platform. + diff --git a/Rakefile b/Rakefile index 23e44bf..2906c15 100644 --- a/Rakefile +++ b/Rakefile @@ -35,7 +35,7 @@ end def changelog_future_release return unless Rake.application.top_level_tasks.include? "changelog" - returnVal = "%s" % JSON.load(File.read('metadata.json'))['version'] + returnVal = "v%s" % 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 diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb index 12ad7f1..e07a669 100644 --- a/lib/puppet/provider/cron/crontab.rb +++ b/lib/puppet/provider/cron/crontab.rb @@ -32,7 +32,6 @@ Puppet::Type.type(:cron).provide(:crontab, parent: Puppet::Provider::ParsedFile, match: %r{^\s*(@\w+|\S+\s+\S+\s+\S+\s+\S+\s+\S+)\s+(.+)$}, absent: '*', block_eval: :instance do - def post_parse(record) time = record.delete(:time) match = %r{@(\S+)}.match(time) diff --git a/lib/puppet/provider/cron/filetype.rb b/lib/puppet/provider/cron/filetype.rb index 153285d..455ec07 100644 --- a/lib/puppet/provider/cron/filetype.rb +++ b/lib/puppet/provider/cron/filetype.rb @@ -12,7 +12,7 @@ class Puppet::Provider::Cron # autoloader meaning that, without this wrapper, the crontab filetypes # would be re-defined, causing Puppet to raise an exception. def newfiletype(name, &block) - return if @filetypes && @filetypes.key?(name) + return if @filetypes&.key?(name) base_newfiletype(name, &block) end @@ -54,11 +54,11 @@ class Puppet::Provider::Cron rescue => detail case detail.to_s when %r{no crontab for} - return '' + '' when %r{are not allowed to} Puppet.debug _('The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).') % { path: @path } - return '' + '' else raise FileReadError, _('Could not read crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace end @@ -117,11 +117,11 @@ class Puppet::Provider::Cron rescue => detail case detail.to_s when %r{can't open your crontab} - return '' + '' when %r{you are not authorized to use cron} Puppet.debug _('The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).') % { path: @path } - return '' + '' else raise FileReadError, _('Could not read crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace end @@ -168,11 +168,11 @@ class Puppet::Provider::Cron rescue => detail case detail.to_s when %r{open.*in.*directory} - return '' + '' when %r{not.*authorized.*cron} Puppet.debug _('The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).') % { path: @path } - return '' + '' else raise FileReadError, _('Could not read crontab for %{path}: %{detail}') % { path: @path, detail: detail }, detail.backtrace end diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index 37188b4..53bb6fd 100644 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -4,19 +4,20 @@ require 'puppet/util/filetype' Puppet::Type.newtype(:cron) do @doc = <<-'EOT' - Installs and manages cron jobs. Every cron resource created by Puppet - requires a command and at least one periodic attribute (hour, minute, - month, monthday, weekday, or special). While the name of the cron job is - not part of the actual job, the name is stored in a comment beginning with - `# Puppet Name: `. These comments are used to match crontab entries created - by Puppet with cron resources. + @summary Installs and manages cron jobs. + + Every cron resource created by Puppet requires a command and at least one + periodic attribute (hour, minute, month, monthday, weekday, or special). While + the name of the cron job is not part of the actual job, the name is stored in a + comment beginning with `# Puppet Name: `. These comments are used to match + crontab entries created by Puppet with cron resources. If an existing crontab entry happens to match the scheduling and command of a cron resource that has never been synced, Puppet defers to the existing crontab entry and does not create a new entry tagged with the `# Puppet Name: ` comment. - Example: + @example cron { 'logrotate': command => '/usr/sbin/logrotate', @@ -25,7 +26,7 @@ Puppet::Type.newtype(:cron) do minute => 0, } - Note that all periodic attributes can be specified as an array of values: + @example Note that all periodic attributes can be specified as an array of values: cron { 'logrotate': command => '/usr/sbin/logrotate', @@ -33,8 +34,7 @@ Puppet::Type.newtype(:cron) do hour => [2, 4], } - ...or using ranges or the step syntax `*/2` (although there's no guarantee - that your `cron` daemon supports these): + @example ...or using ranges or the step syntax `*/2` (although there's no guarantee that your `cron` daemon supports these): cron { 'logrotate': command => '/usr/sbin/logrotate', @@ -155,17 +155,17 @@ Puppet::Type.newtype(:cron) do end # Allow step syntax - if value.to_s =~ %r{^\*/[0-9]+$} + if %r{^\*/[0-9]+$}.match?(value.to_s) return value end # Allow ranges - if value.to_s =~ %r{^[0-9]+-[0-9]+$} + if %r{^[0-9]+-[0-9]+$}.match?(value.to_s) return value end # Allow ranges with step - if value.to_s =~ %r{^[0-9]+-[0-9]+/[0-9]+$} + if %r{^[0-9]+-[0-9]+/[0-9]+$}.match?(value.to_s) return value end @@ -210,7 +210,7 @@ Puppet::Type.newtype(:cron) do def retrieve return_value = super - return_value = return_value[0] if return_value && return_value.is_a?(Array) + return_value = return_value[0] if return_value&.is_a?(Array) return_value end diff --git a/rakelib/commits.rake b/rakelib/commits.rake index a900ee2..42eb209 100644 --- a/rakelib/commits.rake +++ b/rakelib/commits.rake @@ -7,7 +7,7 @@ task(:commits) do %x{git log --no-merges --pretty=%s #{commit_range}}.each_line do |commit_summary| # This regex tests for the currently supported commit summary tokens. # The exception tries to explain it in more full. - if /^\((maint|packaging|doc|docs|modules-\d+)\)|revert/i.match(commit_summary).nil? + if /^Release prep|\((maint|packaging|doc|docs|modules-\d+)\)|revert/i.match(commit_summary).nil? raise "\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \ "\n\t\t#{commit_summary}\n" \ "\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n" \ @@ -16,6 +16,7 @@ task(:commits) do "\t\t(docs)(DOCUMENT-)\n" \ "\t\t(packaging)\n" "\t\t(maint)\n" \ + "\t\tRelease prep v\n" \ "\n\tThis test for the commit summary is case-insensitive.\n\n\n" else puts "#{commit_summary}" diff --git a/spec/acceptance/tests/resource/cron/should_fail_to_write_a_nonexistent_users_crontab_spec.rb b/spec/acceptance/tests/resource/cron/should_fail_to_write_a_nonexistent_users_crontab_spec.rb index 40fbbd9..167260a 100644 --- a/spec/acceptance/tests/resource/cron/should_fail_to_write_a_nonexistent_users_crontab_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_fail_to_write_a_nonexistent_users_crontab_spec.rb @@ -12,7 +12,7 @@ RSpec.context 'when Puppet attempts to write the crontab of a nonexistent user' end compatible_agents.each do |agent| - it "should fail on #{agent}" do + it "fails on #{agent}" do manifest = cron_manifest('second_entry', command: 'ls', user: nonexistent_username) apply_manifest_on(agent, manifest, expect_failures: true) end diff --git a/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb b/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb index 6a5b2c6..60c51c9 100644 --- a/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_not_overwrite_crontab_file_on_file_read_error_spec.rb @@ -44,7 +44,7 @@ RSpec.context 'when Puppet cannot read a crontab file' do end compatible_agents.each do |agent| - it "should not overwrite it on #{agent}" do + it "does not overwrite it on #{agent}" do if older_agent?(agent) skip('Skipping this test since we are on an older agent that does not have the PUP-9217 changes') end diff --git a/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb b/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb index 1846523..e95dc29 100644 --- a/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_only_fail_associated_resources_on_file_read_error_spec.rb @@ -42,7 +42,7 @@ RSpec.context 'when Puppet cannot read a crontab file' do end compatible_agents.each do |agent| - it "should only fail the associated resources on #{agent}" do + it "onlies fail the associated resources on #{agent}" do if older_agent?(agent) skip('Skipping this test since we are on an older agent that does not have the PUP-9217 changes') end diff --git a/spec/acceptance/tests/resource/cron/should_write_an_originally_unauthorized_users_crontab_if_puppet_authorizes_them_spec.rb b/spec/acceptance/tests/resource/cron/should_write_an_originally_unauthorized_users_crontab_if_puppet_authorizes_them_spec.rb index 834cac7..07d5375 100644 --- a/spec/acceptance/tests/resource/cron/should_write_an_originally_unauthorized_users_crontab_if_puppet_authorizes_them_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_write_an_originally_unauthorized_users_crontab_if_puppet_authorizes_them_spec.rb @@ -61,7 +61,7 @@ RSpec.context 'when Puppet authorizes a previously unauthorized user to use cron compatible_agents.each do |agent| is_aix_or_solaris_agent = agent['platform'].include?('aix') || agent['platform'].include?('solaris') - it "should write that user's crontab on #{agent}", if: is_aix_or_solaris_agent do + it "writes that user's crontab on #{agent}", if: is_aix_or_solaris_agent do step 'Add the unauthorized user to the cron.deny file' do on(agent, "echo #{unauthorized_username} >> #{cron_deny_path[agent]}") end diff --git a/spec/acceptance/tests/resource/cron/should_write_new_users_crontab_after_puppet_creates_them_spec.rb b/spec/acceptance/tests/resource/cron/should_write_new_users_crontab_after_puppet_creates_them_spec.rb index 12506ad..6fb7396 100644 --- a/spec/acceptance/tests/resource/cron/should_write_new_users_crontab_after_puppet_creates_them_spec.rb +++ b/spec/acceptance/tests/resource/cron/should_write_new_users_crontab_after_puppet_creates_them_spec.rb @@ -31,7 +31,7 @@ RSpec.context 'when Puppet creates a user in the middle of its run' do end compatible_agents.each do |agent| - it "should be able to write their crontab on #{agent}" do + it "is able to write their crontab on #{agent}" do puppet_result = nil step "Create the new user, and the known + new user's crontab entries with Puppet" do # Placing Cron[first_entry] before creating the new user diff --git a/spec/unit/provider/cron/crontab_spec.rb b/spec/unit/provider/cron/crontab_spec.rb index 6e28393..4047f82 100644 --- a/spec/unit/provider/cron/crontab_spec.rb +++ b/spec/unit/provider/cron/crontab_spec.rb @@ -37,11 +37,11 @@ describe Puppet::Type.type(:cron).provider(:crontab) do samples = YAML.load(File.read(my_fixture('single_line.yaml'))) # rubocop:disable Security/YAMLLoad samples.each do |name, data| - it "should parse crontab line #{name} correctly" do + it "parses crontab line #{name} correctly" do compare_crontab_record subject.parse_line(data[:text]), data[:record] end - it "should reconstruct the crontab line #{name} from the record" do + it "reconstructs the crontab line #{name} from the record" do expect(subject.to_line(data[:record])).to eq(data[:text]) end end diff --git a/spec/unit/provider/cron/parsed_spec.rb b/spec/unit/provider/cron/parsed_spec.rb index e4fa4cd..8e02ce6 100644 --- a/spec/unit/provider/cron/parsed_spec.rb +++ b/spec/unit/provider/cron/parsed_spec.rb @@ -81,7 +81,7 @@ describe Puppet::Type.type(:cron).provider(:crontab) do # I'd use expect(ENV).to receive(:[]).with('USER') but this does not work because # ENV["USER"] is evaluated at load time. describe 'when determining the default target' do - it "should use the current user #{ENV['USER']}", if: ENV['USER'] do + it "uses the current user #{ENV['USER']}", if: ENV['USER'] do expect(described_class.default_target).to eq(ENV['USER']) end @@ -166,7 +166,7 @@ describe Puppet::Type.type(:cron).provider(:crontab) do describe 'it should support special strings' do ['reboot', 'yearly', 'anually', 'monthly', 'weekly', 'daily', 'midnight', 'hourly'].each do |special| - it "should support @#{special}" do + it "supports @#{special}" do expect(described_class.parse_line("@#{special} /bin/true")).to eq(record_type: :crontab, hour: :absent, minute: :absent, @@ -300,7 +300,7 @@ describe Puppet::Type.type(:cron).provider(:crontab) do command: '/bin/false', target: 'nobody', }.each_pair do |field, new_value| - it "should not match a record when #{field} does not match" do + it "does not match a record when #{field} does not match" do record[field] = new_value expect(described_class.match(record, resource[:name] => resource)).to be_falsey end @@ -317,7 +317,7 @@ describe Puppet::Type.type(:cron).provider(:crontab) do command: '/bin/false', target: 'root', }.each_pair do |field, new_value| - it "should not match a record when #{field} does not match" do + it "does not match a record when #{field} does not match" do record_special[field] = new_value expect(described_class.match(record_special, resource_special[:name] => resource_special)).to be_falsey end diff --git a/spec/unit/type/cron_spec.rb b/spec/unit/type/cron_spec.rb index 78deabf..9564d16 100644 --- a/spec/unit/type/cron_spec.rb +++ b/spec/unit/type/cron_spec.rb @@ -21,19 +21,19 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do describe 'when validating attributes' do [:name, :provider].each do |param| - it "should have a #{param} parameter" do + it "has a #{param} parameter" do expect(described_class.attrtype(param)).to eq(:param) end end [:command, :special, :minute, :hour, :weekday, :month, :monthday, :environment, :user, :target].each do |property| - it "should have a #{property} property" do + it "has a #{property} property" do expect(described_class.attrtype(property)).to eq(:property) end end [:command, :minute, :hour, :weekday, :month, :monthday].each do |cronparam| - it "should have #{cronparam} of type CronParam" do + it "has #{cronparam} of type CronParam" do expect(described_class.attrclass(cronparam).ancestors).to include CronParam end end @@ -490,7 +490,7 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do describe 'special' do ['reboot', 'yearly', 'annually', 'monthly', 'weekly', 'daily', 'midnight', 'hourly'].each do |value| - it "should support the value '#{value}'" do + it "supports the value '#{value}'" do expect { described_class.new(name: 'foo', special: value) }.not_to raise_error end end @@ -498,7 +498,7 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do context 'when combined with numeric schedule fields' do context "which are 'absent'" do [['reboot', 'yearly', 'annually', 'monthly', 'weekly', 'daily', 'midnight', 'hourly'], :absent].flatten.each do |value| - it "should accept the value '#{value}' for special" do + it "accepts the value '#{value}' for special" do expect { described_class.new(name: 'foo', minute: :absent, special: value) }.not_to raise_error @@ -507,7 +507,7 @@ describe Puppet::Type.type(:cron), unless: Puppet.features.microsoft_windows? do end context 'which are not absent' do ['reboot', 'yearly', 'annually', 'monthly', 'weekly', 'daily', 'midnight', 'hourly'].each do |value| - it "should not accept the value '#{value}' for special" do + it "does not accept the value '#{value}' for special" do expect { described_class.new(name: 'foo', minute: '1', special: value) }.to raise_error(Puppet::Error, %r{cannot specify both a special schedule and a value}) -- cgit v1.2.3