From 1baf0e78e0daa0361256ae5d80b2aef8878f0e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=A1gr?= Date: Tue, 4 Aug 2015 17:26:04 +0200 Subject: [PATCH] Allow to change archive destination Adds 'destination' parameter to keystone::cron::token_flush Change-Id: I5e51562338f68b4ba1b2e942907e6f6a0ab7a61e --- manifests/cron/token_flush.pp | 21 +++--- .../classes/keystone_cron_token_flush_spec.rb | 67 +++++++++++-------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/manifests/cron/token_flush.pp b/manifests/cron/token_flush.pp index 331eeba56..6dba32b47 100644 --- a/manifests/cron/token_flush.pp +++ b/manifests/cron/token_flush.pp @@ -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, diff --git a/spec/classes/keystone_cron_token_flush_spec.rb b/spec/classes/keystone_cron_token_flush_spec.rb index 88e1fd519..24ebcd8aa 100644 --- a/spec/classes/keystone_cron_token_flush_spec.rb +++ b/spec/classes/keystone_cron_token_flush_spec.rb @@ -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