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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion manifests/base.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'/etc/logrotate.conf':
ensure => file,
mode => '0444',
source => 'puppet:///modules/logrotate/etc/logrotate.conf';
content => template('logrotate/etc/logrotate.conf.erb');
'/etc/logrotate.d':
ensure => directory,
mode => '0755';
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class logrotate {}
14 changes: 14 additions & 0 deletions manifests/rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
# (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,
Expand Down Expand Up @@ -138,6 +143,7 @@
$mailfirst = 'undef',
$maillast = 'undef',
$maxage = 'undef',
$maxsize = 'undef',
$minsize = 'undef',
$missingok = 'undef',
$olddir = 'undef',
Expand Down Expand Up @@ -304,6 +310,14 @@
}
}

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

case $minsize {
'undef': {}
/^\d+[kMG]?$/: {}
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'owner' => 'root',
'group' => 'root',
'mode' => '0444',
'source' => 'puppet:///modules/logrotate/etc/logrotate.conf',
'content' => /# THIS FILE IS AUTOMATICALLY DISTRIBUTED BY PUPPET. ANY CHANGES WILL BE/,
'require' => 'Package[logrotate]',
})

Expand Down
58 changes: 58 additions & 0 deletions spec/defines/rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions files/etc/logrotate.conf → templates/etc/logrotate.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# rotate log files weekly
weekly

<% if @lsbmajdistrelease and (scope.function_versioncmp([@lsbmajdistrelease, '14']) >= 0) -%>
# use the syslog group by default, since this is the owning group
# # of /var/log/syslog.
su root syslog
<%- end -%>

# keep 4 weeks worth of backlogs
rotate 4

Expand Down
2 changes: 1 addition & 1 deletion templates/etc/logrotate.d/rule.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Binary file removed vendor/cache/diff-lcs-1.2.5.gem
Binary file not shown.
Binary file removed vendor/cache/facter-1.7.1.gem
Binary file not shown.
Binary file removed vendor/cache/hiera-1.2.1.gem
Binary file not shown.
Binary file removed vendor/cache/json_pure-1.8.0.gem
Binary file not shown.
Binary file removed vendor/cache/metaclass-0.0.1.gem
Binary file not shown.
Binary file removed vendor/cache/mocha-0.14.0.gem
Binary file not shown.
Binary file removed vendor/cache/puppet-3.2.1.gem
Binary file not shown.
Binary file removed vendor/cache/puppet-lint-0.3.2.gem
Binary file not shown.
Binary file removed vendor/cache/rake-10.0.4.gem
Binary file not shown.
Binary file removed vendor/cache/rgen-0.6.2.gem
Binary file not shown.
Binary file removed vendor/cache/rspec-2.14.1.gem
Binary file not shown.
Binary file removed vendor/cache/rspec-core-2.14.7.gem
Binary file not shown.
Binary file removed vendor/cache/rspec-expectations-2.14.4.gem
Binary file not shown.
Binary file removed vendor/cache/rspec-mocks-2.14.4.gem
Binary file not shown.
Binary file removed vendor/cache/rspec-puppet-1.0.1.gem
Binary file not shown.