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 127 128 129 130 131 132 133 134 135 136 137 138
|
require 'spec_helper'
require 'date'
describe 'nova::cron::purge_shadow_tables' do
shared_examples_for 'nova::cron::purge_shadow_tables' do
let :params do
{ :minute => 0,
:hour => 12,
:monthday => '*',
:month => '*',
:weekday => '6',
:user => 'nova',
:maxdelay => 0,
:destination => '/var/log/nova/nova-rowspurge.log',
:age => 10 }
end
context 'ensure the cron job is absent' do
before :each do
params.merge!(
:ensure => :absent,
)
end
it 'removes the cron job' do
is_expected.to contain_cron('nova-manage db purge').with_ensure(:absent)
end
end
context 'verbose is true' do
before :each do
params.merge!(
:verbose => true,
)
end
it 'configures a nova purge cron with verbose output' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` --verbose >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[nova::dbsync::end]',
)
end
end
context 'verbose is false' do
before :each do
params.merge!(
:verbose => false,
)
end
it 'configures a nova purge cron without verbose output' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[nova::dbsync::end]',
)
end
end
context 'all_cells is true' do
before :each do
params.merge!(
:all_cells => true,
)
end
it 'configures a nova purge cron with all cells enabled' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` --all-cells >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[nova::dbsync::end]',
)
end
end
context 'cron with maxdelay' do
before :each do
params.merge!(
:maxdelay => 600
)
end
it 'configures a nova purge cron with maxdelay' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
:minute => params[:minute],
:hour => params[:hour],
:monthday => params[:monthday],
:month => params[:month],
:weekday => params[:weekday],
:require => 'Anchor[nova::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_configures 'nova::cron::purge_shadow_tables'
end
end
end
|