From 919fc8160ae616b211aafedc8a0043a63cf5fb27 Mon Sep 17 00:00:00 2001 From: Carlos Camacho Date: Mon, 12 Mar 2018 11:59:24 +0100 Subject: [PATCH] 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 --- manifests/cron/archive_deleted_rows.pp | 39 +++++++-- manifests/cron/purge_shadow_tables.pp | 85 +++++++++++++++++++ .../add-purge-to-cron-9b7c80e3e915fb4f.yaml | 10 +++ spec/acceptance/nova_wsgi_apache_spec.rb | 2 +- .../nova_cron_archive_deleted_rows_spec.rb | 51 ++++++++++- spec/classes/nova_cron_purge_shadow_tables.rb | 65 ++++++++++++++ 6 files changed, 240 insertions(+), 12 deletions(-) create mode 100644 manifests/cron/purge_shadow_tables.pp create mode 100644 releasenotes/notes/add-purge-to-cron-9b7c80e3e915fb4f.yaml create mode 100644 spec/classes/nova_cron_purge_shadow_tables.rb diff --git a/manifests/cron/archive_deleted_rows.pp b/manifests/cron/archive_deleted_rows.pp index 207c45f44..5bed5d4db 100644 --- a/manifests/cron/archive_deleted_rows.pp +++ b/manifests/cron/archive_deleted_rows.pp @@ -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, diff --git a/manifests/cron/purge_shadow_tables.pp b/manifests/cron/purge_shadow_tables.pp new file mode 100644 index 000000000..b4dd7e995 --- /dev/null +++ b/manifests/cron/purge_shadow_tables.pp @@ -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'] + } +} diff --git a/releasenotes/notes/add-purge-to-cron-9b7c80e3e915fb4f.yaml b/releasenotes/notes/add-purge-to-cron-9b7c80e3e915fb4f.yaml new file mode 100644 index 000000000..10c3bcc7b --- /dev/null +++ b/releasenotes/notes/add-purge-to-cron-9b7c80e3e915fb4f.yaml @@ -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. diff --git a/spec/acceptance/nova_wsgi_apache_spec.rb b/spec/acceptance/nova_wsgi_apache_spec.rb index 7a092fd20..dc6edc1d9 100644 --- a/spec/acceptance/nova_wsgi_apache_spec.rb +++ b/spec/acceptance/nova_wsgi_apache_spec.rb @@ -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 diff --git a/spec/classes/nova_cron_archive_deleted_rows_spec.rb b/spec/classes/nova_cron_archive_deleted_rows_spec.rb index ad09d66da..72dd34926 100644 --- a/spec/classes/nova_cron_archive_deleted_rows_spec.rb +++ b/spec/classes/nova_cron_archive_deleted_rows_spec.rb @@ -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], diff --git a/spec/classes/nova_cron_purge_shadow_tables.rb b/spec/classes/nova_cron_purge_shadow_tables.rb new file mode 100644 index 000000000..c58ba0012 --- /dev/null +++ b/spec/classes/nova_cron_purge_shadow_tables.rb @@ -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