Add support for --verbose option in archive command

... so that users can record number of records processed by the archive
command. This change also updates order of parameters so that two
classes to manage cron job has consistent order.

Change-Id: I85c28aa3cc7bf0be09d15af7b1c03c8bdb247263
This commit is contained in:
Takashi Kajinami 2021-06-29 10:19:29 +09:00
parent c5cf15fd74
commit b864b57e94
4 changed files with 54 additions and 12 deletions

View File

@ -61,11 +61,9 @@
# which will automatically do a full db purge when complete.
# Defaults to false.
#
# [*maxdelay*]
# (optional) In Seconds. Should be a positive integer.
# Induces a random delay before running the cronjob to avoid running
# all cron jobs at the same time on all hosts this job is configured.
# Defaults to 0.
# [*age*]
# (optional) Adds a retention policy when purging the shadow tables
# Defaults to undef.
#
# [*all_cells*]
# (optional) Adds --all-cells to the archive command
@ -75,15 +73,22 @@
# (optional) Adds --task-log to the archive command
# Defaults to false.
#
# [*age*]
# (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.
#
# [*verbose*]
# (optional) Adds --verbose to the purge command
# If specified, will print information about the archived rows.
# Defaults to false.
#
# [*maxdelay*]
# (optional) In Seconds. Should be a positive integer.
# Induces a random delay before running the cronjob to avoid running
# all cron jobs at the same time on all hosts this job is configured.
# Defaults to 0.
#
class nova::cron::archive_deleted_rows (
$minute = 1,
$hour = 0,
@ -95,11 +100,12 @@ class nova::cron::archive_deleted_rows (
$destination = '/var/log/nova/nova-rowsflush.log',
$until_complete = false,
$purge = false,
$maxdelay = 0,
$age = undef,
$all_cells = false,
$task_log = false,
$age = undef,
$sleep = undef,
$verbose = false,
$maxdelay = 0,
) {
include nova::deps
@ -119,6 +125,13 @@ class nova::cron::archive_deleted_rows (
$purge_real = ''
}
if $verbose {
$verbose_real = ' --verbose'
}
else {
$verbose_real = ''
}
if $all_cells {
$all_cells_real = ' --all-cells'
}
@ -154,7 +167,7 @@ class nova::cron::archive_deleted_rows (
$cron_cmd = 'nova-manage db archive_deleted_rows'
cron { 'nova-manage db archive_deleted_rows':
command => "${delay_cmd}${cron_cmd}${purge_real} --max_rows ${max_rows}${age_real}${until_complete_real}${all_cells_real}${task_log_real}${sleep_real} \
command => "${delay_cmd}${cron_cmd}${purge_real} --max_rows ${max_rows}${verbose_real}${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

@ -54,6 +54,7 @@
# [*verbose*]
# (optional) Adds --verbose to the purge command
# If specified, will print information about the purged rows.
# Defaults to false.
#
# [*maxdelay*]
# (optional) In Seconds. Should be a positive integer.

View File

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

View File

@ -12,6 +12,7 @@ describe 'nova::cron::archive_deleted_rows' do
:weekday => '*',
:max_rows => '100',
:user => 'nova',
:verbose => false,
:until_complete => false,
:all_cells => false,
:age => false,
@ -36,6 +37,28 @@ describe 'nova::cron::archive_deleted_rows' do
end
end
context 'verbose is true' do
before :each do
params.merge!(
:verbose => true,
)
end
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]} --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 'until_complete is true' do
before :each do
params.merge!(