puppet-heat/spec/classes/heat_cron_purge_deleted_spec.rb
Takashi Kajinami 67139207a9 Enable DB purge cron job after database is initialized
The DB purge operation expects the target database is already
initialized. This change ensures db sync is completed before cron job
is enabled.

Closes-Bug: #1955829
Change-Id: I742ea262bde8b9412627a475c53b27d25e132787
2021-12-28 10:39:22 +09:00

114 lines
3.4 KiB
Ruby

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 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
describe 'when setting a wrong age_type' do
before :each do
params.merge!(
:age_type => 'foobar'
)
end
it_raises 'a Puppet::Error', /age_type possible values are only days, hours, minutes, or seconds./
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