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 # 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. # 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 ( class keystone::cron::token_flush (
$ensure = present, $ensure = present,
$minute = 1, $minute = 1,
$hour = 0, $hour = 0,
$monthday = '*', $monthday = '*',
$month = '*', $month = '*',
$weekday = '*', $weekday = '*',
$maxdelay = 0, $maxdelay = 0,
$destination = '/var/log/keystone/keystone-tokenflush.log'
) { ) {
if $maxdelay == 0 { if $maxdelay == 0 {
@ -63,7 +68,7 @@ class keystone::cron::token_flush (
cron { 'keystone-manage token_flush': cron { 'keystone-manage token_flush':
ensure => $ensure, 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', environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => 'keystone', user => 'keystone',
minute => $minute, minute => $minute,

View File

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