Merge "Allow unwinding nova DB manage cron jobs"

This commit is contained in:
Zuul 2023-03-13 10:05:39 +00:00 committed by Gerrit Code Review
commit ebdb481364
6 changed files with 59 additions and 2 deletions

View File

@ -88,6 +88,10 @@
# all cron jobs at the same time on all hosts this job is configured.
# Defaults to 0.
#
# [*ensure*]
# (optional) Ensure cron jobs present or absent
# Defaults to present.
#
class nova::cron::archive_deleted_rows (
$minute = 1,
$hour = 0,
@ -105,6 +109,7 @@ class nova::cron::archive_deleted_rows (
$sleep = undef,
$verbose = false,
$maxdelay = 0,
Enum['present', 'absent'] $ensure = 'present',
) inherits nova::params {
include nova::deps
@ -165,6 +170,7 @@ class nova::cron::archive_deleted_rows (
$cron_cmd = 'nova-manage db archive_deleted_rows'
cron { 'nova-manage db archive_deleted_rows':
ensure => $ensure,
# lint:ignore:140chars
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",
# lint:endignore

View File

@ -60,7 +60,11 @@
# 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.
#
# [*ensure*]
# (optional) Ensure cron jobs present or absent
# Defaults to present.
#
class nova::cron::purge_shadow_tables (
$minute = 0,
$hour = 5,
@ -73,6 +77,7 @@ class nova::cron::purge_shadow_tables (
$all_cells = false,
$verbose = false,
$maxdelay = 0,
Enum['present', 'absent'] $ensure = 'present',
) inherits nova::params {
include nova::deps
@ -101,6 +106,7 @@ class nova::cron::purge_shadow_tables (
$cron_cmd = 'nova-manage db purge'
cron { 'nova-manage db purge':
ensure => $ensure,
# lint:ignore:140chars
command => "${delay_cmd}${cron_cmd} --before `date --date='today - ${age} days' +\\%D`${verbose_real}${all_cells_real} >>${destination} 2>&1",
# lint:endignore

View File

@ -0,0 +1,8 @@
---
fixes:
- |
The new parameters, ``nova::cron::archive_deleted_rows::ensure`` and
``nova::cron::purge_shadow_tables::ensure``, have been added.
These parameters control the corresponding cron jobs existence. When either
of two classes included, they can be given ``ensure => absent`` to unwind
existing cron jobs.

View File

@ -39,7 +39,6 @@ describe 'nova::cache' do
:hashclient_retry_delay => '<SERVICE DEFAULT>',
:dead_timeout => '<SERVICE DEFAULT>',
:manage_backend_package => true,
:manage_backend_package => true,
)
end
end

View File

@ -21,9 +21,22 @@ describe 'nova::cron::archive_deleted_rows' do
:destination => '/var/log/nova/nova-rowsflush.log' }
end
context 'ensure the cron job is absent' do
before :each do
params.merge!(
:ensure => :absent,
)
end
it 'removes the cron job' do
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with_ensure(:absent)
end
end
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(
:ensure => :present,
: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],
@ -46,6 +59,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(
:ensure => :present,
: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],
@ -68,6 +82,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(
:ensure => :present,
: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],
@ -90,6 +105,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(
:ensure => :present,
: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],
@ -112,6 +128,7 @@ describe 'nova::cron::archive_deleted_rows' do
it 'configures a cron with task_log' do
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
:ensure => :present,
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --task-log >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
@ -134,6 +151,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(
:ensure => :present,
: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],
@ -157,6 +175,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(
:ensure => :present,
: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],
@ -179,6 +198,7 @@ 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(
:ensure => :present,
: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],
@ -201,6 +221,7 @@ describe 'nova::cron::archive_deleted_rows' do
it 'configures a cron with --before' do
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
:ensure => :present,
: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],
@ -224,6 +245,7 @@ describe 'nova::cron::archive_deleted_rows' do
it 'configures a cron with --before' do
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
:ensure => :present,
: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],

View File

@ -17,6 +17,18 @@ describe 'nova::cron::purge_shadow_tables' do
:age => 10 }
end
context 'ensure the cron job is absent' do
before :each do
params.merge!(
:ensure => :absent,
)
end
it 'removes the cron job' do
is_expected.to contain_cron('nova-manage db purge').with_ensure(:absent)
end
end
context 'verbose is true' do
before :each do
params.merge!(
@ -26,6 +38,7 @@ describe 'nova::cron::purge_shadow_tables' do
it 'configures a nova purge cron with verbose output' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` --verbose >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
@ -48,6 +61,7 @@ describe 'nova::cron::purge_shadow_tables' do
it 'configures a nova purge cron without verbose output' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
@ -70,6 +84,7 @@ describe 'nova::cron::purge_shadow_tables' do
it 'configures a nova purge cron with all cells enabled' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` --all-cells >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
@ -92,6 +107,7 @@ describe 'nova::cron::purge_shadow_tables' do
it 'configures a nova purge cron with maxdelay' do
is_expected.to contain_cron('nova-manage db purge').with(
:ensure => :present,
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; nova-manage db purge --before `date --date='today - #{params[:age]} days' +\\%D` >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],