From bf4534ab802d2e6189699edbe22683fa15926c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=A1gr?= Date: Tue, 4 Aug 2015 11:31:16 +0200 Subject: [PATCH] DB purge cron job Adds cinder::cron::db_purge for setting up cron job which runs "cinder-manage db purge". Change-Id: I677f2ef3d9ca81fff0f672c8e34b6e4278674a96 --- manifests/cron/db_purge.pp | 76 +++++++++++++++++++++++ spec/acceptance/basic_cinder_spec.rb | 6 ++ spec/classes/cinder_cron_db_purge_spec.rb | 33 ++++++++++ 3 files changed, 115 insertions(+) create mode 100644 manifests/cron/db_purge.pp create mode 100644 spec/classes/cinder_cron_db_purge_spec.rb diff --git a/manifests/cron/db_purge.pp b/manifests/cron/db_purge.pp new file mode 100644 index 00000000..559f7848 --- /dev/null +++ b/manifests/cron/db_purge.pp @@ -0,0 +1,76 @@ +# +# Copyright (C) 2015 Red Hat Inc. +# +# Author: Martin Magr +# +# 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'], + } +} diff --git a/spec/acceptance/basic_cinder_spec.rb b/spec/acceptance/basic_cinder_spec.rb index f12c9e03..9b5595b7 100644 --- a/spec/acceptance/basic_cinder_spec.rb +++ b/spec/acceptance/basic_cinder_spec.rb @@ -102,6 +102,7 @@ describe 'basic cinder' do class { '::cinder::scheduler': } class { '::cinder::scheduler::filter': } class { '::cinder::volume': } + class { '::cinder::cron::db_purge': } # TODO: create a backend and spawn a volume EOS @@ -115,5 +116,10 @@ describe 'basic cinder' do it { is_expected.to be_listening.with('tcp') } 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 diff --git a/spec/classes/cinder_cron_db_purge_spec.rb b/spec/classes/cinder_cron_db_purge_spec.rb new file mode 100644 index 00000000..f78e9a7b --- /dev/null +++ b/spec/classes/cinder_cron_db_purge_spec.rb @@ -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