Decouple memcached configuration from proxy

It is possible that the memcache server(s) may
reside on different machines than the swift
proxy.

This commit decouples the configurations of the
two services.
This commit is contained in:
Dan Bode 2012-03-02 20:07:56 -08:00
parent c7caf05c36
commit 4752a3d85f
3 changed files with 177 additions and 41 deletions

@ -1,19 +1,33 @@
#
# TODO - assumes that proxy server is always a memcached server
#
# TODO - the full list of all things that can be configured is here
# https://github.com/openstack/swift/tree/master/swift/common/middleware
#
# Installs and configures the swift proxy node.
#
# [*Parameters*]
#
# [*allow_account_management*]
# [*account_autocreate*] Rather accounts should automatically be created.
# I think this may be tempauth specific
# [*proxy_local_net_ip*] The address that the proxy will bind to.
# [*proxy_port*] Port that the swift proxy service will bind to.
# Optional. Defaults to 11211
# Required.
# [*port*] The port to which the proxy server will bind.
# Optional. Defaults to 8080.
# [*workers*] Number of threads to process requests.
# Optional. Defaults to the number of processors.
# [*auth_type*] - Type of authorization to use.
# valid values are tempauth, swauth, and keystone.
# Optional. Defaults to tempauth.
# [*allow_account_management*]
# Rather or not requests through this proxy can create and
# delete accounts. Optional. Defaults to true.
# [*account_autocreate*] Rather accounts should automatically be created.
# Has to be set to true for tempauth. Optional. Defaults to true.
# [*proxy_port*] Port that the swift proxy service will bind to.
# Optional. Defaults to 11211
# [*package_ensure*] Ensure state of the swift proxy package.
# Optional. Defaults to present.
#
# [*cache_servers*] A list of the memcache servers to be used. Entries
# should be in the form host:port.
# == sw auth specific configuration
# [*swauth_endpoint*]
# [*swauth_super_admin_user*]
@ -33,21 +47,30 @@
# Copyright 2011 Puppetlabs Inc, unless otherwise noted.
#
class swift::proxy(
# why did cloudbuilders default this to false?
$proxy_local_net_ip,
$port = '8080',
$workers = $::processorcount,
$cache_servers = ['127.0.0.1:11211'],
$allow_account_management = true,
$account_autocreate = false,
$proxy_port = '11211',
$auth_type = 'tempauth',
$account_autocreate = true,
$swauth_endpoint = '127.0.0.1',
$swauth_super_admin_key = 'swauthkey',
$package_ensure = 'present'
) inherits swift {
Class['memcached'] -> Class['swift::proxy']
validate_bool($account_autocreate)
validate_bool($allow_account_management)
validate_re($auth_type, 'tempauth|swauth|keystone')
if($auth_type == 'tempauth' and ! $account_autocreate ){
fail("\$account_autocreate must be set to true when auth type is tempauth")
}
if $cache_server_ips =~ /^127\.0\.0\.1/ {
Class['memcached'] -> Class['swift::proxy']
}
if(auth_type == 'keystone') {
fail('Keystone is currently not supported, it should be supported soon :)')
}

@ -29,14 +29,20 @@ describe 'swift::proxy' do
class { 'ssh::server::install': }"
end
describe 'with default parameters' do
describe 'without the proxy local network ip address being specified' do
it "should fail" do
expect do
subject
end.should raise_error(Puppet::Error, /Must pass proxy_local_net_ip/)
end
end
let :config_file do
File.join(fixture_dir, 'default_proxy_server')
describe 'when proxy_local_net_ip is set' do
let :params do
{:proxy_local_net_ip => '127.0.0.1'}
end
it { should contain_package('swift-proxy').with_ensure('present') }
it { should_not contain_package('python-swauth') }
it { should contain_service('swift-proxy').with(
{:ensure => 'running',
:provider => 'upstart',
@ -49,58 +55,167 @@ describe 'swift::proxy' do
:owner => 'swift',
:group => 'swift',
:mode => '0660',
:content => File.read(config_file),
:require => 'Package[swift-proxy]'
}
)}
it 'should contain default config file' do
content = param_value(
subject,
'file', '/etc/swift/proxy-server.conf',
'content'
)
expected_lines =
[
'[DEFAULT]',
'bind_port = 8080',
"workers = #{facts[:processorcount]}",
'user = swift',
'[pipeline:main]',
'pipeline = healthcheck cache tempauth proxy-server',
'[app:proxy-server]',
'use = egg:swift#proxy',
'allow_account_management = true',
'account_autocreate = true',
'[filter:healthcheck]',
'use = egg:swift#healthcheck',
'[filter:cache]',
'use = egg:swift#memcache',
'memcache_servers = 127.0.0.1:11211'
]
(content.split("\n") & expected_lines).should =~ expected_lines
end
describe 'when more parameters are set' do
let :params do
{
:proxy_local_net_ip => '10.0.0.2',
:port => '80',
:workers => 3,
:cache_servers => ['foo:1', 'bar:2'],
:allow_account_management => true
}
end
it 'should contain default config file' do
content = param_value(
subject,
'file', '/etc/swift/proxy-server.conf',
'content'
)
expected_lines =
[
'bind_port = 80',
"workers = 3",
'allow_account_management = true',
'memcache_servers = foo:1,bar:2'
]
(content.split("\n") & expected_lines).should =~ expected_lines
end
end
# TODO this resource should just be here temporarily until packaging
# is fixed
it { should contain_file('/etc/init/swift-proxy.conf') }
describe 'when using tempauth' do
it { should_not contain_package('python-swauth') }
it 'should fail when setting account_autocreate to false' do
params[:auth_type] = 'tempauth'
params[:account_autocreate] = false
expect do
subject
end.should raise_error(Puppet::Error, /account_autocreate must be set to true when auth type is tempauth/)
end
it 'should contain tempauth configuration' do
content = param_value(
subject,
'file', '/etc/swift/proxy-server.conf',
'content'
)
expected_lines =
[
'pipeline = healthcheck cache tempauth proxy-server',
'[filter:tempauth]',
'use = egg:swift#tempauth',
'user_admin_admin = admin .admin .reseller_admin',
'user_test_tester = testing .admin',
'user_test2_tester2 = testing2 .admin',
'user_test_tester3 = testing3'
]
(content.split("\n") & expected_lines).should =~ expected_lines
end
end
describe 'when supplying bad values for parameters' do
[:account_autocreate, :allow_account_management].each do |param|
it "should fail when #{param} is not passed a boolean" do
params[param] = 'false'
expect do
subject
end.should raise_error(Puppet::Error, /is not a boolean/)
end
end
end
end
describe 'when using swauth' do
let :params do
{:auth_type => 'swauth' }
{:proxy_local_net_ip => '127.0.0.1',
:auth_type => 'swauth' }
end
describe 'with defaults' do
let :config_file do
File.join(fixture_dir, 'swauth_default_proxy_server')
end
it { should contain_package('python-swauth').with(
{:ensure => 'present',
:before => 'Package[swift-proxy]'
}
)}
it { should contain_file('/etc/swift/proxy-server.conf').with(
{:content => File.read(config_file)}
)}
it 'should create a config file with default swauth config' do
content = param_value(
subject,
'file', '/etc/swift/proxy-server.conf',
'content'
)
expected_lines =
[
'[filter:swauth]',
'use = egg:swauth#swauth',
'default_swift_cluster = local#127.0.0.1',
'super_admin_key = swauthkey'
]
(content.split("\n") & expected_lines).should =~ expected_lines
end
end
describe 'with parameter overrides' do
let :params do
{:auth_type => 'swauth',
{:proxy_local_net_ip => '127.0.0.1',
:auth_type => 'swauth',
:swauth_endpoint => '10.0.0.1',
:swauth_super_admin_key => 'key'
}
end
let :config_file do
File.join(fixture_dir, 'swauth_overrides_proxy_server')
it 'should create a config file with default swauth config' do
content = param_value(
subject,
'file', '/etc/swift/proxy-server.conf',
'content'
)
expected_lines =
[
'[filter:swauth]',
'use = egg:swauth#swauth',
'default_swift_cluster = local#10.0.0.1',
'super_admin_key = key'
]
(content.split("\n") & expected_lines).should =~ expected_lines
end
it { should contain_file('/etc/swift/proxy-server.conf').with(
{:content => File.read(config_file)}
)}
end
end
end
end

@ -1,10 +1,8 @@
# This file is managed by puppet. Do not edit
#
[DEFAULT]
#cert_file = /etc/swift/cert.crt
#key_file = /etc/swift/cert.key
bind_port = 8080
workers = 8
bind_port = <%= port %>
workers = <%= workers %>
user = swift
[pipeline:main]
@ -37,4 +35,4 @@ use = egg:swift#healthcheck
[filter:cache]
use = egg:swift#memcache
# multi-proxy config not supported
memcache_servers = <%= proxy_local_net_ip %>:<%= proxy_port %>
memcache_servers = <%= cache_servers.to_a.join(',') %>