Allow customizing status of cron job
... so that users can even remove the job. This follows what was added to puppet-nova by [1]. [1] https://review.opendev.org/c/openstack/puppet-nova/+/877096 Change-Id: I1f6ff0d39998695d2c69fd0cfc0bcf08e2cafe4a
This commit is contained in:
parent
293c3d20de
commit
bb44895619
|
@ -30,6 +30,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 glance::cache::cleaner(
|
||||
$minute = 1,
|
||||
$hour = 0,
|
||||
|
@ -37,7 +41,8 @@ class glance::cache::cleaner(
|
|||
$month = '*',
|
||||
$weekday = '*',
|
||||
$command_options = '',
|
||||
$maxdelay = 0
|
||||
$maxdelay = 0,
|
||||
Enum['present', 'absent'] $ensure = 'present',
|
||||
) {
|
||||
|
||||
include glance::deps
|
||||
|
@ -50,6 +55,7 @@ class glance::cache::cleaner(
|
|||
}
|
||||
|
||||
cron { 'glance-cache-cleaner':
|
||||
ensure => $ensure,
|
||||
command => "${sleep}${glance::params::cache_cleaner_command} ${command_options}",
|
||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
user => $::glance::params::user,
|
||||
|
|
|
@ -30,6 +30,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 glance::cache::pruner(
|
||||
$minute = '*/30',
|
||||
$hour = '*',
|
||||
|
@ -37,7 +41,8 @@ class glance::cache::pruner(
|
|||
$month = '*',
|
||||
$weekday = '*',
|
||||
$command_options = '',
|
||||
$maxdelay = 0
|
||||
$maxdelay = 0,
|
||||
Enum['present', 'absent'] $ensure = 'present',
|
||||
) {
|
||||
|
||||
include glance::deps
|
||||
|
@ -50,6 +55,7 @@ class glance::cache::pruner(
|
|||
}
|
||||
|
||||
cron { 'glance-cache-pruner':
|
||||
ensure => $ensure,
|
||||
command => "${sleep}${glance::params::cache_pruner_command} ${command_options}",
|
||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
user => $::glance::params::user,
|
||||
|
|
|
@ -58,6 +58,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 glance::cron::db_purge (
|
||||
$minute = 1,
|
||||
$hour = 0,
|
||||
|
@ -68,7 +72,8 @@ class glance::cron::db_purge (
|
|||
$age = 30,
|
||||
$max_rows = 100,
|
||||
$destination = '/var/log/glance/glance-rowsflush.log',
|
||||
$maxdelay = 0
|
||||
$maxdelay = 0,
|
||||
Enum['present', 'absent'] $ensure = 'present',
|
||||
) inherits glance::params {
|
||||
|
||||
include glance::deps
|
||||
|
@ -82,6 +87,7 @@ class glance::cron::db_purge (
|
|||
$opts = "--age_in_days ${age} --max_rows ${max_rows}"
|
||||
|
||||
cron { 'glance-manage db purge':
|
||||
ensure => $ensure,
|
||||
command => "${sleep}glance-manage db purge ${opts} >>${destination} 2>&1",
|
||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
user => $user,
|
||||
|
|
|
@ -58,6 +58,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 glance::cron::db_purge_images_table (
|
||||
$minute = 1,
|
||||
$hour = 0,
|
||||
|
@ -68,7 +72,8 @@ class glance::cron::db_purge_images_table (
|
|||
$age = 30,
|
||||
$max_rows = 100,
|
||||
$destination = '/var/log/glance/glance-images-rowsflush.log',
|
||||
$maxdelay = 0
|
||||
$maxdelay = 0,
|
||||
Enum['present', 'absent'] $ensure = 'present',
|
||||
) inherits glance::params {
|
||||
|
||||
include glance::deps
|
||||
|
@ -82,6 +87,7 @@ class glance::cron::db_purge_images_table (
|
|||
$opts = "--age_in_days ${age} --max_rows ${max_rows}"
|
||||
|
||||
cron { 'glance-manage db purge_images_table':
|
||||
ensure => $ensure,
|
||||
command => "${sleep}glance-manage db purge_images_table ${opts} >>${destination} 2>&1",
|
||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
user => $user,
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
The following classes now support the ``ensure`` parameter which controls
|
||||
state of the cron jobs.
|
||||
|
||||
- ``glance::cache::cleaner``
|
||||
- ``glance::cache::pruner``
|
||||
- ``glance::cron::db_purge``
|
||||
- ``glance::cron::db_purge_image_table``
|
|
@ -8,6 +8,7 @@ describe 'glance::cache::cleaner' do
|
|||
|
||||
it 'configures a cron' do
|
||||
is_expected.to contain_cron('glance-cache-cleaner').with(
|
||||
:ensure => :present,
|
||||
:command => 'glance-cache-cleaner ',
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
:user => 'glance',
|
||||
|
@ -38,6 +39,7 @@ describe 'glance::cache::cleaner' do
|
|||
end
|
||||
it 'configures a cron' do
|
||||
is_expected.to contain_cron('glance-cache-cleaner').with(
|
||||
:ensure => :present,
|
||||
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-cleaner --config-dir /etc/glance/',
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
:user => 'glance',
|
||||
|
@ -49,6 +51,15 @@ describe 'glance::cache::cleaner' do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ensure is set to absent' do
|
||||
let :params do
|
||||
{
|
||||
:ensure => :absent
|
||||
}
|
||||
end
|
||||
it { should contain_cron('glance-cache-cleaner').with_ensure(:absent) }
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
|
@ -59,15 +70,6 @@ describe 'glance::cache::cleaner' do
|
|||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
let(:platform_params) do
|
||||
case facts[:os]['family']
|
||||
when 'Debian'
|
||||
{ :api_package_name => 'glance-api' }
|
||||
when 'RedHat'
|
||||
{ :api_package_name => 'openstack-glance' }
|
||||
end
|
||||
end
|
||||
|
||||
it_configures 'glance cache cleaner'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ describe 'glance::cache::pruner' do
|
|||
|
||||
it 'configures a cron' do
|
||||
is_expected.to contain_cron('glance-cache-pruner').with(
|
||||
:ensure => :present,
|
||||
:command => 'glance-cache-pruner ',
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
:user => 'glance',
|
||||
|
@ -37,6 +38,7 @@ describe 'glance::cache::pruner' do
|
|||
end
|
||||
it 'configures a cron' do
|
||||
is_expected.to contain_cron('glance-cache-pruner').with(
|
||||
:ensure => :present,
|
||||
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-pruner --config-dir /etc/glance/',
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||
:user => 'glance',
|
||||
|
@ -48,6 +50,15 @@ describe 'glance::cache::pruner' do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ensure is set to absent' do
|
||||
let :params do
|
||||
{
|
||||
:ensure => :absent
|
||||
}
|
||||
end
|
||||
it { should contain_cron('glance-cache-pruner').with_ensure(:absent) }
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
|
@ -58,15 +69,6 @@ describe 'glance::cache::pruner' do
|
|||
facts.merge!(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
let(:platform_params) do
|
||||
case facts[:os]['family']
|
||||
when 'Debian'
|
||||
{ :api_package_name => 'glance-api' }
|
||||
when 'RedHat'
|
||||
{ :api_package_name => 'openstack-glance' }
|
||||
end
|
||||
end
|
||||
|
||||
it_configures 'glance cache pruner'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,7 @@ describe 'glance::cron::db_purge_images_table' do
|
|||
shared_examples 'glance::cron::db_purge_images_table' do
|
||||
context 'with required parameters' do
|
||||
it { is_expected.to contain_cron('glance-manage db purge_images_table').with(
|
||||
:ensure => :present,
|
||||
:command => "glance-manage db purge_images_table --age_in_days #{params[:age]} --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
|
@ -31,6 +32,15 @@ describe 'glance::cron::db_purge_images_table' do
|
|||
)}
|
||||
end
|
||||
|
||||
context 'with ensure set to absent' do
|
||||
before :each do
|
||||
params.merge!(
|
||||
:ensure => :absent
|
||||
)
|
||||
end
|
||||
it { should contain_cron('glance-manage db purge_images_table').with_ensure(:absent) }
|
||||
end
|
||||
|
||||
context 'with required parameters with max delay enabled' do
|
||||
before :each do
|
||||
params.merge!(
|
||||
|
@ -39,6 +49,7 @@ describe 'glance::cron::db_purge_images_table' do
|
|||
end
|
||||
|
||||
it { should contain_cron('glance-manage db purge_images_table').with(
|
||||
:ensure => :present,
|
||||
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; glance-manage db purge_images_table --age_in_days #{params[:age]} --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
|
|
|
@ -19,6 +19,7 @@ describe 'glance::cron::db_purge' do
|
|||
shared_examples 'glance::cron::db_purge' do
|
||||
context 'with required parameters' do
|
||||
it { is_expected.to contain_cron('glance-manage db purge').with(
|
||||
:ensure => :present,
|
||||
:command => "glance-manage db purge --age_in_days #{params[:age]} --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
|
@ -31,6 +32,15 @@ describe 'glance::cron::db_purge' do
|
|||
)}
|
||||
end
|
||||
|
||||
context 'with ensure set to absent' do
|
||||
before :each do
|
||||
params.merge!(
|
||||
:ensure => :absent
|
||||
)
|
||||
end
|
||||
it { should contain_cron('glance-manage db purge').with_ensure(:absent) }
|
||||
end
|
||||
|
||||
context 'with required parameters with max delay enabled' do
|
||||
before :each do
|
||||
params.merge!(
|
||||
|
@ -39,6 +49,7 @@ describe 'glance::cron::db_purge' do
|
|||
end
|
||||
|
||||
it { should contain_cron('glance-manage db purge').with(
|
||||
:ensure => :present,
|
||||
:command => "sleep `expr ${RANDOM} \\% #{params[:maxdelay]}`; glance-manage db purge --age_in_days #{params[:age]} --max_rows #{params[:max_rows]} >>#{params[:destination]} 2>&1",
|
||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||
:user => params[:user],
|
||||
|
|
Loading…
Reference in New Issue