Merge "Add support for --sleep option of the archive command"

This commit is contained in:
Zuul 2021-09-28 09:42:17 +00:00 committed by Gerrit Code Review
commit b7efab4265
4 changed files with 45 additions and 7 deletions

View File

@ -79,7 +79,11 @@
# (optional) Adds a retention policy when purging the shadow tables
# Defaults to undef.
#
# [*sleep*]
# (optional) The amount of time in seconds to sleep between batches when
# until_complete is used
# Defaults to undef.
#
class nova::cron::archive_deleted_rows (
$minute = 1,
$hour = 0,
@ -95,6 +99,7 @@ class nova::cron::archive_deleted_rows (
$all_cells = false,
$task_log = false,
$age = undef,
$sleep = undef,
) {
include nova::deps
@ -129,9 +134,9 @@ class nova::cron::archive_deleted_rows (
}
if $maxdelay == 0 {
$sleep = ''
$delay_cmd = ''
} else {
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
$delay_cmd = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
}
if $age {
@ -140,10 +145,16 @@ class nova::cron::archive_deleted_rows (
$age_real = ''
}
if $sleep != undef {
$sleep_real = " --sleep ${sleep}"
} else {
$sleep_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}${age_real}${until_complete_real}${all_cells_real}${task_log_real} \
command => "${delay_cmd}${cron_cmd}${purge_real} --max_rows ${max_rows}${age_real}${until_complete_real}${all_cells_real}${task_log_real}${sleep_real} \
>>${destination} 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => pick($user, $::nova::params::nova_user),

View File

@ -93,15 +93,15 @@ class nova::cron::purge_shadow_tables (
}
if $maxdelay == 0 {
$sleep = ''
$delay_cmd = ''
} else {
$sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
$delay_cmd = "sleep `expr \${RANDOM} \\% ${maxdelay}`; "
}
$cron_cmd = 'nova-manage db purge'
cron { 'nova-manage db purge':
command => "${sleep}${cron_cmd} --before `date --date='today - ${age} days' +\\%D`${verbose_real}${all_cells_real} \
command => "${delay_cmd}${cron_cmd} --before `date --date='today - ${age} days' +\\%D`${verbose_real}${all_cells_real} \
>>${destination} 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => pick($user, $::nova::params::nova_user),

View File

@ -0,0 +1,5 @@
---
features:
- |
The new ``nova::cron::archive_deleted_rows::sleep`` parameter has been
added.

View File

@ -191,6 +191,28 @@ describe 'nova::cron::archive_deleted_rows' do
end
end
context 'until_complete enabled and sleep set' do
before :each do
params.merge!(
:until_complete => true,
:sleep => 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]} --until-complete --sleep #{params[:sleep]} >>#{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({