DB purge cron job
Adds cinder::cron::db_purge for setting up cron job which runs "cinder-manage db purge". Change-Id: I677f2ef3d9ca81fff0f672c8e34b6e4278674a96
This commit is contained in:
76
manifests/cron/db_purge.pp
Normal file
76
manifests/cron/db_purge.pp
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2015 Red Hat Inc.
|
||||||
|
#
|
||||||
|
# Author: Martin Magr <mmagr@redhat.com>
|
||||||
|
#
|
||||||
|
# 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: cinder::cron::db_purge
|
||||||
|
#
|
||||||
|
# Move deleted instances to another table that you don't have to backup
|
||||||
|
# unless you have data retention policies.
|
||||||
|
#
|
||||||
|
# === Parameters
|
||||||
|
#
|
||||||
|
# [*minute*]
|
||||||
|
# (optional) Defaults to '1'.
|
||||||
|
#
|
||||||
|
# [*hour*]
|
||||||
|
# (optional) Defaults to '0'.
|
||||||
|
#
|
||||||
|
# [*monthday*]
|
||||||
|
# (optional) Defaults to '*'.
|
||||||
|
#
|
||||||
|
# [*month*]
|
||||||
|
# (optional) Defaults to '*'.
|
||||||
|
#
|
||||||
|
# [*weekday*]
|
||||||
|
# (optional) Defaults to '*'.
|
||||||
|
#
|
||||||
|
# [*user*]
|
||||||
|
# (optional) User with access to cinder files.
|
||||||
|
# Defaults to 'cinder'.
|
||||||
|
#
|
||||||
|
# [*age*]
|
||||||
|
# (optional) Number of days prior to today for deletion,
|
||||||
|
# e.g. value 60 means to purge deleted rows that have the "deleted_at"
|
||||||
|
# column greater than 60 days ago.
|
||||||
|
# Defaults to 30
|
||||||
|
#
|
||||||
|
# [*destination*]
|
||||||
|
# (optional) Path to file to which rows should be archived
|
||||||
|
# Defaults to '/var/log/cinder/cinder-rowsflush.log'.
|
||||||
|
#
|
||||||
|
class cinder::cron::db_purge (
|
||||||
|
$minute = 1,
|
||||||
|
$hour = 0,
|
||||||
|
$monthday = '*',
|
||||||
|
$month = '*',
|
||||||
|
$weekday = '*',
|
||||||
|
$user = 'cinder',
|
||||||
|
$age = 30,
|
||||||
|
$destination = '/var/log/cinder/cinder-rowsflush.log'
|
||||||
|
) {
|
||||||
|
|
||||||
|
cron { 'cinder-manage db purge':
|
||||||
|
command => "cinder-manage db purge ${age} >>${destination} 2>&1",
|
||||||
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
|
user => $user,
|
||||||
|
minute => $minute,
|
||||||
|
hour => $hour,
|
||||||
|
monthday => $monthday,
|
||||||
|
month => $month,
|
||||||
|
weekday => $weekday,
|
||||||
|
require => Package['cinder'],
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,6 +102,7 @@ describe 'basic cinder' do
|
|||||||
class { '::cinder::scheduler': }
|
class { '::cinder::scheduler': }
|
||||||
class { '::cinder::scheduler::filter': }
|
class { '::cinder::scheduler::filter': }
|
||||||
class { '::cinder::volume': }
|
class { '::cinder::volume': }
|
||||||
|
class { '::cinder::cron::db_purge': }
|
||||||
# TODO: create a backend and spawn a volume
|
# TODO: create a backend and spawn a volume
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
@@ -115,5 +116,10 @@ describe 'basic cinder' do
|
|||||||
it { is_expected.to be_listening.with('tcp') }
|
it { is_expected.to be_listening.with('tcp') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe cron do
|
||||||
|
it { is_expected.to have_entry('1 0 * * * cinder-manage db purge 30 >>/var/log/cinder/cinder-rowsflush.log 2>&1').with_user('cinder') }
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
33
spec/classes/cinder_cron_db_purge_spec.rb
Normal file
33
spec/classes/cinder_cron_db_purge_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'cinder::cron::db_purge' do
|
||||||
|
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'RedHat' }
|
||||||
|
end
|
||||||
|
|
||||||
|
let :params do
|
||||||
|
{ :minute => 1,
|
||||||
|
:hour => 0,
|
||||||
|
:monthday => '*',
|
||||||
|
:month => '*',
|
||||||
|
:weekday => '*',
|
||||||
|
:user => 'cinder',
|
||||||
|
:age => '30',
|
||||||
|
:destination => '/var/log/cinder/cinder-rowsflush.log' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configures a cron' do
|
||||||
|
is_expected.to contain_cron('cinder-manage db purge').with(
|
||||||
|
:command => "cinder-manage db purge #{params[:age]} >>#{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 => 'Package[cinder]',
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user