From b8a59c770654ad30868239773725c803c61e3a7b Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Mon, 22 Sep 2014 10:38:29 +0200 Subject: [PATCH] add command_options to glance::cache::[cleaner|pruner] The parameter command_options allows to add options (like config file to use) to the cron job command. This makes it also possible to redirect the output. Extend tests, to support different operating systems and test parameters. Change-Id: I12a76e742db7279eafa3f3ec3c92947ff551b782 --- manifests/cache/cleaner.pp | 18 ++++-- manifests/cache/pruner.pp | 18 ++++-- spec/classes/glance_cache_cleaner_spec.rb | 71 ++++++++++++++++++----- spec/classes/glance_cache_pruner_spec.rb | 71 ++++++++++++++++++----- 4 files changed, 138 insertions(+), 40 deletions(-) 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