Add a retention policy (age) when purging shadow tables

This submission changes the --all default parameter in the purge shadow tables
cron to a '--before <date>' allowing to define a retention policy. Age name was
used as puppet-cinder already use it so to have a consitancy across the
projects.

Also, it's added the option --all-cells causing the purge to be applied
against all cell databases.

Co-Authored-By: Sergii Golovatiuk <sgolovat@redhat.com>

Change-Id: I2dcf37417c36fb8b1bde207c60d22d580005715c
This commit is contained in:
Carlos Camacho
2018-03-21 16:58:45 +00:00
parent 919fc8160a
commit 285554ba88
4 changed files with 239 additions and 159 deletions

View File

@@ -23,7 +23,7 @@
# (optional) Defaults to '0'. # (optional) Defaults to '0'.
# #
# [*hour*] # [*hour*]
# (optional) Defaults to '12'. # (optional) Defaults to '5'.
# #
# [*monthday*] # [*monthday*]
# (optional) Defaults to '*'. # (optional) Defaults to '*'.
@@ -32,7 +32,7 @@
# (optional) Defaults to '*'. # (optional) Defaults to '*'.
# #
# [*weekday*] # [*weekday*]
# (optional) Defaults to '6'. # (optional) Defaults to '*'.
# #
# [*user*] # [*user*]
# (optional) User with access to nova files. # (optional) User with access to nova files.
@@ -43,6 +43,14 @@
# (optional) Path to file to which rows should be archived # (optional) Path to file to which rows should be archived
# Defaults to '/var/log/nova/nova-rowspurge.log'. # Defaults to '/var/log/nova/nova-rowspurge.log'.
# #
# [*age*]
# (optional) Adds a retention policy when purging the shadow tables
# Defaults to 14.
#
# [*all_cells*]
# (optional) Adds --all-cells to the purge command
# Defaults to false.
#
# [*verbose*] # [*verbose*]
# (optional) Adds --verbose to the purge command # (optional) Adds --verbose to the purge command
# If specified, will print information about the purged rows. # If specified, will print information about the purged rows.
@@ -50,12 +58,14 @@
class nova::cron::purge_shadow_tables ( class nova::cron::purge_shadow_tables (
$minute = 0, $minute = 0,
$hour = 12, $hour = 5,
$monthday = '*', $monthday = '*',
$month = '*', $month = '*',
$weekday = '6', $weekday = '*',
$user = undef, $user = undef,
$destination = '/var/log/nova/nova-rowspurge.log', $destination = '/var/log/nova/nova-rowspurge.log',
$age = 14,
$all_cells = false,
$verbose = false, $verbose = false,
) { ) {
@@ -69,10 +79,17 @@ class nova::cron::purge_shadow_tables (
$verbose_real = '' $verbose_real = ''
} }
if $all_cells {
$all_cells_real = '--all-cells'
}
else {
$all_cells_real = ''
}
$cron_cmd = 'nova-manage db purge' $cron_cmd = 'nova-manage db purge'
cron { 'nova-manage db purge': cron { 'nova-manage db purge':
command => "${cron_cmd} --all ${verbose_real} >>${destination} 2>&1", command => "${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', environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => pick($user, $::nova::params::nova_user), user => pick($user, $::nova::params::nova_user),
minute => $minute, minute => $minute,

View File

@@ -0,0 +1,14 @@
---
features:
- |
This patch will add a new parameter (age) to define a
retention policy when purging the Nova shadow tables.
Also will add the parameter all_cells (defaulted to false)
to run the purge command over the cells tables.
fixes:
- |
Fix the default values to saner ones, this is because
operators might run both the archive and the purge cron
jobs. The defaults will make the purge job to run each
day at 5 hours but the retention policy parameter will
retain the data for 14 days.

View File

@@ -2,9 +2,7 @@ require 'spec_helper'
describe 'nova::cron::archive_deleted_rows' do describe 'nova::cron::archive_deleted_rows' do
let :facts do shared_examples_for 'nova::cron::archive_deleted_rows' do
OSDefaults.get_facts({ :osfamily => 'Debian' })
end
let :params do let :params do
{ :minute => 1, { :minute => 1,
@@ -104,4 +102,18 @@ describe 'nova::cron::archive_deleted_rows' do
) )
end end
end end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_configures 'nova::cron::archive_deleted_rows'
end
end
end end

View File

@@ -1,10 +1,9 @@
require 'spec_helper' require 'spec_helper'
require 'date'
describe 'nova::cron::purge_shadow_tables' do describe 'nova::cron::purge_shadow_tables' do
let :facts do shared_examples_for 'nova::cron::purge_shadow_tables' do
OSDefaults.get_facts({ :osfamily => 'Debian' })
end
let :params do let :params do
{ :minute => 0, { :minute => 0,
@@ -13,7 +12,8 @@ describe 'nova::cron::purge_shadow_tables' do
:month => '*', :month => '*',
:weekday => '6', :weekday => '6',
:user => 'nova', :user => 'nova',
:destination => '/var/log/nova/nova-rowspurge.log' } :destination => '/var/log/nova/nova-rowspurge.log',
:age => 10 }
end end
context 'verbose is true' do context 'verbose is true' do
@@ -25,7 +25,7 @@ describe 'nova::cron::purge_shadow_tables' do
it 'configures a nova purge cron with verbose output' do it 'configures a nova purge cron with verbose output' do
is_expected.to contain_cron('nova-manage db purge').with( is_expected.to contain_cron('nova-manage db purge').with(
:command => "nova-manage db purge --all --verbose >>#{params[:destination]} 2>&1", :command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +%D` --verbose >>#{params[:destination]} 2>&1",
:user => 'nova', :user => 'nova',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh', :environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user], :user => params[:user],
@@ -48,7 +48,30 @@ describe 'nova::cron::purge_shadow_tables' do
it 'configures a nova purge cron without verbose output' do it 'configures a nova purge cron without verbose output' do
is_expected.to contain_cron('nova-manage db purge').with( is_expected.to contain_cron('nova-manage db purge').with(
:command => "nova-manage db purge --all >>#{params[:destination]} 2>&1", :command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +%D` >>#{params[:destination]} 2>&1",
:user => 'nova',
: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 'all_cells is true' do
before :each do
params.merge!(
:all_cells => true,
)
end
it 'configures a nova purge cron with all cells enabled' do
is_expected.to contain_cron('nova-manage db purge').with(
:command => "nova-manage db purge --before `date --date='today - #{params[:age]} days' +%D` --verbose --all-cells >>#{params[:destination]} 2>&1",
:user => 'nova', :user => 'nova',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh', :environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user], :user => params[:user],
@@ -63,3 +86,17 @@ describe 'nova::cron::purge_shadow_tables' do
end end
end end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_configures 'nova::cron::purge_shadow_tables'
end
end
end