Allow disabling or delaying the token_flush cron

Add the max_delay parameter to prevent running all cron jobs at the
exact same time in case this cron job is installed on more than one
server. The default is to not wait though.

Add the ensure parameter to allow removing the cron job.

Change-Id: I1cd231305a1ecc642c638af6cef7d591d1e3fe3e
This commit is contained in:
François Charlier 2014-11-26 18:02:42 +01:00
parent 29b6875331
commit 8e502087aa
2 changed files with 77 additions and 12 deletions

View File

@ -21,6 +21,10 @@
#
# === Parameters
#
# [*ensure*]
# (optional) Defaults to present.
# Valid values are present, absent.
#
# [*minute*]
# (optional) Defaults to '1'.
#
@ -36,16 +40,30 @@
# [*weekday*]
# (optional) Defaults to '*'.
#
# [*maxdelay*]
# (optional) Seconds. Defaults to 0. Should be a positive integer.
# Induces a random delay before running the cronjob to avoid running all
# cron jobs at the same time on all hosts this job is configured.
#
class keystone::cron::token_flush (
$ensure = present,
$minute = 1,
$hour = 0,
$monthday = '*',
$month = '*',
$weekday = '*',
$maxdelay = 0,
) {
if $maxdelay == 0 {
$sleep = ''
} else {
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
}
cron { 'keystone-manage token_flush':
command => 'keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1',
ensure => $ensure,
command => "${sleep}keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
user => 'keystone',
minute => $minute,

View File

@ -6,8 +6,10 @@ describe 'keystone::cron::token_flush' do
{ :osfamily => 'Debian' }
end
describe 'with default parameters' do
it 'configures a cron' do
should contain_cron('keystone-manage token_flush').with(
:ensure => 'present',
:command => 'keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
:user => 'keystone',
@ -19,3 +21,48 @@ describe 'keystone::cron::token_flush' do
)
end
end
describe 'when specifying a maxdelay param' do
let :params do
{
:maxdelay => 600
}
end
it 'configures a cron with delay' do
should contain_cron('keystone-manage token_flush').with(
:ensure => 'present',
:command => 'sleep `expr ${RANDOM} \\% 600`; keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
:user => 'keystone',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
)
end
end
describe 'when specifying a maxdelay param' do
let :params do
{
:ensure => 'absent'
}
end
it 'configures a cron with delay' do
should contain_cron('keystone-manage token_flush').with(
:ensure => 'absent',
:command => 'keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
:user => 'keystone',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
)
end
end
end