Allow to change archive destination

Adds 'destination' parameter to keystone::cron::token_flush

Change-Id: I5e51562338f68b4ba1b2e942907e6f6a0ab7a61e
This commit is contained in:
Martin Mágr 2015-08-04 17:26:04 +02:00
parent f654d3cd9b
commit 1baf0e78e0
2 changed files with 52 additions and 36 deletions

View File

@ -45,14 +45,19 @@
# 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.
#
# [*destination*]
# (optional) Path to file to which rows should be archived
# Defaults to '/var/log/keystone/keystone-tokenflush.log'.
#
class keystone::cron::token_flush (
$ensure = present,
$minute = 1,
$hour = 0,
$monthday = '*',
$month = '*',
$weekday = '*',
$maxdelay = 0,
$ensure = present,
$minute = 1,
$hour = 0,
$monthday = '*',
$month = '*',
$weekday = '*',
$maxdelay = 0,
$destination = '/var/log/keystone/keystone-tokenflush.log'
) {
if $maxdelay == 0 {
@ -63,7 +68,7 @@ class keystone::cron::token_flush (
cron { 'keystone-manage token_flush':
ensure => $ensure,
command => "${sleep}keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1",
command => "${sleep}keystone-manage token_flush >>${destination} 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => 'keystone',
minute => $minute,

View File

@ -6,62 +6,73 @@ describe 'keystone::cron::token_flush' do
{ :osfamily => 'Debian' }
end
let :params do
{ :ensure => 'present',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*',
:maxdelay => 0,
:destination => '/var/log/keystone/keystone-tokenflush.log' }
end
describe 'with default parameters' do
it 'configures a cron' do
is_expected.to contain_cron('keystone-manage token_flush').with(
:ensure => 'present',
:command => 'keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1',
:ensure => params[:ensure],
:command => "keystone-manage token_flush >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'keystone',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday]
)
end
end
describe 'when specifying a maxdelay param' do
let :params do
{
before :each do
params.merge!(
:maxdelay => 600
}
)
end
it 'configures a cron with delay' do
is_expected.to 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',
:ensure => params[:ensure],
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; keystone-manage token_flush >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'keystone',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday]
)
end
end
describe 'when specifying a maxdelay param' do
let :params do
{
describe 'when disabling cron job' do
before :each do
params.merge!(
:ensure => 'absent'
}
)
end
it 'configures a cron with delay' do
is_expected.to contain_cron('keystone-manage token_flush').with(
:ensure => 'absent',
:command => 'keystone-manage token_flush >>/var/log/keystone/keystone-tokenflush.log 2>&1',
:ensure => params[:ensure],
:command => "keystone-manage token_flush >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'keystone',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday]
)
end
end