Add Panko expirer class

This sets up a cron task to run periodically and
expire panko events in db.

Change-Id: I23359239008105cd77a599d2c08c067f132099b7
Partial-Bug: #1746514
This commit is contained in:
Pradeep Kilambi 2018-01-31 11:34:10 -05:00
parent ae02d117bb
commit 54de0d59e5
4 changed files with 118 additions and 0 deletions

60
manifests/expirer.pp Normal file
View File

@ -0,0 +1,60 @@
#
# == Class: panko::expirer
#
# Setups Panko Expirer service to enable TTL feature.
#
# === Parameters
#
# [*enable_cron*]
# (optional) Whether to configure a crontab entry to run the expiry.
# When set to False, Puppet will try to remove the crontab.
# Defaults to true.
#
# [*minute*]
# (optional) Defaults to '1'.
#
# [*hour*]
# (optional) Defaults to '0'.
#
# [*monthday*]
# (optional) Defaults to '*'.
#
# [*month*]
# (optional) Defaults to '*'.
#
# [*weekday*]
# (optional) Defaults to '*'.
#
class panko::expirer (
$enable_cron = true,
$minute = 1,
$hour = 0,
$monthday = '*',
$month = '*',
$weekday = '*',
) {
include ::panko::params
include ::panko::deps
Anchor['panko::install::end'] ~> Class['panko::expirer']
if $enable_cron {
$ensure = 'present'
} else {
$ensure = 'absent'
}
cron { 'panko-expirer':
ensure => $ensure,
command => $panko::params::expirer_command,
environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
user => 'panko',
minute => $minute,
hour => $hour,
monthday => $monthday,
month => $month,
weekday => $weekday
}
}

View File

@ -4,6 +4,7 @@ class panko::params {
include ::openstacklib::defaults
$client_package_name = 'python-pankoclient'
$group = 'panko'
$expirer_command = 'panko-expirer'
case $::osfamily {
'RedHat': {

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Add panko expirer class so we can configure it in crontab accordingly.

View File

@ -0,0 +1,53 @@
#
# Unit tests for panko::expirer
#
require 'spec_helper'
describe 'panko::expirer' do
shared_examples_for 'panko-expirer' do
it { is_expected.to contain_class('panko::deps') }
it { is_expected.to contain_class('panko::params') }
let :params do
{ }
end
it 'configures a cron' do
is_expected.to contain_cron('panko-expirer').with(
:ensure => 'present',
:command => 'panko-expirer',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'panko',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
)
end
context 'with cron not enabled' do
before do
params.merge!({
:enable_cron => false })
end
it {
is_expected.to contain_cron('panko-expirer').with(
:ensure => 'absent',
:command => 'panko-expirer',
:environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh',
:user => 'panko',
:minute => 1,
:hour => 0,
:monthday => '*',
:month => '*',
:weekday => '*'
)
}
end
end
end