diff --git a/manifests/cron/archive_deleted_rows.pp b/manifests/cron/archive_deleted_rows.pp index 4765a1a05..c8f65c2ff 100644 --- a/manifests/cron/archive_deleted_rows.pp +++ b/manifests/cron/archive_deleted_rows.pp @@ -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), diff --git a/manifests/cron/purge_shadow_tables.pp b/manifests/cron/purge_shadow_tables.pp index 858eaed62..49c8efad7 100644 --- a/manifests/cron/purge_shadow_tables.pp +++ b/manifests/cron/purge_shadow_tables.pp @@ -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), diff --git a/releasenotes/notes/archive-sleep-c3de94ddd2066c01.yaml b/releasenotes/notes/archive-sleep-c3de94ddd2066c01.yaml new file mode 100644 index 000000000..6710bd6fc --- /dev/null +++ b/releasenotes/notes/archive-sleep-c3de94ddd2066c01.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new ``nova::cron::archive_deleted_rows::sleep`` 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 e98b56d6c..005c6976a 100644 --- a/spec/classes/nova_cron_archive_deleted_rows_spec.rb +++ b/spec/classes/nova_cron_archive_deleted_rows_spec.rb @@ -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({