Make log_udp_port optional

The [DEFAULT] log_udp_port option defaults to syslog udp port in case
it's not set, so users don't have to set this option explicitly.

Change-Id: I274271fd5bbcbac830d119797a0895f8651ba9df
This commit is contained in:
Takashi Kajinami 2023-12-01 15:26:29 +09:00
parent e1f6e41ad0
commit 300802a79d
4 changed files with 16 additions and 52 deletions

View File

@ -40,11 +40,11 @@
#
# [*log_udp_host*]
# (optional) If not set, the UDP receiver for syslog is disabled.
# Defaults to an empty string
# Defaults to $facts['os_service_default'].
#
# [*log_udp_port*]
# (optional) Port value for UDP receiver, if enabled.
# Defaults to an empty string
# Defaults to $facts['os_service_default'].
#
# [*log_address*]
# (optional) Location where syslog sends the logs to.
@ -160,8 +160,8 @@ class swift::proxy(
Boolean $allow_account_management = true,
Boolean $account_autocreate = true,
$log_headers = 'False',
$log_udp_host = undef,
$log_udp_port = undef,
$log_udp_host = $facts['os_service_default'],
$log_udp_port = $facts['os_service_default'],
$log_address = '/dev/log',
$log_level = 'INFO',
$log_facility = 'LOG_LOCAL2',
@ -210,10 +210,6 @@ 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

@ -256,8 +256,8 @@ define swift::storage::server(
$log_level = 'INFO',
$log_address = '/dev/log',
$log_name = "${type}-server",
$log_udp_host = undef,
$log_udp_port = undef,
$log_udp_host = $facts['os_service_default'],
$log_udp_port = $facts['os_service_default'],
$log_requests = true,
# this parameters needs to be specified after type and name
Boolean $statsd_enabled = false,
@ -297,10 +297,6 @@ define swift::storage::server(
fail("${type}-server must be the last element in pipeline")
}
if ($log_udp_port and !$log_udp_host) {
fail ('log_udp_port requires log_udp_host to be set')
}
include "::swift::storage::${type}"
# rsync::server should be included before rsync::server::module
@ -374,6 +370,8 @@ define swift::storage::server(
'DEFAULT/log_facility' => {'value' => $log_facility},
'DEFAULT/log_level' => {'value' => $log_level},
'DEFAULT/log_address' => {'value' => $log_address},
'DEFAULT/log_udp_host' => {'value' => $log_udp_host},
'DEFAULT/log_udp_port' => {'value' => $log_udp_port},
# pipeline
'pipeline:main/pipeline' => {'value' => join($pipeline, ' ')},
# server
@ -395,19 +393,6 @@ define swift::storage::server(
-> File[$config_file_full_path]
~> Anchor['swift::config::end']
# udp log transfer
if $log_udp_host {
$log_udp_opts = {
'DEFAULT/log_udp_host' => {'value' => $log_udp_host},
'DEFAULT/log_udp_port' => {'value' => pick($log_udp_port, $facts['os_service_default'])},
}
} else {
$log_udp_opts = {
'DEFAULT/log_udp_host' => {'value' => $facts['os_service_default']},
'DEFAULT/log_udp_port' => {'value' => $facts['os_service_default']},
}
}
# statsd
if $statsd_enabled {
$log_statsd_opts = {
@ -489,7 +474,6 @@ define swift::storage::server(
create_resources("swift_${type}_config", merge(
$common_opts,
$log_udp_opts,
$log_statsd_opts,
$type_opts,
), {

View File

@ -57,6 +57,8 @@ describe 'swift::proxy' do
it { should contain_swift_proxy_config('DEFAULT/log_level').with_value('INFO') }
it { should contain_swift_proxy_config('DEFAULT/log_headers').with_value('False') }
it { should contain_swift_proxy_config('DEFAULT/log_address').with_value('/dev/log') }
it { should contain_swift_proxy_config('DEFAULT/log_udp_host').with_value('<SERVICE DEFAULT>') }
it { should contain_swift_proxy_config('DEFAULT/log_udp_port').with_value('<SERVICE DEFAULT>') }
it { should contain_swift_proxy_config('DEFAULT/client_timeout').with_value('<SERVICE DEFAULT>') }
it { should contain_swift_proxy_config('pipeline:main/pipeline').with_value(
['catch_errors', 'gatekeeper', 'healthcheck', 'proxy-logging', 'cache',
@ -173,30 +175,6 @@ describe 'swift::proxy' do
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',
:recoverable_node_timeout => '15',
:cors_allow_origin => 'http://foo.bar:1234,https://foo.bar',
}
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
{

View File

@ -70,6 +70,8 @@ describe 'swift::storage::server' do
is_expected.to contain_swift_account_config('DEFAULT/log_facility').with_value('LOG_LOCAL2')
is_expected.to contain_swift_account_config('DEFAULT/log_level').with_value('INFO')
is_expected.to contain_swift_account_config('DEFAULT/log_address').with_value('/dev/log')
is_expected.to contain_swift_account_config('DEFAULT/log_udp_host').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_account_config('DEFAULT/log_udp_port').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_account_config('pipeline:main/pipeline').with_value('account-server')
is_expected.to contain_swift_account_config('app:account-server/use').with_value('egg:swift#account')
is_expected.to contain_swift_account_config('app:account-server/set log_name').with_value('account-server')
@ -218,6 +220,8 @@ describe 'swift::storage::server' do
is_expected.to contain_swift_container_config('DEFAULT/log_facility').with_value('LOG_LOCAL2')
is_expected.to contain_swift_container_config('DEFAULT/log_level').with_value('INFO')
is_expected.to contain_swift_container_config('DEFAULT/log_address').with_value('/dev/log')
is_expected.to contain_swift_container_config('DEFAULT/log_udp_host').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_container_config('DEFAULT/log_udp_port').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_container_config('pipeline:main/pipeline').with_value('container-server')
is_expected.to contain_swift_container_config('app:container-server/use').with_value('egg:swift#container')
is_expected.to contain_swift_container_config('app:container-server/set log_name').with_value('container-server')
@ -371,6 +375,8 @@ describe 'swift::storage::server' do
is_expected.to contain_swift_object_config('DEFAULT/log_facility').with_value('LOG_LOCAL2')
is_expected.to contain_swift_object_config('DEFAULT/log_level').with_value('INFO')
is_expected.to contain_swift_object_config('DEFAULT/log_address').with_value('/dev/log')
is_expected.to contain_swift_object_config('DEFAULT/log_udp_host').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_config('DEFAULT/log_udp_port').with_value('<SERVICE DEFAULT>')
is_expected.to contain_swift_object_config('pipeline:main/pipeline').with_value('object-server')
is_expected.to contain_swift_object_config('app:object-server/use').with_value('egg:swift#object')
is_expected.to contain_swift_object_config('app:object-server/set log_name').with_value('object-server')