Merge "Allow customizing status of cron job"

This commit is contained in:
Zuul 2023-03-13 16:58:34 +00:00 committed by Gerrit Code Review
commit d23bbbde40
3 changed files with 22 additions and 0 deletions

View File

@ -54,6 +54,9 @@
# 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 manila::cron::db_purge (
$minute = 1,
@ -65,6 +68,7 @@ class manila::cron::db_purge (
$age = 0,
$destination = '/var/log/manila/manila-rowsflush.log',
$maxdelay = 0,
Enum['present', 'absent'] $ensure = 'present',
) inherits manila::params {
include manila::deps
@ -76,6 +80,7 @@ class manila::cron::db_purge (
}
cron { 'manila-manage db purge':
ensure => $ensure,
command => "${sleep}manila-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 ``manila::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 'manila::cron::db_purge' do
shared_examples 'manila::cron::db_purge' do
context 'with required parameters' do
it { is_expected.to contain_cron('manila-manage db purge').with(
:ensure => :present,
:command => "manila-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 'manila::cron::db_purge' do
)}
end
context 'with ensure set to absent' do
before :each do
params.merge!(
:ensure => :absent
)
end
it { should contain_cron('manila-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 'manila::cron::db_purge' do
end
it { should contain_cron('manila-manage db purge').with(
:ensure => :present,
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; manila-manage db purge #{params[:age]} >>#{params[:destination]} 2>&1",
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => params[:user],