Added rsyslog logging support to object-server

Also change both proxy-server and object-server
.conf templates to test if log_udp_server and
log_udp_port are nil, instead of an empty string.
Testing for an empty string would have retruned
true if set to 'undef' - for futer parser compat.

Change-Id: Idac805f628dbec70a4adb6a1c021d85a743fdb72
This commit is contained in:
Adam Vinsh 2015-05-03 18:15:11 -06:00
parent 76d9827938
commit c9809f8c92
9 changed files with 156 additions and 9 deletions

View File

@ -116,8 +116,8 @@ class swift::proxy(
$allow_account_management = true,
$account_autocreate = true,
$log_headers = 'False',
$log_udp_host = '',
$log_udp_port = '',
$log_udp_host = undef,
$log_udp_port = undef,
$log_address = '/dev/log',
$log_level = 'INFO',
$log_facility = 'LOG_LOCAL1',
@ -163,6 +163,10 @@ class swift::proxy(
fail('account_autocreate must be set to true when auth_type is tempauth')
}
if ($log_udp_port and !$log_udp_host) {
fail ('log_udp_port requires log_udp_host to be set')
}
package { 'swift-proxy':
ensure => $package_ensure,
name => $::swift::params::proxy_package_name,

View File

@ -46,6 +46,18 @@
# (optional) Syslog log facility
# Defaults to 'LOG_LOCAL2'
#
# [*log_level*]
# (optional) Log level.
# Defaults to 'INFO'.
#
# [*log_udp_host*]
# (optional) If not set, the UDP receiver for syslog is disabled.
# Defaults to undef.
#
# [*log_udp_port*]
# (optional) Port value for UDP receiver, if enabled.
# Defaults to undef.
#
class swift::storage::all(
$storage_local_net_ip,
$devices = '/srv/node',
@ -57,7 +69,10 @@ class swift::storage::all(
$allow_versions = false,
$mount_check = false,
$account_pipeline = undef,
$log_facility = 'LOG_LOCAL2'
$log_facility = 'LOG_LOCAL2',
$log_level = 'INFO',
$log_udp_host = undef,
$log_udp_port = undef,
) {
class { '::swift::storage':
@ -68,6 +83,9 @@ class swift::storage::all(
devices => $devices,
storage_local_net_ip => $storage_local_net_ip,
mount_check => $mount_check,
log_level => $log_level,
log_udp_host => $log_udp_host,
log_udp_port => $log_udp_port,
}
swift::storage::server { $account_port:

View File

@ -18,6 +18,14 @@
# *NOTE*: Recommended parameter: 'Du=rwx,g=rx,o=rx,Fu=rw,g=r,o=r'
# This mask translates to 0755 for directories and 0644 for files.
#
# [*log_udp_host*]
# (optional) If not set, the UDP receiver for syslog is disabled.
# Defaults to undef.
#
# [*log_udp_port*]
# (optional) Port value for UDP receiver, if enabled.
# Defaults to undef.
#
define swift::storage::server(
$type,
$storage_local_net_ip,
@ -39,6 +47,8 @@ define swift::storage::server(
$log_level = 'INFO',
$log_address = '/dev/log',
$log_name = "${type}-server",
$log_udp_host = undef,
$log_udp_port = undef,
# this parameters needs to be specified after type and name
$config_file_path = "${type}-server/${name}.conf"
) {
@ -60,6 +70,10 @@ define swift::storage::server(
warning("swift storage server ${type} must specify ${type}-server")
}
if ($log_udp_port and !$log_udp_host) {
fail ('log_udp_port requires log_udp_host to be set')
}
include "::swift::storage::${type}"
include ::concat::setup

View File

@ -60,7 +60,7 @@ describe 'swift::proxy' do
'bind_port = 8080',
"workers = #{facts[:processorcount]}",
'user = swift',
'log_name = swift',
'log_name = proxy-server',
'log_level = INFO',
'log_headers = False',
'log_address = /dev/log',
@ -128,7 +128,73 @@ describe 'swift::proxy' do
it { is_expected.to contain_concat__fragment('swift_proxy').with_before(
'Class[Swift::Proxy::Swauth]'
)}
end
describe "when log udp port is set" do
context 'and log_udp_host is not set' do
let :params do
{
:proxy_local_net_ip => '10.0.0.2',
:port => '80',
:workers => 3,
:pipeline => ['swauth', 'proxy-server'],
:allow_account_management => false,
:account_autocreate => false,
:log_level => 'DEBUG',
:log_name => 'swift-proxy-server',
:log_udp_port => '514',
:read_affinity => 'r1z1=100, r1=200',
:write_affinity => 'r1',
:write_affinity_node_count => '2 * replicas',
:node_timeout => '20',
}
end
it_raises 'a Puppet::Error', /log_udp_port requires log_udp_host to be set/
end
context 'and log_udp_host is set' do
let :params do
{
:proxy_local_net_ip => '10.0.0.2',
:port => '80',
:workers => 3,
:pipeline => ['swauth', 'proxy-server'],
:allow_account_management => false,
:account_autocreate => false,
:log_level => 'DEBUG',
:log_name => 'swift-proxy-server',
:log_udp_host => '127.0.0.1',
:log_udp_port => '514',
:read_affinity => 'r1z1=100, r1=200',
:write_affinity => 'r1',
:write_affinity_node_count => '2 * replicas',
:node_timeout => '20',
}
end
it 'should build the header file with provided values' do
verify_contents(catalogue, fragment_path,
[
'[DEFAULT]',
'bind_port = 80',
"workers = 3",
'user = swift',
'log_level = DEBUG',
'log_udp_host = 127.0.0.1',
'log_udp_port = 514',
'[pipeline:main]',
'pipeline = swauth proxy-server',
'[app:proxy-server]',
'use = egg:swift#proxy',
'set log_name = swift-proxy-server',
'allow_account_management = false',
'account_autocreate = false',
'read_affinity = r1z1=100, r1=200',
'write_affinity = r1',
'write_affinity_node_count = 2 * replicas',
'node_timeout = 20'
]
)
end
end
end
describe 'when supplying bad values for parameters' do
[:account_autocreate, :allow_account_management].each do |param|

View File

@ -67,7 +67,7 @@ describe 'swift::storage::server' do
:user => 'dan',
:mount_check => true,
:workers => 7,
:pipeline => ['foo']
:pipeline => ['foo'],
}.each do |k,v|
describe "when #{k} is set" do
let :params do req_params.merge({k => v}) end
@ -117,6 +117,20 @@ describe 'swift::storage::server' do
it { is_expected.to contain_file(fragment_file).with_content(/\[app:container-server\]\nallow_versions\s*=\s*false\s*$/m)}
end
end
describe "when log_udp_port is set" do
context 'and log_udp_host is not set' do
let :params do req_params.merge({ :log_udp_port => 514}) end
it_raises 'a Puppet::Error', /log_udp_port requires log_udp_host to be set/
end
context 'and log_udp_host is set' do
let :params do req_params.merge(
{ :log_udp_host => '127.0.0.1',
:log_udp_port => '514'})
end
it { is_expected.to contain_file(fragment_file).with_content(/^log_udp_host\s*=\s*127\.0\.0\.1\s*$/) }
it { is_expected.to contain_file(fragment_file).with_content(/^log_udp_port\s*=\s*514\s*$/) }
end
end
end
describe 'with all allowed defaults' do

View File

@ -4,8 +4,19 @@ bind_ip = <%= @storage_local_net_ip %>
bind_port = <%= @bind_port %>
mount_check = <%= @mount_check %>
user = <%= @user %>
log_facility = <%= @log_facility %>
workers = <%= @workers %>
log_name = <%= @log_name %>
log_facility = <%= @log_facility %>
log_level = <%= @log_level %>
log_address = <%= @log_address %>
<% if @log_udp_host -%>
# If set, log_udp_host will override log_address
log_udp_host = <%= @log_udp_host -%>
<% end %>
<% if @log_udp_host and @log_udp_port -%>
log_udp_port = <%= @log_udp_port -%>
<% end %>
[pipeline:main]
pipeline = <%= @pipeline.to_a.join(' ') %>

View File

@ -4,7 +4,17 @@ bind_ip = <%= @storage_local_net_ip %>
bind_port = <%= @bind_port %>
mount_check = <%= @mount_check %>
user = <%= @user %>
log_name = <%= @log_name %>
log_facility = <%= @log_facility %>
log_level = <%= @log_level %>
log_address = <%= @log_address %>
<% if @log_udp_host -%>
# If set, log_udp_host will override log_address
log_udp_host = <%= @log_udp_host -%>
<% end %>
<% if @log_udp_host and @log_udp_port -%>
log_udp_port = <%= @log_udp_port -%>
<% end %>
workers = <%= @workers %>
allowed_sync_hosts = <%= scope.lookupvar("swift::storage::container::allowed_sync_hosts").to_a.join(',') %>

View File

@ -4,7 +4,17 @@ bind_ip = <%= @storage_local_net_ip %>
bind_port = <%= @bind_port %>
mount_check = <%= @mount_check %>
user = <%= @user %>
log_name = <%= @log_name %>
log_facility = <%= @log_facility %>
log_level = <%= @log_level %>
log_address = <%= @log_address %>
<% if @log_udp_host -%>
# If set, log_udp_host will override log_address
log_udp_host = <%= @log_udp_host -%>
<% end %>
<% if @log_udp_host and @log_udp_port -%>
log_udp_port = <%= @log_udp_port -%>
<% end %>
workers = <%= @workers %>
[pipeline:main]

View File

@ -7,16 +7,16 @@ bind_ip = <%= @proxy_local_net_ip %>
<% end %>
workers = <%= @workers %>
user = swift
log_name = swift
log_name = <%= @log_name %>
log_facility = <%= @log_facility %>
log_level = <%= @log_level %>
log_headers = <%= @log_headers %>
log_address = <%= @log_address %>
<% if @log_udp_host != '' -%>
<% if @log_udp_host -%>
# If set, log_udp_host will override log_address
log_udp_host = <%= @log_udp_host -%>
<% end %>
<% if @log_udp_host !='' and @log_udp_port != '' -%>
<% if @log_udp_host and @log_udp_port -%>
log_udp_port = <%= @log_udp_port -%>
<% end %>