Skip to content

fix idempotency for empty environment #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/cron/crontab.rb
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ def self.prefetch_hook(records)
record[:unmanaged] = true
end
if envs.nil? || envs.empty?
record[:environment] = :absent
record[:environment] = []
else
# Collect all of the environment lines, and mark the records to be skipped,
# since their data is included in our crontab record.
Original file line number Diff line number Diff line change
@@ -18,14 +18,14 @@
compatible_agents.each do |agent|
it "ensures idempotency on #{agent}" do
step 'Cron: basic - verify that it can be created'
result = apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}')
result = apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present, environment => [],}')
expect(result.stdout).to match(%r{ensure: created})

result = run_cron_on(agent, :list, 'tstuser')
expect(result.stdout).to match(%r{. . . . . .bin.true})

step 'Cron: basic - should not create again'
result = apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present,}')
result = apply_manifest_on(agent, 'cron { "myjob": command => "/bin/true", user => "tstuser", hour => "*", minute => [1], ensure => present, environment => [],}')
expect(result.stdout).not_to match(%r{ensure: created})
end
end
6 changes: 3 additions & 3 deletions spec/unit/provider/cron/parsed_spec.rb
Original file line number Diff line number Diff line change
@@ -223,7 +223,7 @@
expect(parameters[0][:special]).to eq(:absent)
expect(parameters[0][:command]).to match(%r{\$HOME/bin/daily.job >> \$HOME/tmp/out 2>&1})
expect(parameters[0][:ensure]).to eq(:present)
expect(parameters[0][:environment]).to eq(:absent)
expect(parameters[0][:environment]).to eq([])
expect(parameters[0][:user]).to eq(:absent)

expect(parameters[1][:name]).to match(%r{unmanaged:\$HOME/bin/monthly-\d+})
@@ -235,7 +235,7 @@
expect(parameters[1][:special]).to eq(:absent)
expect(parameters[1][:command]).to match(%r{\$HOME/bin/monthly})
expect(parameters[1][:ensure]).to eq(:present)
expect(parameters[1][:environment]).to eq(:absent)
expect(parameters[1][:environment]).to eq([])
expect(parameters[1][:user]).to eq(:absent)
expect(parameters[1][:target]).to eq('foobar')
end
@@ -259,7 +259,7 @@
special: :absent,
command: '/bin/true',
ensure: :present,
environment: :absent,
environment: [],
user: :absent,
target: 'foobar',
},