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

Support timestamp and logfile config options #389

Merged
Merged
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
16 changes: 16 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@
# [*check_standby*]
# True/false parameter specifying whether puppet should return an error log
# message if a node is in standby. Useful for monitoring node state.

# [*log_timestamp*]
# Boolean parameter specifying whether a timestamp should be placed on all
# log messages. Default: false
#
# [*log_file*]
# Boolean parameter specifying whether Corosync should produce debug
# output in a logfile. Default: true.
#
# [*log_file_name*]
# Absolute path to the logfile Corosync should use when `$log_file` (see
# above) is true. Default: not set
#
# [*debug*]
# True/false parameter specifying whether Corosync should produce debug
# output in its logs.
Expand Down Expand Up @@ -231,7 +239,9 @@
$unicast_addresses = $::corosync::params::unicast_addresses,
$force_online = $::corosync::params::force_online,
$check_standby = $::corosync::params::check_standby,
$log_timestamp = $::corosync::params::log_timestamp,
$log_file = $::corosync::params::log_file,
$log_file_name = $::corosync::params::log_file_name,
$debug = $::corosync::params::debug,
$log_stderr = $::corosync::params::log_stderr,
$syslog_priority = $::corosync::params::syslog_priority,
Expand Down Expand Up @@ -311,6 +321,10 @@
validate_bool($force_online)
validate_bool($check_standby)
validate_bool($log_file)
if getvar('log_file_name') and $log_file == true {
validate_absolute_path($log_file_name)
}
validate_bool($log_timestamp)
validate_bool($debug)
validate_bool($log_stderr)
validate_re($syslog_priority, '^(debug|info|notice|warning|err|emerg)$')
Expand Down Expand Up @@ -373,7 +387,9 @@
# - $unicast_addresses
# - $multicast_address
# - $cluster_name
# - $log_timestamp
# - $log_file
# - $log_file_name
# - $debug
# - $bind_address
# - $port
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
$unicast_addresses = 'UNSET'
$force_online = false
$check_standby = false
$log_timestamp = false
$log_file = true
$log_file_name = undef
$debug = false
$log_stderr = true
$syslog_priority = 'info'
Expand Down
82 changes: 82 additions & 0 deletions spec/classes/corosync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,89 @@
end
end

context 'when log_timestamp is not set' do
it 'does not set timestamp' do
is_expected.to contain_file('/etc/corosync/corosync.conf').without_content(
%r{timestamp}
)
end
end

context 'when log_timestamp is false' do
before do
params.merge!(
log_timestamp: false
)
end

it 'does not set timestamp' do
is_expected.to contain_file('/etc/corosync/corosync.conf').without_content(
%r{timestamp}
)
end
end

context 'when log_timestamp is set' do
before do
params.merge!(
log_timestamp: true
)
end

it 'does set timestamp' do
is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
%r{timestamp.*on}
)
end
end

context 'when log_file is not set' do
it 'does set to_logfile' do
is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
%r{to_logfile.*yes}
)
end
it 'does not set logfile' do
is_expected.to contain_file('/etc/corosync/corosync.conf').without_content(
%r{^\s*logfile}
)
end
end

context 'when log_file and log_file_name are set' do
before do
params.merge!(
log_file: true,
log_file_name: '/var/log/corosync/corosync.log'
)
end

it 'does set to_logfile' do
is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
%r{to_logfile.*yes}
)
end
it 'does set logfile' do
is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
%r{logfile.*\/var\/log\/corosync/corosync\.log}
)
end
end

context 'when log_file_name is not an absolute path' do
before do
params.merge!(
log_file: true,
log_file_name: 'corosync.log'
)
end

it 'raises error' do
is_expected.to raise_error(
Puppet::Error,
%r{is not an absolute path}
)
end
end

context 'when log_file is disabled' do
Expand All @@ -333,6 +410,11 @@
%r{to_logfile.*no}
)
end
it 'does not set logfile' do
is_expected.to contain_file('/etc/corosync/corosync.conf').without_content(
%r{^\s*logfile}
)
end
end

{
Expand Down
6 changes: 6 additions & 0 deletions templates/corosync.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ totem {

logging {
fileline: off
<% if @log_timestamp -%>
timestamp: on
<% end -%>
<% if @log_stderr -%>
to_stderr: yes
<% else -%>
to_stderr: no
<% end -%>
<% if @log_file -%>
to_logfile: yes
<% if @log_file_name -%>
logfile: <%= @log_file_name %>
<% end -%>
<% else -%>
to_logfile: no
<% end -%>
Expand Down