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.
|
# all cron jobs at the same time on all hosts this job is configured.
|
||||||
# Defaults to 0.
|
# Defaults to 0.
|
||||||
#
|
#
|
||||||
|
# [*ensure*]
|
||||||
|
# (optional) Ensure cron jobs present or absent
|
||||||
|
# Defaults to present.
|
||||||
|
#
|
||||||
class glance::cache::cleaner(
|
class glance::cache::cleaner(
|
||||||
$minute = 1,
|
$minute = 1,
|
||||||
$hour = 0,
|
$hour = 0,
|
||||||
|
@ -37,7 +41,8 @@ class glance::cache::cleaner(
|
||||||
$month = '*',
|
$month = '*',
|
||||||
$weekday = '*',
|
$weekday = '*',
|
||||||
$command_options = '',
|
$command_options = '',
|
||||||
$maxdelay = 0
|
$maxdelay = 0,
|
||||||
|
Enum['present', 'absent'] $ensure = 'present',
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include glance::deps
|
include glance::deps
|
||||||
|
@ -50,6 +55,7 @@ class glance::cache::cleaner(
|
||||||
}
|
}
|
||||||
|
|
||||||
cron { 'glance-cache-cleaner':
|
cron { 'glance-cache-cleaner':
|
||||||
|
ensure => $ensure,
|
||||||
command => "${sleep}${glance::params::cache_cleaner_command} ${command_options}",
|
command => "${sleep}${glance::params::cache_cleaner_command} ${command_options}",
|
||||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
user => $::glance::params::user,
|
user => $::glance::params::user,
|
||||||
|
|
|
@ -30,6 +30,10 @@
|
||||||
# all cron jobs at the same time on all hosts this job is configured.
|
# all cron jobs at the same time on all hosts this job is configured.
|
||||||
# Defaults to 0.
|
# Defaults to 0.
|
||||||
#
|
#
|
||||||
|
# [*ensure*]
|
||||||
|
# (optional) Ensure cron jobs present or absent
|
||||||
|
# Defaults to present.
|
||||||
|
#
|
||||||
class glance::cache::pruner(
|
class glance::cache::pruner(
|
||||||
$minute = '*/30',
|
$minute = '*/30',
|
||||||
$hour = '*',
|
$hour = '*',
|
||||||
|
@ -37,7 +41,8 @@ class glance::cache::pruner(
|
||||||
$month = '*',
|
$month = '*',
|
||||||
$weekday = '*',
|
$weekday = '*',
|
||||||
$command_options = '',
|
$command_options = '',
|
||||||
$maxdelay = 0
|
$maxdelay = 0,
|
||||||
|
Enum['present', 'absent'] $ensure = 'present',
|
||||||
) {
|
) {
|
||||||
|
|
||||||
include glance::deps
|
include glance::deps
|
||||||
|
@ -50,6 +55,7 @@ class glance::cache::pruner(
|
||||||
}
|
}
|
||||||
|
|
||||||
cron { 'glance-cache-pruner':
|
cron { 'glance-cache-pruner':
|
||||||
|
ensure => $ensure,
|
||||||
command => "${sleep}${glance::params::cache_pruner_command} ${command_options}",
|
command => "${sleep}${glance::params::cache_pruner_command} ${command_options}",
|
||||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
user => $::glance::params::user,
|
user => $::glance::params::user,
|
||||||
|
|
|
@ -58,6 +58,10 @@
|
||||||
# all cron jobs at the same time on all hosts this job is configured.
|
# all cron jobs at the same time on all hosts this job is configured.
|
||||||
# Defaults to 0.
|
# Defaults to 0.
|
||||||
#
|
#
|
||||||
|
# [*ensure*]
|
||||||
|
# (optional) Ensure cron jobs present or absent
|
||||||
|
# Defaults to present.
|
||||||
|
#
|
||||||
class glance::cron::db_purge (
|
class glance::cron::db_purge (
|
||||||
$minute = 1,
|
$minute = 1,
|
||||||
$hour = 0,
|
$hour = 0,
|
||||||
|
@ -68,7 +72,8 @@ class glance::cron::db_purge (
|
||||||
$age = 30,
|
$age = 30,
|
||||||
$max_rows = 100,
|
$max_rows = 100,
|
||||||
$destination = '/var/log/glance/glance-rowsflush.log',
|
$destination = '/var/log/glance/glance-rowsflush.log',
|
||||||
$maxdelay = 0
|
$maxdelay = 0,
|
||||||
|
Enum['present', 'absent'] $ensure = 'present',
|
||||||
) inherits glance::params {
|
) inherits glance::params {
|
||||||
|
|
||||||
include glance::deps
|
include glance::deps
|
||||||
|
@ -82,6 +87,7 @@ class glance::cron::db_purge (
|
||||||
$opts = "--age_in_days ${age} --max_rows ${max_rows}"
|
$opts = "--age_in_days ${age} --max_rows ${max_rows}"
|
||||||
|
|
||||||
cron { 'glance-manage db purge':
|
cron { 'glance-manage db purge':
|
||||||
|
ensure => $ensure,
|
||||||
command => "${sleep}glance-manage db purge ${opts} >>${destination} 2>&1",
|
command => "${sleep}glance-manage db purge ${opts} >>${destination} 2>&1",
|
||||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
user => $user,
|
user => $user,
|
||||||
|
|
|
@ -58,6 +58,10 @@
|
||||||
# all cron jobs at the same time on all hosts this job is configured.
|
# all cron jobs at the same time on all hosts this job is configured.
|
||||||
# Defaults to 0.
|
# Defaults to 0.
|
||||||
#
|
#
|
||||||
|
# [*ensure*]
|
||||||
|
# (optional) Ensure cron jobs present or absent
|
||||||
|
# Defaults to present.
|
||||||
|
#
|
||||||
class glance::cron::db_purge_images_table (
|
class glance::cron::db_purge_images_table (
|
||||||
$minute = 1,
|
$minute = 1,
|
||||||
$hour = 0,
|
$hour = 0,
|
||||||
|
@ -68,7 +72,8 @@ class glance::cron::db_purge_images_table (
|
||||||
$age = 30,
|
$age = 30,
|
||||||
$max_rows = 100,
|
$max_rows = 100,
|
||||||
$destination = '/var/log/glance/glance-images-rowsflush.log',
|
$destination = '/var/log/glance/glance-images-rowsflush.log',
|
||||||
$maxdelay = 0
|
$maxdelay = 0,
|
||||||
|
Enum['present', 'absent'] $ensure = 'present',
|
||||||
) inherits glance::params {
|
) inherits glance::params {
|
||||||
|
|
||||||
include glance::deps
|
include glance::deps
|
||||||
|
@ -82,6 +87,7 @@ class glance::cron::db_purge_images_table (
|
||||||
$opts = "--age_in_days ${age} --max_rows ${max_rows}"
|
$opts = "--age_in_days ${age} --max_rows ${max_rows}"
|
||||||
|
|
||||||
cron { 'glance-manage db purge_images_table':
|
cron { 'glance-manage db purge_images_table':
|
||||||
|
ensure => $ensure,
|
||||||
command => "${sleep}glance-manage db purge_images_table ${opts} >>${destination} 2>&1",
|
command => "${sleep}glance-manage db purge_images_table ${opts} >>${destination} 2>&1",
|
||||||
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
user => $user,
|
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``
|
|
@ -7,7 +7,8 @@ describe 'glance::cache::cleaner' do
|
||||||
context 'when default parameters' do
|
context 'when default parameters' do
|
||||||
|
|
||||||
it 'configures a cron' do
|
it 'configures a cron' do
|
||||||
is_expected.to contain_cron('glance-cache-cleaner').with(
|
is_expected.to contain_cron('glance-cache-cleaner').with(
|
||||||
|
:ensure => :present,
|
||||||
:command => 'glance-cache-cleaner ',
|
:command => 'glance-cache-cleaner ',
|
||||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
:user => 'glance',
|
:user => 'glance',
|
||||||
|
@ -38,6 +39,7 @@ describe 'glance::cache::cleaner' do
|
||||||
end
|
end
|
||||||
it 'configures a cron' do
|
it 'configures a cron' do
|
||||||
is_expected.to contain_cron('glance-cache-cleaner').with(
|
is_expected.to contain_cron('glance-cache-cleaner').with(
|
||||||
|
:ensure => :present,
|
||||||
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-cleaner --config-dir /etc/glance/',
|
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-cleaner --config-dir /etc/glance/',
|
||||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
:user => 'glance',
|
:user => 'glance',
|
||||||
|
@ -49,6 +51,15 @@ describe 'glance::cache::cleaner' do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
on_supported_os({
|
on_supported_os({
|
||||||
|
@ -59,15 +70,6 @@ describe 'glance::cache::cleaner' do
|
||||||
facts.merge!(OSDefaults.get_facts())
|
facts.merge!(OSDefaults.get_facts())
|
||||||
end
|
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'
|
it_configures 'glance cache cleaner'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,7 @@ describe 'glance::cache::pruner' do
|
||||||
|
|
||||||
it 'configures a cron' do
|
it 'configures a cron' do
|
||||||
is_expected.to contain_cron('glance-cache-pruner').with(
|
is_expected.to contain_cron('glance-cache-pruner').with(
|
||||||
|
:ensure => :present,
|
||||||
:command => 'glance-cache-pruner ',
|
:command => 'glance-cache-pruner ',
|
||||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
:user => 'glance',
|
:user => 'glance',
|
||||||
|
@ -37,6 +38,7 @@ describe 'glance::cache::pruner' do
|
||||||
end
|
end
|
||||||
it 'configures a cron' do
|
it 'configures a cron' do
|
||||||
is_expected.to contain_cron('glance-cache-pruner').with(
|
is_expected.to contain_cron('glance-cache-pruner').with(
|
||||||
|
:ensure => :present,
|
||||||
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-pruner --config-dir /etc/glance/',
|
:command => 'sleep `expr ${RANDOM} \\% 3600`; glance-cache-pruner --config-dir /etc/glance/',
|
||||||
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin',
|
||||||
:user => 'glance',
|
:user => 'glance',
|
||||||
|
@ -48,6 +50,15 @@ describe 'glance::cache::pruner' do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
on_supported_os({
|
on_supported_os({
|
||||||
|
@ -58,15 +69,6 @@ describe 'glance::cache::pruner' do
|
||||||
facts.merge!(OSDefaults.get_facts())
|
facts.merge!(OSDefaults.get_facts())
|
||||||
end
|
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'
|
it_configures 'glance cache pruner'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,7 @@ describe 'glance::cron::db_purge_images_table' do
|
||||||
shared_examples 'glance::cron::db_purge_images_table' do
|
shared_examples 'glance::cron::db_purge_images_table' do
|
||||||
context 'with required parameters' do
|
context 'with required parameters' do
|
||||||
it { is_expected.to contain_cron('glance-manage db purge_images_table').with(
|
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",
|
: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',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
:user => params[:user],
|
:user => params[:user],
|
||||||
|
@ -31,6 +32,15 @@ describe 'glance::cron::db_purge_images_table' do
|
||||||
)}
|
)}
|
||||||
end
|
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
|
context 'with required parameters with max delay enabled' do
|
||||||
before :each do
|
before :each do
|
||||||
params.merge!(
|
params.merge!(
|
||||||
|
@ -39,6 +49,7 @@ describe 'glance::cron::db_purge_images_table' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it { should contain_cron('glance-manage db purge_images_table').with(
|
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",
|
: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',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
:user => params[:user],
|
:user => params[:user],
|
||||||
|
|
|
@ -19,6 +19,7 @@ describe 'glance::cron::db_purge' do
|
||||||
shared_examples 'glance::cron::db_purge' do
|
shared_examples 'glance::cron::db_purge' do
|
||||||
context 'with required parameters' do
|
context 'with required parameters' do
|
||||||
it { is_expected.to contain_cron('glance-manage db purge').with(
|
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",
|
: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',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
:user => params[:user],
|
:user => params[:user],
|
||||||
|
@ -31,6 +32,15 @@ describe 'glance::cron::db_purge' do
|
||||||
)}
|
)}
|
||||||
end
|
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
|
context 'with required parameters with max delay enabled' do
|
||||||
before :each do
|
before :each do
|
||||||
params.merge!(
|
params.merge!(
|
||||||
|
@ -39,6 +49,7 @@ describe 'glance::cron::db_purge' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it { should contain_cron('glance-manage db purge').with(
|
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",
|
: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',
|
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
|
||||||
:user => params[:user],
|
:user => params[:user],
|
||||||
|
|
Loading…
Reference in New Issue