puppet-cinder/spec/classes/cinder_cron_db_purge_spec.rb
Takashi Kajinami f4c9e359fa Add sleep in cinder cron jobs
The current cron job for purge is executed at the precisely same time,
if we deploy multiple controller nodes with database clusterd,
for example using Galera cluster, it could cause DB spike.

This patch introduces a randomized sleep before executing purge job,
to avoid such kind of collision.

This commit is a kind of cherry-pick of the commit in puppet-nova
with change id I093a713a4f0ba48686de615aa8cb22b17a56917b .

Co-Authored-By: Rajesh Tailor <ratailor@redhat.com>

Change-Id: I36cf5f1e66fed580786970d9a953d983539a6e43
2019-03-18 01:22:03 +00:00

66 lines
2.0 KiB
Ruby

require 'spec_helper'
describe 'cinder::cron::db_purge' do
let :params do
{
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*',
:user => 'cinder',
:age => '30',
:maxdelay => 0,
:destination => '/var/log/cinder/cinder-rowsflush.log'
}
end
shared_examples 'cinder::cron::db_purge' do
context 'with required parameters' do
it { is_expected.to contain_cron('cinder-manage db purge').with(
:command => "cinder-manage db purge #{params[:age]} >>#{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[cinder::install::end]'
)}
end
context 'with required parameters with max delay enabled' do
before :each do
params.merge!(
:maxdelay => 600
)
end
it { should contain_cron('cinder-manage db purge').with(
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; cinder-manage db purge #{params[:age]} >>#{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[cinder::install::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 'cinder::cron::db_purge'
end
end
end