Merge "Allow customizing status of cron job"

This commit is contained in:
Zuul 2023-03-13 22:27:39 +00:00 committed by Gerrit Code Review
commit 2cde035bbc
3 changed files with 24 additions and 1 deletions

View File

@ -57,6 +57,10 @@
# all cron jobs at the same time on all hosts this job is configured.
# Defaults to 0.
#
# [*ensure*]
# (optional) Ensure cron jobs present or absent
# Defaults to present.
#
class cinder::cron::db_purge (
$minute = 1,
$hour = 0,
@ -66,7 +70,8 @@ class cinder::cron::db_purge (
$user = 'cinder',
$age = 30,
$destination = '/var/log/cinder/cinder-rowsflush.log',
$maxdelay = 0
$maxdelay = 0,
Enum['present', 'absent'] $ensure = 'present',
) {
include cinder::deps
@ -78,6 +83,7 @@ class cinder::cron::db_purge (
}
cron { 'cinder-manage db purge':
ensure => $ensure,
command => "${sleep}cinder-manage db purge ${age} >>${destination} 2>&1",
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => $user,

View File

@ -0,0 +1,5 @@
---
features:
- |
The new ``cinder::cron::db_purge::ensure`` parameter has been added, so
that status of the cron job can be customized.

View File

@ -18,6 +18,7 @@ describe 'cinder::cron::db_purge' do
shared_examples 'cinder::cron::db_purge' do
context 'with required parameters' do
it { is_expected.to contain_cron('cinder-manage db purge').with(
:ensure => :present,
:command => "cinder-manage db purge #{params[:age]} >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],
@ -30,6 +31,16 @@ describe 'cinder::cron::db_purge' do
)}
end
context 'with ensure set to absent' do
before :each do
params.merge!(
:ensure => :absent
)
end
it { should contain_cron('cinder-manage db purge').with_ensure(:absent) }
end
context 'with required parameters with max delay enabled' do
before :each do
params.merge!(
@ -38,6 +49,7 @@ describe 'cinder::cron::db_purge' do
end
it { should contain_cron('cinder-manage db purge').with(
:ensure => :present,
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; cinder-manage db purge #{params[:age]} >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],