Adds --before archive parameter to cron job
Adds --before to the archive command based on age parameter provided. If added, it will run with: --before `date --date='today - #{params[:age]} days' +\\%F` Change-Id: I3af194696b87f6e17e9576c48f69ec7dde2640fd
This commit is contained in:
parent
bb08feae87
commit
2716ce36e0
|
@ -71,6 +71,10 @@
|
|||
# (optional) Adds --all-cells to the archive command
|
||||
# Defaults to false.
|
||||
#
|
||||
# [*age*]
|
||||
# (optional) Adds a retention policy when purging the shadow tables
|
||||
# Defaults to undef.
|
||||
#
|
||||
|
||||
class nova::cron::archive_deleted_rows (
|
||||
$minute = 1,
|
||||
|
@ -85,6 +89,7 @@ class nova::cron::archive_deleted_rows (
|
|||
$purge = false,
|
||||
$maxdelay = 0,
|
||||
$all_cells = false,
|
||||
$age = undef,
|
||||
) {
|
||||
|
||||
include ::nova::deps
|
||||
|
@ -117,10 +122,16 @@ class nova::cron::archive_deleted_rows (
|
|||
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
|
||||
}
|
||||
|
||||
if $age {
|
||||
$age_real = "--before `date --date=\'today - ${age} days\' +\\%F`"
|
||||
} else {
|
||||
$age_real = ''
|
||||
}
|
||||
|
||||
$cron_cmd = 'nova-manage db archive_deleted_rows'
|
||||
|
||||
cron { 'nova-manage db archive_deleted_rows':
|
||||
command => "${sleep}${cron_cmd} ${purge_real} --max_rows ${max_rows} ${until_complete_real} \
|
||||
command => "${sleep}${cron_cmd} ${purge_real} --max_rows ${max_rows} ${age_real} ${until_complete_real} \
|
||||
${all_cells_real} >>${destination} 2>&1",
|
||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
user => pick($user, $::nova::params::nova_user),
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
features:
|
||||
- Adds --before to the archive command
|
||||
based on age parameter provided.
|
||||
If added, it will run with
|
||||
--before `date --date='today - age days' +\\%F`
|
|
@ -58,7 +58,7 @@ describe 'basic nova' do
|
|||
end
|
||||
|
||||
describe cron do
|
||||
it { is_expected.to have_entry('1 0 * * * nova-manage db archive_deleted_rows --max_rows 100 >>/var/log/nova/nova-rowsflush.log 2>&1').with_user('nova') }
|
||||
it { is_expected.to have_entry('1 0 * * * nova-manage db archive_deleted_rows --max_rows 100 >>/var/log/nova/nova-rowsflush.log 2>&1').with_user('nova') }
|
||||
end
|
||||
|
||||
describe 'nova aggregate' do
|
||||
|
|
|
@ -14,6 +14,7 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||
:user => 'nova',
|
||||
:until_complete => false,
|
||||
:all_cells => false,
|
||||
:age => false,
|
||||
:maxdelay => 0,
|
||||
:destination => '/var/log/nova/nova-rowsflush.log' }
|
||||
end
|
||||
|
@ -21,7 +22,7 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||
context 'until_complete and all_cells is false' do
|
||||
it 'configures a cron without until_complete and all_cells' do
|
||||
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
:minute => params[:minute],
|
||||
|
@ -43,7 +44,7 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||
|
||||
it 'configures a cron with until_complete' do
|
||||
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --until-complete >>#{params[:destination]} 2>&1",
|
||||
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --until-complete >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
:minute => params[:minute],
|
||||
|
@ -65,7 +66,7 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||
|
||||
it 'configures a cron with all_cells' do
|
||||
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --all-cells >>#{params[:destination]} 2>&1",
|
||||
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --all-cells >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
:minute => params[:minute],
|
||||
|
@ -87,7 +88,7 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||
|
||||
it 'configures a cron with purge' do
|
||||
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||
:command => "nova-manage db archive_deleted_rows --purge --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:command => "nova-manage db archive_deleted_rows --purge --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
:minute => params[:minute],
|
||||
|
@ -110,7 +111,7 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||
|
||||
it 'configures a cron with all purge params' do
|
||||
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||
:command => "nova-manage db archive_deleted_rows --purge --max_rows #{params[:max_rows]} --until-complete >>#{params[:destination]} 2>&1",
|
||||
:command => "nova-manage db archive_deleted_rows --purge --max_rows #{params[:max_rows]} --until-complete >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
:minute => params[:minute],
|
||||
|
@ -132,7 +133,29 @@ describe 'nova::cron::archive_deleted_rows' do
|
|||
|
||||
it 'configures a cron with maxdelay' do
|
||||
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} >>#{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 age' do
|
||||
before :each do
|
||||
params.merge!(
|
||||
:age => 5
|
||||
)
|
||||
end
|
||||
|
||||
it 'configures a cron with --before' do
|
||||
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
|
||||
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --before `date --date='today - #{params[:age]} days' +\\%F` >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
:minute => params[:minute],
|
||||
|
|
Loading…
Reference in New Issue