diff --git a/manifests/cache/cleaner.pp b/manifests/cache/cleaner.pp index 9ef5dbe5..f05258db 100644 --- a/manifests/cache/cleaner.pp +++ b/manifests/cache/cleaner.pp @@ -19,18 +19,24 @@ # [*weekday*] # (optional) Defaults to '*'. # +# [*command_options*] +# command options to add to the cronjob +# (eg. point to config file, or redirect output) +# (optional) Defaults to ''. +# class glance::cache::cleaner ( - $minute = 1, - $hour = 0, - $monthday = '*', - $month = '*', - $weekday = '*', + $minute = 1, + $hour = 0, + $monthday = '*', + $month = '*', + $weekday = '*', + $command_options = '', ) { include glance::params cron { 'glance-cache-cleaner': - command => $glance::params::cache_cleaner_command, + command => "${glance::params::cache_cleaner_command} ${command_options}", environment => 'PATH=/bin:/usr/bin:/usr/sbin', user => 'glance', minute => $minute, diff --git a/manifests/cache/pruner.pp b/manifests/cache/pruner.pp index 2cee4381..96e135fb 100644 --- a/manifests/cache/pruner.pp +++ b/manifests/cache/pruner.pp @@ -19,18 +19,24 @@ # [*weekday*] # (optional) Defaults to '*'. # +# [*command_options*] +# command options to add to the cronjob +# (eg. point to config file, or redirect output) +# (optional) Defaults to ''. +# class glance::cache::pruner ( - $minute = '*/30', - $hour = '*', - $monthday = '*', - $month = '*', - $weekday = '*', + $minute = '*/30', + $hour = '*', + $monthday = '*', + $month = '*', + $weekday = '*', + $command_options = '', ) { include glance::params cron { 'glance-cache-pruner': - command => $glance::params::cache_pruner_command, + command => "${glance::params::cache_pruner_command} ${command_options}", environment => 'PATH=/bin:/usr/bin:/usr/sbin', user => 'glance', minute => $minute, diff --git a/spec/classes/glance_cache_cleaner_spec.rb b/spec/classes/glance_cache_cleaner_spec.rb index 4a25cb5a..a5bb314c 100644 --- a/spec/classes/glance_cache_cleaner_spec.rb +++ b/spec/classes/glance_cache_cleaner_spec.rb @@ -2,21 +2,64 @@ require 'spec_helper' describe 'glance::cache::cleaner' do - let :facts do - { :osfamily => 'Debian' } + shared_examples_for 'glance cache cleaner' do + + context 'when default parameters' do + + it 'configures a cron' do + should contain_cron('glance-cache-cleaner').with( + :command => 'glance-cache-cleaner ', + :environment => 'PATH=/bin:/usr/bin:/usr/sbin', + :user => 'glance', + :minute => 1, + :hour => 0, + :monthday => '*', + :month => '*', + :weekday => '*' + ) + end + end + + context 'when overriding parameters' do + let :params do + { + :minute => 59, + :hour => 23, + :monthday => '1', + :month => '2', + :weekday => '3', + :command_options => '--config-dir /etc/glance/', + } + end + it 'configures a cron' do + should contain_cron('glance-cache-cleaner').with( + :command => 'glance-cache-cleaner --config-dir /etc/glance/', + :environment => 'PATH=/bin:/usr/bin:/usr/sbin', + :user => 'glance', + :minute => 59, + :hour => 23, + :monthday => '1', + :month => '2', + :weekday => '3' + ) + end + end end - it 'configures a cron' do - should contain_cron('glance-cache-cleaner').with( - :command => 'glance-cache-cleaner', - :environment => 'PATH=/bin:/usr/bin:/usr/sbin', - :user => 'glance', - :minute => 1, - :hour => 0, - :monthday => '*', - :month => '*', - :weekday => '*', - :require => 'Package[glance-api]' - ) + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian' } + end + include_examples 'glance cache cleaner' + it { should contain_cron('glance-cache-cleaner').with(:require => 'Package[glance-api]')} end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat' } + end + include_examples 'glance cache cleaner' + it { should contain_cron('glance-cache-cleaner').with(:require => 'Package[openstack-glance]')} + end + end diff --git a/spec/classes/glance_cache_pruner_spec.rb b/spec/classes/glance_cache_pruner_spec.rb index 25876a0f..87bb46ca 100644 --- a/spec/classes/glance_cache_pruner_spec.rb +++ b/spec/classes/glance_cache_pruner_spec.rb @@ -2,21 +2,64 @@ require 'spec_helper' describe 'glance::cache::pruner' do - let :facts do - { :osfamily => 'Debian' } + shared_examples_for 'glance cache pruner' do + + context 'when default parameters' do + + it 'configures a cron' do + should contain_cron('glance-cache-pruner').with( + :command => 'glance-cache-pruner ', + :environment => 'PATH=/bin:/usr/bin:/usr/sbin', + :user => 'glance', + :minute => '*/30', + :hour => '*', + :monthday => '*', + :month => '*', + :weekday => '*' + ) + end + end + + context 'when overriding parameters' do + let :params do + { + :minute => 59, + :hour => 23, + :monthday => '1', + :month => '2', + :weekday => '3', + :command_options => '--config-dir /etc/glance/', + } + end + it 'configures a cron' do + should contain_cron('glance-cache-pruner').with( + :command => 'glance-cache-pruner --config-dir /etc/glance/', + :environment => 'PATH=/bin:/usr/bin:/usr/sbin', + :user => 'glance', + :minute => 59, + :hour => 23, + :monthday => '1', + :month => '2', + :weekday => '3' + ) + end + end end - it 'configures a cron' do - should contain_cron('glance-cache-pruner').with( - :command => 'glance-cache-pruner', - :environment => 'PATH=/bin:/usr/bin:/usr/sbin', - :user => 'glance', - :minute => '*/30', - :hour => '*', - :monthday => '*', - :month => '*', - :weekday => '*', - :require => 'Package[glance-api]' - ) + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian' } + end + include_examples 'glance cache pruner' + it { should contain_cron('glance-cache-pruner').with(:require => 'Package[glance-api]')} end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat' } + end + include_examples 'glance cache pruner' + it { should contain_cron('glance-cache-pruner').with(:require => 'Package[openstack-glance]')} + end + end