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
This commit is contained in:
Benedikt Trefzer 2014-09-22 10:38:29 +02:00
parent 246842f13c
commit b8a59c7706
4 changed files with 138 additions and 40 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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