Merge "Allow disabling or delaying the token_flush cron"

This commit is contained in:
Jenkins 2014-12-02 15:48:28 +00:00 committed by Gerrit Code Review
commit 0df9701dcf
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,16 +6,63 @@ describe 'keystone::cron::token_flush' do
{ :osfamily => 'Debian' }
end
it 'configures a cron' do
should contain_cron('keystone-manage token_flush').with(
: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 => '*'
)
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',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
)
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