1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
require 'spec_helper'
describe 'heat::cron::purge_deleted' do
shared_examples_for 'heat::cron::purge_deleted' do
let :params do
{ :ensure => 'present',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*',
:maxdelay => 0,
:user => 'heat',
:age => 1,
:age_type => 'days',
:destination => '/var/log/heat/heat-purge_deleted.log' }
end
let :pre_condition do
"class { 'heat::keystone::authtoken':
password => 'password',
}
include heat"
end
describe 'with default parameters' do
it 'configures a cron' do
is_expected.to contain_cron('heat-manage purge_deleted').with(
:ensure => params[:ensure],
:command => "heat-manage purge_deleted -g days 1 >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'heat',
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[heat::dbsync::end]'
)
end
end
describe 'when specifying a maxdelay param' do
before :each do
params.merge!(
:maxdelay => 600
)
end
it 'configures a cron with delay' do
is_expected.to contain_cron('heat-manage purge_deleted').with(
:ensure => params[:ensure],
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; heat-manage purge_deleted -g days 1 >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'heat',
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[heat::dbsync::end]'
)
end
end
describe 'when batch_size is set' do
before :each do
params.merge!(
:batch_size => 100
)
end
it 'disables the cron job' do
is_expected.to contain_cron('heat-manage purge_deleted').with(
:ensure => params[:ensure],
:command => "heat-manage purge_deleted -g days 1 -b #{params[:batch_size]} >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'heat',
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[heat::dbsync::end]'
)
end
end
describe 'when disabling cron job' do
before :each do
params.merge!(
:ensure => 'absent'
)
end
it 'disables the cron job' do
is_expected.to contain_cron('heat-manage purge_deleted').with(
:ensure => params[:ensure],
:command => "heat-manage purge_deleted -g days 1 >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'heat',
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[heat::dbsync::end]'
)
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_behaves_like 'heat::cron::purge_deleted'
end
end
end
|