From b864b57e945b243f4e574a5fdfe7f2ea10b9462d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 29 Jun 2021 10:19:29 +0900 Subject: [PATCH] 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 --- manifests/cron/archive_deleted_rows.pp | 37 +++++++++++++------ manifests/cron/purge_shadow_tables.pp | 1 + ...cron-archive-verbose-9ad22f6d02bb9ad5.yaml | 5 +++ .../nova_cron_archive_deleted_rows_spec.rb | 23 ++++++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 releasenotes/notes/cron-archive-verbose-9ad22f6d02bb9ad5.yaml diff --git a/manifests/cron/archive_deleted_rows.pp b/manifests/cron/archive_deleted_rows.pp index c8f65c2ff..96d17986e 100644 --- a/manifests/cron/archive_deleted_rows.pp +++ b/manifests/cron/archive_deleted_rows.pp @@ -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), diff --git a/manifests/cron/purge_shadow_tables.pp b/manifests/cron/purge_shadow_tables.pp index 49c8efad7..1d67e9971 100644 --- a/manifests/cron/purge_shadow_tables.pp +++ b/manifests/cron/purge_shadow_tables.pp @@ -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. diff --git a/releasenotes/notes/cron-archive-verbose-9ad22f6d02bb9ad5.yaml b/releasenotes/notes/cron-archive-verbose-9ad22f6d02bb9ad5.yaml new file mode 100644 index 000000000..5d0c4287f --- /dev/null +++ b/releasenotes/notes/cron-archive-verbose-9ad22f6d02bb9ad5.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new ``nova::cron::archive_deleted_rows::verbose`` parameter has been + added. diff --git a/spec/classes/nova_cron_archive_deleted_rows_spec.rb b/spec/classes/nova_cron_archive_deleted_rows_spec.rb index 005c6976a..07a2c759f 100644 --- a/spec/classes/nova_cron_archive_deleted_rows_spec.rb +++ b/spec/classes/nova_cron_archive_deleted_rows_spec.rb @@ -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!(