Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing the ability to set maxsize allowed #69

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allowing the ability to set maxsize allowed
jacobmw committed Jan 30, 2016
commit 21a4d18053fa5add2f6dc5356037dc6a9f382413
13 changes: 13 additions & 0 deletions manifests/rule.pp
Original file line number Diff line number Diff line change
@@ -46,6 +46,10 @@
# (optional).
# maxage - The Integer maximum number of days that a rotated log file
# can stay on the system (optional).
# maxsize - The String maximum size a log file can be before being rotated,
# even before the additionally specified time interval (optional).
# The default units are bytes, append k, M or G for kilobytes,
# megabytes and gigabytes respectively.
# minsize - The String minimum size a log file must be to be rotated,
# but not before the scheduled rotation time (optional).
# The default units are bytes, append k, M or G for kilobytes,
@@ -138,6 +142,7 @@
$mailfirst = 'undef',
$maillast = 'undef',
$maxage = 'undef',
$maxsize = 'undef',
$minsize = 'undef',
$missingok = 'undef',
$olddir = 'undef',
@@ -304,6 +309,14 @@
}
}

case $maxsize {
'undef': {}
/^\d+[kMG]?$/: {}
default: {
fail("Logrotate::Rule[${name}]: maxsize must match /\\d+[kMG]?/")
}
}

case $minsize {
'undef': {}
/^\d+[kMG]?$/: {}
58 changes: 58 additions & 0 deletions spec/defines/rule_spec.rb
Original file line number Diff line number Diff line change
@@ -540,6 +540,64 @@
end
end

###########################################################################
# MAXSIZE
context 'and maxsize => 100' do
let(:params) {
{:path => '/var/log/foo.log', :maxsize => 100}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ maxsize 100$/)
end
end

context 'and maxsize => 100k' do
let(:params) {
{:path => '/var/log/foo.log', :maxsize => '100k'}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ maxsize 100k$/)
end
end

context 'and maxsize => 100M' do
let(:params) {
{:path => '/var/log/foo.log', :maxsize => '100M'}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ maxsize 100M$/)
end
end

context 'and maxsize => 100G' do
let(:params) {
{:path => '/var/log/foo.log', :maxsize => '100G'}
}

it do
should contain_file('/etc/logrotate.d/test') \
.with_content(/^ maxsize 100G$/)
end
end

context 'and maxsize => foo' do
let(:params) {
{:path => '/var/log/foo.log', :maxsize => 'foo'}
}

it do
expect {
should contain_file('/etc/logrotate.d/test')
}.to raise_error(Puppet::Error, /maxsize must match/)
end
end

###########################################################################
# MINSIZE
context 'and minsize => 100' do
2 changes: 1 addition & 1 deletion templates/etc/logrotate.d/rule.erb
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@

[
'compresscmd', 'compressext', 'compressoptions', 'dateformat', 'extension',
'maxage', 'minsize', 'rotate', 'size', 'shredcycles', 'start',
'maxage', 'maxsize', 'minsize', 'rotate', 'size', 'shredcycles', 'start',
'uncompresscmd'
].each do |key|
value = scope.to_hash[key]