Support --purge in Nova cleanup crons.

This patch adds the --purge parameter from
'nova-manage db' when executing the cleanup
tasks.

It will add the --purge parameter to the
archive_deleted_rows cron and will add an additional
cron to exclusively purge the shadow tables.

This feature is relevant due to the fact that we
were not purging the databases before running
upgrades, leading to the increase of the DB sizes.

Change-Id: I4ac0c9bd30463c546b141326b1293c78f845cf81
This commit is contained in:
Carlos Camacho 2018-03-12 11:59:24 +01:00
parent 77ef32602d
commit 919fc8160a
6 changed files with 240 additions and 12 deletions

View File

@ -54,16 +54,25 @@
# (optional) Adds --until-complete to the archive command
# Defaults to false.
#
# [*purge*]
# (optional) Adds --purge to the archive command
# This option will fully purge shadow table data after
# archiving, it adds a --purge flag to archive_deleted_rows
# which will automatically do a full db purge when complete.
# Defaults to false.
#
class nova::cron::archive_deleted_rows (
$minute = 1,
$hour = 0,
$monthday = '*',
$month = '*',
$weekday = '*',
$max_rows = '100',
$user = undef,
$destination = '/var/log/nova/nova-rowsflush.log',
$minute = 1,
$hour = 0,
$monthday = '*',
$month = '*',
$weekday = '*',
$max_rows = '100',
$user = undef,
$destination = '/var/log/nova/nova-rowsflush.log',
$until_complete = false,
$purge = false,
) {
include ::nova::deps
@ -72,9 +81,21 @@ class nova::cron::archive_deleted_rows (
if $until_complete {
$until_complete_real = '--until-complete'
}
else {
$until_complete_real = ''
}
if $purge {
$purge_real = '--purge'
}
else {
$purge_real = ''
}
$cron_cmd = 'nova-manage db archive_deleted_rows'
cron { 'nova-manage db archive_deleted_rows':
command => "nova-manage db archive_deleted_rows --max_rows ${max_rows} ${until_complete_real} >>${destination} 2>&1",
command => "${cron_cmd} ${purge_real} --max_rows ${max_rows} ${until_complete_real} >>${destination} 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => pick($user, $::nova::params::nova_user),
minute => $minute,

View File

@ -0,0 +1,85 @@
#
# Copyright (C) 2018 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Class: nova::cron::purge_shadow_tables
#
# Clean shadow tables
#
# === Parameters
#
# [*minute*]
# (optional) Defaults to '0'.
#
# [*hour*]
# (optional) Defaults to '12'.
#
# [*monthday*]
# (optional) Defaults to '*'.
#
# [*month*]
# (optional) Defaults to '*'.
#
# [*weekday*]
# (optional) Defaults to '6'.
#
# [*user*]
# (optional) User with access to nova files.
# nova::params::nova_user will be used if this is undef.
# Defaults to undef.
#
# [*destination*]
# (optional) Path to file to which rows should be archived
# Defaults to '/var/log/nova/nova-rowspurge.log'.
#
# [*verbose*]
# (optional) Adds --verbose to the purge command
# If specified, will print information about the purged rows.
#
class nova::cron::purge_shadow_tables (
$minute = 0,
$hour = 12,
$monthday = '*',
$month = '*',
$weekday = '6',
$user = undef,
$destination = '/var/log/nova/nova-rowspurge.log',
$verbose = false,
) {
include ::nova::deps
include ::nova::params
if $verbose {
$verbose_real = '--verbose'
}
else {
$verbose_real = ''
}
$cron_cmd = 'nova-manage db purge'
cron { 'nova-manage db purge':
command => "${cron_cmd} --all ${verbose_real} >>${destination} 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => pick($user, $::nova::params::nova_user),
minute => $minute,
hour => $hour,
monthday => $monthday,
month => $month,
weekday => $weekday,
require => Anchor['nova::dbsync::end']
}
}

View File

@ -0,0 +1,10 @@
---
features:
- |
OpenStack Nova in Rocky has the ability
of also purging the shadow data.
This patch enables the cron configuration
of this parameter for the archive rows
Cron and adds an additional Cron to run the
purge of the shadow tables without running
the archive task.

View File

@ -57,7 +57,7 @@ describe 'basic nova' do
end
describe cron do
it { is_expected.to have_entry('1 0 * * * nova-manage db archive_deleted_rows --max_rows 100 >>/var/log/nova/nova-rowsflush.log 2>&1').with_user('nova') }
it { is_expected.to have_entry('1 0 * * * nova-manage db archive_deleted_rows --max_rows 100 >>/var/log/nova/nova-rowsflush.log 2>&1').with_user('nova') }
end
describe 'nova aggregate' do

View File

@ -21,7 +21,7 @@ describe 'nova::cron::archive_deleted_rows' do
context 'until_complete is false' do
it 'configures a cron without 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]} >>#{params[:destination]} 2>&1",
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
:user => 'nova',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
@ -44,7 +44,54 @@ 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(
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --until-complete >>#{params[:destination]} 2>&1",
:command => "nova-manage db archive_deleted_rows --max_rows #{params[:max_rows]} --until-complete >>#{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 'purge is true' do
before :each do
params.merge!(
:purge => true,
)
end
it 'configures a cron with purge' do
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
:command => "nova-manage db archive_deleted_rows --purge --max_rows #{params[:max_rows]} >>#{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 'full purge' do
before :each do
params.merge!(
:purge => true,
:until_complete => true,
)
end
it 'configures a cron with all purge params' do
is_expected.to contain_cron('nova-manage db archive_deleted_rows').with(
:command => "nova-manage db archive_deleted_rows --purge --max_rows #{params[:max_rows]} --until-complete >>#{params[:destination]} 2>&1",
:user => 'nova',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],

View File

@ -0,0 +1,65 @@
require 'spec_helper'
describe 'nova::cron::purge_shadow_tables' do
let :facts do
OSDefaults.get_facts({ :osfamily => 'Debian' })
end
let :params do
{ :minute => 0,
:hour => 12,
:monthday => '*',
:month => '*',
:weekday => '6',
:user => 'nova',
:destination => '/var/log/nova/nova-rowspurge.log' }
end
context 'verbose is true' do
before :each do
params.merge!(
:verbose => true,
)
end
it 'configures a nova purge cron with verbose output' do
is_expected.to contain_cron('nova-manage db purge').with(
:command => "nova-manage db purge --all --verbose >>#{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 'verbose is false' do
before :each do
params.merge!(
:verbose => false,
)
end
it 'configures a nova purge cron without verbose output' do
is_expected.to contain_cron('nova-manage db purge').with(
:command => "nova-manage db purge --all >>#{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
end